Bladeren bron

pms 编辑保养计划 查看保养计划详情 查询保养项的累计运行时长 累计运行公里数 逻辑 运行记录模板包含多个累计类型属性

zhangcl 1 maand geleden
bovenliggende
commit
8b7a4426aa

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

@@ -1,6 +1,7 @@
 package cn.iocoder.yudao.module.pms.controller.admin.iotmaintenancebom;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.pojo.PageParam;
@@ -31,6 +32,7 @@ import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Stream;
 
@@ -111,12 +113,27 @@ public class IotMaintenanceBomController {
         // 组装bom关联的设备信息
         Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(convertListByFlatMap(BOMs,
                 bom -> Stream.of(bom.getDeviceId())));
+        // 查询所有保养明细 已经 绑定了多个累计属性的记录
+        Set<String> pointNames = new HashSet<>();
+        // 多个累计类型属性名称集合
+        Set<String> multiPointNames = new HashSet<>();
+        BOMs.forEach(bom -> {
+            if (StrUtil.isNotBlank(bom.getCode())) {
+                pointNames.add(bom.getCode());
+            }
+            if (StrUtil.isNotBlank(bom.getType())) {
+                pointNames.add(bom.getType());
+            }
+        });
         // 设备对应的设备分类 map
         Map<Long, Long> deviceCategoryPair = new HashMap<>();
         Set<Long> deviceCategoryIds = new HashSet<>();
+        // 设备id集合 根据设备id查询 运行记录模板中包含多个累计类型属性的 累计时长 累计公里数
+        Set<Long> deviceIds = new HashSet<>();
         // 通过设备id集合查询到设备分类id集合
         if (CollUtil.isNotEmpty(deviceMap)) {
             deviceMap.forEach((k,v) -> {
+                deviceIds.add(k);
                 deviceCategoryIds.add(v.getAssetClass());
                 deviceCategoryPair.put(k, v.getAssetClass());
             });
@@ -124,12 +141,27 @@ public class IotMaintenanceBomController {
         // k设备id   v设备分类包含的模板中与累计运行时长、累计运行公里数相关的属性集合
         Map<Long, List<IotModelTemplateAttrsDO>> deviceAttrsPair = new HashMap<>();
         if (CollUtil.isNotEmpty(deviceCategoryIds)) {
+            // 查询设备分类id集合对应的运行记录模板中涉及多个 累计运行时长、累计运行公里数 的属性
+            IotModelTemplateAttrsPageReqVO multiReqVO = new IotModelTemplateAttrsPageReqVO();
+            multiReqVO.setMultipleFlag("Y");
+            multiReqVO.setDeviceCategoryIds(new ArrayList<>(deviceCategoryIds));
+            multiReqVO.setIsSum(1);  // 累计属性标识
+            List<IotModelTemplateAttrsDO> multiAccumulatedAttrs = iotModelTemplateAttrsService.getIotDeviceTemplateAttrs(multiReqVO);
+            // k设备分类id   v设备分类包含的模板中 多个 累计运行时长 累计运行公里数相关的属性集合
+            Map<Long, List<IotModelTemplateAttrsDO>> multiAccumulatedAttrPair = new HashMap<>();
+            if (CollUtil.isNotEmpty(multiAccumulatedAttrs)) {
+                multiAccumulatedAttrs.forEach(attr -> {
+                    multiPointNames.add(attr.getName());
+                });
+            }
+
             // 查询设备分类id集合对应的运行记录模板中涉及 累计运行时长、累计运行公里数 的属性
             IotModelTemplateAttrsPageReqVO reqVO = new IotModelTemplateAttrsPageReqVO();
             List<String> codes = new ArrayList<>(Arrays.asList("sc", "gls"));
             reqVO.setCodes(codes);
             reqVO.setDeviceCategoryIds(new ArrayList<>(deviceCategoryIds));
             reqVO.setIsSum(1);  // 累计属性标识
+            // 查询标识的累计类型属性 累计运行时长 累计运行公里数 正常的累计属性
             List<IotModelTemplateAttrsDO> accumulatedAttrs = iotModelTemplateAttrsService.getIotDeviceTemplateAttrs(reqVO);
             // k设备分类id   v设备分类包含的模板中与累计运行时长 累计运行公里数相关的属性集合
             Map<Long, List<IotModelTemplateAttrsDO>> accumulatedAttrPair = new HashMap<>();
@@ -158,6 +190,33 @@ public class IotMaintenanceBomController {
                 });
             }
         }
+        // key设备id  value设备对应的运行记录模板中涉及多个累计时长累计公里数的属性集合
+        Map<Long, List<IotDeviceRunLogRespVO>> deviceRunLogPair = new HashMap<>();
+        // key(设备id-累计时长属性名称)    value时长属性累计时长数值
+        Map<String, BigDecimal> tempTotalRunDataPair = new HashMap<>();
+        List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
+        // key(设备id-累计公里数属性名称)    value公里数属性累计公里数值
+        Map<String, BigDecimal> tempTotalMileagePair = new HashMap<>();
+        // 查询指定设备 指定 多累计属性名称 的设备运行记录数据集合数据
+        if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(multiPointNames)) {
+            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, multiPointNames);
+        }
+        if (CollUtil.isNotEmpty(multipleAccumulatedData)) {
+            multipleAccumulatedData.forEach(data -> {
+                String uniqueKey = StrUtil.join("-", data.getDeviceId(), data.getPointName());
+                tempTotalRunDataPair.put(uniqueKey, data.getTotalRunTime());
+                // 设置每个设备对应的多个累计类型属性集合
+                if (deviceRunLogPair.containsKey(data.getDeviceId())) {
+                    List<IotDeviceRunLogRespVO> tempRunLogs = deviceRunLogPair.get(data.getDeviceId());
+                    tempRunLogs.add(data);
+                    deviceRunLogPair.put(data.getDeviceId(), tempRunLogs);
+                } else {
+                    List<IotDeviceRunLogRespVO> tempRunLogs = new ArrayList<>();
+                    tempRunLogs.add(data);
+                    deviceRunLogPair.put(data.getDeviceId(), tempRunLogs);
+                }
+            });
+        }
         Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(convertListByFlatMap(BOMs,
                 bom -> Stream.of(bom.getDeviceId())));
         // 2. 转换成 VO
@@ -167,16 +226,46 @@ public class IotMaintenanceBomController {
                     device -> bomVO.setDeviceName(device.getDeviceName()));
             MapUtils.findAndThen(deviceMap, bomVO.getDeviceId(),
                     device -> bomVO.setDeviceCode(device.getDeviceCode()));
-            // 获取设备ID对应的累积类型的属性集合
+            // 获取设备ID对应的累积类型的属性集合 正常的累计类型属性
             List<IotModelTemplateAttrsDO> deviceAttrs = deviceAttrsPair.get(bomVO.getDeviceId());
             if (CollUtil.isNotEmpty(deviceAttrs) && deviceAttrs.size() > 2) {
-                // 模板属性中有多个 累计运行时长 或 累计运行公里数 属性 需要使用另外的方式赋值(保养计划配置时选择)
+                // 模板属性中有多个 累计运行时长 或 累计运行公里数 属性 需要使用另外的方式赋值(保养计划配置时 绑定运行记录模板属性)
             } else {
                 MapUtils.findAndThen(deviceRunLogMap, bomVO.getDeviceId(),
                         device -> bomVO.setTotalMileage(device.getTotalMileage()));
                 MapUtils.findAndThen(deviceRunLogMap, bomVO.getDeviceId(),
                         device -> bomVO.setTotalRunTime(device.getTotalRunTime()));
             }
+            // 组装 运行记录模板中包含的多个累计类型属性
+            if (StrUtil.isNotBlank(bomVO.getCode())) {
+                // code 累计运行时长属性名称
+                String uniqueKey = StrUtil.join("-", bomVO.getDeviceId(), bomVO.getCode());
+                if (tempTotalRunDataPair.containsKey(uniqueKey)) {
+                    bomVO.setTempTotalRunTime(tempTotalRunDataPair.get(uniqueKey));
+                }
+            }
+            if (StrUtil.isNotBlank(bomVO.getType())) {
+                // type 累计运行公里数属性名称
+                String uniqueKey = StrUtil.join("-", bomVO.getDeviceId(), bomVO.getType());
+                if (tempTotalRunDataPair.containsKey(uniqueKey)) {
+                    bomVO.setTempTotalMileage(tempTotalRunDataPair.get(uniqueKey));
+                }
+            }
+            if (deviceRunLogPair.containsKey(bomVO.getDeviceId())) {
+                // 设置每个保养项对应的 多个累计类型属性集合
+                // 区分开 时间 里程 的累计属性列表 便于前端选择
+                List<IotDeviceRunLogRespVO> mileageRunLogs = new ArrayList<>();
+                List<IotDeviceRunLogRespVO> timeRunLogs = deviceRunLogPair.get(bomVO.getDeviceId());
+                timeRunLogs.forEach(log -> {
+                    log.setType(1);
+                    IotDeviceRunLogRespVO tempRunLog = new IotDeviceRunLogRespVO();
+                    BeanUtils.copyProperties(log, tempRunLog);
+                    tempRunLog.setType(2);
+                    mileageRunLogs.add(tempRunLog);
+                });
+                bomVO.setTimeAccumulatedAttrs(timeRunLogs);
+                bomVO.setMileageAccumulatedAttrs(mileageRunLogs);
+            }
         });
     }
 

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

@@ -1,5 +1,6 @@
 package cn.iocoder.yudao.module.pms.controller.admin.iotmaintenancebom.vo;
 
+import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO;
 import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
 import com.alibaba.excel.annotation.ExcelProperty;
 import io.swagger.v3.oas.annotations.media.Schema;
@@ -7,6 +8,7 @@ import lombok.Data;
 
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
+import java.util.List;
 
 @Schema(description = "管理后台 - PMS 保养计划明细BOM Response VO")
 @Data
@@ -147,4 +149,15 @@ public class IotMaintenanceBomRespVO {
     @Schema(description = "累计运行公里数", example = "20238km")
     private BigDecimal totalMileage;
 
+    @Schema(description = "临时 累计运行时间 用于运行记录模板中包含多个累计类型属性的场景", example = "30000H")
+    private BigDecimal tempTotalRunTime;
+    @Schema(description = "临时 累计运行公里数 用于运行记录模板中包含多个累计类型属性的场景", example = "20238km")
+    private BigDecimal tempTotalMileage;
+
+    @Schema(description = "模板中涉及多个累计运转时长的属性集合")
+    private List<IotDeviceRunLogRespVO> timeAccumulatedAttrs;
+
+    @Schema(description = "模板中涉及多个累计运行公里数的属性集合")
+    private List<IotDeviceRunLogRespVO> mileageAccumulatedAttrs;
+
 }

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

@@ -9,10 +9,7 @@ import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDevice
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO;
 
 import javax.validation.Valid;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * 设备运行数据记录 中间表 Service 接口
@@ -66,6 +63,13 @@ public interface IotDeviceRunLogService {
      */
     List<IotDeviceRunLogRespVO> distinctDevices(List<Long> ids);
 
+    /**
+     * 查询指定设备 运行记录模板属性对应的累计时长 累计里程
+     * @param deviceIds
+     * @return
+     */
+    List<IotDeviceRunLogRespVO> multipleAccumulatedData(Collection<Long> deviceIds, Collection<String> attrNames);
+
     /**
      * 根据设备id查询设备关联信息
      *

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

@@ -12,6 +12,7 @@ import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
 
+import java.util.Collection;
 import java.util.List;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -76,4 +77,9 @@ public class IotDeviceRunLogServiceImpl implements IotDeviceRunLogService {
         return iotDeviceRunLogMapper.distinctDevices(ids);
     }
 
+    @Override
+    public List<IotDeviceRunLogRespVO> multipleAccumulatedData(Collection<Long> deviceIds, Collection<String> attrNames) {
+        return iotDeviceRunLogMapper.multipleAccumulatedData(deviceIds, attrNames);
+    }
+
 }