|
|
@ -257,114 +257,45 @@ public class CollectionParamsManageServiceImpl implements ICollectionParamsManag |
|
|
|
if (collectionParamsManages.isEmpty()) { |
|
|
|
if (collectionParamsManages.isEmpty()) { |
|
|
|
return List.of(); |
|
|
|
return List.of(); |
|
|
|
} |
|
|
|
} |
|
|
|
// 得出的collectionParamsManages进行数据赋值,如果paramType="1',则是运行状态,则赋值给runStatus,
|
|
|
|
// 根据deviceLedgerId进行分组,然后得出deviceLedgerId,deviceName赋值给DeviceOperateMonitorVO的id和name
|
|
|
|
// 如果paramType="5",则是故障报警,则赋值给alarmStatus
|
|
|
|
// 按设备台账ID分组
|
|
|
|
// 如果paramType="6",则是手自动状态,则赋值给handOrAuto
|
|
|
|
Map<String, List<CollectionParamsManageVO>> groupedByDevice = collectionParamsManages.stream() |
|
|
|
// 如果paramType="4",则是频率反馈,则赋值给frequency
|
|
|
|
.collect(Collectors.groupingBy(CollectionParamsManageVO::getDeviceLedgerId)); |
|
|
|
// 使用Stream API处理数据
|
|
|
|
|
|
|
|
Map<String, List<DeviceOperateMonitorVO>> groupedByDeviceType = collectionParamsManages.stream() |
|
|
|
|
|
|
|
.collect(Collectors.groupingBy(CollectionParamsManageVO::getId)) |
|
|
|
|
|
|
|
.values() |
|
|
|
|
|
|
|
.stream() |
|
|
|
|
|
|
|
.map(params -> { |
|
|
|
|
|
|
|
DeviceOperateMonitorVO deviceOperateMonitorVO = new DeviceOperateMonitorVO(); |
|
|
|
|
|
|
|
for (CollectionParamsManageVO param : params) { |
|
|
|
|
|
|
|
switch (param.getParamType()) { |
|
|
|
|
|
|
|
case "1": |
|
|
|
|
|
|
|
deviceOperateMonitorVO.setRunStatus(param.getCurValue().intValue()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "2": |
|
|
|
|
|
|
|
deviceOperateMonitorVO.setRunStatus(param.getCurValue().intValue()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "3": |
|
|
|
|
|
|
|
deviceOperateMonitorVO.setSetFrequency(param.getCurValue()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "4": |
|
|
|
|
|
|
|
deviceOperateMonitorVO.setFrequency(param.getCurValue()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "5": |
|
|
|
|
|
|
|
deviceOperateMonitorVO.setAlarmStatus(param.getCurValue().intValue()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "6": |
|
|
|
|
|
|
|
deviceOperateMonitorVO.setHandOrAuto(param.getCurValue().intValue()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "7": |
|
|
|
|
|
|
|
if ("阀开反馈".contains(param.getOtherName()) && param.getCurValue().intValue() == 1) { |
|
|
|
|
|
|
|
deviceOperateMonitorVO.setValveStatus(1); |
|
|
|
|
|
|
|
} else if ("阀关反馈".contains(param.getOtherName()) && param.getCurValue().intValue() == 1) { |
|
|
|
|
|
|
|
deviceOperateMonitorVO.setValveStatus(0); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
deviceOperateMonitorVO.setValveStatus(0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case "8": |
|
|
|
|
|
|
|
deviceOperateMonitorVO.setSetValveOpen(param.getCurValue().intValue()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "9": |
|
|
|
|
|
|
|
deviceOperateMonitorVO.setSetValveClose(param.getCurValue().intValue()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
// 处理未知的paramType
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
deviceOperateMonitorVO.setId(param.getId()); |
|
|
|
|
|
|
|
deviceOperateMonitorVO.setDeviceType(param.getMtType()); |
|
|
|
|
|
|
|
deviceOperateMonitorVO.setCollectName(param.getDeviceName()); |
|
|
|
|
|
|
|
deviceOperateMonitorVO.setCollectTime(param.getCurTime()); |
|
|
|
|
|
|
|
deviceOperateMonitorVO.setDeviceLedgerId(param.getDeviceLedgerId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return deviceOperateMonitorVO; |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.collect(Collectors.groupingBy(DeviceOperateMonitorVO::getDeviceLedgerId)); |
|
|
|
|
|
|
|
// 根据得出的分组数据之后,同样类型的分组数据进行合并起来变成一条数据,这里合并的规则就是某个值为空的,拿同样另一个值不为空的补上,得出List<DeviceMonitorVO>结果集
|
|
|
|
|
|
|
|
// 创建最终结果集合
|
|
|
|
|
|
|
|
List<DeviceOperateMonitorVO> result = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 遍历分组后的数据
|
|
|
|
// 转换分组结果为监控VO列表
|
|
|
|
groupedByDeviceType.forEach((deviceLedgerId, voList) -> { |
|
|
|
List<DeviceOperateMonitorVO> monitorData = groupedByDevice.values().stream() |
|
|
|
// 创建合并后的VO对象
|
|
|
|
.map(group -> { |
|
|
|
DeviceOperateMonitorVO mergedVO = new DeviceOperateMonitorVO(); |
|
|
|
// 取组内第一个元素获取公共信息(假设同设备台账ID的设备名称相同)
|
|
|
|
|
|
|
|
CollectionParamsManageVO firstItem = group.get(0); |
|
|
|
|
|
|
|
|
|
|
|
// 设置设备类型
|
|
|
|
DeviceOperateMonitorVO vo = new DeviceOperateMonitorVO(); |
|
|
|
mergedVO.setDeviceLedgerId(deviceLedgerId); |
|
|
|
vo.setId(firstItem.getDeviceLedgerId()); |
|
|
|
|
|
|
|
vo.setName(firstItem.getDeviceName()); |
|
|
|
|
|
|
|
|
|
|
|
// 设置设备类型
|
|
|
|
// 可补充其他需要聚合的字段
|
|
|
|
mergedVO.setDeviceType(voList.getFirst().getDeviceType()); |
|
|
|
// vo.setStatus(calculateStatus(group));
|
|
|
|
|
|
|
|
|
|
|
|
// 遍历同类型设备的所有监控数据
|
|
|
|
return vo; |
|
|
|
voList.forEach(vo -> { |
|
|
|
}) |
|
|
|
// 合并规则:当目标字段为空时,用当前VO的对应字段值补上
|
|
|
|
.toList(); |
|
|
|
if (mergedVO.getRunStatus() == null) { |
|
|
|
// 在遍历monitorData,根据deviceLedgerId查询出collectionParamsManages集合对应的设备id,otherName对应name,curValue对应value,curTime对应time,paramType对应paramType,然后拼接到monitorData中children中
|
|
|
|
mergedVO.setRunStatus(vo.getRunStatus()); |
|
|
|
// 处理子节点数据
|
|
|
|
} |
|
|
|
monitorData.forEach(mainVO -> { |
|
|
|
if (mergedVO.getAlarmStatus() == null) { |
|
|
|
// 根据主设备ID过滤参数
|
|
|
|
mergedVO.setAlarmStatus(vo.getAlarmStatus()); |
|
|
|
List<DeviceOperateMonitorVO> children = collectionParamsManages.stream() |
|
|
|
} |
|
|
|
.filter(p -> mainVO.getId().equals(p.getDeviceLedgerId())) |
|
|
|
if (mergedVO.getHandOrAuto() == null) { |
|
|
|
.map(param -> { |
|
|
|
mergedVO.setHandOrAuto(vo.getHandOrAuto()); |
|
|
|
DeviceOperateMonitorVO child = new DeviceOperateMonitorVO(); |
|
|
|
} |
|
|
|
child.setId(param.getId()); |
|
|
|
if (mergedVO.getFrequency() == null) { |
|
|
|
child.setName(param.getOtherName()); |
|
|
|
mergedVO.setFrequency(vo.getFrequency()); |
|
|
|
child.setValue(String.valueOf(param.getCurValue())); |
|
|
|
} |
|
|
|
child.setTime(param.getCurTime()); |
|
|
|
if (mergedVO.getValveStatus() == null) { |
|
|
|
child.setParamType(param.getParamType()); |
|
|
|
mergedVO.setValveStatus(vo.getValveStatus()); |
|
|
|
return child; |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
// 合并基础字段(取第一个有效值)
|
|
|
|
mainVO.setChildren(children); |
|
|
|
if (mergedVO.getId() == null) { |
|
|
|
|
|
|
|
mergedVO.setId(vo.getId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (mergedVO.getCollectName() == null) { |
|
|
|
|
|
|
|
mergedVO.setCollectName(vo.getCollectName()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (mergedVO.getCollectTime() == null || |
|
|
|
|
|
|
|
vo.getCollectTime().after(mergedVO.getCollectTime())) { |
|
|
|
|
|
|
|
// 取最新的采集时间
|
|
|
|
|
|
|
|
mergedVO.setCollectTime(vo.getCollectTime()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.add(mergedVO); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
return result; |
|
|
|
return monitorData; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|