|
@@ -147,6 +147,12 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
|
return iotMainWorkOrderMapper.selectPage(pageReqVO);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<IotMainWorkOrderDO> workOrders(IotMainWorkOrderPageReqVO pageReqVO) {
|
|
|
+ List<IotMainWorkOrderDO> orders= iotMainWorkOrderMapper.selectList(pageReqVO);
|
|
|
+ return CollUtil.isNotEmpty(orders) ? orders : new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public PageResult<IotMainWorkOrderRespVO> sortedMainWorkOrderPage(IotMainWorkOrderPageReqVO pageReqVO) {
|
|
|
// 查询 未执行 计划生成 的工单
|
|
@@ -423,6 +429,8 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
|
Map<Long, List<Map<String, Object>>> orderDistancePair = new HashMap<>();
|
|
|
// 设备保养明细 key设备id value设备保养工单明细下所有保养规则数据最小值
|
|
|
Map<Long, String> resultMap = new HashMap<>();
|
|
|
+ // 记录保养项的 提前量 key设备id-保养项id-距离保养值 value提前量
|
|
|
+ Map<String, BigDecimal> bomLeadPair = new HashMap<>();
|
|
|
if (CollUtil.isNotEmpty(mainBomS)) {
|
|
|
// 遍历保养计划明细 计算 保养计划中的设备 的最近的保养时间
|
|
|
for (IotMaintenanceBomDO bom : mainBomS) {
|
|
@@ -446,6 +454,8 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
|
BigDecimal runningTimePeriod = bom.getNextRunningTime(); // 运行时间周期
|
|
|
BigDecimal timePeriodLead = bom.getTimePeriodLead(); // 运行时间周期提前量
|
|
|
runningTimeDistance = runningTimePeriod.subtract(totalRunTime.subtract(lastRunningTime));
|
|
|
+ String uniqueKey = StrUtil.join("-", bom.getDeviceId(), bom.getBomNodeId(), runningTimeDistance);
|
|
|
+ bomLeadPair.put(uniqueKey, timePeriodLead);
|
|
|
}
|
|
|
if (ObjUtil.isNotEmpty(bom.getMileageRule()) && 0 == bom.getMileageRule()) {
|
|
|
// 运行里程保养规则 累计运行里程规则 累计运行里程 >= (上次保养运行里程+运行里程周期-提前量)
|
|
@@ -463,6 +473,8 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
|
BigDecimal runningKiloPeriod = bom.getNextRunningKilometers(); // 运行里程周期
|
|
|
BigDecimal kiloCycleLead = bom.getKiloCycleLead(); // 运行里程周期提前量
|
|
|
runningKiloDistance = runningKiloPeriod.subtract(totalMileage.subtract(lastRunningKilo));
|
|
|
+ String uniqueKey = StrUtil.join("-", bom.getDeviceId(), bom.getBomNodeId(), runningKiloDistance);
|
|
|
+ bomLeadPair.put(uniqueKey, kiloCycleLead);
|
|
|
}
|
|
|
if (ObjUtil.isNotEmpty(bom.getNaturalDateRule()) && 0 == bom.getNaturalDateRule()) {
|
|
|
// 自然日期保养规则
|
|
@@ -478,6 +490,8 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
// 计算日期差值(以天为单位)
|
|
|
naturalDateDistance = new BigDecimal(ChronoUnit.DAYS.between(now, targetDate));
|
|
|
+ String uniqueKey = StrUtil.join("-", bom.getDeviceId(), bom.getBomNodeId(), naturalDateDistance);
|
|
|
+ bomLeadPair.put(uniqueKey, natualDateLead);
|
|
|
}
|
|
|
}
|
|
|
// 找出距离0最近的数,作为工单的最近保养距离数据
|
|
@@ -500,9 +514,6 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
|
orderDistancePair.put(bom.getDeviceId(), tempDistances);
|
|
|
}
|
|
|
}
|
|
|
- mainBomS.forEach(bom -> {
|
|
|
-
|
|
|
- });
|
|
|
}
|
|
|
// 计算出每个保养工单明细的不同保养规则的保养距离最小值
|
|
|
if (CollUtil.isNotEmpty(workOrderBomS)) {
|
|
@@ -573,6 +584,32 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
|
}
|
|
|
// 以设备id 为维度 统计每个保养工单明细中 距离最近的保养数据
|
|
|
resultMap = findClosestToZero(orderDistancePair);
|
|
|
+ // 根据保养项规则应该生成保养工单的设备id集合
|
|
|
+ Set<Long> shouldWorkOrderFlags = new HashSet<>();
|
|
|
+ // 找出设备保养项距离保养最小值对应的 提前量
|
|
|
+ if (CollUtil.isNotEmpty(resultMap)) {
|
|
|
+ resultMap.forEach((k,v) -> {
|
|
|
+ // k设备id v距离保养最小值(带单位)
|
|
|
+ // 去掉v中带的单位 310 D -61.00 H
|
|
|
+ String[] distanceStrs = v.split(" ");
|
|
|
+ BigDecimal tempDistance = new BigDecimal(distanceStrs[0]);
|
|
|
+ if (tempDistance.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ shouldWorkOrderFlags.add(k);
|
|
|
+ }
|
|
|
+ if (CollUtil.isNotEmpty(bomLeadPair)) {
|
|
|
+ bomLeadPair.forEach((key,value) -> {
|
|
|
+ // key设备id-保养项id-距离保养值 value提前量
|
|
|
+ String[] uniqueKeyStrs = key.split("-");
|
|
|
+ if (uniqueKeyStrs.length == 3) {
|
|
|
+ if (String.valueOf(k).equals(uniqueKeyStrs[0]) && distanceStrs[0].equals(uniqueKeyStrs[2])
|
|
|
+ && tempDistance.compareTo(BigDecimal.ZERO)>=0 && tempDistance.compareTo(value)<=0 ) {
|
|
|
+ shouldWorkOrderFlags.add(k);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
// 对集合 resultMap 中所有数据进行排序 按照 map 的value值 去除后面的 字符后 升序排列
|
|
|
// 排序后输出一个 List<Long> 类型的集合,排序对应上面的排序规则
|
|
|
List<Long> sortedDeviceIds = sortByNumericValue(resultMap);
|
|
@@ -608,6 +645,9 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
|
device.setPlanId(alarmDevicePair.get(device.getId()).getPlanId());
|
|
|
device.setWorkOrderId(alarmDevicePair.get(device.getId()).getWorkOrderId());
|
|
|
}
|
|
|
+ if (shouldWorkOrderFlags.contains(device.getId())) {
|
|
|
+ device.setShouldWorkOrder(true);
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
return new PageResult<>(page.getRecords(), page.getTotal());
|