1
0

2 Revīzijas 6b64f2b224 ... 451ca01dd7

Autors SHA1 Ziņojums Datums
  zhangcl 451ca01dd7 Merge remote-tracking branch 'origin/master' 4 dienas atpakaļ
  zhangcl 7dbe1d0ee8 pms 查询设备累计运行公里/时长 逻辑优化 4 dienas atpakaļ
12 mainītis faili ar 166 papildinājumiem un 26 dzēšanām
  1. 5 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdevicerunlog/vo/IotDeviceRunLogRespVO.java
  2. 1 1
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmaintenancebom/IotMaintenanceBomController.java
  3. 12 2
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmainworkorderbom/IotMainWorkOrderBomController.java
  4. 7 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotdevicerunlog/IotDeviceRunLogMapper.java
  5. 15 2
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/mainworkorder/CreateMainWorkOrderJob.java
  6. 1 1
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotDeviceServiceImpl.java
  7. 4 4
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdevicerunlog/IotDeviceRunLogService.java
  8. 23 4
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdevicerunlog/IotDeviceRunLogServiceImpl.java
  9. 62 11
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotmainworkorder/IotMainWorkOrderServiceImpl.java
  10. 19 1
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotmainworkorderbom/IotMainWorkOrderBomServiceImpl.java
  11. 16 0
      yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotDeviceRunLogMapper.xml
  12. 1 0
      yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotMainWorkOrderMapper.xml

+ 5 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdevicerunlog/vo/IotDeviceRunLogRespVO.java

@@ -79,4 +79,9 @@ public class IotDeviceRunLogRespVO {
 
     private String fillContent;
 
+    /**
+     * 扩展字段
+     */
+    @Schema(description = "设备类别id")
+    private Long deviceCategoryId;
 }

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

@@ -269,7 +269,7 @@ public class IotMaintenanceBomController {
         // 查询正常的累计运行时长 公里数 时需要 携带 设备分类id 方便快速定位 累计属性值
 
         Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(convertListByFlatMap(BOMs,
-                bom -> Stream.of(bom.getDeviceId())), new ArrayList<>(deviceCategoryIds));
+                bom -> Stream.of(bom.getDeviceId())), new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
         // 2. 转换成 VO
         return BeanUtils.toBean(BOMs, IotMaintenanceBomRespVO.class, bomVO -> {
             // 设置设备相关信息

+ 12 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmainworkorderbom/IotMainWorkOrderBomController.java

@@ -154,13 +154,14 @@ public class IotMainWorkOrderBomController {
         // 组装bom关联的设备信息
         Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(convertListByFlatMap(BOMs,
                 bom -> Stream.of(bom.getDeviceId())));
-        Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(convertListByFlatMap(BOMs,
-                bom -> Stream.of(bom.getDeviceId())));
+
         // 查询保养工单明细中继承自保养计划明细 的 code累计运行时长属性名称 type累计运行公里数属性名称
         // 所有保养工单明细 已经 绑定了多个累计属性名称集合
         Set<String> pointNames = new HashSet<>();
         // 所有保养工单明细包含的设备id集合
         Set<Long> deviceIds = new HashSet<>();
+        Set<Long> deviceCategoryIds = new HashSet<>();
+        Map<Long, Long> deviceCategoryPair = new HashMap<>();
         // 保养j明细 保养项BOM节点id集合
         Set<Long> bomNodeIds = new HashSet<>();
         BOMs.forEach(bom -> {
@@ -176,7 +177,16 @@ public class IotMainWorkOrderBomController {
                 pointNames.add(bom.getType());
             }
             bomNodeIds.add(bom.getBomNodeId());
+            // 组装bom关联的设备信息
+            if (CollUtil.isNotEmpty(deviceMap)) {
+                deviceMap.forEach((k,v) -> {
+                    deviceCategoryIds.add(v.getAssetClass());
+                    deviceCategoryPair.put(k, v.getAssetClass());
+                });
+            }
         });
+        Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(convertListByFlatMap(BOMs,
+                bom -> Stream.of(bom.getDeviceId())), new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
         // 查询 运行记录模板中包含多个累计 时长 公里数 属性的集合
         List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
         // key(设备id-累计时长属性名称)    value多累计时长属性运行记录填报数值

+ 7 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotdevicerunlog/IotDeviceRunLogMapper.java

@@ -50,6 +50,13 @@ public interface IotDeviceRunLogMapper extends BaseMapperX<IotDeviceRunLogDO> {
     List<IotDeviceRunLogRespVO> distinctDevices(@Param("deviceIds") Collection<Long> deviceIds,
                                                 @Param("deviceCategoryIds") Collection<Long> deviceCategoryIds);
 
+    /**
+     * 查询运行记录模板中正常的累积类型属性
+     * @param deviceCategoryIds
+     * @return
+     */
+    List<IotDeviceRunLogRespVO> normalCumulativeAttrs(@Param("deviceCategoryIds") Collection<Long> deviceCategoryIds);
+
     /**
      * 查询指定设备 运行记录模板属性对应的累计时长 累计里程
      * @param deviceIds

+ 15 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/mainworkorder/CreateMainWorkOrderJob.java

@@ -105,6 +105,8 @@ public class CreateMainWorkOrderJob implements JobHandler {
         });
 
         List<Long> deviceIds = new ArrayList<>();
+        Set<Long> deviceCategoryIds = new HashSet<>();
+        Map<Long, Long> deviceCategoryPair = new HashMap<>();
         // 运行记录模板中 多种 累计时长 公里数 属性名称集合
         Set<String> boundedMultiAttrNames = new HashSet<>();
         mainBomList.forEach(bom -> {
@@ -121,6 +123,17 @@ public class CreateMainWorkOrderJob implements JobHandler {
         if (CollUtil.isEmpty(deviceIds)) {
             return "没有设备信息";
         }
+        if (CollUtil.isNotEmpty(mainBomList)) {
+            // 组装bom关联的设备信息
+            Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(convertListByFlatMap(mainBomList,
+                    bom -> Stream.of(bom.getDeviceId())));
+            if (CollUtil.isNotEmpty(deviceMap)) {
+                deviceMap.forEach((k,v) -> {
+                    deviceCategoryIds.add(v.getAssetClass());
+                    deviceCategoryPair.put(k, v.getAssetClass());
+                });
+            }
+        }
         // 查询所有设备的责任人
         IotDevicePersonPageReqVO devicePersonReqVO = new IotDevicePersonPageReqVO();
         devicePersonReqVO.setDeviceIds(deviceIds);
@@ -154,8 +167,8 @@ public class CreateMainWorkOrderJob implements JobHandler {
         }
 
         // 查询保养计划明细中所有设备的累计运行里程、累计运行时间
-        Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(convertListByFlatMap(mainBomList,
-                bom -> Stream.of(bom.getDeviceId())));
+        Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(convertListByFlatMap(mainBomList,
+                bom -> Stream.of(bom.getDeviceId())), new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
         List<IotMaintenanceBomDO> tobeMaintenanceBomList = new ArrayList<>();
         // 触发保养规则的设备id 集合
         List<Long> tobeMainDeviceIds = new ArrayList<>();

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

@@ -538,7 +538,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
                     });
                 }
                 // 根据设备id集合查询正常的 累计时长 累计公里数
-                deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(new ArrayList<>(deviceIds));
+                deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(new ArrayList<>(deviceIds), new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
 
                 // 根据设备id 运行记录模板属性名称 查询对应的 累计运行时长 累计运行公里数
                 if (CollUtil.isNotEmpty(multipleAttrDeviceIds) && CollUtil.isNotEmpty(multipleAttrNames)) {

+ 4 - 4
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdevicerunlog/IotDeviceRunLogService.java

@@ -61,7 +61,7 @@ public interface IotDeviceRunLogService {
      *
      * @return 设备运行数据记录
      */
-    List<IotDeviceRunLogRespVO> distinctDevices(List<Long> ids, List<Long> deviceCategoryIds);
+    List<IotDeviceRunLogRespVO> distinctDevices(List<Long> ids, List<Long> deviceCategoryIds, Map<Long, Long> deviceCategoryPair);
 
     /**
      * 查询指定设备 运行记录模板属性对应的累计时长 累计里程
@@ -77,7 +77,7 @@ public interface IotDeviceRunLogService {
      * @return 设备bom 关联 列表
      */
     default Map<Long, IotDeviceRunLogRespVO> getDeviceRunLogMap(List<Long> ids){
-        List<IotDeviceRunLogRespVO> list = distinctDevices(ids, null);
+        List<IotDeviceRunLogRespVO> list = distinctDevices(ids, null, null);
         // 删除集合中的NULL元素
         list.removeIf(deviceLog -> isAllFieldsNull(deviceLog));
         // 暂时将查询出的2条记录设置为1条
@@ -110,8 +110,8 @@ public interface IotDeviceRunLogService {
      * @param ids 设备id集合
      * @return 设备bom 关联 列表
      */
-    default Map<Long, IotDeviceRunLogRespVO> getDeviceRunLogMapAlone(List<Long> ids, List<Long> deviceCategoryIds){
-        List<IotDeviceRunLogRespVO> list = distinctDevices(ids, deviceCategoryIds);
+    default Map<Long, IotDeviceRunLogRespVO> getDeviceRunLogMapAlone(List<Long> ids, List<Long> deviceCategoryIds, Map<Long, Long> deviceCategoryPair){
+        List<IotDeviceRunLogRespVO> list = distinctDevices(ids, deviceCategoryIds, deviceCategoryPair);
         // 删除集合中的NULL元素
         list.removeIf(deviceLog -> isAllFieldsNull(deviceLog));
         // 暂时将查询出的2条记录设置为1条

+ 23 - 4
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdevicerunlog/IotDeviceRunLogServiceImpl.java

@@ -1,5 +1,6 @@
 package cn.iocoder.yudao.module.pms.service.iotdevicerunlog;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO;
@@ -12,8 +13,7 @@ import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
 
-import java.util.Collection;
-import java.util.List;
+import java.util.*;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_DEVICE_RUN_LOG_NOT_EXISTS;
@@ -73,8 +73,27 @@ public class IotDeviceRunLogServiceImpl implements IotDeviceRunLogService {
     }
 
     @Override
-    public List<IotDeviceRunLogRespVO> distinctDevices(List<Long> ids, List<Long> deviceCategoryIds) {
-        return iotDeviceRunLogMapper.distinctDevices(ids, deviceCategoryIds);
+    public List<IotDeviceRunLogRespVO> distinctDevices(List<Long> ids, List<Long> deviceCategoryIds, Map<Long, Long> deviceCategoryPair) {
+        // 先根据设备分类集合查询出所有正常累积的 公里数 时长
+        List<IotDeviceRunLogRespVO> normalCumulativeAttrs = iotDeviceRunLogMapper.normalCumulativeAttrs(deviceCategoryIds);
+        List<IotDeviceRunLogRespVO> tempDeviceRunLogs = iotDeviceRunLogMapper.distinctDevices(ids, deviceCategoryIds);
+        Set<Long> categoryIds = new HashSet<>();
+        if (CollUtil.isNotEmpty(normalCumulativeAttrs)) {
+            normalCumulativeAttrs.forEach(attr -> {
+                categoryIds.add(attr.getDeviceCategoryId());
+            });
+        }
+        List<IotDeviceRunLogRespVO> normalAttrDeviceRunLogs = new ArrayList<>();
+        if (CollUtil.isNotEmpty(tempDeviceRunLogs)) {
+            tempDeviceRunLogs.forEach(runLog -> {
+                if (deviceCategoryPair.containsKey(runLog.getDeviceId())) {
+                    if (categoryIds.contains(deviceCategoryPair.get(runLog.getDeviceId()))) {
+                        normalAttrDeviceRunLogs.add(runLog);
+                    }
+                }
+            });
+        }
+        return normalAttrDeviceRunLogs;
     }
 
     @Override

+ 62 - 11
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotmainworkorder/IotMainWorkOrderServiceImpl.java

@@ -162,6 +162,8 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
         Set<String> boundedMultiAttrNames = new HashSet<>();
         // 工单保养项中包含的设备id集合
         Set<Long> deviceIds = new HashSet<>();
+        Set<Long> deviceCategoryIds = new HashSet<>();
+        Map<Long, Long> deviceCategoryPair = new HashMap<>();
         if (CollUtil.isNotEmpty(workOrderBomS)) {
             // 查询所有保养计划 保养项 中已经绑定的 多个累计时长 公里数 属性名称值
             workOrderBomS.forEach(bom -> {
@@ -177,7 +179,17 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
                     deviceIds.add(bom.getDeviceId());
                 }
             });
+            // 组装bom关联的设备信息
+            Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(convertListByFlatMap(workOrderBomS,
+                    bom -> Stream.of(bom.getDeviceId())));
+            if (CollUtil.isNotEmpty(deviceMap)) {
+                deviceMap.forEach((k,v) -> {
+                    deviceCategoryIds.add(v.getAssetClass());
+                    deviceCategoryPair.put(k, v.getAssetClass());
+                });
+            }
         }
+
         // 查询 运行记录模板中包含多个累计 时长 公里数 属性的集合
         List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
         if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(boundedMultiAttrNames)) {
@@ -192,7 +204,8 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
             });
         }
         // 查询 运行记录模板中 正常的累计时长 公里数集合
-        Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(new ArrayList<>(deviceIds));
+        Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(new ArrayList<>(deviceIds),
+                new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
         // 以保养工单为维度 统计每个工单相关的保养项的最近保养距离 key保养工单id    value保养工单下每个保养项的的最小保养距离集合
         Map<Long, List<Map<String, Object>>> orderDistancePair = new HashMap<>();
         // key保养工单id  value设备保养工单明细下所有保养规则数据最小值
@@ -318,12 +331,7 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
         reqVO.setResult(1);
         reqVO.setType(1);
         List<Long> workOrderIds = new ArrayList<>();
-        // List<IotMainWorkOrderDO> workOrders = iotMainWorkOrderMapper.selectList(reqVO);
-        /* if (CollUtil.isNotEmpty(workOrders)) {
-            workOrders.forEach(order -> {
-                workOrderIds.add(order.getId());
-            });
-        } */
+
         List<IotMainWorkOrderBomDO> workOrderBomS = new ArrayList<>();
         if (CollUtil.isNotEmpty(workOrderIds)) {
             bomReqVO.setWorkOrderIds(workOrderIds);
@@ -348,6 +356,8 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
             mainBomS = iotMaintenanceBomMapper.selectList(mainBomReqVO);
         }
         Set<String> boundedMultiAttrNames = new HashSet<>();
+        Set<Long> deviceCategoryIds = new HashSet<>();
+        Map<Long, Long> deviceCategoryPair = new HashMap<>();
         if (CollUtil.isNotEmpty(mainBomS)) {
             mainBomDeviceIds = CollUtil.isEmpty(mainBomS)
                     ? Collections.emptySet()
@@ -366,6 +376,16 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
                     boundedMultiAttrNames.add(bom.getCode());
                 }
             });
+            // 查询所有设备类别id
+            // 组装bom关联的设备信息
+            Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(convertListByFlatMap(mainBomS,
+                    bom -> Stream.of(bom.getDeviceId())));
+            if (CollUtil.isNotEmpty(deviceMap)) {
+                deviceMap.forEach((k,v) -> {
+                    deviceCategoryIds.add(v.getAssetClass());
+                    deviceCategoryPair.put(k, v.getAssetClass());
+                });
+            }
         }
         deviceIds.addAll(mainBomDeviceIds);
         if (CollUtil.isEmpty(deviceIds)){
@@ -387,14 +407,16 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
         }
 
         // 查询 运行记录模板中 正常的累计时长 公里数集合
-        Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(new ArrayList<>(deviceIds));
+        // Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(new ArrayList<>(deviceIds));
+        Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap =
+                iotDeviceRunLogService.getDeviceRunLogMapAlone(new ArrayList<>(deviceIds), new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
         // 以设备为维度统计每个设备相关的保养项的最近保养距离 key设备id    value设备下每个保养项的的最小保养距离集合
         Map<Long, List<Map<String, Object>>> orderDistancePair = new HashMap<>();
         // 设备保养明细 key设备id  value设备保养工单明细下所有保养规则数据最小值
         Map<Long, String> resultMap = new HashMap<>();
         if (CollUtil.isNotEmpty(mainBomS)) {
             // 遍历保养计划明细 计算 保养计划中的设备 的最近的保养时间
-            mainBomS.forEach(bom -> {
+            for (IotMaintenanceBomDO bom : mainBomS) {
                 BigDecimal runningTimeDistance = null;
                 BigDecimal runningKiloDistance = null;
                 BigDecimal naturalDateDistance = null;
@@ -468,6 +490,9 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
                     tempDistances.add(tempDistance);
                     orderDistancePair.put(bom.getDeviceId(), tempDistances);
                 }
+            }
+            mainBomS.forEach(bom -> {
+
             });
         }
         // 计算出每个保养工单明细的不同保养规则的保养距离最小值
@@ -589,6 +614,8 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
     public PageResult<IotDeviceRespVO> maintenanceSearch(IotMainWorkOrderPageReqVO pageReqVO) {
         // 所有保养计划 明细中待保养的最近距离 里程/时间/自然日
         Set<Long> deviceIds = new HashSet<>();
+        Set<Long> deviceCategoryIds = new HashSet<>();
+        Map<Long, Long> deviceCategoryPair = new HashMap<>();
         Set<Long> orderDeviceIds = new HashSet<>();
         // 查询保养计划明细中不包含 deviceIds 的设备id集合
         List<IotMaintenanceBomDO> mainBomS = new ArrayList<>();
@@ -615,6 +642,15 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
                     boundedMultiAttrNames.add(bom.getCode());
                 }
             });
+            // 组装bom关联的设备信息
+            Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(convertListByFlatMap(mainBomS,
+                    bom -> Stream.of(bom.getDeviceId())));
+            if (CollUtil.isNotEmpty(deviceMap)) {
+                deviceMap.forEach((k,v) -> {
+                    deviceCategoryIds.add(v.getAssetClass());
+                    deviceCategoryPair.put(k, v.getAssetClass());
+                });
+            }
         }
         deviceIds.addAll(mainBomDeviceIds);
         if (CollUtil.isEmpty(deviceIds)){
@@ -636,7 +672,8 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
         }
 
         // 查询 运行记录模板中 正常的累计时长 公里数集合
-        Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(new ArrayList<>(deviceIds));
+        Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(new ArrayList<>(deviceIds),
+                new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
         // 以设备为维度统计每个设备相关的保养项的最近保养距离 key设备id    value设备下每个保养项的的最小保养距离集合
         Map<Long, List<Map<String, Object>>> orderDistancePair = new HashMap<>();
         // 设备保养明细 key设备id  value设备保养工单明细下所有保养规则数据最小值
@@ -1204,6 +1241,8 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
         AtomicBoolean mainCompleted = new AtomicBoolean(true);
         // 已经完成保养的保养项关联的 设备id 集合
         Set<Long> deviceIds = new HashSet<>();
+        Set<Long> deviceCategoryIds = new HashSet<>();
+        Map<Long, Long> deviceCategoryPair = new HashMap<>();
         // 需要更新 运行时长周期 的设备id 集合
         Set<Long> mctDeviceIds = new HashSet<>();
         // 需要更新 运行时长周期 的保养项id 集合
@@ -1270,6 +1309,17 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
                 deviceBomPair.put(uniqueKey, bom);
             }
         });
+        if (CollUtil.isNotEmpty(workOrderBOMs)) {
+            // 组装bom关联的设备信息
+            Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(convertListByFlatMap(workOrderBOMs,
+                    bom -> Stream.of(bom.getDeviceId())));
+            if (CollUtil.isNotEmpty(deviceMap)) {
+                deviceMap.forEach((k,v) -> {
+                    deviceCategoryIds.add(v.getAssetClass());
+                    deviceCategoryPair.put(k, v.getAssetClass());
+                });
+            }
+        }
         iotMainWorkOrderBomMapper.updateBatch(workOrderBomDOS);
         // 只有工单明细中所有保养项的物料都选择完成,才会将工单结果设置为 ‘已执行’
         if (mainCompleted.get()) {
@@ -1279,7 +1329,8 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
         // 如果有保养项已经保养完成,根据保养项规则 实时更新 关联 的 保养计划 明细 保养项的 ‘上次保养运行时间、上次保养自然日期、上次保养公里数’
         // 查询明细中所有设备的累计运行里程、累计运行时间
         if (CollUtil.isNotEmpty(deviceIds)) {
-            Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(new ArrayList<>(deviceIds));
+            Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(new ArrayList<>(deviceIds),
+                    new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
             // 查询保养工单关联的保养计划 明细
             IotMaintenanceBomPageReqVO reqVO = new IotMaintenanceBomPageReqVO();
             reqVO.setPlanId(updateObj.getPlanId());

+ 19 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotmainworkorderbom/IotMainWorkOrderBomServiceImpl.java

@@ -8,9 +8,11 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbom.vo.IotMainWorkOrderBomPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbom.vo.IotMainWorkOrderBomSaveReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotmainworkorderbom.IotMainWorkOrderBomDO;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotmainworkorderbom.IotMainWorkOrderBomMapper;
 import cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant;
+import cn.iocoder.yudao.module.pms.service.IotDeviceService;
 import cn.iocoder.yudao.module.pms.service.iotdevicebom.IotDeviceBomService;
 import cn.iocoder.yudao.module.pms.service.iotdevicerunlog.IotDeviceRunLogService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,8 +24,10 @@ import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.temporal.ChronoUnit;
 import java.util.*;
+import java.util.stream.Stream;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
 
 /**
  * PMS 保养计划明细BOM Service 实现类
@@ -40,6 +44,8 @@ public class IotMainWorkOrderBomServiceImpl implements IotMainWorkOrderBomServic
     private IotDeviceRunLogService iotDeviceRunLogService;
     @Autowired
     private IotDeviceBomService iotDeviceBomService;
+    @Resource
+    private IotDeviceService iotDeviceService;
 
     @Override
     public Long createIotMainWorkOrderBom(IotMainWorkOrderBomSaveReqVO createReqVO) {
@@ -115,6 +121,8 @@ public class IotMainWorkOrderBomServiceImpl implements IotMainWorkOrderBomServic
         // 遍历工单明细 找出每个工单中 触发保养时间最近的 时间/里程/自然日
         if (CollUtil.isNotEmpty(workOrderBomS)) {
             Set<Long> deviceIds = new HashSet<>();
+            Set<Long> deviceCategoryIds = new HashSet<>();
+            Map<Long, Long> deviceCategoryPair = new HashMap<>();
             workOrderBomS.forEach(bom -> {
                 deviceIds.add(bom.getDeviceId());
                 if (StrUtil.isNotBlank(bom.getCode())) {
@@ -124,6 +132,15 @@ public class IotMainWorkOrderBomServiceImpl implements IotMainWorkOrderBomServic
                     boundedMultiAttrNames.add(bom.getType());
                 }
             });
+            // 组装bom关联的设备信息
+            Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(convertListByFlatMap(workOrderBomS,
+                    bom -> Stream.of(bom.getDeviceId())));
+            if (CollUtil.isNotEmpty(deviceMap)) {
+                deviceMap.forEach((k,v) -> {
+                    deviceCategoryIds.add(v.getAssetClass());
+                    deviceCategoryPair.put(k, v.getAssetClass());
+                });
+            }
             // 查询 保养工单保养明细中已经绑定的 多种累计时长 公里数 属性运行记录值集合
             List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
             if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(boundedMultiAttrNames)) {
@@ -139,7 +156,8 @@ public class IotMainWorkOrderBomServiceImpl implements IotMainWorkOrderBomServic
             }
 
             // 查询当前所有设备的 累计运行里程 累计运行时间
-            Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(new ArrayList<>(deviceIds));
+            Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(new ArrayList<>(deviceIds),
+                    new ArrayList<>(deviceIds), deviceCategoryPair);
             Map<Long, List<Map<String, Object>>> orderDistancePair = new HashMap<>();
             workOrderBomS.forEach(bom -> {
                 BigDecimal runningTimeDistance = null;

+ 16 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotDeviceRunLogMapper.xml

@@ -34,6 +34,22 @@
         GROUP BY drl.device_id, mta.`code`
     </select>
 
+    <!-- 查询正常统计的累计 公里数 时长 -->
+    <select id="normalCumulativeAttrs"
+            resultType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO">
+        SELECT
+            mta.device_category_id,
+            mta.`name` pointName
+        FROM rq_iot_model_template_attrs mta
+        WHERE mta.deleted = 0
+        AND (mta.`code` ='sc' OR mta.`code`='gls')
+        <if test="deviceCategoryIds != null and deviceCategoryIds.size &gt; 0">
+            AND mta.device_category_id IN
+            <foreach collection="deviceCategoryIds" index="index" item="key" open="(" separator="," close=")">
+                #{key}
+            </foreach>
+        </if>
+    </select>
 
     <select id="selectListByCreateTimeAndDeptList" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO"
             resultType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO">

+ 1 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotMainWorkOrderMapper.xml

@@ -21,6 +21,7 @@
                 AND rimwob.device_id = #{deviceId}
             </if>
         )
+        AND rimwo.deleted = 0
         ORDER BY rimwo.id DESC
     </select>