Browse Source

设备成套相关逻辑

lipenghui 1 day ago
parent
commit
bbcb3beb1a

+ 12 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/IotDeviceController.java

@@ -41,6 +41,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
 import cn.iocoder.yudao.module.system.service.dept.DeptService;
 import cn.iocoder.yudao.module.system.service.dict.DictDataService;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.Parameters;
@@ -56,6 +57,7 @@ import javax.annotation.security.PermitAll;
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import java.io.IOException;
+import java.io.Serializable;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
@@ -654,4 +656,14 @@ public class IotDeviceController {
         List<DeviceImportExcelVO> list = ExcelUtils.read(file, DeviceImportExcelVO.class);
         iotDeviceService.importDevice(list);
     }
+
+    @Operation(summary = "根据部门id获取设备列表")
+    @GetMapping("/dept/{id}")
+    public CommonResult<List<ImmutableMap<String, ? extends Serializable>>> findDeviceByDept(@PathVariable Long id) {
+        IotDevicePageReqVO iotDevicePageReqVO = new IotDevicePageReqVO();
+        iotDevicePageReqVO.setDeptId(id);
+        List<IotDeviceDO> allDevices = iotDeviceService.getAllDevices(iotDevicePageReqVO);
+        List<ImmutableMap<String, ? extends Serializable>> collect = allDevices.stream().map(e -> ImmutableMap.of("id", e.getId(), "deviceName", e.getDeviceName(), "deviceCode", e.getDeviceCode())).collect(Collectors.toList());
+        return success(collect);
+    }
 }

+ 22 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/devicegroup/IotDeviceGroupController.java

@@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.pms.dal.dataobject.devicegroup.IotDeviceGroupDeta
 import cn.iocoder.yudao.module.pms.dal.dataobject.inspect.IotInspectOrderDetailDO;
 import cn.iocoder.yudao.module.pms.service.devicegroup.IotDeviceGroupDetailService;
 import cn.iocoder.yudao.module.pms.service.devicegroup.IotDeviceGroupService;
+import cn.iocoder.yudao.module.system.api.dept.DeptApi;
+import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.validation.annotation.Validated;
@@ -47,6 +49,8 @@ public class IotDeviceGroupController {
     private IotDeviceGroupService iotDeviceGroupService;
     @Autowired
     private IotDeviceGroupDetailService iotDeviceGroupDetailService;
+    @Autowired
+    private DeptApi deptApi;
 
     @PostMapping("/create")
     @Operation(summary = "创建PMS成套")
@@ -92,6 +96,10 @@ public class IotDeviceGroupController {
         List<IotDeviceGroupRespVO> collect = pageResult.getList().stream().map(e -> {
             IotDeviceGroupRespVO bean = BeanUtil.toBean(e, IotDeviceGroupRespVO.class);
             List<IotDeviceGroupDetailDO> iotDeviceGroupDetailListByGroupId = iotDeviceGroupDetailService.getIotDeviceGroupDetailListByGroupId(e.getId());
+            DeptRespDTO dept = deptApi.getDept(e.getDeptId());
+            if (dept != null) {
+                bean.setDeptName(dept.getName());
+            }
             bean.setDetails(iotDeviceGroupDetailListByGroupId);
             return bean;
         }).collect(Collectors.toList());
@@ -116,8 +124,20 @@ public class IotDeviceGroupController {
     @Operation(summary = "获得某设备的成套信息")
     @Parameter(name = "id", description = "编号", required = true, example = "1024")
     @PreAuthorize("@ss.hasPermission('rq:iot-device-group:query')")
-    public CommonResult<PageResult<IotDeviceGroupDetailDO>> getDeviceGroup(@Valid IotDeviceGroupDetailPageReqVO reqVO) {
+    public CommonResult<PageResult<IotDeviceGroupDetailRespVO>> getDeviceGroup(@Valid IotDeviceGroupDetailPageReqVO reqVO) {
         PageResult<IotDeviceGroupDetailDO> deviceGroupList = iotDeviceGroupService.getDeviceGroupList(reqVO);
-        return success(deviceGroupList);
+        if (Objects.isNull(deviceGroupList.getList())){
+            return success(new PageResult<>(new ArrayList<>(),0L));
+        }
+        List<IotDeviceGroupDetailRespVO> collect = deviceGroupList.getList().stream().map(e -> {
+            IotDeviceGroupDetailRespVO bean = BeanUtil.toBean(e, IotDeviceGroupDetailRespVO.class);
+            IotDeviceGroupDO iotDeviceGroup = iotDeviceGroupService.getIotDeviceGroup(e.getGroupId());
+            if (iotDeviceGroup != null) {
+                bean.setGroupName(iotDeviceGroup.getName());
+            }
+            return bean;
+        }).collect(Collectors.toList());
+        return success(new PageResult<>(collect, deviceGroupList.getTotal()));
+//        return success(deviceGroupList);
     }
 }

+ 2 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/devicegroup/IotDeviceGroupDetailRespVO.java

@@ -48,4 +48,6 @@ public class IotDeviceGroupDetailRespVO {
     @ExcelProperty("创建时间")
     private LocalDateTime createTime;
 
+    private String groupName;
+
 }

+ 2 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/devicegroup/IotDeviceGroupRespVO.java

@@ -38,5 +38,7 @@ public class IotDeviceGroupRespVO {
     @ExcelProperty("创建时间")
     private LocalDateTime createTime;
 
+    private String deptName;
+
     private List<IotDeviceGroupDetailDO> details;
 }

+ 1 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/devicegroup/IotDeviceGroupDetailMapper.java

@@ -27,7 +27,7 @@ public interface IotDeviceGroupDetailMapper extends BaseMapperX<IotDeviceGroupDe
                 .eqIfPresent(IotDeviceGroupDetailDO::getRemark, reqVO.getRemark())
                 .eqIfPresent(IotDeviceGroupDetailDO::getDeptId, reqVO.getDeptId())
                 .betweenIfPresent(IotDeviceGroupDetailDO::getCreateTime, reqVO.getCreateTime())
-                .orderByDesc(IotDeviceGroupDetailDO::getId));
+                .orderByDesc(IotDeviceGroupDetailDO::getIfMaster));
     }
 
 }

+ 8 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/devicegroup/IotDeviceGroupServiceImpl.java

@@ -1,6 +1,7 @@
 package cn.iocoder.yudao.module.pms.service.devicegroup;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
 import cn.iocoder.yudao.framework.common.exception.ErrorCode;
 import cn.iocoder.yudao.module.pms.controller.admin.devicegroup.IotDeviceGroupDetailPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.devicegroup.IotDeviceGroupDetailSaveReqVO;
@@ -114,11 +115,16 @@ public class IotDeviceGroupServiceImpl implements IotDeviceGroupService {
     public PageResult<IotDeviceGroupDetailDO> getDeviceGroupList(IotDeviceGroupDetailPageReqVO reqVO) {
         IotDeviceDO iotDevice = iotDeviceService.getIotDevice(reqVO.getDeviceId());
         List<IotDeviceGroupDetailDO> deviceCodes = iotDeviceGroupDetailMapper.selectList("device_code", iotDevice.getDeviceCode());
+        if (CollUtil.isEmpty(deviceCodes)) {
+            return new PageResult<>();
+        }
         IotDeviceGroupDetailDO iotDeviceGroupDetailDO = deviceCodes.get(0);
         Long groupId = iotDeviceGroupDetailDO.getGroupId();
 //        IotDeviceGroupDetailPageReqVO pageReqVO = new IotDeviceGroupDetailPageReqVO();
-        reqVO.setGroupId(groupId);
-        PageResult<IotDeviceGroupDetailDO> iotDeviceGroupDetailDOPageResult = iotDeviceGroupDetailMapper.selectPage(reqVO);
+        IotDeviceGroupDetailPageReqVO pageReqVO = new IotDeviceGroupDetailPageReqVO();
+        pageReqVO.setGroupId(groupId);
+        pageReqVO.setDeviceCode(reqVO.getDeviceCode());
+        PageResult<IotDeviceGroupDetailDO> iotDeviceGroupDetailDOPageResult = iotDeviceGroupDetailMapper.selectPage(pageReqVO);
         return iotDeviceGroupDetailDOPageResult;
     }