|
@@ -148,10 +148,13 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
|
workOrderIds.add(order.getId());
|
|
|
});
|
|
|
}
|
|
|
- bomReqVO.setWorkOrderIds(workOrderIds);
|
|
|
- List<IotMainWorkOrderBomDO> workOrderBomS = iotMainWorkOrderBomMapper.selectList(bomReqVO);
|
|
|
+ List<IotMainWorkOrderBomDO> workOrderBomS = new ArrayList<>();
|
|
|
+ if (CollUtil.isNotEmpty(workOrderIds)) {
|
|
|
+ bomReqVO.setWorkOrderIds(workOrderIds);
|
|
|
+ workOrderBomS= iotMainWorkOrderBomMapper.selectList(bomReqVO);
|
|
|
+ }
|
|
|
Set<Long> deviceIds = CollUtil.isEmpty(workOrderBomS)
|
|
|
- ? Collections.emptySet()
|
|
|
+ ? new HashSet<>()
|
|
|
: workOrderBomS.stream()
|
|
|
.map(IotMainWorkOrderBomDO::getDeviceId) // 获取 deviceId
|
|
|
.filter(Objects::nonNull) // 过滤非空值
|
|
@@ -161,18 +164,28 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
|
// 查询保养计划明细中不包含 deviceIds 的设备id集合
|
|
|
List<IotMaintenanceBomDO> mainBomS = new ArrayList<>();
|
|
|
Set<Long> mainBomDeviceIds = new HashSet<>();
|
|
|
+ IotMaintenanceBomPageReqVO mainBomReqVO = new IotMaintenanceBomPageReqVO();
|
|
|
if (CollUtil.isNotEmpty(deviceIds)) {
|
|
|
- IotMaintenanceBomPageReqVO mainBomReqVO = new IotMaintenanceBomPageReqVO();
|
|
|
mainBomReqVO.setDeviceIds(new ArrayList<>(deviceIds));
|
|
|
mainBomS = iotMaintenanceBomMapper.selectAlarmList(mainBomReqVO);
|
|
|
+ } else {
|
|
|
+ mainBomS = iotMaintenanceBomMapper.selectList(mainBomReqVO);
|
|
|
+ }
|
|
|
+ if (CollUtil.isNotEmpty(mainBomS)) {
|
|
|
mainBomDeviceIds = CollUtil.isEmpty(mainBomS)
|
|
|
? Collections.emptySet()
|
|
|
: mainBomS.stream()
|
|
|
.map(IotMaintenanceBomDO::getDeviceId) // 获取 deviceId
|
|
|
.filter(Objects::nonNull) // 过滤非空值
|
|
|
.collect(Collectors.toSet()); // 收集到 Set 中
|
|
|
- deviceIds.addAll(mainBomDeviceIds);
|
|
|
}
|
|
|
+ deviceIds.addAll(mainBomDeviceIds);
|
|
|
+ if (CollUtil.isEmpty(deviceIds)){
|
|
|
+ // 没有设备信息,返回空列表
|
|
|
+ return PageResult.empty();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果没有待执行的保养工单,
|
|
|
Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(new ArrayList<>(deviceIds));
|
|
|
// 以设备为维度统计每个设备相关的保养项的最近保养距离 key设备id value设备下每个保养项的的最小保养距离集合
|
|
|
Map<Long, List<Map<String, Object>>> orderDistancePair = new HashMap<>();
|
|
@@ -310,55 +323,55 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
|
orderDistancePair.put(bom.getDeviceId(), tempDistances);
|
|
|
}
|
|
|
});
|
|
|
- // 以设备id 为维度 统计每个保养工单明细中 距离最近的保养数据
|
|
|
- resultMap = findClosestToZero(orderDistancePair);
|
|
|
- // 对集合 resultMap 中所有数据进行排序 按照 map 的value值 去除后面的 字符后 升序排列
|
|
|
- // 排序后输出一个 List<Long> 类型的集合,排序对应上面的排序规则
|
|
|
- List<Long> sortedDeviceIds = sortByNumericValue(resultMap);
|
|
|
- try {
|
|
|
- // 左侧组织树 组织层级查询
|
|
|
- Set<Long> ids = new HashSet<>();
|
|
|
- if (Objects.nonNull(pageReqVO.getDeptId())) {
|
|
|
- ids = deptService.getChildDeptIdListFromCache(pageReqVO.getDeptId());
|
|
|
- ids.add(pageReqVO.getDeptId());
|
|
|
- }
|
|
|
- // 筛选出已计算出保养距离的设备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);
|
|
|
- // 处理当前分页数据 拼接上已经排序的 筛选出的设备保养项 最小保养距离
|
|
|
- List<Long> alarmDeviceIds = new ArrayList<>();
|
|
|
- Map<Long, IotDeviceRespVO> alarmDevicePair = new HashMap<>();
|
|
|
- if (CollUtil.isNotEmpty(alarmDevices)) {
|
|
|
- for (IotDeviceRespVO device : alarmDevices) {
|
|
|
- if (resultMap.containsKey(device.getId())) {
|
|
|
- device.setMainDistance(resultMap.get(device.getId()));
|
|
|
- alarmDeviceIds.add(device.getId());
|
|
|
- }
|
|
|
- alarmDevicePair.put(device.getId(), device);
|
|
|
+ }
|
|
|
+ // 以设备id 为维度 统计每个保养工单明细中 距离最近的保养数据
|
|
|
+ resultMap = findClosestToZero(orderDistancePair);
|
|
|
+ // 对集合 resultMap 中所有数据进行排序 按照 map 的value值 去除后面的 字符后 升序排列
|
|
|
+ // 排序后输出一个 List<Long> 类型的集合,排序对应上面的排序规则
|
|
|
+ List<Long> sortedDeviceIds = sortByNumericValue(resultMap);
|
|
|
+ try {
|
|
|
+ // 左侧组织树 组织层级查询
|
|
|
+ Set<Long> ids = new HashSet<>();
|
|
|
+ if (Objects.nonNull(pageReqVO.getDeptId())) {
|
|
|
+ ids = deptService.getChildDeptIdListFromCache(pageReqVO.getDeptId());
|
|
|
+ ids.add(pageReqVO.getDeptId());
|
|
|
+ }
|
|
|
+ // 筛选出已计算出保养距离的设备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);
|
|
|
+ // 处理当前分页数据 拼接上已经排序的 筛选出的设备保养项 最小保养距离
|
|
|
+ List<Long> alarmDeviceIds = new ArrayList<>();
|
|
|
+ Map<Long, IotDeviceRespVO> alarmDevicePair = new HashMap<>();
|
|
|
+ if (CollUtil.isNotEmpty(alarmDevices)) {
|
|
|
+ for (IotDeviceRespVO device : alarmDevices) {
|
|
|
+ if (resultMap.containsKey(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());
|
|
|
- } catch (Exception exception) {
|
|
|
- if (exception.getMessage().contains("Table does not exist")) {
|
|
|
- return PageResult.empty();
|
|
|
- }
|
|
|
- throw exception;
|
|
|
}
|
|
|
+ // 查询所有设备列表 通过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());
|
|
|
+ } catch (Exception exception) {
|
|
|
+ if (exception.getMessage().contains("Table does not exist")) {
|
|
|
+ return PageResult.empty();
|
|
|
+ }
|
|
|
+ throw exception;
|
|
|
}
|
|
|
- return PageResult.empty();
|
|
|
+ // return PageResult.empty();
|
|
|
}
|
|
|
|
|
|
/**
|