|
@@ -156,11 +156,92 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
.map(IotMainWorkOrderBomDO::getDeviceId) // 获取 deviceId
|
|
.map(IotMainWorkOrderBomDO::getDeviceId) // 获取 deviceId
|
|
.filter(Objects::nonNull) // 过滤非空值
|
|
.filter(Objects::nonNull) // 过滤非空值
|
|
.collect(Collectors.toSet()); // 收集到 Set 中
|
|
.collect(Collectors.toSet()); // 收集到 Set 中
|
|
|
|
+ Set<Long> orderDeviceIds = new HashSet<>();
|
|
|
|
+ orderDeviceIds.addAll(deviceIds);
|
|
|
|
+ // 查询保养计划明细中不包含 deviceIds 的设备id集合
|
|
|
|
+ List<IotMaintenanceBomDO> mainBomS = new ArrayList<>();
|
|
|
|
+ Set<Long> mainBomDeviceIds = new HashSet<>();
|
|
|
|
+ if (CollUtil.isNotEmpty(deviceIds)) {
|
|
|
|
+ IotMaintenanceBomPageReqVO mainBomReqVO = new IotMaintenanceBomPageReqVO();
|
|
|
|
+ mainBomReqVO.setDeviceIds(new ArrayList<>(deviceIds));
|
|
|
|
+ mainBomS = iotMaintenanceBomMapper.selectAlarmList(mainBomReqVO);
|
|
|
|
+ mainBomDeviceIds = CollUtil.isEmpty(mainBomS)
|
|
|
|
+ ? Collections.emptySet()
|
|
|
|
+ : mainBomS.stream()
|
|
|
|
+ .map(IotMaintenanceBomDO::getDeviceId) // 获取 deviceId
|
|
|
|
+ .filter(Objects::nonNull) // 过滤非空值
|
|
|
|
+ .collect(Collectors.toSet()); // 收集到 Set 中
|
|
|
|
+ deviceIds.addAll(mainBomDeviceIds);
|
|
|
|
+ }
|
|
Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(new ArrayList<>(deviceIds));
|
|
Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(new ArrayList<>(deviceIds));
|
|
// 以设备为维度统计每个设备相关的保养项的最近保养距离 key设备id value设备下每个保养项的的最小保养距离集合
|
|
// 以设备为维度统计每个设备相关的保养项的最近保养距离 key设备id value设备下每个保养项的的最小保养距离集合
|
|
Map<Long, List<Map<String, Object>>> orderDistancePair = new HashMap<>();
|
|
Map<Long, List<Map<String, Object>>> orderDistancePair = new HashMap<>();
|
|
// 设备保养明细 key设备id value设备保养工单明细下所有保养规则数据最小值
|
|
// 设备保养明细 key设备id value设备保养工单明细下所有保养规则数据最小值
|
|
Map<Long, String> resultMap = new HashMap<>();
|
|
Map<Long, String> resultMap = new HashMap<>();
|
|
|
|
+ if (CollUtil.isNotEmpty(mainBomS)) {
|
|
|
|
+ // 遍历保养计划明细 计算 保养计划中的设备 的最近的保养时间
|
|
|
|
+ mainBomS.forEach(bom -> {
|
|
|
|
+ BigDecimal runningTimeDistance = null;
|
|
|
|
+ BigDecimal runningKiloDistance = null;
|
|
|
|
+ BigDecimal naturalDateDistance = null;
|
|
|
|
+ // 计算每个保养项 每个保养规则下的 距离保养时间 单位 小时
|
|
|
|
+ if (0 == bom.getRunningTimeRule()) {
|
|
|
|
+ // 运行时间保养规则
|
|
|
|
+ if (deviceRunLogMap.containsKey(bom.getDeviceId())) {
|
|
|
|
+ BigDecimal totalRunTime = deviceRunLogMap.get(bom.getDeviceId()).getTotalRunTime();
|
|
|
|
+ BigDecimal lastRunningTime = bom.getLastRunningTime(); // 上次保养运行时间
|
|
|
|
+ BigDecimal runningTimePeriod = bom.getNextRunningTime(); // 运行时间周期
|
|
|
|
+ BigDecimal timePeriodLead = bom.getTimePeriodLead(); // 运行时间周期提前量
|
|
|
|
+ runningTimeDistance = (lastRunningTime.add(runningTimePeriod).subtract(timePeriodLead)).subtract(totalRunTime);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (0 == bom.getMileageRule()) {
|
|
|
|
+ // 运行里程保养规则 累计运行里程规则 累计运行里程 >= (上次保养运行里程+运行里程周期-提前量)
|
|
|
|
+ if (deviceRunLogMap.containsKey(bom.getDeviceId())) {
|
|
|
|
+ BigDecimal totalMileage = deviceRunLogMap.get(bom.getDeviceId()).getTotalMileage();
|
|
|
|
+ BigDecimal lastRunningKilo = bom.getLastRunningKilometers(); // 上次保养运行里程
|
|
|
|
+ BigDecimal runningKiloPeriod = bom.getNextRunningKilometers(); // 运行里程周期
|
|
|
|
+ BigDecimal kiloCycleLead = bom.getKiloCycleLead(); // 运行里程周期提前量
|
|
|
|
+ runningKiloDistance = (lastRunningKilo.add(runningKiloPeriod).subtract(kiloCycleLead)).subtract(totalMileage);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (0 == bom.getNaturalDateRule()) {
|
|
|
|
+ // 自然日期保养规则
|
|
|
|
+ LocalDateTime lastNaturalDate = bom.getLastNaturalDate(); // 上次保养自然日期
|
|
|
|
+ BigDecimal naturalDatePeriod = bom.getNextNaturalDate(); // 自然日周期
|
|
|
|
+ BigDecimal natualDateLead = bom.getNaturalDatePeriodLead(); // 自然日周期提前量
|
|
|
|
+ if (ObjUtil.isNotEmpty(lastNaturalDate) && ObjUtil.isNotEmpty(naturalDatePeriod) && ObjUtil.isNotEmpty(natualDateLead)) {
|
|
|
|
+ // 计算有效天数 = 自然日周期 - 提前量
|
|
|
|
+ long days = naturalDatePeriod.subtract(natualDateLead).longValue(); // 转为长整型天数
|
|
|
|
+ // 计算目标日期:上次保养日期 + 有效天数(注意:LocalDateTime加天数会自动处理日期进位)
|
|
|
|
+ LocalDateTime targetDate = lastNaturalDate.plusDays(days);
|
|
|
|
+ // 获取当前日期时间
|
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
|
+ // 计算日期差值(以天为单位)
|
|
|
|
+ naturalDateDistance = new BigDecimal(ChronoUnit.DAYS.between(targetDate, now));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 找出距离0最近的数,作为工单的最近保养距离数据
|
|
|
|
+ Object closet = chooseNearestDistance(runningTimeDistance, runningKiloDistance, naturalDateDistance);
|
|
|
|
+ Map<String, Object> tempDistance = new HashMap<>();
|
|
|
|
+ if (closet == runningTimeDistance) {
|
|
|
|
+ tempDistance.put("H", closet);
|
|
|
|
+ } else if (closet == runningKiloDistance) {
|
|
|
|
+ tempDistance.put("KM", closet);
|
|
|
|
+ } else if (closet == naturalDateDistance) {
|
|
|
|
+ tempDistance.put("D", closet);
|
|
|
|
+ }
|
|
|
|
+ if (orderDistancePair.containsKey(bom.getDeviceId())) {
|
|
|
|
+ List<Map<String, Object>> tempDistances = orderDistancePair.get(bom.getDeviceId());
|
|
|
|
+ tempDistances.add(tempDistance);
|
|
|
|
+ orderDistancePair.put(bom.getDeviceId(), tempDistances);
|
|
|
|
+ } else {
|
|
|
|
+ List<Map<String, Object>> tempDistances = new ArrayList<>();
|
|
|
|
+ tempDistances.add(tempDistance);
|
|
|
|
+ orderDistancePair.put(bom.getDeviceId(), tempDistances);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
// 计算出每个保养工单明细的不同保养规则的保养距离最小值
|
|
// 计算出每个保养工单明细的不同保养规则的保养距离最小值
|
|
if (CollUtil.isNotEmpty(workOrderBomS)) {
|
|
if (CollUtil.isNotEmpty(workOrderBomS)) {
|
|
workOrderBomS.forEach(bom -> {
|
|
workOrderBomS.forEach(bom -> {
|
|
@@ -231,22 +312,40 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
// 排序后输出一个 List<Long> 类型的集合,排序对应上面的排序规则
|
|
// 排序后输出一个 List<Long> 类型的集合,排序对应上面的排序规则
|
|
List<Long> sortedDeviceIds = sortByNumericValue(resultMap);
|
|
List<Long> sortedDeviceIds = sortByNumericValue(resultMap);
|
|
try {
|
|
try {
|
|
- // 组织层级查询
|
|
|
|
|
|
+ // 左侧组织树 组织层级查询
|
|
Set<Long> ids = new HashSet<>();
|
|
Set<Long> ids = new HashSet<>();
|
|
if (Objects.nonNull(pageReqVO.getDeptId())) {
|
|
if (Objects.nonNull(pageReqVO.getDeptId())) {
|
|
ids = deptService.getChildDeptIdListFromCache(pageReqVO.getDeptId());
|
|
ids = deptService.getChildDeptIdListFromCache(pageReqVO.getDeptId());
|
|
ids.add(pageReqVO.getDeptId());
|
|
ids.add(pageReqVO.getDeptId());
|
|
}
|
|
}
|
|
- IPage<IotDeviceRespVO> page = iotDeviceMapper.deviceDistances(
|
|
|
|
- new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()), pageReqVO, sortedDeviceIds, ids);
|
|
|
|
|
|
+ // 筛选出已计算出保养距离的设备id
|
|
|
|
+ /* IPage<IotDeviceRespVO> page = iotDeviceMapper.deviceDistances(
|
|
|
|
+ new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()), pageReqVO, sortedDeviceIds, orderDeviceIds, mainBomDeviceIds, ids); */
|
|
|
|
+ List<IotDeviceRespVO> alarmDevices = iotDeviceMapper.deviceAlarmDistances(sortedDeviceIds, orderDeviceIds, mainBomDeviceIds);
|
|
// 处理当前分页数据 拼接上已经排序的 筛选出的设备保养项 最小保养距离
|
|
// 处理当前分页数据 拼接上已经排序的 筛选出的设备保养项 最小保养距离
|
|
- if (CollUtil.isNotEmpty(page.getRecords())) {
|
|
|
|
- for (IotDeviceRespVO device : page.getRecords()) {
|
|
|
|
|
|
+ List<Long> alarmDeviceIds = new ArrayList<>();
|
|
|
|
+ Map<Long, IotDeviceRespVO> alarmDevicePair = new HashMap<>();
|
|
|
|
+ if (CollUtil.isNotEmpty(alarmDevices)) {
|
|
|
|
+ for (IotDeviceRespVO device : alarmDevices) {
|
|
if (resultMap.containsKey(device.getId())) {
|
|
if (resultMap.containsKey(device.getId())) {
|
|
device.setMainDistance(resultMap.get(device.getId()));
|
|
device.setMainDistance(resultMap.get(device.getId()));
|
|
|
|
+ alarmDeviceIds.add(device.getId());
|
|
}
|
|
}
|
|
|
|
+ alarmDevicePair.put(device.getId(), device);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ // 查询所有设备列表 通过SQL形式 使用 FIELD 字段
|
|
|
|
+ IPage<IotDeviceRespVO> page = iotDeviceMapper.allDeviceDistances(
|
|
|
|
+ new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()), pageReqVO, alarmDeviceIds, ids);
|
|
|
|
+ if (CollUtil.isNotEmpty(page.getRecords())) {
|
|
|
|
+ page.getRecords().forEach(device -> {
|
|
|
|
+ if (alarmDevicePair.containsKey(device.getId())) {
|
|
|
|
+ device.setMainDistance(alarmDevicePair.get(device.getId()).getMainDistance());
|
|
|
|
+ device.setPlanId(alarmDevicePair.get(device.getId()).getPlanId());
|
|
|
|
+ device.setWorkOrderId(alarmDevicePair.get(device.getId()).getWorkOrderId());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
return new PageResult<>(page.getRecords(), page.getTotal());
|
|
return new PageResult<>(page.getRecords(), page.getTotal());
|
|
} catch (Exception exception) {
|
|
} catch (Exception exception) {
|
|
if (exception.getMessage().contains("Table does not exist")) {
|
|
if (exception.getMessage().contains("Table does not exist")) {
|
|
@@ -581,8 +680,8 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
.filter(order -> !order.getId().equals(updateObj.getId()))
|
|
.filter(order -> !order.getId().equals(updateObj.getId()))
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
if (CollUtil.isNotEmpty(filteredOrders)) {
|
|
if (CollUtil.isNotEmpty(filteredOrders)) {
|
|
- // 将关联工单设置为 已执行
|
|
|
|
- filteredOrders.forEach(order -> order.setResult(2));
|
|
|
|
|
|
+ // 将关联工单设置为 已执行 直接删除
|
|
|
|
+ filteredOrders.forEach(order -> {order.setResult(2); order.setDeleted(true);});
|
|
iotMainWorkOrderMapper.updateBatch(filteredOrders);
|
|
iotMainWorkOrderMapper.updateBatch(filteredOrders);
|
|
List<Long> workOrderIds = filteredOrders.stream()
|
|
List<Long> workOrderIds = filteredOrders.stream()
|
|
.map(IotMainWorkOrderDO::getId)
|
|
.map(IotMainWorkOrderDO::getId)
|