Эх сурвалжийг харах

pms 保养计划 多种累计属性值功能优化

zhangcl 3 өдөр өмнө
parent
commit
42b855339c

+ 98 - 48
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotDeviceServiceImpl.java

@@ -679,15 +679,17 @@ public class IotDeviceServiceImpl implements IotDeviceService {
         Map<Long, Long> deviceCategoryPair = new HashMap<>();
         // k设备id   v设备分类包含的模板中与累计运行时长、累计运行公里数相关的属性集合
         Map<Long, List<IotModelTemplateAttrsDO>> deviceAttrsPair = new HashMap<>();
+        // k设备id   v设备分类包含的模板中与累计运行时长、累计运行公里数相关的属性(多种累计属性)集合
+        Map<Long, List<IotModelTemplateAttrsDO>> deviceMultiAttrsPair = new HashMap<>();
         // 查询所有 设备boms节点的所有上级节点名称 拼接出 全路径 的bom节点
         List<Long> bomNodeIds = new ArrayList<>();
         // key设备id  value设备对应的运行记录模板中涉及多个累计时长累计公里数的属性集合
         Map<Long, List<IotDeviceRunLogRespVO>> deviceRunLogPair = new HashMap<>();
         // 设备所属部门id集合
         Set<Long> deptIds = new HashSet<>();
+        // 设备运行模板中正常的 累计时长 累计里程 集合
+        Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = new HashMap<>();
         if (CollUtil.isNotEmpty(devices)) {
-            // 设备运行模板中正常的 累计时长 累计里程 集合
-            Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = new HashMap<>();
             devices.forEach(device -> {
                 deviceIds.add(device.getId());
                 bomNodeIds.add(Long.valueOf(device.getBomNodeId()));
@@ -701,12 +703,14 @@ public class IotDeviceServiceImpl implements IotDeviceService {
 
             if (CollUtil.isNotEmpty(deviceCategoryIds)) {
                 // 查询设备分类id集合对应的运行记录模板中涉及 累计运行时长、累计运行公里数 的属性
-                IotModelTemplateAttrsPageReqVO reqVO = new IotModelTemplateAttrsPageReqVO();
-                reqVO.setMultipleFlag("Y");
-                reqVO.setDeviceCategoryIds(new ArrayList<>(deviceCategoryIds));
-                reqVO.setIsSum(1);  // 累计属性标识
-                List<IotModelTemplateAttrsDO> accumulatedAttrs = iotModelTemplateAttrsService.getIotDeviceTemplateAttrs(reqVO);
-                // k设备分类id   v设备分类包含的模板中 多个 累计运行时长 累计运行公里数相关的属性集合
+                IotModelTemplateAttrsPageReqVO singleAttrreqVO = new IotModelTemplateAttrsPageReqVO();
+                List<String> codes = new ArrayList<>(Arrays.asList("sc", "gls"));
+                singleAttrreqVO.setCodes(codes);
+                singleAttrreqVO.setDeviceCategoryIds(new ArrayList<>(deviceCategoryIds));
+                singleAttrreqVO.setIsSum(1);  // 累计属性标识
+                // 查询标识的累计类型属性 累计运行时长 累计运行公里数 正常的累计属性
+                List<IotModelTemplateAttrsDO> accumulatedAttrs = iotModelTemplateAttrsService.getIotDeviceTemplateAttrs(singleAttrreqVO);
+                // k设备分类id   v设备分类包含的模板中与累计运行时长 累计运行公里数相关的属性集合
                 Map<Long, List<IotModelTemplateAttrsDO>> accumulatedAttrPair = new HashMap<>();
                 if (CollUtil.isNotEmpty(accumulatedAttrs)) {
                     accumulatedAttrs.forEach(attr -> {
@@ -719,17 +723,50 @@ public class IotDeviceServiceImpl implements IotDeviceService {
                             tempAttrs.add(attr);
                             accumulatedAttrPair.put(attr.getDeviceCategoryId(), tempAttrs);
                         }
-                        multipleAttrNames.add(attr.getName());
                     });
                 }
                 if (CollUtil.isNotEmpty(accumulatedAttrPair)) {
                     accumulatedAttrPair.forEach((k,v) -> {
+                        // k设备分类id   v设备分类包含的模板中与累计运行时长 累计运行公里数相关的属性集合
+                        deviceCategoryPair.forEach((ik, iv) -> {
+                            // ik设备id   iv设备分类id
+                            if (iv.equals(k)) {
+                                deviceAttrsPair.put(ik, v);
+                            }
+                        });
+                    });
+                }
+
+                // 查询设备分类id集合对应的运行记录模板中涉及 累计运行时长、累计运行公里数 的属性
+                IotModelTemplateAttrsPageReqVO reqVO = new IotModelTemplateAttrsPageReqVO();
+                reqVO.setMultipleFlag("Y");
+                reqVO.setDeviceCategoryIds(new ArrayList<>(deviceCategoryIds));
+                reqVO.setIsSum(1);  // 累计属性标识
+                List<IotModelTemplateAttrsDO> multiAccumulatedAttrs = iotModelTemplateAttrsService.getIotDeviceTemplateAttrs(reqVO);
+                // k设备分类id   v设备分类包含的模板中 多个 累计运行时长 累计运行公里数相关的属性集合
+                Map<Long, List<IotModelTemplateAttrsDO>> multiAccumulatedAttrPair = new HashMap<>();
+                if (CollUtil.isNotEmpty(multiAccumulatedAttrs)) {
+                    multiAccumulatedAttrs.forEach(attr -> {
+                        if (multiAccumulatedAttrPair.containsKey(attr.getDeviceCategoryId())) {
+                            List<IotModelTemplateAttrsDO> tempAttrs = multiAccumulatedAttrPair.get(attr.getDeviceCategoryId());
+                            tempAttrs.add(attr);
+                            multiAccumulatedAttrPair.put(attr.getDeviceCategoryId(), tempAttrs);
+                        } else {
+                            List<IotModelTemplateAttrsDO> tempAttrs = new ArrayList<>();
+                            tempAttrs.add(attr);
+                            multiAccumulatedAttrPair.put(attr.getDeviceCategoryId(), tempAttrs);
+                        }
+                        multipleAttrNames.add(attr.getName());
+                    });
+                }
+                if (CollUtil.isNotEmpty(multiAccumulatedAttrPair)) {
+                    multiAccumulatedAttrPair.forEach((k,v) -> {
                         // k设备分类id   v设备分类包含的模板中 多个累计运行时长 累计运行公里数 相关的属性集合
                         deviceCategoryPair.forEach((ik, iv) -> {
                             // ik设备id   iv设备分类id
                             if (iv.equals(k)) {
                                 // key设备id  value设备分类包含的模板中 多个累计运行时长 累计运行公里数 相关的属性集合
-                                deviceAttrsPair.put(ik, v);
+                                deviceMultiAttrsPair.put(ik, v);
                                 multipleAttrDeviceIds.add(ik);
                             }
                         });
@@ -737,6 +774,22 @@ public class IotDeviceServiceImpl implements IotDeviceService {
                 }
                 // 根据设备id集合查询正常的 累计时长 累计公里数
                 deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(new ArrayList<>(deviceIds), new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
+                // 没有产生运行记录的单累计属性 返回前端 0 deviceAttrsPair单属性属性集合
+                Map<Long, IotDeviceRunLogRespVO> finalDeviceRunLogMap = deviceRunLogMap;
+                if (CollUtil.isNotEmpty(deviceAttrsPair)) {
+                    deviceAttrsPair.forEach((deviceId, attrs) -> {
+                        if (!finalDeviceRunLogMap.containsKey(deviceId)) {
+                            // 当前设备没有产生运行记录数据
+                            attrs.forEach(attr -> {
+                                IotDeviceRunLogRespVO runLog = new IotDeviceRunLogRespVO();
+                                runLog.setTotalRunTime(BigDecimal.ZERO);
+                                runLog.setTotalMileage(BigDecimal.ZERO);
+                                runLog.setPointName(attr.getName());
+                                finalDeviceRunLogMap.put(deviceId, runLog);
+                            });
+                        }
+                    });
+                }
 
                 // 根据设备id 运行记录模板属性名称 查询对应的 累计运行时长 累计运行公里数
                 if (CollUtil.isNotEmpty(multipleAttrDeviceIds) && CollUtil.isNotEmpty(multipleAttrNames)) {
@@ -769,7 +822,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
                         });
                     }
                     // todo 如果还没有记录运行记录数据 也要显示出来
-                    deviceAttrsPair.forEach((deviceId, templateAttrs) -> {
+                    deviceMultiAttrsPair.forEach((deviceId, templateAttrs) -> {
                         // 循环每个设备对应的多累计属性集合 找到没有生成运行记录的属性 使用空对象补全
                         List<String> loggedAttrNames;
                         if (loggedAttrNamePair.containsKey(deviceId)) {
@@ -801,44 +854,41 @@ public class IotDeviceServiceImpl implements IotDeviceService {
                     });
 
                 }
-            }
-
-            // 查询 bomNodeIds 集合中每个bom节点的所有上级节点
-            Map<Long, String> bomFullPaths = iotDeviceBomService.buildBomFullPaths(bomNodeIds);
-            Map<Long, IotDeviceRunLogRespVO> finalDeviceRunLogMap = deviceRunLogMap;
-            devices.forEach(device -> {
-                String uniqueKey = StrUtil.join("-", device.getId(), device.getBomNodeId());
-                if (bomMaterialsPair.containsKey(uniqueKey)) {
-                    device.setDeviceBomMaterials(bomMaterialsPair.get(uniqueKey));
-                }
-                // 保养项全路径名
-                if (bomFullPaths.containsKey(Long.valueOf(device.getBomNodeId()))) {
-                    if (StrUtil.isNotBlank(bomFullPaths.get(Long.valueOf(device.getBomNodeId())))) {
-                        device.setName(bomFullPaths.get(Long.valueOf(device.getBomNodeId())));
+                // 查询 bomNodeIds 集合中每个bom节点的所有上级节点
+                Map<Long, String> bomFullPaths = iotDeviceBomService.buildBomFullPaths(bomNodeIds);
+                devices.forEach(device -> {
+                    String uniqueKey = StrUtil.join("-", device.getId(), device.getBomNodeId());
+                    if (bomMaterialsPair.containsKey(uniqueKey)) {
+                        device.setDeviceBomMaterials(bomMaterialsPair.get(uniqueKey));
                     }
-                }
-                if (deviceRunLogPair.containsKey(device.getId())) {
-                    // 区分开 时间 里程 的累计属性列表 便于前端选择
-                    List<IotDeviceRunLogRespVO> mileageRunLogs = new ArrayList<>();
-                    List<IotDeviceRunLogRespVO> timeRunLogs = deviceRunLogPair.get(device.getId());
-                    timeRunLogs.forEach(log -> {
-                        log.setType(1);
-                        IotDeviceRunLogRespVO tempRunLog = new IotDeviceRunLogRespVO();
-                        BeanUtils.copyProperties(log, tempRunLog);
-                        tempRunLog.setType(2);
-                        mileageRunLogs.add(tempRunLog);
-                    });
-                    device.setTimeAccumulatedAttrs(timeRunLogs);
-                    device.setMileageAccumulatedAttrs(mileageRunLogs);
-                }
-                // 这里只赋值正常的 累计时长 累计公里数 多个累计属性的需要在保养配置中选择
-                if (CollUtil.isNotEmpty(finalDeviceRunLogMap) && finalDeviceRunLogMap.containsKey(device.getId())) {
-                    IotDeviceRunLogRespVO tempRunLog = finalDeviceRunLogMap.get(device.getId());
-                    device.setTotalRunTime(tempRunLog.getTotalRunTime());
-                    device.setTotalMileage(tempRunLog.getTotalMileage());
-                }
-            });
-
+                    // 保养项全路径名
+                    if (bomFullPaths.containsKey(Long.valueOf(device.getBomNodeId()))) {
+                        if (StrUtil.isNotBlank(bomFullPaths.get(Long.valueOf(device.getBomNodeId())))) {
+                            device.setName(bomFullPaths.get(Long.valueOf(device.getBomNodeId())));
+                        }
+                    }
+                    if (deviceRunLogPair.containsKey(device.getId())) {
+                        // 区分开 时间 里程 的累计属性列表 便于前端选择
+                        List<IotDeviceRunLogRespVO> mileageRunLogs = new ArrayList<>();
+                        List<IotDeviceRunLogRespVO> timeRunLogs = deviceRunLogPair.get(device.getId());
+                        timeRunLogs.forEach(log -> {
+                            log.setType(1);
+                            IotDeviceRunLogRespVO tempRunLog = new IotDeviceRunLogRespVO();
+                            BeanUtils.copyProperties(log, tempRunLog);
+                            tempRunLog.setType(2);
+                            mileageRunLogs.add(tempRunLog);
+                        });
+                        device.setTimeAccumulatedAttrs(timeRunLogs);
+                        device.setMileageAccumulatedAttrs(mileageRunLogs);
+                    }
+                    // 这里只赋值正常的 累计时长 累计公里数 多个累计属性的需要在保养配置中选择
+                    if (CollUtil.isNotEmpty(finalDeviceRunLogMap) && finalDeviceRunLogMap.containsKey(device.getId())) {
+                        IotDeviceRunLogRespVO tempRunLog = finalDeviceRunLogMap.get(device.getId());
+                        device.setTotalRunTime(tempRunLog.getTotalRunTime());
+                        device.setTotalMileage(tempRunLog.getTotalMileage());
+                    }
+                });
+            }
         }
         return devices;
     }