|
@@ -109,13 +109,35 @@ public class IotMainWorkOrderBomServiceImpl implements IotMainWorkOrderBomServic
|
|
|
public Map<Long, String> mainWorkOrderNearestDistance(IotMainWorkOrderBomPageReqVO pageReqVO) {
|
|
|
List<IotMainWorkOrderBomDO> workOrderBomS = getIotMainWorkOrderBomList(pageReqVO);
|
|
|
Map<Long, String> resultMap = new HashMap<>();
|
|
|
-
|
|
|
+ // 查找所有保养工单明细 继承自 保养计划明细 的 code累计运行时长属性名称 type累计运行公里数属性名称
|
|
|
+ // 运行记录模板中 多种 累计时长 公里数 属性名称集合
|
|
|
+ Set<String> boundedMultiAttrNames = new HashSet<>();
|
|
|
// 遍历工单明细 找出每个工单中 触发保养时间最近的 时间/里程/自然日
|
|
|
if (CollUtil.isNotEmpty(workOrderBomS)) {
|
|
|
Set<Long> deviceIds = new HashSet<>();
|
|
|
workOrderBomS.forEach(bom -> {
|
|
|
deviceIds.add(bom.getDeviceId());
|
|
|
+ if (StrUtil.isNotBlank(bom.getCode())) {
|
|
|
+ boundedMultiAttrNames.add(bom.getCode());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(bom.getType())) {
|
|
|
+ boundedMultiAttrNames.add(bom.getType());
|
|
|
+ }
|
|
|
});
|
|
|
+ // 查询 保养工单保养明细中已经绑定的 多种累计时长 公里数 属性运行记录值集合
|
|
|
+ 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(new ArrayList<>(deviceIds));
|
|
|
Map<Long, List<Map<String, Object>>> orderDistancePair = new HashMap<>();
|
|
@@ -123,31 +145,50 @@ public class IotMainWorkOrderBomServiceImpl implements IotMainWorkOrderBomServic
|
|
|
BigDecimal runningTimeDistance = null;
|
|
|
BigDecimal runningKiloDistance = null;
|
|
|
BigDecimal naturalDateDistance = null;
|
|
|
+ // 运行记录模板中维护的属性 填报的累计值
|
|
|
+ BigDecimal totalRunTime = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalMileage = BigDecimal.ZERO;
|
|
|
+ if (deviceRunLogMap.containsKey(bom.getDeviceId())) {
|
|
|
+ // 正常的累计时长 公里数
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ // 保养项绑定的 累计公里数类型的属性值
|
|
|
+ String uniqueKeyType = StrUtil.join("-", bom.getDeviceId(), bom.getType());
|
|
|
+ if (tempTotalRunDataPair.containsKey(uniqueKeyType)) {
|
|
|
+ totalMileage = tempTotalRunDataPair.get(uniqueKeyType);
|
|
|
+ }
|
|
|
+ }
|
|
|
// 计算每个保养项 每个保养规则下的 距离保养时间
|
|
|
if (ObjUtil.isNotEmpty(bom.getRunningTimeRule()) && 0 == bom.getRunningTimeRule()) {
|
|
|
// 运行时间保养规则
|
|
|
- if (deviceRunLogMap.containsKey(bom.getDeviceId())) {
|
|
|
- BigDecimal totalRunTime = deviceRunLogMap.get(bom.getDeviceId()).getTotalRunTime();
|
|
|
+ // if (deviceRunLogMap.containsKey(bom.getDeviceId())) {
|
|
|
+ // BigDecimal totalRunTime = deviceRunLogMap.get(bom.getDeviceId()).getTotalRunTime();
|
|
|
BigDecimal lastRunningTime = bom.getLastRunningTime(); // 上次保养运行时间
|
|
|
BigDecimal runningTimePeriod = bom.getNextRunningTime(); // 运行时间周期
|
|
|
BigDecimal timePeriodLead = bom.getTimePeriodLead(); // 运行时间周期提前量
|
|
|
BigDecimal delayDuration = bom.getDelayDuration(); // 推迟运行时长H
|
|
|
// runningTimeDistance = (lastRunningTime.add(runningTimePeriod).subtract(timePeriodLead)).subtract(totalRunTime);
|
|
|
runningTimeDistance = (runningTimePeriod.subtract(totalRunTime.subtract(lastRunningTime))).add(delayDuration);
|
|
|
- }
|
|
|
+ // }
|
|
|
}
|
|
|
if (ObjUtil.isNotEmpty(bom.getMileageRule()) && 0 == bom.getMileageRule()) {
|
|
|
// 运行里程保养规则
|
|
|
// 累计运行里程规则 累计运行里程 >= (上次保养运行里程+运行里程周期-提前量)
|
|
|
- if (deviceRunLogMap.containsKey(bom.getDeviceId())) {
|
|
|
- BigDecimal totalMileage = deviceRunLogMap.get(bom.getDeviceId()).getTotalMileage();
|
|
|
+ // if (deviceRunLogMap.containsKey(bom.getDeviceId())) {
|
|
|
+ // BigDecimal totalMileage = deviceRunLogMap.get(bom.getDeviceId()).getTotalMileage();
|
|
|
BigDecimal lastRunningKilo = bom.getLastRunningKilometers(); // 上次保养运行里程
|
|
|
BigDecimal runningKiloPeriod = bom.getNextRunningKilometers(); // 运行里程周期
|
|
|
BigDecimal kiloCycleLead = bom.getKiloCycleLead(); // 运行里程周期提前量
|
|
|
BigDecimal delayKilometers = bom.getDelayKilometers(); // 推迟运行公里数KM
|
|
|
// runningKiloDistance = (lastRunningKilo.add(runningKiloPeriod).subtract(kiloCycleLead)).subtract(totalMileage);
|
|
|
runningKiloDistance = (runningKiloPeriod.subtract(totalMileage.subtract(lastRunningKilo))).add(delayKilometers);
|
|
|
- }
|
|
|
+ // }
|
|
|
}
|
|
|
if (ObjUtil.isNotEmpty(bom.getNaturalDateRule()) && 0 == bom.getNaturalDateRule()) {
|
|
|
// 自然日期保养规则
|