|
@@ -42,7 +42,6 @@ import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
|
-import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
@@ -91,9 +90,18 @@ public class CreateMainWorkOrderJob implements JobHandler {
|
|
|
return "没有待保养项";
|
|
|
}
|
|
|
List<Long> deviceIds = new ArrayList<>();
|
|
|
+ // 运行记录模板中 多种 累计时长 公里数 属性名称集合
|
|
|
+ Set<String> boundedMultiAttrNames = new HashSet<>();
|
|
|
mainBomList.forEach(bom -> {
|
|
|
// 查询保养计划明细中所有设备id
|
|
|
deviceIds.add(bom.getDeviceId());
|
|
|
+ // 查询保养计划明细已经绑定的 多种 累计时长 公里数 属性名称
|
|
|
+ if (StrUtil.isNotBlank(bom.getCode())) {
|
|
|
+ boundedMultiAttrNames.add(bom.getCode());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(bom.getType())) {
|
|
|
+ boundedMultiAttrNames.add(bom.getType());
|
|
|
+ }
|
|
|
});
|
|
|
if (CollUtil.isEmpty(deviceIds)) {
|
|
|
return "没有设备信息";
|
|
@@ -116,6 +124,20 @@ public class CreateMainWorkOrderJob implements JobHandler {
|
|
|
}
|
|
|
// 查询所有设备名称 设备编码集合
|
|
|
Map<Long, IotDeviceRespVO> devices = iotDeviceService.getDeviceMap(deviceIds);
|
|
|
+ // 查询 保养计划保养明细中已经绑定的 多种累计时长 公里数 属性集合
|
|
|
+ List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
|
|
|
+ if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(boundedMultiAttrNames)) {
|
|
|
+ multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames);
|
|
|
+ }
|
|
|
+ // key(设备id-累计时长属性名称) value时长属性累计时长数值
|
|
|
+ Map<String, BigDecimal> tempTotalRunDataPair = new HashMap<>();
|
|
|
+ if (CollUtil.isNotEmpty(multipleAccumulatedData)) {
|
|
|
+ multipleAccumulatedData.forEach(data -> {
|
|
|
+ String uniqueKey = StrUtil.join("-", data.getDeviceId(), data.getPointName());
|
|
|
+ tempTotalRunDataPair.put(uniqueKey, data.getTotalRunTime());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
// 查询保养计划明细中所有设备的累计运行里程、累计运行时间
|
|
|
Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(convertListByFlatMap(mainBomList,
|
|
|
bom -> Stream.of(bom.getDeviceId())));
|
|
@@ -130,30 +152,44 @@ public class CreateMainWorkOrderJob implements JobHandler {
|
|
|
boolean runningKiloArrive = false;
|
|
|
boolean naturalDateArrive = false;
|
|
|
// 只有维护了累计运行时间、累计运行里程 运行记录的设备才能触发 里程周期 时间周期 保养规则
|
|
|
+ BigDecimal totalRunTime = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalMileage = BigDecimal.ZERO;
|
|
|
if (deviceRunLogMap.containsKey(bom.getDeviceId())) {
|
|
|
- BigDecimal totalRunTime = deviceRunLogMap.get(bom.getDeviceId()).getTotalRunTime();
|
|
|
- BigDecimal totalMileage = deviceRunLogMap.get(bom.getDeviceId()).getTotalMileage();
|
|
|
- if (0 == bom.getRunningTimeRule()) {
|
|
|
- // 累计运行时间规则 累计运行时间 >= (上次保养运行时间+运行时间周期-提前量)
|
|
|
- BigDecimal lastRunningTime = bom.getLastRunningTime(); // 上次保养运行时间
|
|
|
- BigDecimal runningTimePeriod = bom.getNextRunningTime(); // 运行时间周期
|
|
|
- BigDecimal timePeriodLead = bom.getTimePeriodLead(); // 运行时间周期提前量
|
|
|
- if (((runningTimePeriod.subtract(totalRunTime.subtract(lastRunningTime))).subtract(timePeriodLead)).compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
- runningTimeArrive = true;
|
|
|
- }
|
|
|
+ // 正常的累计时长 公里数
|
|
|
+ totalRunTime = deviceRunLogMap.get(bom.getDeviceId()).getTotalRunTime();
|
|
|
+ totalMileage = deviceRunLogMap.get(bom.getDeviceId()).getTotalMileage();
|
|
|
+ } else {
|
|
|
+ // 保养项绑定的 累计时长 类型的属性值
|
|
|
+ String uniqueKey = StrUtil.join("-", bom.getDeviceId(), bom.getCode());
|
|
|
+ if (tempTotalRunDataPair.containsKey(uniqueKey)) {
|
|
|
+ totalRunTime = tempTotalRunDataPair.get(uniqueKey);
|
|
|
}
|
|
|
- if (0 == bom.getMileageRule()) {
|
|
|
- // 累计运行里程规则 累计运行里程 >= (上次保养运行里程+运行里程周期-提前量)
|
|
|
- BigDecimal lastRunningKilo = bom.getLastRunningKilometers(); // 上次保养运行里程
|
|
|
- BigDecimal runningKiloPeriod = bom.getNextRunningKilometers(); // 运行里程周期
|
|
|
- BigDecimal kiloCycleLead = bom.getKiloCycleLead(); // 运行里程周期提前量
|
|
|
- if (((runningKiloPeriod.subtract(totalMileage.subtract(lastRunningKilo))).subtract(kiloCycleLead)).compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
- runningTimeArrive = true;
|
|
|
- }
|
|
|
+ // 保养项绑定的 累计公里数类型的属性值
|
|
|
+ String uniqueKeyType = StrUtil.join("-", bom.getDeviceId(), bom.getType());
|
|
|
+ if (tempTotalRunDataPair.containsKey(uniqueKeyType)) {
|
|
|
+ totalMileage = tempTotalRunDataPair.get(uniqueKeyType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjUtil.isNotEmpty(bom.getRunningTimeRule()) && 0 == bom.getRunningTimeRule()) {
|
|
|
+ // 累计运行时间规则 累计运行时间 >= (上次保养运行时间+运行时间周期-提前量)
|
|
|
+ BigDecimal lastRunningTime = bom.getLastRunningTime(); // 上次保养运行时间
|
|
|
+ BigDecimal runningTimePeriod = bom.getNextRunningTime(); // 运行时间周期
|
|
|
+ BigDecimal timePeriodLead = bom.getTimePeriodLead(); // 运行时间周期提前量
|
|
|
+ if (((runningTimePeriod.subtract(totalRunTime.subtract(lastRunningTime))).subtract(timePeriodLead)).compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ runningTimeArrive = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjUtil.isNotEmpty(bom.getMileageRule()) && 0 == bom.getMileageRule()) {
|
|
|
+ // 累计运行里程规则 累计运行里程 >= (上次保养运行里程+运行里程周期-提前量)
|
|
|
+ BigDecimal lastRunningKilo = bom.getLastRunningKilometers(); // 上次保养运行里程
|
|
|
+ BigDecimal runningKiloPeriod = bom.getNextRunningKilometers(); // 运行里程周期
|
|
|
+ BigDecimal kiloCycleLead = bom.getKiloCycleLead(); // 运行里程周期提前量
|
|
|
+ if (((runningKiloPeriod.subtract(totalMileage.subtract(lastRunningKilo))).subtract(kiloCycleLead)).compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ runningTimeArrive = true;
|
|
|
}
|
|
|
}
|
|
|
// 没有维护 累计运行时间、累计运行里程 运行记录的设备 可以触发 自然日周期 保养规则
|
|
|
- if (0 == bom.getNaturalDateRule()) {
|
|
|
+ if (ObjUtil.isNotEmpty(bom.getNaturalDateRule()) && 0 == bom.getNaturalDateRule()) {
|
|
|
// 自然日期规则 当前日期 >= (上次保养自然日期+自然日周期-提前量)
|
|
|
LocalDateTime lastNaturalDate = bom.getLastNaturalDate(); // 上次保养自然日期
|
|
|
BigDecimal naturalDatePeriod = bom.getNextNaturalDate(); // 自然日周期
|