|
@@ -30,6 +30,7 @@ import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
+import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
|
|
@@ -78,7 +79,18 @@ public class CreateMainWorkOrderJob implements JobHandler {
|
|
|
IotDevicePersonPageReqVO devicePersonReqVO = new IotDevicePersonPageReqVO();
|
|
|
devicePersonReqVO.setDeviceIds(deviceIds);
|
|
|
List<IotDevicePersonDO> devicePersons = iotDevicePersonService.getPersonsByDeviceIds(devicePersonReqVO);
|
|
|
-
|
|
|
+ Map<Long, List<Long>> devicePersonPair = new HashMap<>();
|
|
|
+ if (CollUtil.isNotEmpty(devicePersons)) {
|
|
|
+ devicePersonPair = devicePersons.stream()
|
|
|
+ .filter(person -> person.getDeviceId() != null) // 过滤deviceId为null的记录
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ IotDevicePersonDO::getDeviceId, // 按deviceId分组
|
|
|
+ Collectors.mapping(
|
|
|
+ IotDevicePersonDO::getPersonId, // 提取personId
|
|
|
+ Collectors.toList() // 收集为列表
|
|
|
+ )
|
|
|
+ ));
|
|
|
+ }
|
|
|
// 查询保养计划明细中所有设备的累计运行里程、累计运行时间
|
|
|
Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(convertListByFlatMap(mainBomList,
|
|
|
bom -> Stream.of(bom.getDeviceId())));
|
|
@@ -141,11 +153,11 @@ public class CreateMainWorkOrderJob implements JobHandler {
|
|
|
tobeMainBomIds.add(bom.getBomNodeId());
|
|
|
}
|
|
|
});
|
|
|
+ // key保养计划id value保养计划
|
|
|
Map<Long, IotMaintenancePlanDO> maintenancePair = new HashMap<>();
|
|
|
plans.forEach(plan -> {
|
|
|
maintenancePair.put(plan.getId(), plan);
|
|
|
});
|
|
|
- System.out.println("保养计划集合中所有元素:" + maintenancePair.size());
|
|
|
if (CollUtil.isNotEmpty(tobeMaintenanceBomList)) {
|
|
|
// 如果有可以触发的保养项 查询保养工单明细中是否存在相同保养项 未填报完成的保养工单 如果有则不生成新的保养工单
|
|
|
IotMainWorkOrderBomPageReqVO bomReqVO = new IotMainWorkOrderBomPageReqVO();
|
|
@@ -194,12 +206,14 @@ public class CreateMainWorkOrderJob implements JobHandler {
|
|
|
}
|
|
|
});
|
|
|
// 以保养计划id对待保养工单分组 分组后便于生成 保养工单主表记录
|
|
|
+ // key保养计划id value待保养工单明细集合
|
|
|
Map<Long, List<IotMainWorkOrderBomDO>> workOrderBomPair = new HashMap<>();
|
|
|
+ // 以设备为维度 统计每种设备对应的 保养项集合 key保养计划id+设备id value设备对应的保养项集合
|
|
|
+ Map<String, List<IotMainWorkOrderBomDO>> deviceBomPair = new HashMap<>();
|
|
|
// 最终使用的保养工单明细 设置了保养工单主表id
|
|
|
List<IotMainWorkOrderBomDO> finalWorkOrderBomS = new ArrayList<>();
|
|
|
if (CollUtil.isNotEmpty(workOrderBOMs)) {
|
|
|
workOrderBOMs.forEach(workOrderBom -> {
|
|
|
- System.out.println("保养工单明细中保留的临时保养计划id:" + workOrderBom.getWorkOrderId());
|
|
|
if (workOrderBomPair.containsKey(workOrderBom.getWorkOrderId())) {
|
|
|
List<IotMainWorkOrderBomDO> tempOrderBomS = workOrderBomPair.get(workOrderBom.getWorkOrderId());
|
|
|
tempOrderBomS.add(workOrderBom);
|
|
@@ -210,12 +224,28 @@ public class CreateMainWorkOrderJob implements JobHandler {
|
|
|
workOrderBomPair.put(workOrderBom.getWorkOrderId(), tempOrderBomS);
|
|
|
}
|
|
|
});
|
|
|
+ // 组装设备及对应的 保养项集合 map
|
|
|
+ workOrderBOMs.forEach(bom -> {
|
|
|
+ String uniqueKey = bom.getWorkOrderId()+"-"+bom.getDeviceId();
|
|
|
+ if (deviceBomPair.containsKey(uniqueKey)) {
|
|
|
+ List<IotMainWorkOrderBomDO> tempOrderBomS = deviceBomPair.get(uniqueKey);
|
|
|
+ tempOrderBomS.add(bom);
|
|
|
+ deviceBomPair.put(uniqueKey, tempOrderBomS);
|
|
|
+ } else {
|
|
|
+ List<IotMainWorkOrderBomDO> tempOrderBomS = new ArrayList<>();
|
|
|
+ tempOrderBomS.add(bom);
|
|
|
+ deviceBomPair.put(uniqueKey, tempOrderBomS);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 按照 保养计划id+设备id 分组 每个"保养计划id+设备id" 生成一个工单
|
|
|
+ deviceBomPair.forEach((k,v) -> {
|
|
|
+
|
|
|
+ });
|
|
|
|
|
|
workOrderBomPair.forEach((k,v) -> {
|
|
|
// k保养计划id v已经触发的保养工单明细
|
|
|
- // 根据每个保养计划生成一个保养工单
|
|
|
IotMaintenancePlanDO plan = maintenancePair.get(k);
|
|
|
- System.out.println("保养计划id:" + k);
|
|
|
IotMainWorkOrderDO workOrder = new IotMainWorkOrderDO();
|
|
|
theMaxId.getAndSet(theMaxId.get() + 1);
|
|
|
workOrder.setId(theMaxId.get());
|
|
@@ -245,7 +275,6 @@ public class CreateMainWorkOrderJob implements JobHandler {
|
|
|
iotMainWorkOrderBomService.batchAddOrderBOMs(finalWorkOrderBomS);
|
|
|
}
|
|
|
}
|
|
|
- // 查询需要保养的node节点是否包含在正在执行的保养工单中
|
|
|
return "创建成功";
|
|
|
}
|
|
|
}
|