|
@@ -12,11 +12,14 @@ import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDevice
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmaintenancebom.vo.IotMaintenanceBomPageReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmaintenancebom.vo.IotMaintenanceBomPageReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmaintenancebom.vo.IotMaintenanceBomRespVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmaintenancebom.vo.IotMaintenanceBomRespVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmaintenancebom.vo.IotMaintenanceBomSaveReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmaintenancebom.vo.IotMaintenanceBomSaveReqVO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotmodeltemplateattrs.vo.IotModelTemplateAttrsPageReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotmaintenancebom.IotMaintenanceBomDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotmaintenancebom.IotMaintenanceBomDO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotmodeltemplateattrs.IotModelTemplateAttrsDO;
|
|
import cn.iocoder.yudao.module.pms.service.IotDeviceService;
|
|
import cn.iocoder.yudao.module.pms.service.IotDeviceService;
|
|
import cn.iocoder.yudao.module.pms.service.iotdevicerunlog.IotDeviceRunLogService;
|
|
import cn.iocoder.yudao.module.pms.service.iotdevicerunlog.IotDeviceRunLogService;
|
|
import cn.iocoder.yudao.module.pms.service.iotmaintenancebom.IotMaintenanceBomService;
|
|
import cn.iocoder.yudao.module.pms.service.iotmaintenancebom.IotMaintenanceBomService;
|
|
|
|
+import cn.iocoder.yudao.module.pms.service.iotmodeltemplateattrs.IotModelTemplateAttrsService;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
@@ -28,9 +31,7 @@ import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.util.Collections;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.stream.Stream;
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
|
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
|
@@ -49,6 +50,8 @@ public class IotMaintenanceBomController {
|
|
private IotDeviceService iotDeviceService;
|
|
private IotDeviceService iotDeviceService;
|
|
@Resource
|
|
@Resource
|
|
private IotDeviceRunLogService iotDeviceRunLogService;
|
|
private IotDeviceRunLogService iotDeviceRunLogService;
|
|
|
|
+ @Resource
|
|
|
|
+ private IotModelTemplateAttrsService iotModelTemplateAttrsService;
|
|
|
|
|
|
@PostMapping("/create")
|
|
@PostMapping("/create")
|
|
@Operation(summary = "创建PMS 保养计划明细BOM")
|
|
@Operation(summary = "创建PMS 保养计划明细BOM")
|
|
@@ -108,6 +111,53 @@ public class IotMaintenanceBomController {
|
|
// 组装bom关联的设备信息
|
|
// 组装bom关联的设备信息
|
|
Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(convertListByFlatMap(BOMs,
|
|
Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(convertListByFlatMap(BOMs,
|
|
bom -> Stream.of(bom.getDeviceId())));
|
|
bom -> Stream.of(bom.getDeviceId())));
|
|
|
|
+ // 设备对应的设备分类 map
|
|
|
|
+ Map<Long, Long> deviceCategoryPair = new HashMap<>();
|
|
|
|
+ Set<Long> deviceCategoryIds = new HashSet<>();
|
|
|
|
+ // 通过设备id集合查询到设备分类id集合
|
|
|
|
+ if (CollUtil.isNotEmpty(deviceMap)) {
|
|
|
|
+ deviceMap.forEach((k,v) -> {
|
|
|
|
+ deviceCategoryIds.add(v.getAssetClass());
|
|
|
|
+ deviceCategoryPair.put(k, v.getAssetClass());
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ // k设备id v设备分类包含的模板中与累计运行时长、累计运行公里数相关的属性集合
|
|
|
|
+ Map<Long, List<IotModelTemplateAttrsDO>> deviceAttrsPair = new HashMap<>();
|
|
|
|
+ if (CollUtil.isNotEmpty(deviceCategoryIds)) {
|
|
|
|
+ // 查询设备分类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<>();
|
|
|
|
+ if (CollUtil.isNotEmpty(accumulatedAttrs)) {
|
|
|
|
+ accumulatedAttrs.forEach(attr -> {
|
|
|
|
+ if (accumulatedAttrPair.containsKey(attr.getDeviceCategoryId())) {
|
|
|
|
+ List<IotModelTemplateAttrsDO> tempAttrs = accumulatedAttrPair.get(attr.getDeviceCategoryId());
|
|
|
|
+ tempAttrs.add(attr);
|
|
|
|
+ accumulatedAttrPair.put(attr.getDeviceCategoryId(), tempAttrs);
|
|
|
|
+ } else {
|
|
|
|
+ List<IotModelTemplateAttrsDO> tempAttrs = new ArrayList<>();
|
|
|
|
+ tempAttrs.add(attr);
|
|
|
|
+ accumulatedAttrPair.put(attr.getDeviceCategoryId(), tempAttrs);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if (CollUtil.isNotEmpty(accumulatedAttrPair)) {
|
|
|
|
+ accumulatedAttrPair.forEach((k,v) -> {
|
|
|
|
+ // k设备分类id v设备分类包含的模板中与累计运行时长 累计运行公里数相关的属性集合
|
|
|
|
+ deviceCategoryPair.forEach((ik, iv) -> {
|
|
|
|
+ // ik设备id iv设备分类id
|
|
|
|
+ if (iv.equals(k)) {
|
|
|
|
+ deviceAttrsPair.put(ik, v);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(convertListByFlatMap(BOMs,
|
|
Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(convertListByFlatMap(BOMs,
|
|
bom -> Stream.of(bom.getDeviceId())));
|
|
bom -> Stream.of(bom.getDeviceId())));
|
|
// 2. 转换成 VO
|
|
// 2. 转换成 VO
|
|
@@ -117,10 +167,16 @@ public class IotMaintenanceBomController {
|
|
device -> bomVO.setDeviceName(device.getDeviceName()));
|
|
device -> bomVO.setDeviceName(device.getDeviceName()));
|
|
MapUtils.findAndThen(deviceMap, bomVO.getDeviceId(),
|
|
MapUtils.findAndThen(deviceMap, bomVO.getDeviceId(),
|
|
device -> bomVO.setDeviceCode(device.getDeviceCode()));
|
|
device -> bomVO.setDeviceCode(device.getDeviceCode()));
|
|
- MapUtils.findAndThen(deviceRunLogMap, bomVO.getDeviceId(),
|
|
|
|
- device -> bomVO.setTotalMileage(device.getTotalMileage()));
|
|
|
|
- MapUtils.findAndThen(deviceRunLogMap, bomVO.getDeviceId(),
|
|
|
|
- device -> bomVO.setTotalRunTime(device.getTotalRunTime()));
|
|
|
|
|
|
+ // 获取设备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()));
|
|
|
|
+ }
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|