فهرست منبع

pms 保养工单 保养开始时间的累计运行时长

zhangcl 5 روز پیش
والد
کامیت
913c27ebc0
16فایلهای تغییر یافته به همراه259 افزوده شده و 53 حذف شده
  1. 16 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdevicerunlog/vo/IotDeviceRunLogPageReqVO.java
  2. 2 2
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmaintenancebom/IotMaintenanceBomController.java
  3. 125 2
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmainworkorderbom/IotMainWorkOrderBomController.java
  4. 2 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmainworkorderbom/vo/IotMainWorkOrderBomPageReqVO.java
  5. 13 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmainworkorderbom/vo/IotMainWorkOrderBomRespVO.java
  6. 6 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmainworkorderbom/vo/IotMainWorkOrderBomSaveReqVO.java
  7. 6 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/iotdevicerunlog/IotDeviceRunLogDO.java
  8. 8 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/iotmainworkorderbom/IotMainWorkOrderBomDO.java
  9. 4 2
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotdevicerunlog/IotDeviceRunLogMapper.java
  10. 2 2
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/mainworkorder/CreateMainWorkOrderJob.java
  11. 6 5
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdevicerunlog/IotDeviceRunLogService.java
  12. 5 4
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdevicerunlog/IotDeviceRunLogServiceImpl.java
  13. 42 34
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotmainworkorder/IotMainWorkOrderServiceImpl.java
  14. 8 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotmainworkorderbom/IotMainWorkOrderBomService.java
  15. 8 2
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotmainworkorderbom/IotMainWorkOrderBomServiceImpl.java
  16. 6 0
      yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotDeviceRunLogMapper.xml

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

@@ -69,6 +69,22 @@ public class IotDeviceRunLogPageReqVO extends PageParam {
     @Schema(description = "创建时间")
     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
     private LocalDateTime[] createTime;
+
+    /**
+     * 扩展字段
+     */
     @Schema(description = "部门ids")
     private List<Long> deptIds;
+
+    @Schema(description = "设备id集合")
+    private List<Long> deviceIds;
+
+    @Schema(description = "设备编码集合")
+    private List<Long> deviceCodes;
+
+    @Schema(description = "累计类型属性集合")
+    private List<String> pointNames;
+
+    @Schema(description = "保养开始时间")
+    private LocalDateTime actualStartTime;
 }

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

@@ -248,7 +248,7 @@ public class IotMaintenanceBomController {
         Map<String, BigDecimal> tempTotalMileagePair = new HashMap<>();
         // 查询指定设备 指定 多累计属性名称 的设备运行记录数据集合数据
         if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(multiPointNames)) {
-            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, multiPointNames);
+            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, multiPointNames, null);
         }
         if (CollUtil.isNotEmpty(multipleAccumulatedData)) {
             multipleAccumulatedData.forEach(data -> {
@@ -298,7 +298,7 @@ public class IotMaintenanceBomController {
         // 查询正常的累计运行时长 公里数 时需要 携带 设备分类id 方便快速定位 累计属性值
         // 相同设备如果都包含 totalRuntime totalMileage 则返回1个对象
         Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(convertListByFlatMap(BOMs,
-                bom -> Stream.of(bom.getDeviceId())), new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
+                bom -> Stream.of(bom.getDeviceId())), new ArrayList<>(deviceCategoryIds), deviceCategoryPair, null);
         // 没有产生运行记录的单累计属性 返回前端 0 deviceAttrsPair单属性属性集合
         if (CollUtil.isNotEmpty(deviceAttrsPair)) {
             deviceAttrsPair.forEach((deviceId, attrs) -> {

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

@@ -16,6 +16,7 @@ import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbom.vo.IotMa
 import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbom.vo.IotMainWorkOrderBomRespVO;
 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.iotmainworkorder.IotMainWorkOrderDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotmainworkorderbom.IotMainWorkOrderBomDO;
 import cn.iocoder.yudao.module.pms.service.IotDeviceService;
 import cn.iocoder.yudao.module.pms.service.iotdevicematerial.IotDeviceMaterialService;
@@ -35,7 +36,9 @@ import javax.validation.Valid;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Stream;
 
 import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
@@ -110,6 +113,15 @@ public class IotMainWorkOrderBomController {
         return success(buildMainWorkOrderBomList(workOrderBOMs));
     }
 
+    @GetMapping("/maintenanceCumulativeValue")
+    @Operation(summary = "获得PMS 保养工单明细BOM列表 保养时累计公里数 时长")
+    @PreAuthorize("@ss.hasPermission('pms:iot-main-work-order-bom:query')")
+    public CommonResult<List<IotMainWorkOrderBomRespVO>> maintenanceCumulativeValue(@Valid IotMainWorkOrderBomPageReqVO reqVO) {
+        List<IotMainWorkOrderBomDO> workOrderBOMs = iotMainWorkOrderBomService.getIotMainWorkOrderBomList(reqVO);
+        // 组装bom关联的设备 保养时累计公里数 时长
+        return success(buildMaintenanceCumulativeValue(workOrderBOMs, reqVO.getActualStartTime()));
+    }
+
     @GetMapping("/export-excel")
     @Operation(summary = "导出PMS 保养计划明细BOM Excel")
     @PreAuthorize("@ss.hasPermission('pms:iot-main-work-order-bom:export')")
@@ -127,6 +139,9 @@ public class IotMainWorkOrderBomController {
         if (CollUtil.isEmpty(BOMs)) {
             return Collections.emptyList();
         }
+        // 保养工单都是基于单设备 查询 保养工单主表信息 获取 保养开始时间
+        // 如果 保养开始时间 有值,根据保养开始时间查询对应的保养时累计时长/里程
+
         // 组装bom关联的设备信息
         Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(convertListByFlatMap(BOMs,
                 bom -> Stream.of(bom.getDeviceId())));
@@ -142,6 +157,7 @@ public class IotMainWorkOrderBomController {
         Set<Long> bomNodeIds = new HashSet<>();
         // 设备所属部门id集合
         Set<Long> deptIds = new HashSet<>();
+        AtomicReference<Long> workOrderId = new AtomicReference<>();    // 保养工单id
         BOMs.forEach(bom -> {
             if (ObjUtil.isNotEmpty(bom.getDeviceId())) {
                 deviceIds.add(bom.getDeviceId());
@@ -163,16 +179,29 @@ public class IotMainWorkOrderBomController {
                     deptIds.add(v.getDeptId());
                 });
             }
+            workOrderId.set(bom.getWorkOrderId());
         });
+        // 如果 保养开始时间 有值,根据保养开始时间查询对应的保养时累计时长/里程
+        IotMainWorkOrderDO workOrder = iotMainWorkOrderService.getIotMainWorkOrder(workOrderId.get());
+        Map<Long, IotDeviceRunLogRespVO> specifiedDateDeviceRunLogMap = new HashMap<>();
+        if (ObjUtil.isNotEmpty(workOrder.getActualStartTime())) {
+            // 定义格式化器(线程安全,可直接复用)
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            // 转换 LocalDateTime 为指定格式的字符串
+            String actualStartDate = workOrder.getActualStartTime().format(formatter);
+            specifiedDateDeviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(convertListByFlatMap(BOMs,
+                    bom -> Stream.of(bom.getDeviceId())), new ArrayList<>(deviceCategoryIds), deviceCategoryPair, actualStartDate);
+        }
+
         Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(convertListByFlatMap(BOMs,
-                bom -> Stream.of(bom.getDeviceId())), new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
+                bom -> Stream.of(bom.getDeviceId())), new ArrayList<>(deviceCategoryIds), deviceCategoryPair, null);
         // 查询 运行记录模板中包含多个累计 时长 公里数 属性的集合
         List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
         // key(设备id-累计时长属性名称)    value多累计时长属性运行记录填报数值
         Map<String, BigDecimal> tempTotalRunDataPair = new HashMap<>();
         // 查询指定设备 指定 多累计属性名称 的设备运行记录数据集合数据
         if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(pointNames)) {
-            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, pointNames);
+            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, pointNames, null);
         }
         if (CollUtil.isNotEmpty(multipleAccumulatedData)) {
             multipleAccumulatedData.forEach(data -> {
@@ -195,12 +224,19 @@ public class IotMainWorkOrderBomController {
         // key设备id-bom节点id      value设备物料集合
         Map<String, List<IotDeviceMaterialRespVO>> deviceBomMaterialPair = iotDeviceMaterialService.bomMaterials(deptIds, deviceIds, bomNodeIds);
 
+        Map<Long, IotDeviceRunLogRespVO> finalSpecifiedDateDeviceRunLogMap = specifiedDateDeviceRunLogMap;
         return BeanUtils.toBean(BOMs, IotMainWorkOrderBomRespVO.class, bomVO -> {
             // 设置设备相关信息
             MapUtils.findAndThen(deviceMap, bomVO.getDeviceId(),
                     device -> bomVO.setDeviceName(device.getDeviceName()));
             MapUtils.findAndThen(deviceMap, bomVO.getDeviceId(),
                     device -> bomVO.setDeviceCode(device.getDeviceCode()));
+
+            MapUtils.findAndThen(finalSpecifiedDateDeviceRunLogMap, bomVO.getDeviceId(),
+                    device -> bomVO.setMainRuntime(device.getTotalRunTime()));
+            MapUtils.findAndThen(finalSpecifiedDateDeviceRunLogMap, bomVO.getDeviceId(),
+                    device -> bomVO.setMainMileage(device.getTotalMileage()));
+
             MapUtils.findAndThen(deviceRunLogMap, bomVO.getDeviceId(),
                     device -> bomVO.setTotalMileage(device.getTotalMileage()));
             MapUtils.findAndThen(deviceRunLogMap, bomVO.getDeviceId(),
@@ -231,4 +267,91 @@ public class IotMainWorkOrderBomController {
             }
         });
     }
+
+    /**
+     * 保养工单填报 查询各保养项指定时间的累计运行里程 时长 前端根据 bomNodeId 匹配
+     * @param BOMs
+     * @return
+     */
+    private List<IotMainWorkOrderBomRespVO> buildMaintenanceCumulativeValue(List<IotMainWorkOrderBomDO> BOMs, String actualStartTime) {
+        if (CollUtil.isEmpty(BOMs) || StrUtil.isBlank(actualStartTime)) {
+            return Collections.emptyList();
+        }
+        // 组装bom关联的设备信息
+        Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(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<>();
+        // 设备所属部门id集合
+        Set<Long> deptIds = new HashSet<>();
+        BOMs.forEach(bom -> {
+            if (ObjUtil.isNotEmpty(bom.getDeviceId())) {
+                deviceIds.add(bom.getDeviceId());
+            }
+            // 累计运行时长属性名称
+            if (StrUtil.isNotBlank(bom.getCode())) {
+                pointNames.add(bom.getCode());
+            }
+            // 累计运行公里数属性名称
+            if (StrUtil.isNotBlank(bom.getType())) {
+                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());
+                    deptIds.add(v.getDeptId());
+                });
+            }
+        });
+        Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(convertListByFlatMap(BOMs,
+                bom -> Stream.of(bom.getDeviceId())), new ArrayList<>(deviceCategoryIds), deviceCategoryPair, actualStartTime);
+        // 查询 运行记录模板中包含多个累计 时长 公里数 属性的集合
+        List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
+        // key(设备id-累计时长属性名称)    value多累计时长属性运行记录填报数值
+        Map<String, BigDecimal> tempTotalRunDataPair = new HashMap<>();
+        // 查询指定设备 指定 多累计属性名称 的设备运行记录数据集合数据
+        if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(pointNames)) {
+            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, pointNames, actualStartTime);
+        }
+        if (CollUtil.isNotEmpty(multipleAccumulatedData)) {
+            multipleAccumulatedData.forEach(data -> {
+                String uniqueKey = StrUtil.join("-", data.getDeviceId(), data.getPointName());
+                tempTotalRunDataPair.put(uniqueKey, data.getTotalRunTime());
+            });
+        }
+
+        return BeanUtils.toBean(BOMs, IotMainWorkOrderBomRespVO.class, bomVO -> {
+            MapUtils.findAndThen(deviceRunLogMap, bomVO.getDeviceId(),
+                    device -> bomVO.setMainMileage(device.getTotalMileage()));
+            MapUtils.findAndThen(deviceRunLogMap, bomVO.getDeviceId(),
+                    device -> bomVO.setMainRuntime(device.getTotalRunTime()));
+
+            // 运行记录模板中包含的多个累计类型属性
+            if (StrUtil.isNotBlank(bomVO.getCode())) {
+                // code 累计运行时长属性名称
+                String uniqueKey = StrUtil.join("-", bomVO.getDeviceId(), bomVO.getCode());
+                if (tempTotalRunDataPair.containsKey(uniqueKey)) {
+                    bomVO.setTempMainRunTime(tempTotalRunDataPair.get(uniqueKey));
+                }
+            }
+            if (StrUtil.isNotBlank(bomVO.getType())) {
+                // type 累计运行公里数属性名称
+                String uniqueKey = StrUtil.join("-", bomVO.getDeviceId(), bomVO.getType());
+                if (tempTotalRunDataPair.containsKey(uniqueKey)) {
+                    bomVO.setTempMainMileage(tempTotalRunDataPair.get(uniqueKey));
+                }
+            }
+        });
+    }
 }

+ 2 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmainworkorderbom/vo/IotMainWorkOrderBomPageReqVO.java

@@ -155,4 +155,6 @@ public class IotMainWorkOrderBomPageReqVO extends PageParam {
     private List<Long> bomNodeIds;
     @Schema(description = "保养工单id集合")
     private List<Long> workOrderIds;
+    @Schema(description = "保养开始时间")
+    private String actualStartTime;
 }

+ 13 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmainworkorderbom/vo/IotMainWorkOrderBomRespVO.java

@@ -55,6 +55,14 @@ public class IotMainWorkOrderBomRespVO {
     @ExcelProperty("保养规则-运行时间(0启用 1停用)")
     private Integer runningTimeRule;
 
+    @Schema(description = "保养时累计运行里程KM")
+    @ExcelProperty("保养时累计运行里程KM")
+    private BigDecimal mainMileage;
+
+    @Schema(description = "保养时累计运行时长H")
+    @ExcelProperty("保养时累计运行时长H")
+    private BigDecimal mainRuntime;
+
     @Schema(description = "上次保养运行时长(小时)")
     @ExcelProperty("上次保养运行时长(小时)")
     private BigDecimal lastRunningTime;
@@ -196,6 +204,11 @@ public class IotMainWorkOrderBomRespVO {
     @Schema(description = "临时 累计运行公里数 用于运行记录模板中包含多个累计类型属性的场景", example = "20238km")
     private BigDecimal tempTotalMileage;
 
+    @Schema(description = "保养时累计运行时间 多个累计类型属性", example = "30000H")
+    private BigDecimal tempMainRunTime;
+    @Schema(description = "保养时累计运行公里数 多个累计类型属性", example = "20238km")
+    private BigDecimal tempMainMileage;
+
     @Schema(description = "上次保养时间")
     private LocalDateTime lastMaintenanceDate;
 

+ 6 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmainworkorderbom/vo/IotMainWorkOrderBomSaveReqVO.java

@@ -40,6 +40,12 @@ public class IotMainWorkOrderBomSaveReqVO {
     @Schema(description = "保养规则-运行时间(0启用 1停用)")
     private Integer runningTimeRule;
 
+    @Schema(description = "保养时累计运行里程KM")
+    private BigDecimal mainMileage;
+
+    @Schema(description = "保养时累计运行时长H")
+    private BigDecimal mainRuntime;
+
     @Schema(description = "上次保养运行时长(小时)")
     private BigDecimal lastRunningTime;
 

+ 6 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/iotdevicerunlog/IotDeviceRunLogDO.java

@@ -93,8 +93,14 @@ public class IotDeviceRunLogDO extends BaseDO {
      */
     private String remark;
 
+    /**
+     * 运行记录 日报 填写数值
+     */
     private String fillContent;
 
+    /**
+     * 累计类型字段标识 1累积值   0填报值
+     */
     private int isSum;
 
 }

+ 8 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/iotmainworkorderbom/IotMainWorkOrderBomDO.java

@@ -65,6 +65,14 @@ public class IotMainWorkOrderBomDO extends BaseDO {
      * 保养规则-运行时间(0启用 1停用)
      */
     private Integer runningTimeRule;
+    /**
+     * 保养时累计运行里程KM
+     */
+    private BigDecimal mainMileage;
+    /**
+     * 保养时累计运行时长H
+     */
+    private BigDecimal mainRuntime;
     /**
      * 上次保养运行时长(小时)
      */

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

@@ -54,7 +54,8 @@ public interface IotDeviceRunLogMapper extends BaseMapperX<IotDeviceRunLogDO> {
      * @return
      */
     List<IotDeviceRunLogRespVO> distinctDevices(@Param("deviceIds") Collection<Long> deviceIds,
-                                                @Param("deviceCategoryIds") Collection<Long> deviceCategoryIds);
+                                                @Param("deviceCategoryIds") Collection<Long> deviceCategoryIds,
+                                                @Param("actualStartTime") String actualStartTime);
 
     /**
      * 查询运行记录模板中正常的累积类型属性
@@ -69,7 +70,8 @@ public interface IotDeviceRunLogMapper extends BaseMapperX<IotDeviceRunLogDO> {
      * @return
      */
     List<IotDeviceRunLogRespVO> multipleAccumulatedData(@Param("deviceIds") Collection<Long> deviceIds,
-                                                        @Param("attrNames") Collection<String> attrNames);
+                                                        @Param("attrNames") Collection<String> attrName,
+                                                        @Param("actualStartTime") String actualStartTime);
 
 
     @TenantIgnore

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

@@ -172,7 +172,7 @@ public class CreateMainWorkOrderJob implements JobHandler {
         // 查询 保养计划保养明细中已经绑定的 多种累计时长 公里数 属性集合
         List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
         if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(boundedMultiAttrNames)) {
-            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames);
+            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames, null);
         }
         // key(设备id-累计时长属性名称)    value时长属性累计时长数值
         Map<String, BigDecimal> tempTotalRunDataPair = new HashMap<>();
@@ -185,7 +185,7 @@ public class CreateMainWorkOrderJob implements JobHandler {
 
         // 查询保养计划明细中所有设备的累计运行里程、累计运行时间
         Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(convertListByFlatMap(mainBomList,
-                bom -> Stream.of(bom.getDeviceId())), new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
+                bom -> Stream.of(bom.getDeviceId())), new ArrayList<>(deviceCategoryIds), deviceCategoryPair, null);
         List<IotMaintenanceBomDO> tobeMaintenanceBomList = new ArrayList<>();
         // 触发保养规则的设备id 集合
         List<Long> tobeMainDeviceIds = new ArrayList<>();

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

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

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

@@ -73,10 +73,11 @@ public class IotDeviceRunLogServiceImpl implements IotDeviceRunLogService {
     }
 
     @Override
-    public List<IotDeviceRunLogRespVO> distinctDevices(List<Long> ids, List<Long> deviceCategoryIds, Map<Long, Long> deviceCategoryPair) {
+    public List<IotDeviceRunLogRespVO> distinctDevices(List<Long> ids, List<Long> deviceCategoryIds,
+                                                       Map<Long, Long> deviceCategoryPair, String actualStartTime) {
         // 先根据设备分类集合查询出所有正常累积的 公里数 时长
         List<IotDeviceRunLogRespVO> normalCumulativeAttrs = iotDeviceRunLogMapper.normalCumulativeAttrs(deviceCategoryIds);
-        List<IotDeviceRunLogRespVO> tempDeviceRunLogs = iotDeviceRunLogMapper.distinctDevices(ids, deviceCategoryIds);
+        List<IotDeviceRunLogRespVO> tempDeviceRunLogs = iotDeviceRunLogMapper.distinctDevices(ids, deviceCategoryIds, actualStartTime);
         Set<Long> categoryIds = new HashSet<>();
         if (CollUtil.isNotEmpty(normalCumulativeAttrs)) {
             normalCumulativeAttrs.forEach(attr -> {
@@ -97,8 +98,8 @@ public class IotDeviceRunLogServiceImpl implements IotDeviceRunLogService {
     }
 
     @Override
-    public List<IotDeviceRunLogRespVO> multipleAccumulatedData(Collection<Long> deviceIds, Collection<String> attrNames) {
-        return iotDeviceRunLogMapper.multipleAccumulatedData(deviceIds, attrNames);
+    public List<IotDeviceRunLogRespVO> multipleAccumulatedData(Collection<Long> deviceIds, Collection<String> attrNames, String actualStartTime) {
+        return iotDeviceRunLogMapper.multipleAccumulatedData(deviceIds, attrNames, actualStartTime);
     }
 
 }

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

@@ -257,7 +257,7 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
         // 查询 运行记录模板中包含多个累计 时长 公里数 属性的集合
         List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
         if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(boundedMultiAttrNames)) {
-            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames);
+            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames, null);
         }
         // key(设备id-累计时长属性名称)    value时长属性累计时长数值
         Map<String, BigDecimal> tempTotalRunDataPair = new HashMap<>();
@@ -269,7 +269,7 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
         }
         // 查询 运行记录模板中 正常的累计时长 公里数集合
         Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(new ArrayList<>(deviceIds),
-                new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
+                new ArrayList<>(deviceCategoryIds), deviceCategoryPair, null);
         // 以保养工单为维度 统计每个工单相关的保养项的最近保养距离 key保养工单id    value保养工单下每个保养项的的最小保养距离集合
         Map<Long, List<Map<String, Object>>> orderDistancePair = new HashMap<>();
         // key保养工单id  value设备保养工单明细下所有保养规则数据最小值
@@ -459,7 +459,7 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
         // 查询 运行记录模板中包含多个累计 时长 公里数 属性的集合
         List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
         if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(boundedMultiAttrNames)) {
-            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames);
+            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames, null);
         }
         // key(设备id-累计时长属性名称)    value时长属性累计时长数值
         Map<String, BigDecimal> tempTotalRunDataPair = new HashMap<>();
@@ -471,9 +471,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);
+                iotDeviceRunLogService.getDeviceRunLogMapAlone(new ArrayList<>(deviceIds), new ArrayList<>(deviceCategoryIds), deviceCategoryPair, null);
         // 以设备为维度统计每个设备相关的保养项的最近保养距离 key设备id    value设备下每个保养项的的最小保养距离集合
         Map<Long, List<Map<String, Object>>> orderDistancePair = new HashMap<>();
         // 设备保养明细 key设备id  value设备保养工单明细下所有保养规则数据最小值
@@ -770,7 +769,7 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
         // 查询 运行记录模板中包含多个累计 时长 公里数 属性的集合
         List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
         if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(boundedMultiAttrNames)) {
-            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames);
+            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames, null);
         }
         // key(设备id-累计时长属性名称)    value时长属性累计时长数值
         Map<String, BigDecimal> tempTotalRunDataPair = new HashMap<>();
@@ -784,7 +783,7 @@ 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);
+                iotDeviceRunLogService.getDeviceRunLogMapAlone(new ArrayList<>(deviceIds), new ArrayList<>(deviceCategoryIds), deviceCategoryPair, null);
         // 以设备为维度统计每个设备相关的保养项的最近保养距离 key设备id    value设备下每个保养项的的最小保养距离集合
         Map<Long, List<Map<String, Object>>> orderDistancePair = new HashMap<>();
         // 设备保养明细 key设备id  value设备保养工单明细下所有保养规则数据最小值
@@ -1018,7 +1017,7 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
             // 查询 运行记录模板中包含多个累计 时长 公里数 属性的集合
             List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
             if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(boundedMultiAttrNames)) {
-                multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames);
+                multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames, null);
             }
             // key(设备id-累计时长属性名称)    value时长属性累计时长数值
             Map<String, BigDecimal> tempTotalRunDataPair = new HashMap<>();
@@ -1032,7 +1031,7 @@ 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);
+                    iotDeviceRunLogService.getDeviceRunLogMapAlone(new ArrayList<>(deviceIds), new ArrayList<>(deviceCategoryIds), deviceCategoryPair, null);
             // 以设备为维度统计每个设备相关的保养项的最近保养距离 key设备id    value设备下每个保养项的的最小保养距离集合
             Map<Long, List<Map<String, Object>>> orderDistancePair = new HashMap<>();
             // 设备保养明细 key设备id  value设备保养工单明细下所有保养规则数据最小值
@@ -1282,7 +1281,7 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
         // 查询 运行记录模板中包含多个累计 时长 公里数 属性的集合
         List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
         if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(boundedMultiAttrNames)) {
-            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames);
+            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames, null);
         }
         // key(设备id-累计时长属性名称)    value时长属性累计时长数值
         Map<String, BigDecimal> tempTotalRunDataPair = new HashMap<>();
@@ -1295,7 +1294,7 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
 
         // 查询 运行记录模板中 正常的累计时长 公里数集合
         Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(new ArrayList<>(deviceIds),
-                new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
+                new ArrayList<>(deviceCategoryIds), deviceCategoryPair, null);
         // 以设备为维度统计每个设备相关的保养项的最近保养距离 key设备id    value设备下每个保养项的的最小保养距离集合
         Map<Long, List<Map<String, Object>>> orderDistancePair = new HashMap<>();
         // 设备保养明细 key设备id  value设备保养工单明细下所有保养规则数据最小值
@@ -1914,6 +1913,10 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
         Set<Long> completedBomNodeIds = new HashSet<>();
         // 每个保养项关联的物料集合
         Map<Long, List<IotMainWorkOrderBomMaterialSaveReqVO>> bomMaterialsPair = new HashMap<>();
+        // key设备id-bomNodeId    value保养时累计运行里程
+        Map<String, BigDecimal> mainMileagePair = new HashMap<>();
+        // key设备id-bomNodeId    value保养时累计运行时长
+        Map<String, BigDecimal> mainRuntimePair = new HashMap<>();
         // todo 先查询当前工单已经保养完成的保养项 避免重复更新 保养项的 上次保养时长...
         // 统计保养项信息 是否保养完成 是否需要消耗物料
         workOrderBOMs.forEach(bom -> {
@@ -1925,6 +1928,10 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
                 // 保养完成
                 completedBomNodeIds.add(bom.getBomNodeId());
             }
+            // 组装每个保养项的 保养时累计运行里程 时长
+            String uniqueKey = StrUtil.join("-", bom.getDeviceId(), bom.getBomNodeId());
+            mainMileagePair.put(uniqueKey, bom.getMainMileage());
+            mainRuntimePair.put(uniqueKey, bom.getMainRuntime());
         });
         // 只有保养完成的保养项关联的物料才会被统计出库(如果物料来源是 本地库存)
         workOrderMaterials.forEach(material -> {
@@ -2002,7 +2009,7 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
                     tempBom.setStatus(1);
                 } */
             }
-            if ((ObjUtil.isNotEmpty(bom.getStatus()) && 1 == bom.getStatus()) || bomMaterialsPair.containsKey(bom.getBomNodeId())) {
+            if ((ObjUtil.isNotEmpty(bom.getStatus()) && 1 == bom.getStatus()) /* || bomMaterialsPair.containsKey(bom.getBomNodeId()) */) {
                 // 当前保养项已经保养完成 查询当前设备的 累计运行公里数 累计运行时间 当前时间日期 赋值到 关联保养计划 明细 的 对应保养规则数据上
                 deviceIds.add(bom.getDeviceId());
                 // 保养项下如果已经添加了物料 说明该保养项已经保养完成
@@ -2017,25 +2024,25 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
             workOrderBomDOS.add(tempBom);
 
             // 兼容APP未优化完的情况 所有保养项都设置了物料 设置保养工单 为 已执行
-            if (!bomMaterialsPair.containsKey(bom.getBomNodeId())){
+            /* if (!bomMaterialsPair.containsKey(bom.getBomNodeId())){
                 // 存在未添加物料的保养项
                 appCompleted.set(false);
-            }
+            } */
         });
         if (CollUtil.isNotEmpty(workOrderBOMs)) {
             // 组装bom关联的设备信息
-            Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(convertListByFlatMap(workOrderBOMs,
+            /* 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() || appCompleted.get()) {
+        if (mainCompleted.get() /* || appCompleted.get() */) {
             // 兼容APP未优化完成的情况 所有保养项都添加了物料 设置 保养工单 为 已执行
             updateObj.setResult(2);
         }
@@ -2055,22 +2062,22 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
                     boundedMultiAttrNames.add(bom.getType());
                 }
             });
-            List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
+            /* List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
             if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(boundedMultiAttrNames)) {
-                multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames);
-            }
+                multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames, null);
+            } */
             // key(设备id-累计时长属性名称)    value时长属性累计时长数值
-            Map<String, BigDecimal> tempTotalRunDataPair = new HashMap<>();
+            /* Map<String, BigDecimal> tempTotalRunDataPair = new HashMap<>();
             if (CollUtil.isNotEmpty(multipleAccumulatedData)) {
                 multipleAccumulatedData.forEach(data -> {
                     String uniqueKey = StrUtil.join("-", data.getDeviceId(), data.getPointName());
                     tempTotalRunDataPair.put(uniqueKey, data.getTotalRunTime());
                 });
-            }
+            } */
 
             // 单一累计属性集合
-            Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(new ArrayList<>(deviceIds),
-                    new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
+            /* Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(new ArrayList<>(deviceIds),
+                    new ArrayList<>(deviceCategoryIds), deviceCategoryPair, null); */
             // 查询保养工单关联的保养计划 明细
             IotMaintenanceBomPageReqVO reqVO = new IotMaintenanceBomPageReqVO();
             reqVO.setPlanId(updateObj.getPlanId());
@@ -2081,10 +2088,11 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
             if (CollUtil.isNotEmpty(maintenanceBomS)) {
                 List<IotMaintenanceBomDO> tobeUpdatedMainBomS = new ArrayList<>();
                 maintenanceBomS.forEach(bom -> {
+                    String uniqueKey = StrUtil.join("-", bom.getDeviceId(), bom.getBomNodeId());
                     if (ObjUtil.isNotEmpty(bom.getMileageRule()) && 0 == bom.getMileageRule()) {
-                        BigDecimal totalMileage = BigDecimal.ZERO;
+                        // BigDecimal totalMileage = BigDecimal.ZERO;
                         // 设置了 运行里程 保养规则
-                        if (deviceRunLogMap.containsKey(bom.getDeviceId())) {
+                        /* if (deviceRunLogMap.containsKey(bom.getDeviceId())) {
                             IotDeviceRunLogRespVO deviceRunLog = deviceRunLogMap.get(bom.getDeviceId());
                             totalMileage = deviceRunLog.getTotalMileage();
                         } else {
@@ -2093,15 +2101,15 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
                             if (tempTotalRunDataPair.containsKey(uniqueKeyType)) {
                                 totalMileage = tempTotalRunDataPair.get(uniqueKeyType);
                             }
-                        }
-                        if (ObjUtil.isNotEmpty(totalMileage) && totalMileage.compareTo(BigDecimal.ZERO)>0) {
-                            bom.setLastRunningKilometers(totalMileage);
+                        } */
+                        if (mainMileagePair.containsKey(uniqueKey)) {
+                            bom.setLastRunningKilometers(mainMileagePair.get(uniqueKey));
                         }
                     }
                     if (ObjUtil.isNotEmpty(bom.getRunningTimeRule()) && 0 == bom.getRunningTimeRule()) {
-                        BigDecimal totalRunTime = BigDecimal.ZERO;
+                        // BigDecimal totalRunTime = BigDecimal.ZERO;
                         // 设置了 运行时间 保养规则
-                        if (deviceRunLogMap.containsKey(bom.getDeviceId())) {
+                        /* if (deviceRunLogMap.containsKey(bom.getDeviceId())) {
                             IotDeviceRunLogRespVO deviceRunLog = deviceRunLogMap.get(bom.getDeviceId());
                             totalRunTime = deviceRunLog.getTotalRunTime();
                         } else {
@@ -2110,9 +2118,9 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
                             if (tempTotalRunDataPair.containsKey(uniqueKey)) {
                                 totalRunTime = tempTotalRunDataPair.get(uniqueKey);
                             }
-                        }
-                        if (ObjUtil.isNotEmpty(totalRunTime) && totalRunTime.compareTo(BigDecimal.ZERO)>0) {
-                            bom.setLastRunningTime(totalRunTime);
+                        } */
+                        if (mainRuntimePair.containsKey(uniqueKey)) {
+                            bom.setLastRunningTime(mainRuntimePair.get(uniqueKey));
                         }
                     }
                     if (ObjUtil.isNotEmpty(bom.getNaturalDateRule()) && 0 == bom.getNaturalDateRule()) {

+ 8 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotmainworkorderbom/IotMainWorkOrderBomService.java

@@ -62,6 +62,14 @@ public interface IotMainWorkOrderBomService {
      */
     List<IotMainWorkOrderBomDO> getIotMainWorkOrderBomList(IotMainWorkOrderBomPageReqVO pageReqVO);
 
+    /**
+     * 保养计划明细BOM列表
+     *
+     * @param pageReqVO 分页查询
+     * @return PMS 保养计划明细BOM分页
+     */
+    List<IotMainWorkOrderBomDO> maintenanceCumulativeValue(IotMainWorkOrderBomPageReqVO pageReqVO);
+
     /**
      * 根据保养工单id集合查询保养工单明细最近保养时间
      *

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

@@ -111,6 +111,12 @@ public class IotMainWorkOrderBomServiceImpl implements IotMainWorkOrderBomServic
         return workOrderBomS;
     }
 
+    @Override
+    public List<IotMainWorkOrderBomDO> maintenanceCumulativeValue(IotMainWorkOrderBomPageReqVO pageReqVO) {
+        List<IotMainWorkOrderBomDO> workOrderBomS = iotMainWorkOrderBomMapper.selectList(pageReqVO);
+        return workOrderBomS;
+    }
+
     @Override
     public Map<Long, String> mainWorkOrderNearestDistance(IotMainWorkOrderBomPageReqVO pageReqVO) {
         List<IotMainWorkOrderBomDO> workOrderBomS = getIotMainWorkOrderBomList(pageReqVO);
@@ -144,7 +150,7 @@ public class IotMainWorkOrderBomServiceImpl implements IotMainWorkOrderBomServic
             // 查询 保养工单保养明细中已经绑定的 多种累计时长 公里数 属性运行记录值集合
             List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
             if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(boundedMultiAttrNames)) {
-                multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames);
+                multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames, null);
             }
             // key(设备id-累计时长属性名称)    value时长属性累计时长数值
             Map<String, BigDecimal> tempTotalRunDataPair = new HashMap<>();
@@ -157,7 +163,7 @@ public class IotMainWorkOrderBomServiceImpl implements IotMainWorkOrderBomServic
 
             // 查询当前所有设备的 累计运行里程 累计运行时间
             Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(new ArrayList<>(deviceIds),
-                    new ArrayList<>(deviceIds), deviceCategoryPair);
+                    new ArrayList<>(deviceIds), deviceCategoryPair, null);
             Map<Long, List<Map<String, Object>>> orderDistancePair = new HashMap<>();
             workOrderBomS.forEach(bom -> {
                 BigDecimal runningTimeDistance = null;

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

@@ -25,6 +25,9 @@
             </foreach>
         </if>
         AND (mta.`code` = 'sc' OR mta.`code` = 'gls')
+        <if test="actualStartTime!=null and actualStartTime!=''">
+            AND DATE(drl.create_time) = #{actualStartTime}
+        </if>
         <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=")">
@@ -102,6 +105,9 @@
             rq_iot_device_run_log
         WHERE
             deleted = 0
+            <if test="actualStartTime!=null and actualStartTime!=''">
+                AND DATE(create_time) = #{actualStartTime}
+            </if>
             <if test="deviceIds != null and deviceIds.size &gt; 0">
                 AND device_id IN
                 <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">