|
@@ -10,14 +10,18 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotdevicematerial.vo.IotDeviceMaterialPageReqVO;
|
|
|
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.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.iotdevicematerial.IotDeviceMaterialDO;
|
|
|
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;
|
|
|
import cn.iocoder.yudao.module.pms.service.iotdevicerunlog.IotDeviceRunLogService;
|
|
|
+import cn.iocoder.yudao.module.pms.service.iotmainworkorder.IotMainWorkOrderService;
|
|
|
import cn.iocoder.yudao.module.pms.service.iotmainworkorderbom.IotMainWorkOrderBomService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
@@ -31,6 +35,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
@@ -50,6 +55,10 @@ public class IotMainWorkOrderBomController {
|
|
|
private IotDeviceService iotDeviceService;
|
|
|
@Resource
|
|
|
private IotDeviceRunLogService iotDeviceRunLogService;
|
|
|
+ @Resource
|
|
|
+ private IotMainWorkOrderService iotMainWorkOrderService;
|
|
|
+ @Resource
|
|
|
+ private IotDeviceMaterialService iotDeviceMaterialService;
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
@Operation(summary = "创建PMS 保养计划明细BOM")
|
|
@@ -129,16 +138,21 @@ public class IotMainWorkOrderBomController {
|
|
|
Set<String> pointNames = new HashSet<>();
|
|
|
// 所有保养工单明细包含的设备id集合
|
|
|
Set<Long> deviceIds = new HashSet<>();
|
|
|
+ // 保养j明细 保养项BOM节点id集合
|
|
|
+ Set<Long> bomNodeIds = 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());
|
|
|
});
|
|
|
// 查询 运行记录模板中包含多个累计 时长 公里数 属性的集合
|
|
|
List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
|
|
@@ -154,6 +168,40 @@ public class IotMainWorkOrderBomController {
|
|
|
tempTotalRunDataPair.put(uniqueKey, data.getTotalRunTime());
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ // 查询所有保养项 历史保养记录 (保养项所有历史工单中最新的保养时间)
|
|
|
+ Map<String, LocalDateTime> latestMaintenanceDatePair = new HashMap<>();
|
|
|
+ if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(bomNodeIds)) {
|
|
|
+ List<IotMainWorkOrderBomDO> latestWorkOrderBomS = iotMainWorkOrderService.historyWorkOrderBoms(deviceIds, bomNodeIds);
|
|
|
+ if (CollUtil.isNotEmpty(latestWorkOrderBomS)) {
|
|
|
+ latestWorkOrderBomS.forEach(bom -> {
|
|
|
+ String uniqueKey = StrUtil.join("-", bom.getDeviceId(), bom.getBomNodeId());
|
|
|
+ latestMaintenanceDatePair.put(uniqueKey, bom.getUpdateTime());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询每个保养项上关联的物料列表
|
|
|
+ IotDeviceMaterialPageReqVO reqVO = new IotDeviceMaterialPageReqVO();
|
|
|
+ reqVO.setDeviceIds(new ArrayList<>(deviceIds));
|
|
|
+ reqVO.setBomNodeIds(new ArrayList<>(bomNodeIds));
|
|
|
+ List<IotDeviceMaterialDO> deviceBomMaterials = iotDeviceMaterialService.deviceBomMaterials(reqVO);
|
|
|
+ Map<String, List<IotDeviceMaterialDO>> deviceBomMaterialPair = new HashMap<>();
|
|
|
+ if (CollUtil.isNotEmpty(deviceBomMaterials)) {
|
|
|
+ deviceBomMaterials.forEach(bomMaterial -> {
|
|
|
+ String uniqueKey = StrUtil.join("-", bomMaterial.getDeviceId(), bomMaterial.getBomNodeId());
|
|
|
+ if (deviceBomMaterialPair.containsKey(uniqueKey)) {
|
|
|
+ List<IotDeviceMaterialDO> tempBomMaterials = deviceBomMaterialPair.get(uniqueKey);
|
|
|
+ tempBomMaterials.add(bomMaterial);
|
|
|
+ deviceBomMaterialPair.put(uniqueKey, tempBomMaterials);
|
|
|
+ } else {
|
|
|
+ List<IotDeviceMaterialDO> tempBomMaterials = new ArrayList<>();
|
|
|
+ tempBomMaterials.add(bomMaterial);
|
|
|
+ deviceBomMaterialPair.put(uniqueKey, tempBomMaterials);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
// 2. 转换成 VO
|
|
|
return BeanUtils.toBean(BOMs, IotMainWorkOrderBomRespVO.class, bomVO -> {
|
|
|
// 设置设备相关信息
|
|
@@ -181,6 +229,14 @@ public class IotMainWorkOrderBomController {
|
|
|
bomVO.setTempTotalMileage(tempTotalRunDataPair.get(uniqueKey));
|
|
|
}
|
|
|
}
|
|
|
+ // 设置保养项的上次保养时间
|
|
|
+ String uniqueKey = StrUtil.join("-", bomVO.getDeviceId(), bomVO.getBomNodeId());
|
|
|
+ if (latestMaintenanceDatePair.containsKey(uniqueKey)) {
|
|
|
+ bomVO.setLastMaintenanceDate(latestMaintenanceDatePair.get(uniqueKey));
|
|
|
+ }
|
|
|
+ if (deviceBomMaterialPair.containsKey(uniqueKey)) {
|
|
|
+ bomVO.setDeviceBomMaterials(deviceBomMaterialPair.get(uniqueKey));
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
}
|