das接口新增
This commit is contained in:
parent
c24e340de9
commit
8340d356c3
@ -21,4 +21,6 @@ public interface SysOrgMapper extends BaseMapper<SysOrg> {
|
||||
List<SysOrg> queryAllOrgTree(@Param("id") Long id);
|
||||
|
||||
Long queryOrgUserCount(@Param("id") Long id);
|
||||
|
||||
Long queryOrgIdByName(@Param("name")String name);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import com.das.common.constant.SysAuthorityIds;
|
||||
import com.das.common.exceptions.ServiceException;
|
||||
import com.das.common.result.R;
|
||||
import com.das.common.utils.PageDataInfo;
|
||||
import com.das.common.utils.StringUtils;
|
||||
import com.das.modules.auth.entity.SysOrg;
|
||||
import com.das.modules.equipment.domain.dto.SysEquipmentDto;
|
||||
import com.das.modules.equipment.domain.dto.SysIotModelDto;
|
||||
@ -16,11 +17,10 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -145,4 +145,11 @@ public class EquipmentController {
|
||||
sysEquipmentService.exportSysEquipment(sysEquipmentDto,request, response);
|
||||
|
||||
}
|
||||
|
||||
/** 设备导出 */
|
||||
@PostMapping("/import")
|
||||
public R<Void> importSysIotModel(@RequestParam("file") MultipartFile file) throws IOException {
|
||||
sysEquipmentService.importSysEquipment(file);
|
||||
return R.success();
|
||||
}
|
||||
}
|
||||
|
@ -23,4 +23,6 @@ public interface SysEquipmentMapper extends BaseMapper<SysEquipment> {
|
||||
List<SysEquipment> queryEquipmentTree(@Param("info")SysEquipmentDto sysEquipmentDto);
|
||||
|
||||
List<SysEquipmentExcel> queryInfoById (@Param("info") SysEquipmentDto sysEquipmentDto);
|
||||
|
||||
Long queryParentEquipmentIdByName(@Param("name")String name);
|
||||
}
|
||||
|
@ -18,4 +18,6 @@ public interface SysIotModelMapper extends BaseMapper<SysIotModel> {
|
||||
|
||||
List<SysIotModelServiceExcel> queryServiceByModelId(Long id);
|
||||
|
||||
Long queryIotModelIdByName(String name);
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,9 @@ import com.das.modules.equipment.domain.vo.SysIotModelServiceVo;
|
||||
import com.das.modules.equipment.domain.vo.SysIotModelVo;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public interface SysEquipmentService {
|
||||
@ -30,4 +32,6 @@ public interface SysEquipmentService {
|
||||
|
||||
void exportSysEquipment(SysEquipmentDto sysEquipmentDto, HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
void importSysEquipment(MultipartFile file) throws IOException;
|
||||
|
||||
}
|
||||
|
@ -1,14 +1,15 @@
|
||||
package com.das.modules.equipment.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.ExcelReader;
|
||||
import com.alibaba.excel.read.metadata.ReadSheet;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.das.common.config.SessionUtil;
|
||||
import com.das.common.exceptions.ServiceException;
|
||||
import com.das.common.utils.BeanCopyUtils;
|
||||
import com.das.common.utils.ExcelUtil;
|
||||
import com.das.common.utils.PageDataInfo;
|
||||
import com.das.common.utils.PageQuery;
|
||||
import com.das.common.utils.*;
|
||||
import com.das.modules.auth.domain.vo.SysUserVo;
|
||||
import com.das.modules.auth.entity.SysOrg;
|
||||
import com.das.modules.auth.mapper.SysOrgMapper;
|
||||
@ -23,6 +24,8 @@ import com.das.modules.equipment.domain.vo.SysIotModelServiceVo;
|
||||
import com.das.modules.equipment.domain.vo.SysIotModelVo;
|
||||
import com.das.modules.equipment.entity.SysEquipment;
|
||||
import com.das.modules.equipment.entity.SysIotModel;
|
||||
import com.das.modules.equipment.entity.SysIotModelField;
|
||||
import com.das.modules.equipment.listener.ExcelListener;
|
||||
import com.das.modules.equipment.mapper.SysEquipmentMapper;
|
||||
import com.das.modules.equipment.mapper.SysIotModelMapper;
|
||||
import com.das.modules.equipment.service.SysEquipmentService;
|
||||
@ -31,7 +34,10 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@ -45,6 +51,10 @@ public class SysEquipmentServiceImpl implements SysEquipmentService {
|
||||
|
||||
@Autowired
|
||||
private SysOrgMapper sysOrgMapper;
|
||||
|
||||
@Autowired
|
||||
private SysIotModelMapper sysIotModelMapper;
|
||||
|
||||
@Override
|
||||
public SysEquipmentVo creatSysEquipment(SysEquipmentDto sysEquipmentDto) {
|
||||
SysEquipment sysEquipment = new SysEquipment();
|
||||
@ -131,4 +141,43 @@ public class SysEquipmentServiceImpl implements SysEquipmentService {
|
||||
sheetInfoBeanList.add(sheetInfoBean);
|
||||
ExcelUtil.exportMoreSheet(fileName,request,response,sheetInfoBeanList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void importSysEquipment(MultipartFile file) throws IOException {
|
||||
//输入流
|
||||
InputStream inputStream = file.getInputStream();
|
||||
//监视器
|
||||
ExcelListener listener = new ExcelListener();
|
||||
ExcelReader excelReader = EasyExcel.read(inputStream, listener).build();
|
||||
// 第一个sheet读取物模型属性
|
||||
ReadSheet readSheet = EasyExcel.readSheet(0).head(SysEquipmentExcel.class).build();
|
||||
// 开始读取第一个sheet
|
||||
excelReader.read(readSheet);
|
||||
//excel sheet0 信息
|
||||
List<Object> fieldList = listener.getDatas();
|
||||
//List<object> 转 List<实体类>
|
||||
List<SysEquipment> sysEquipmentList = new ArrayList<>();
|
||||
//List object for 转换 实体类
|
||||
for (Object objects : fieldList) {
|
||||
SysEquipmentExcel dto = (SysEquipmentExcel) objects;
|
||||
SysEquipment field = new SysEquipment();
|
||||
BeanUtil.copyProperties(dto,field);
|
||||
// 根据名称获取物模型id
|
||||
Long iotModelId = sysIotModelMapper.queryIotModelIdByName(dto.getIotModelName());
|
||||
Long parentEquipmentId = sysEquipmentMapper.queryParentEquipmentIdByName(dto.getParentEquipmentName());
|
||||
Long orgId = sysOrgMapper.queryOrgIdByName(dto.getOrgName());
|
||||
field.setIotModelId(iotModelId);
|
||||
field.setParentEquipmentId(parentEquipmentId);
|
||||
field.setId(SequenceUtils.generateId());
|
||||
field.setOrgId(orgId);
|
||||
field.setCreatedTime(new Date());
|
||||
field.setUpdatedTime(new Date());
|
||||
field.setRevision(1);
|
||||
// field.setCreatedBy(StpUtil.getLoginIdAsString());
|
||||
// field.setUpdatedBy(StpUtil.getLoginIdAsString());
|
||||
field.setCreatedBy("测试人员");
|
||||
field.setUpdatedBy("测试人员");
|
||||
sysEquipmentList.add(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@
|
||||
|
||||
|
||||
<select id="queryEquipmentTree" resultMap="SysEquipmentMap">
|
||||
select t.* from sys_equipment t WHERE t.org_id = #{info.id} and t.object_type in (10001,10002)
|
||||
select t.* from sys_equipment t WHERE t.org_id = #{info.id} and t.object_type in (10001,10002) and t.parent_equipment_id = 0
|
||||
<if test="info.parentEquipmentId != null and info.parentEquipmentId != ''">
|
||||
and t.parent_equipment_id = #{info.parentEquipmentId}
|
||||
</if>
|
||||
@ -80,5 +80,9 @@
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="queryParentEquipmentIdByName" resultType="java.lang.Long">
|
||||
select id from sys_equipment where name = #{name}
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
@ -28,4 +28,8 @@
|
||||
select sims.*,sim.iot_model_name as iotModelName from sys_iot_model_service sims left join sys_iot_model sim on sims.iot_model_id = sim.id
|
||||
where sims.iot_model_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="queryIotModelIdByName" resultType="java.lang.Long">
|
||||
select id from sys_iot_model where name = #{name}
|
||||
</select>
|
||||
</mapper>
|
||||
|
@ -51,4 +51,11 @@
|
||||
select count(1) from sys_user t where t.org_id=#{id}
|
||||
</select>
|
||||
|
||||
<select id="queryOrgIdByName" resultType="java.lang.Long">
|
||||
select t.id from sys_org t where t.name=#{name}
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
|
||||
</mapper>
|
||||
|
@ -854,3 +854,25 @@ POST请求接口
|
||||
#### 2.3.7 Excel导入设备清单
|
||||
|
||||
> /api/equipment/import
|
||||
|
||||
|
||||
#### 2.3.8 获取设备树
|
||||
|
||||
> /api/equipment/getEquipmentTree
|
||||
|
||||
|
||||
请求参数
|
||||
```json
|
||||
{
|
||||
"orgId":1
|
||||
}
|
||||
```
|
||||
|
||||
返回报文
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"success": true,
|
||||
"msg": "操作成功"
|
||||
}
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user