Ver código fonte

pms 保养计划 多种累计属性值功能优化 避免属性重复

zhangcl 3 dias atrás
pai
commit
3e0403be45

+ 31 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmaintenancebom/IotMaintenanceBomController.java

@@ -266,6 +266,35 @@ public class IotMaintenanceBomController {
                 }
             });
         }
+
+        // deviceRunLogPair 集合中如果存在未生成运行记录的 多累计属性 自动补全
+        Map<Long, List<IotDeviceRunLogRespVO>> copyDeviceRunLogPair = new HashMap<>(deviceRunLogPair);
+        deviceRunLogPair.forEach((deviceId, runLogs) -> {
+            List<IotDeviceRunLogRespVO> copyRunLogs = copyDeviceRunLogPair.get(deviceId);
+            List<IotDeviceRunLogRespVO> timeRunLogs = deviceRunLogPair.get(deviceId);
+            copyDeviceRunLogPair.get(deviceId);
+            if (deviceMultiAttrsPair.containsKey(deviceId)) {
+                List<String> multiAttrNames = deviceMultiAttrsPair.get(deviceId);
+                List<IotDeviceRunLogRespVO> unRunLogs = new ArrayList<>();
+                if (CollUtil.isNotEmpty(multiAttrNames) && (multiAttrNames.size() > copyRunLogs.size())) {
+                    multiAttrNames.forEach(attr -> {
+                        timeRunLogs.forEach(runLog -> {
+                            if (!attr.equals(runLog.getPointName())) {
+                                // 当前的多累计属性没有产生运行记录数据
+                                IotDeviceRunLogRespVO tempRunLog = new IotDeviceRunLogRespVO();
+                                tempRunLog.setPointName(attr);
+                                tempRunLog.setType(1);
+                                tempRunLog.setDeviceId(runLog.getDeviceId());
+                                unRunLogs.add(tempRunLog);
+                            }
+                        });
+                    });
+                    timeRunLogs.addAll(unRunLogs);
+                    copyDeviceRunLogPair.put(deviceId, timeRunLogs);
+                }
+            }
+        });
+
         // 查询正常的累计运行时长 公里数 时需要 携带 设备分类id 方便快速定位 累计属性值
         // 相同设备如果都包含 totalRuntime totalMileage 则返回1个对象
         Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(convertListByFlatMap(BOMs,
@@ -318,11 +347,11 @@ public class IotMaintenanceBomController {
                 }
             }
             // 如果多累计时长 公里数属性 没有运行记录填报数据,且运行记录模板中 属性标识符没有配置 累计时长 累计公里数 只返回 属性名称集合
-            if (deviceRunLogPair.containsKey(bomVO.getDeviceId())) {
+            if (copyDeviceRunLogPair.containsKey(bomVO.getDeviceId())) {
                 // 设置每个保养项对应的 多个累计类型属性集合 包含属性的运行记录值
                 // 区分开 时间 里程 的累计属性列表 便于前端选择
                 List<IotDeviceRunLogRespVO> mileageRunLogs = new ArrayList<>();
-                List<IotDeviceRunLogRespVO> timeRunLogs = deviceRunLogPair.get(bomVO.getDeviceId());
+                List<IotDeviceRunLogRespVO> timeRunLogs = copyDeviceRunLogPair.get(bomVO.getDeviceId());
                 timeRunLogs.forEach(log -> {
                     log.setType(1);
                     IotDeviceRunLogRespVO tempRunLog = new IotDeviceRunLogRespVO();