|
|
|
|
@ -229,11 +229,12 @@ public class DeviceLineServiceImpl implements DeviceLineService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<LineAnalysisTreeDTO.LineNode> deviceParameterAnalysis(String keyword, Integer showDevices) {
|
|
|
|
|
public List<LineAnalysisTreeDTO.LineNode> deviceParameterAnalysis(String keyword, Integer showDevices, Integer filterNoDeviceLine) {
|
|
|
|
|
if (showDevices == null || (showDevices != 1 && showDevices != 2)) {
|
|
|
|
|
showDevices = 1;
|
|
|
|
|
}
|
|
|
|
|
boolean needShowDevices = showDevices == 1;
|
|
|
|
|
boolean needFilterNoDeviceLine = filterNoDeviceLine != null && filterNoDeviceLine == 1;
|
|
|
|
|
boolean hasKeyword = StringUtils.isNotBlank(keyword);
|
|
|
|
|
String lowerKeyword = hasKeyword ? keyword.toLowerCase() : null;
|
|
|
|
|
|
|
|
|
|
@ -274,10 +275,21 @@ public class DeviceLineServiceImpl implements DeviceLineService {
|
|
|
|
|
.filter(item -> item.getDeviceLine() != null)
|
|
|
|
|
.collect(Collectors.groupingBy(item -> item.getDeviceLine().longValue()));
|
|
|
|
|
|
|
|
|
|
Set<Long> validDeviceIds = deviceMap.keySet();
|
|
|
|
|
Set<Long> lineIdsWithDevice = ledgers.stream()
|
|
|
|
|
.filter(item -> item.getDeviceLine() != null)
|
|
|
|
|
.filter(item -> validDeviceIds.contains(item.getDvId()))
|
|
|
|
|
.map(item -> item.getDeviceLine().longValue())
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
Map<Long, List<DeviceLineDO>> childrenByParentId = deviceLines.stream()
|
|
|
|
|
.filter(item -> item.getParentId() != null && item.getParentId() != 0L)
|
|
|
|
|
.collect(Collectors.groupingBy(DeviceLineDO::getParentId));
|
|
|
|
|
|
|
|
|
|
Map<Long, DeviceLineDO> deviceLineMap = deviceLines.stream()
|
|
|
|
|
.collect(Collectors.toMap(DeviceLineDO::getId, Function.identity(), (a, b) -> a));
|
|
|
|
|
Set<Long> lineIdsWithDeviceOrAncestor = buildLineIdsWithDeviceOrAncestor(lineIdsWithDevice, deviceLineMap);
|
|
|
|
|
|
|
|
|
|
Set<Long> matchedNodeIds = new HashSet<>();
|
|
|
|
|
if (hasKeyword) {
|
|
|
|
|
for (DeviceLineDO line : deviceLines) {
|
|
|
|
|
@ -294,8 +306,27 @@ public class DeviceLineServiceImpl implements DeviceLineService {
|
|
|
|
|
matchedNodeIds.addAll(deviceLines.stream().map(DeviceLineDO::getId).collect(Collectors.toSet()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buildDeviceLineAnalysisTree(deviceLines, matchedNodeIds, ledgersByLineId, deviceMap,
|
|
|
|
|
paramsByDeviceId, needShowDevices, hasKeyword, lowerKeyword);
|
|
|
|
|
return buildDeviceLineAnalysisTree(deviceLines, matchedNodeIds, lineIdsWithDeviceOrAncestor, ledgersByLineId, deviceMap,
|
|
|
|
|
paramsByDeviceId, needShowDevices, needFilterNoDeviceLine, hasKeyword, lowerKeyword);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Set<Long> buildLineIdsWithDeviceOrAncestor(Set<Long> lineIdsWithDevice,
|
|
|
|
|
Map<Long, DeviceLineDO> deviceLineMap) {
|
|
|
|
|
Set<Long> result = new HashSet<>(lineIdsWithDevice);
|
|
|
|
|
for (Long lineId : lineIdsWithDevice) {
|
|
|
|
|
DeviceLineDO current = deviceLineMap.get(lineId);
|
|
|
|
|
Long parentId = current == null ? null : current.getParentId();
|
|
|
|
|
Set<Long> visitedParentIds = new HashSet<>();
|
|
|
|
|
while (parentId != null && parentId > 0 && visitedParentIds.add(parentId)) {
|
|
|
|
|
result.add(parentId);
|
|
|
|
|
DeviceLineDO parent = deviceLineMap.get(parentId);
|
|
|
|
|
if (parent == null) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
parentId = parent.getParentId();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isDeviceLineAnalysisMatched(DeviceLineDO line,
|
|
|
|
|
@ -365,10 +396,12 @@ public class DeviceLineServiceImpl implements DeviceLineService {
|
|
|
|
|
private List<LineAnalysisTreeDTO.LineNode> buildDeviceLineAnalysisTree(
|
|
|
|
|
List<DeviceLineDO> deviceLines,
|
|
|
|
|
Set<Long> matchedNodeIds,
|
|
|
|
|
Set<Long> lineIdsWithDeviceOrAncestor,
|
|
|
|
|
Map<Long, List<DeviceLedgerDO>> ledgersByLineId,
|
|
|
|
|
Map<Long, DeviceDO> deviceMap,
|
|
|
|
|
Map<Long, List<DeviceContactModelDO>> paramsByDeviceId,
|
|
|
|
|
boolean needShowDevices,
|
|
|
|
|
boolean needFilterNoDeviceLine,
|
|
|
|
|
boolean hasKeyword,
|
|
|
|
|
String lowerKeyword) {
|
|
|
|
|
|
|
|
|
|
@ -377,6 +410,9 @@ public class DeviceLineServiceImpl implements DeviceLineService {
|
|
|
|
|
if (!matchedNodeIds.contains(line.getId())) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (needFilterNoDeviceLine && !lineIdsWithDeviceOrAncestor.contains(line.getId())) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
nodeMap.put(line.getId(), LineAnalysisTreeDTO.LineNode.builder()
|
|
|
|
|
.id(line.getId())
|
|
|
|
|
.name(line.getName())
|
|
|
|
|
|