Browse Source

pms 保养计划 单累计属性 排除 累计注气量

zhangcl 12 hours ago
parent
commit
cc31a76183

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

@@ -267,9 +267,24 @@ public class IotMaintenanceBomController {
             });
         }
         // 查询正常的累计运行时长 公里数 时需要 携带 设备分类id 方便快速定位 累计属性值
-
+        // 相同设备如果都包含 totalRuntime totalMileage 则返回1个对象
         Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(convertListByFlatMap(BOMs,
                 bom -> Stream.of(bom.getDeviceId())), new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
+        // 没有产生运行记录的单累计属性 返回前端 0 deviceAttrsPair单属性属性集合
+        if (CollUtil.isNotEmpty(deviceAttrsPair)) {
+            deviceAttrsPair.forEach((deviceId, attrs) -> {
+                if (!deviceRunLogMap.containsKey(deviceId)) {
+                    // 当前设备没有产生运行记录数据
+                    attrs.forEach(attr -> {
+                        IotDeviceRunLogRespVO runLog = new IotDeviceRunLogRespVO();
+                        runLog.setTotalRunTime(BigDecimal.ZERO);
+                        runLog.setTotalMileage(BigDecimal.ZERO);
+                        runLog.setPointName(attr.getName());
+                        deviceRunLogMap.put(deviceId, runLog);
+                    });
+                }
+            });
+        }
         // 2. 转换成 VO
         return BeanUtils.toBean(BOMs, IotMaintenanceBomRespVO.class, bomVO -> {
             // 设置设备相关信息
@@ -302,7 +317,7 @@ public class IotMaintenanceBomController {
                     bomVO.setTempTotalMileage(tempTotalRunDataPair.get(uniqueKey));
                 }
             }
-            // 如果多累计时长 公里数属性 没有运行记录填报数据,只返回 属性名称集合
+            // 如果多累计时长 公里数属性 没有运行记录填报数据,且运行记录模板中 属性标识符没有配置 累计时长 累计公里数 只返回 属性名称集合
             if (deviceRunLogPair.containsKey(bomVO.getDeviceId())) {
                 // 设置每个保养项对应的 多个累计类型属性集合 包含属性的运行记录值
                 // 区分开 时间 里程 的累计属性列表 便于前端选择
@@ -321,7 +336,7 @@ public class IotMaintenanceBomController {
                 // 如果多累计属性没有运行记录填报值 则直接返回 名称 可以设置 累计运行时长 或 公里数 为 0
                 List<IotDeviceRunLogRespVO> mileageRunLogs = new ArrayList<>();
                 List<IotDeviceRunLogRespVO> timeRunLogs = new ArrayList<>();
-                if (deviceMultiAttrsPair.containsKey(bomVO.getDeviceId())) {
+                if (deviceMultiAttrsPair.containsKey(bomVO.getDeviceId()) && !deviceAttrsPair.containsKey(bomVO.getDeviceId())) {
                     List<String> attrNames = deviceMultiAttrsPair.get(bomVO.getDeviceId());
                     attrNames.forEach(attrName -> {
                         IotDeviceRunLogRespVO tempRunLog = new IotDeviceRunLogRespVO();