浏览代码

设备资料库初始化处理

lipenghui 1 月之前
父节点
当前提交
a016f3fd3e

+ 14 - 18
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotTreeServiceImpl.java

@@ -71,31 +71,27 @@ public class IotTreeServiceImpl implements IotTreeService {
         List<Long> idds = new ArrayList<>(ids);
         iotDevicePageReqVO.setDeptIds((idds));
         List<Long> deviceIds = iotDeviceMapper.selectList(iotDevicePageReqVO).stream().map(IotDeviceDO::getId).collect(Collectors.toList());
+
         devices.forEach(device -> {
             if (deviceIds.contains(device.getOriginId())) {
+                //更新设备资料库的名称
                 IotDeviceDO iotDevice = iotDeviceService.getIotDevice(device.getOriginId());
                 device.setName(iotDevice.getDeviceCode()+iotDevice.getDeviceName());
+
+                //设备的部门id
+                Long deptId = iotDevice.getDeptId();
+                IotTreeListReqVO iotTreeListReqVO = new IotTreeListReqVO();
+                iotTreeListReqVO.setOriginId(deptId);
+                iotTreeListReqVO.setType("dept");
+                List<IotTreeDO> iotTreeDOS1 = iotTreeMapper.selectList(iotTreeListReqVO);
+                if (CollUtil.isNotEmpty(iotTreeDOS1)&&iotTreeDOS1.size()==1) {
+                    if (!device.getParentId().equals(iotTreeDOS1.get(0).getId())) {
+                        device.setParentId(iotTreeDOS1.get(0).getId());
+                    }
+                }
                 iotTreeMapper.updateById(device);
             }
         });
-
-//        }
-//        List<IotTreeDO> rh = devices.stream().filter(e -> e.getName().contains("RH")).collect(Collectors.toList());
-//        rh.forEach(e -> {
-//            IotDeviceDO iotDevice = iotDeviceService.getIotDevice(e.getOriginId());
-//            if (Objects.nonNull(iotDevice)) {
-//                e.setDeviceCode(iotDevice.getDeviceCode());
-//                e.setName(iotDevice.getDeviceCode()+iotDevice.getDeviceName());
-//                iotTreeMapper.updateById(e);
-//            }
-//        });
-//        devices.forEach(device -> {
-//            Long deviceOriginId = device.getOriginId();
-//            IotDeviceDO iotDevice = iotDeviceService.getIotDevice(deviceOriginId);
-//            device.setDeviceCode(iotDevice.getDeviceCode());
-//            device.setName(device.getDeviceCode()+iotDevice.getDeviceName());
-//            iotTreeMapper.updateById(device);
-//        });
     }
 
     @Override