|
|
|
|
@ -148,6 +148,86 @@ public class EmsBaseMonitorInfoServiceImpl implements IEmsBaseMonitorInfoService
|
|
|
|
|
* @return 树结构列表
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<EmsBaseMonitorInfo> buildMonitorInfoTree(List<EmsBaseMonitorInfo> baseMonitorInfos) {
|
|
|
|
|
// 创建一个List来存储设备编号,只获取监控类型为1L的设备编号
|
|
|
|
|
List<String> monitorCodes = baseMonitorInfos.stream()
|
|
|
|
|
.filter(item -> !ObjectUtils.isEmpty(item) && item.getMonitorType() == 1L)
|
|
|
|
|
.map(EmsBaseMonitorInfo::getMonitorCode)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
// 创建温度数据Map
|
|
|
|
|
Map<String, BigDecimal> tempDataMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
// 如果设备编号列表不为空,批量查询温度数据
|
|
|
|
|
if (CollectionUtils.isNotEmpty(monitorCodes)) {
|
|
|
|
|
// 根据设备编号列表查询最新的温度数据
|
|
|
|
|
List<TWTempertureData> tempDatas = tWTempertureDataMapper.selectLastTWTempertureDataByMonitorCodes(monitorCodes);
|
|
|
|
|
// 将温度数据存入Map,优化查找效率
|
|
|
|
|
tempDataMap = tempDatas.stream()
|
|
|
|
|
.filter(data -> !ObjectUtils.isEmpty(data) && data.getTempreture() != null)
|
|
|
|
|
.collect(Collectors.toMap(
|
|
|
|
|
TWTempertureData::getMonitorId,
|
|
|
|
|
TWTempertureData::getTempreture,
|
|
|
|
|
(v1, v2) -> v1)); // 如果有重复键,保留第一个值
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取所有设备ID,用于确定顶级节点
|
|
|
|
|
Set<Long> allIds = baseMonitorInfos.stream()
|
|
|
|
|
.map(EmsBaseMonitorInfo::getObjId)
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
// 预处理:为设备设置温度值,构建父子关系映射
|
|
|
|
|
Map<Long, List<EmsBaseMonitorInfo>> parentChildMap = new HashMap<>();
|
|
|
|
|
for (EmsBaseMonitorInfo info : baseMonitorInfos) {
|
|
|
|
|
// 设置温度值
|
|
|
|
|
if (info.getMonitorType() == 1L) {
|
|
|
|
|
BigDecimal temperature = tempDataMap.get(info.getMonitorCode());
|
|
|
|
|
if (temperature != null) {
|
|
|
|
|
info.setTemperature(temperature);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构建父子关系映射
|
|
|
|
|
Long parentId = info.getParentId();
|
|
|
|
|
if (parentId != null) {
|
|
|
|
|
parentChildMap.computeIfAbsent(parentId, k -> new ArrayList<>()).add(info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 找出所有顶级节点
|
|
|
|
|
List<EmsBaseMonitorInfo> rootNodes = baseMonitorInfos.stream()
|
|
|
|
|
.filter(info -> info.getParentId() == null || !allIds.contains(info.getParentId()))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
// 为顶级节点设置子节点(递归)
|
|
|
|
|
for (EmsBaseMonitorInfo root : rootNodes) {
|
|
|
|
|
setChildren(root, parentChildMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rootNodes.isEmpty() ? baseMonitorInfos : rootNodes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 为节点设置子节点(优化的递归实现)
|
|
|
|
|
*/
|
|
|
|
|
private void setChildren(EmsBaseMonitorInfo node, Map<Long, List<EmsBaseMonitorInfo>> parentChildMap) {
|
|
|
|
|
List<EmsBaseMonitorInfo> children = parentChildMap.get(node.getObjId());
|
|
|
|
|
if (children != null) {
|
|
|
|
|
node.setChildren(children);
|
|
|
|
|
for (EmsBaseMonitorInfo child : children) {
|
|
|
|
|
setChildren(child, parentChildMap);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构建前端所需要树结构
|
|
|
|
|
*
|
|
|
|
|
* @param
|
|
|
|
|
* @return 树结构列表
|
|
|
|
|
*/
|
|
|
|
|
/* @Override
|
|
|
|
|
public List<EmsBaseMonitorInfo> buildMonitorInfoTree(List<EmsBaseMonitorInfo> baseMonitorInfos) {
|
|
|
|
|
|
|
|
|
|
// 创建一个Map来存储温度数据,键为监控ID,值为TWTempertureData对象
|
|
|
|
|
@ -208,9 +288,9 @@ public class EmsBaseMonitorInfoServiceImpl implements IEmsBaseMonitorInfoService
|
|
|
|
|
}
|
|
|
|
|
return returnList;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*//**
|
|
|
|
|
* 递归列表
|
|
|
|
|
*/
|
|
|
|
|
*//*
|
|
|
|
|
private void recursionFn(List<EmsBaseMonitorInfo> list, EmsBaseMonitorInfo t)
|
|
|
|
|
{
|
|
|
|
|
// 得到子节点列表
|
|
|
|
|
@ -223,7 +303,9 @@ public class EmsBaseMonitorInfoServiceImpl implements IEmsBaseMonitorInfoService
|
|
|
|
|
recursionFn(list, tChild);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 得到子节点列表
|
|
|
|
|
*/
|
|
|
|
|
|