|
@@ -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);
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
|