|
|
|
@ -257,374 +257,405 @@ public class OrganizationServiceImpl implements OrganizationService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<LineAnalysisTreeDTO.LineNode> deviceParameterAnalysis(String keyword) {
|
|
|
|
public List<LineAnalysisTreeDTO.LineNode> deviceParameterAnalysis(String keyword, Integer showDevices) {
|
|
|
|
|
|
|
|
// 参数验证
|
|
|
|
|
|
|
|
if (showDevices == null || (showDevices != 1 && showDevices != 2)) {
|
|
|
|
|
|
|
|
showDevices = 1; // 默认展示设备和参数
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean needShowDevices = showDevices == 1; // 1-展示,2-不展示
|
|
|
|
|
|
|
|
|
|
|
|
//1. 获取产线集合
|
|
|
|
// 1. 获取产线集合
|
|
|
|
OrganizationListReqVO organizationListReqVO = new OrganizationListReqVO();
|
|
|
|
OrganizationListReqVO organizationListReqVO = new OrganizationListReqVO();
|
|
|
|
List<OrganizationDO> organizationDOS = getOrganizationList(organizationListReqVO);
|
|
|
|
List<OrganizationDO> organizationDOS = getOrganizationList(organizationListReqVO);
|
|
|
|
List<OrganizationRespVO> organizationRespVOS = buildVOList(organizationDOS);
|
|
|
|
List<OrganizationRespVO> organizationRespVOS = buildVOList(organizationDOS);
|
|
|
|
if (organizationRespVOS.isEmpty()) {
|
|
|
|
if (organizationRespVOS.isEmpty()) {
|
|
|
|
return Collections.emptyList();
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 获取所有有machineId的产线
|
|
|
|
// 2. 获取所有有machineId的组织
|
|
|
|
List<Long> machineIds = organizationRespVOS.stream()
|
|
|
|
List<Long> deviceIds = organizationRespVOS.stream()
|
|
|
|
.map(OrganizationRespVO::getMachineId)
|
|
|
|
.map(OrganizationRespVO::getMachineId)
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
|
|
|
.distinct()
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 根据machineId查询设备
|
|
|
|
// 3. 查询设备信息
|
|
|
|
List<DeviceDO> allDevices = Collections.emptyList();
|
|
|
|
Map<Long, DeviceDO> deviceMap;
|
|
|
|
if (!machineIds.isEmpty()) {
|
|
|
|
if (!deviceIds.isEmpty()) {
|
|
|
|
LambdaQueryWrapper<DeviceDO> deviceWrapper = new LambdaQueryWrapper<>();
|
|
|
|
LambdaQueryWrapper<DeviceDO> deviceWrapper = new LambdaQueryWrapper<>();
|
|
|
|
deviceWrapper.in(DeviceDO::getId, machineIds)
|
|
|
|
deviceWrapper.in(DeviceDO::getId, deviceIds)
|
|
|
|
.eq(DeviceDO::getIsEnable, true);
|
|
|
|
.eq(DeviceDO::getIsEnable, true);
|
|
|
|
allDevices = deviceMapper.selectList(deviceWrapper);
|
|
|
|
List<DeviceDO> devices = deviceMapper.selectList(deviceWrapper);
|
|
|
|
|
|
|
|
deviceMap = devices.stream()
|
|
|
|
|
|
|
|
.collect(Collectors.toMap(DeviceDO::getId, Function.identity()));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
deviceMap = new HashMap<>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 4. 获取所有参数
|
|
|
|
// 4. 查询设备参数
|
|
|
|
List<DeviceContactModelDO> allParameters = getAllParameters(allDevices);
|
|
|
|
Map<Long, List<DeviceContactModelDO>> paramsByDeviceId;
|
|
|
|
|
|
|
|
if (!deviceIds.isEmpty()) {
|
|
|
|
|
|
|
|
LambdaQueryWrapper<DeviceContactModelDO> paramWrapper = new LambdaQueryWrapper<>();
|
|
|
|
// 5. 构建映射关系
|
|
|
|
paramWrapper.in(DeviceContactModelDO::getDeviceId, deviceIds)
|
|
|
|
Map<Long, DeviceDO> deviceById = allDevices.stream()
|
|
|
|
.orderByAsc(DeviceContactModelDO::getSort);
|
|
|
|
.collect(Collectors.toMap(DeviceDO::getId, Function.identity()));
|
|
|
|
List<DeviceContactModelDO> allParameters = deviceContactModelMapper.selectList(paramWrapper);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
paramsByDeviceId = allParameters.stream()
|
|
|
|
|
|
|
|
.filter(param -> param.getDeviceId() != null)
|
|
|
|
|
|
|
|
.collect(Collectors.groupingBy(DeviceContactModelDO::getDeviceId));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
paramsByDeviceId = new HashMap<>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 6. 构建设备按产线分组的映射
|
|
|
|
// 5. 构建产线ID到orgClass的映射
|
|
|
|
Map<Long, List<DeviceDO>> devicesByLineId = new HashMap<>();
|
|
|
|
Map<Long, String> lineOrgClassMap = new HashMap<>();
|
|
|
|
for (OrganizationRespVO line : organizationRespVOS) {
|
|
|
|
for (int i = 0; i < organizationDOS.size(); i++) {
|
|
|
|
if (line.getMachineId() != null) {
|
|
|
|
OrganizationDO orgDO = organizationDOS.get(i);
|
|
|
|
DeviceDO device = deviceById.get(line.getMachineId());
|
|
|
|
OrganizationRespVO orgVO = organizationRespVOS.get(i);
|
|
|
|
if (device != null) {
|
|
|
|
if (orgDO.getOrgClass() != null && orgVO != null) {
|
|
|
|
devicesByLineId.computeIfAbsent(line.getId(), k -> new ArrayList<>())
|
|
|
|
lineOrgClassMap.put(orgVO.getId(), orgDO.getOrgClass());
|
|
|
|
.add(device);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Map<Long, List<DeviceContactModelDO>> paramsByDeviceId = allParameters.stream()
|
|
|
|
// 6. 构建组织ID到子节点的映射
|
|
|
|
.filter(param -> param.getDeviceId() != null)
|
|
|
|
Map<Long, List<OrganizationRespVO>> childrenByParentId = organizationRespVOS.stream()
|
|
|
|
.collect(Collectors.groupingBy(DeviceContactModelDO::getDeviceId));
|
|
|
|
.filter(org -> org.getParentId() != null && org.getParentId() != 0L)
|
|
|
|
|
|
|
|
.collect(Collectors.groupingBy(OrganizationRespVO::getParentId));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取产线与父节点的映射关系
|
|
|
|
|
|
|
|
Map<Long, Long> lineParentIdMap = organizationRespVOS.stream()
|
|
|
|
|
|
|
|
.collect(Collectors.toMap(
|
|
|
|
|
|
|
|
OrganizationRespVO::getId,
|
|
|
|
|
|
|
|
line -> line.getParentId() != null ? line.getParentId() : 0L, // 如果父节点为空,使用默认值0
|
|
|
|
|
|
|
|
(existing, replacement) -> existing
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
// 构建产线ID到产线对象的映射
|
|
|
|
|
|
|
|
Map<Long, OrganizationRespVO> lineMap = organizationRespVOS.stream()
|
|
|
|
|
|
|
|
.collect(Collectors.toMap(OrganizationRespVO::getId, Function.identity()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取所有匹配的产线(包括下级匹配的)
|
|
|
|
|
|
|
|
List<OrganizationRespVO> matchedLines = getMatchedLinesWithAncestors(
|
|
|
|
|
|
|
|
organizationRespVOS, keyword, allDevices, paramsByDeviceId, lineParentIdMap, lineMap
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 7. 构建树结构
|
|
|
|
|
|
|
|
return buildTreeStructureWithKeyword(matchedLines, devicesByLineId, paramsByDeviceId,keyword,lineParentIdMap);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<OrganizationRespVO> getMatchedLinesWithAncestors(
|
|
|
|
|
|
|
|
List<OrganizationRespVO> allLines,
|
|
|
|
|
|
|
|
String keyword,
|
|
|
|
|
|
|
|
List<DeviceDO> allDevices,
|
|
|
|
|
|
|
|
Map<Long, List<DeviceContactModelDO>> paramsByDeviceId,
|
|
|
|
|
|
|
|
Map<Long, Long> lineParentIdMap,
|
|
|
|
|
|
|
|
Map<Long, OrganizationRespVO> lineMap) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 7. 如果有搜索关键词,筛选匹配的节点
|
|
|
|
|
|
|
|
Set<Long> matchedNodeIds = new HashSet<>();
|
|
|
|
boolean hasKeyword = StringUtils.isNotBlank(keyword);
|
|
|
|
boolean hasKeyword = StringUtils.isNotBlank(keyword);
|
|
|
|
String lowerKeyword = hasKeyword ? keyword.toLowerCase() : "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 存储最终要包含的产线ID
|
|
|
|
if (hasKeyword) {
|
|
|
|
Set<Long> lineIdsToInclude = new HashSet<>();
|
|
|
|
String lowerKeyword = keyword.toLowerCase();
|
|
|
|
|
|
|
|
|
|
|
|
// 1. 首先找出直接匹配的产线
|
|
|
|
// 查找组织名称匹配的节点
|
|
|
|
for (OrganizationRespVO line : allLines) {
|
|
|
|
for (OrganizationRespVO node : organizationRespVOS) {
|
|
|
|
boolean lineMatch = !hasKeyword ||
|
|
|
|
boolean nodeMatched = false;
|
|
|
|
(line.getName() != null && line.getName().toLowerCase().contains(lowerKeyword));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (lineMatch) {
|
|
|
|
// 1. 检查组织名称是否匹配
|
|
|
|
// 添加到结果集
|
|
|
|
if (node.getName() != null && node.getName().toLowerCase().contains(lowerKeyword)) {
|
|
|
|
lineIdsToInclude.add(line.getId());
|
|
|
|
nodeMatched = true;
|
|
|
|
// 向上查找所有父级节点
|
|
|
|
}
|
|
|
|
addAllAncestors(line.getId(), lineParentIdMap, lineMap, lineIdsToInclude);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 查找设备匹配的产线
|
|
|
|
// 2. 如果没有组织名称匹配,检查该节点是否有设备匹配
|
|
|
|
if (hasKeyword) {
|
|
|
|
if (!nodeMatched && needShowDevices && node.getMachineId() != null) {
|
|
|
|
for (DeviceDO device : allDevices) {
|
|
|
|
DeviceDO device = deviceMap.get(node.getMachineId());
|
|
|
|
boolean deviceMatch = device.getDeviceName() != null &&
|
|
|
|
if (device != null) {
|
|
|
|
device.getDeviceName().toLowerCase().contains(lowerKeyword);
|
|
|
|
// 检查设备名称是否匹配
|
|
|
|
|
|
|
|
if (device.getDeviceName() != null &&
|
|
|
|
if (deviceMatch) {
|
|
|
|
device.getDeviceName().toLowerCase().contains(lowerKeyword)) {
|
|
|
|
// 找到这个设备所属的产线
|
|
|
|
nodeMatched = true;
|
|
|
|
for (OrganizationRespVO line : allLines) {
|
|
|
|
|
|
|
|
if (line.getMachineId() != null && line.getMachineId().equals(device.getId())) {
|
|
|
|
|
|
|
|
lineIdsToInclude.add(line.getId());
|
|
|
|
|
|
|
|
addAllAncestors(line.getId(), lineParentIdMap, lineMap, lineIdsToInclude);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 查找参数匹配的产线
|
|
|
|
// 检查设备参数是否匹配
|
|
|
|
if (hasKeyword) {
|
|
|
|
if (!nodeMatched) {
|
|
|
|
for (Map.Entry<Long, List<DeviceContactModelDO>> entry : paramsByDeviceId.entrySet()) {
|
|
|
|
List<DeviceContactModelDO> deviceParams = paramsByDeviceId.getOrDefault(device.getId(), new ArrayList<>());
|
|
|
|
Long deviceId = entry.getKey();
|
|
|
|
boolean hasMatchingParam = deviceParams.stream()
|
|
|
|
List<DeviceContactModelDO> params = entry.getValue();
|
|
|
|
.anyMatch(param -> param.getAttributeName() != null &&
|
|
|
|
|
|
|
|
param.getAttributeName().toLowerCase().contains(lowerKeyword));
|
|
|
|
boolean hasMatchingParam = params.stream()
|
|
|
|
if (hasMatchingParam) {
|
|
|
|
.anyMatch(param -> param.getAttributeName() != null &&
|
|
|
|
nodeMatched = true;
|
|
|
|
param.getAttributeName().toLowerCase().contains(lowerKeyword));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (hasMatchingParam) {
|
|
|
|
|
|
|
|
// 找到这个设备所属的产线
|
|
|
|
|
|
|
|
for (OrganizationRespVO line : allLines) {
|
|
|
|
|
|
|
|
if (line.getMachineId() != null && line.getMachineId().equals(deviceId)) {
|
|
|
|
|
|
|
|
lineIdsToInclude.add(line.getId());
|
|
|
|
|
|
|
|
addAllAncestors(line.getId(), lineParentIdMap, lineMap, lineIdsToInclude);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (nodeMatched) {
|
|
|
|
|
|
|
|
// 将当前节点加入匹配列表
|
|
|
|
|
|
|
|
matchedNodeIds.add(node.getId());
|
|
|
|
|
|
|
|
// 迭代添加所有子节点
|
|
|
|
|
|
|
|
addAllDescendants(node.getId(), childrenByParentId, matchedNodeIds);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果没有关键词,返回所有产线
|
|
|
|
// 如果没有匹配任何节点,返回空列表
|
|
|
|
if (!hasKeyword) {
|
|
|
|
if (matchedNodeIds.isEmpty()) {
|
|
|
|
return allLines;
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 无关键词时,包含所有节点
|
|
|
|
|
|
|
|
matchedNodeIds.addAll(organizationRespVOS.stream()
|
|
|
|
|
|
|
|
.map(OrganizationRespVO::getId)
|
|
|
|
|
|
|
|
.collect(Collectors.toSet()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 只返回需要包含的产线
|
|
|
|
// 8. 找到最顶层的匹配节点(没有匹配的父节点)
|
|
|
|
return allLines.stream()
|
|
|
|
Set<Long> topLevelNodeIds = new HashSet<>(matchedNodeIds);
|
|
|
|
.filter(line -> lineIdsToInclude.contains(line.getId()))
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void addAllAncestors(Long lineId,
|
|
|
|
|
|
|
|
Map<Long, Long> lineParentIdMap,
|
|
|
|
|
|
|
|
Map<Long, OrganizationRespVO> lineMap,
|
|
|
|
|
|
|
|
Set<Long> lineIdsToInclude) {
|
|
|
|
|
|
|
|
Long currentParentId = lineParentIdMap.get(lineId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 递归向上查找所有父级节点
|
|
|
|
|
|
|
|
while (currentParentId != null && currentParentId != 0L) {
|
|
|
|
|
|
|
|
lineIdsToInclude.add(currentParentId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 继续向上查找
|
|
|
|
// 从匹配节点中移除那些父节点也在匹配列表中的节点
|
|
|
|
currentParentId = lineParentIdMap.get(currentParentId);
|
|
|
|
for (OrganizationRespVO node : organizationRespVOS) {
|
|
|
|
|
|
|
|
if (matchedNodeIds.contains(node.getId()) && node.getParentId() != null &&
|
|
|
|
|
|
|
|
node.getParentId() != 0L && matchedNodeIds.contains(node.getParentId())) {
|
|
|
|
|
|
|
|
topLevelNodeIds.remove(node.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<LineAnalysisTreeDTO.LineNode> buildTreeStructureWithKeyword(List<OrganizationRespVO> lines,
|
|
|
|
// 9. 获取顶层节点
|
|
|
|
Map<Long, List<DeviceDO>> devicesByLineId,
|
|
|
|
Map<Long, OrganizationRespVO> nodeMap = organizationRespVOS.stream()
|
|
|
|
Map<Long, List<DeviceContactModelDO>> paramsByDeviceId,
|
|
|
|
.collect(Collectors.toMap(OrganizationRespVO::getId, Function.identity()));
|
|
|
|
String keyword,
|
|
|
|
|
|
|
|
Map<Long, Long> lineParentIdMap) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 统一处理关键词
|
|
|
|
List<OrganizationRespVO> topLevelNodes = topLevelNodeIds.stream()
|
|
|
|
boolean hasKeyword = StringUtils.isNotBlank(keyword);
|
|
|
|
.map(nodeMap::get)
|
|
|
|
String lowerKeyword = hasKeyword ? keyword.toLowerCase() : "";
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
// 如果lines已经过滤过,这里不再需要复杂的匹配判断
|
|
|
|
// 10. 构建树结构
|
|
|
|
if (!hasKeyword) {
|
|
|
|
return buildOrganizationTreeWithChildren(topLevelNodes, matchedNodeIds, childrenByParentId,
|
|
|
|
// 没有关键词时,返回完整的树结构
|
|
|
|
deviceMap, paramsByDeviceId, lineOrgClassMap, keyword, organizationRespVOS, needShowDevices, hasKeyword);
|
|
|
|
return lines.stream().map(line -> {
|
|
|
|
}
|
|
|
|
Long parentId = lineParentIdMap.getOrDefault(line.getId(), 0L);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取该产线的设备
|
|
|
|
/**
|
|
|
|
List<DeviceDO> lineDevices = devicesByLineId.getOrDefault(line.getId(), new ArrayList<>());
|
|
|
|
* 迭代添加所有子孙节点
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void addAllDescendants(Long nodeId,
|
|
|
|
|
|
|
|
Map<Long, List<OrganizationRespVO>> childrenByParentId,
|
|
|
|
|
|
|
|
Set<Long> matchedNodeIds) {
|
|
|
|
|
|
|
|
if (childrenByParentId == null || childrenByParentId.isEmpty()) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 构建设备节点(显示所有设备和参数)
|
|
|
|
// 使用队列进行广度优先遍历
|
|
|
|
List<LineAnalysisTreeDTO.EquipmentNode> equipmentNodes = lineDevices.stream()
|
|
|
|
Queue<Long> queue = new LinkedList<>();
|
|
|
|
.map(device -> {
|
|
|
|
queue.offer(nodeId);
|
|
|
|
List<DeviceContactModelDO> deviceParams = paramsByDeviceId.getOrDefault(device.getId(), new ArrayList<>());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<LineAnalysisTreeDTO.ParameterNode> parameterNodes = deviceParams.stream()
|
|
|
|
while (!queue.isEmpty()) {
|
|
|
|
.map(this::buildParameterNode)
|
|
|
|
Long currentId = queue.poll();
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return LineAnalysisTreeDTO.EquipmentNode.builder()
|
|
|
|
List<OrganizationRespVO> children = childrenByParentId.get(currentId);
|
|
|
|
.id(device.getId())
|
|
|
|
if (children != null && !children.isEmpty()) {
|
|
|
|
.name(device.getDeviceName())
|
|
|
|
for (OrganizationRespVO child : children) {
|
|
|
|
.parameters(parameterNodes)
|
|
|
|
matchedNodeIds.add(child.getId());
|
|
|
|
.build();
|
|
|
|
queue.offer(child.getId());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return LineAnalysisTreeDTO.LineNode.builder()
|
|
|
|
|
|
|
|
.id(line.getId())
|
|
|
|
|
|
|
|
.name(line.getName())
|
|
|
|
|
|
|
|
.parentId(parentId)
|
|
|
|
|
|
|
|
.equipments(equipmentNodes)
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 有关键词时,lines已经包含了匹配的产线及其父级产线
|
|
|
|
|
|
|
|
// 但我们仍然需要根据关键词过滤设备和参数
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 记录匹配情况
|
|
|
|
|
|
|
|
Map<Long, Boolean> lineMatchedMap = new HashMap<>();
|
|
|
|
|
|
|
|
Map<Long, Boolean> deviceMatchedMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 第一遍:分析匹配情况
|
|
|
|
|
|
|
|
for (OrganizationRespVO line : lines) {
|
|
|
|
|
|
|
|
// 产线是否匹配
|
|
|
|
|
|
|
|
boolean lineMatch = line.getName() != null &&
|
|
|
|
|
|
|
|
line.getName().toLowerCase().contains(lowerKeyword);
|
|
|
|
|
|
|
|
lineMatchedMap.put(line.getId(), lineMatch);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查该产线的设备
|
|
|
|
|
|
|
|
List<DeviceDO> lineDevices = devicesByLineId.getOrDefault(line.getId(), new ArrayList<>());
|
|
|
|
|
|
|
|
for (DeviceDO device : lineDevices) {
|
|
|
|
|
|
|
|
// 设备是否匹配
|
|
|
|
|
|
|
|
boolean deviceMatch = device.getDeviceName() != null &&
|
|
|
|
|
|
|
|
device.getDeviceName().toLowerCase().contains(lowerKeyword);
|
|
|
|
|
|
|
|
deviceMatchedMap.put(device.getId(), deviceMatch);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 第二遍:构建树结构
|
|
|
|
/**
|
|
|
|
return lines.stream().map(line -> {
|
|
|
|
* 构建组织树(包含当前节点及其所有子节点)
|
|
|
|
boolean lineMatch = lineMatchedMap.getOrDefault(line.getId(), false);
|
|
|
|
*/
|
|
|
|
Long parentId = lineParentIdMap.getOrDefault(line.getId(), 0L);
|
|
|
|
private List<LineAnalysisTreeDTO.LineNode> buildOrganizationTreeWithChildren(
|
|
|
|
|
|
|
|
List<OrganizationRespVO> topLevelNodes,
|
|
|
|
|
|
|
|
Set<Long> matchedNodeIds,
|
|
|
|
|
|
|
|
Map<Long, List<OrganizationRespVO>> childrenByParentId,
|
|
|
|
|
|
|
|
Map<Long, DeviceDO> deviceMap,
|
|
|
|
|
|
|
|
Map<Long, List<DeviceContactModelDO>> paramsByDeviceId,
|
|
|
|
|
|
|
|
Map<Long, String> lineOrgClassMap,
|
|
|
|
|
|
|
|
String keyword,
|
|
|
|
|
|
|
|
List<OrganizationRespVO> allOrganizationRespVOS,
|
|
|
|
|
|
|
|
boolean needShowDevices,
|
|
|
|
|
|
|
|
boolean hasKeyword) {
|
|
|
|
|
|
|
|
|
|
|
|
// 获取该产线的设备
|
|
|
|
// 创建节点映射
|
|
|
|
List<DeviceDO> lineDevices = devicesByLineId.getOrDefault(line.getId(), new ArrayList<>());
|
|
|
|
Map<Long, LineAnalysisTreeDTO.LineNode> nodeMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
// 构建设备节点
|
|
|
|
// 创建所有组织节点的映射
|
|
|
|
List<LineAnalysisTreeDTO.EquipmentNode> equipmentNodes = lineDevices.stream()
|
|
|
|
Map<Long, OrganizationRespVO> allNodesMap = allOrganizationRespVOS.stream()
|
|
|
|
.map(device -> {
|
|
|
|
.collect(Collectors.toMap(OrganizationRespVO::getId, Function.identity()));
|
|
|
|
boolean deviceMatch = deviceMatchedMap.getOrDefault(device.getId(), false);
|
|
|
|
|
|
|
|
List<DeviceContactModelDO> deviceParams = paramsByDeviceId.getOrDefault(device.getId(), new ArrayList<>());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果产线匹配,显示该产线下的所有设备
|
|
|
|
// 获取所有匹配节点的完整列表(包括所有子孙节点)
|
|
|
|
if (lineMatch) {
|
|
|
|
Set<Long> allMatchedAndDescendantIds = new HashSet<>();
|
|
|
|
List<LineAnalysisTreeDTO.ParameterNode> parameterNodes = deviceParams.stream()
|
|
|
|
for (Long matchedId : matchedNodeIds) {
|
|
|
|
.map(this::buildParameterNode)
|
|
|
|
allMatchedAndDescendantIds.add(matchedId);
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
addAllDescendants(matchedId, childrenByParentId, allMatchedAndDescendantIds);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return LineAnalysisTreeDTO.EquipmentNode.builder()
|
|
|
|
// 构建所有匹配节点的树节点
|
|
|
|
.id(device.getId())
|
|
|
|
for (OrganizationRespVO node : allOrganizationRespVOS) {
|
|
|
|
.name(device.getDeviceName())
|
|
|
|
if (!allMatchedAndDescendantIds.contains(node.getId())) {
|
|
|
|
.parameters(parameterNodes)
|
|
|
|
continue;
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果设备匹配,显示该设备的所有参数
|
|
|
|
// 构建设备节点
|
|
|
|
if (deviceMatch) {
|
|
|
|
List<LineAnalysisTreeDTO.EquipmentNode> equipmentNodes = new ArrayList<>();
|
|
|
|
List<LineAnalysisTreeDTO.ParameterNode> parameterNodes = deviceParams.stream()
|
|
|
|
|
|
|
|
.map(this::buildParameterNode)
|
|
|
|
if (needShowDevices) {
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
// 有搜索关键词时获取所有设备,无关键词时只获取当前节点的设备
|
|
|
|
|
|
|
|
List<Long> deviceIds = hasKeyword ?
|
|
|
|
return LineAnalysisTreeDTO.EquipmentNode.builder()
|
|
|
|
getAllDeviceIdsForNode(node.getId(), childrenByParentId, allNodesMap, allMatchedAndDescendantIds) :
|
|
|
|
.id(device.getId())
|
|
|
|
getCurrentDeviceId(node, allNodesMap);
|
|
|
|
.name(device.getDeviceName())
|
|
|
|
|
|
|
|
.parameters(parameterNodes)
|
|
|
|
for (Long deviceId : deviceIds) {
|
|
|
|
.build();
|
|
|
|
DeviceDO device = deviceMap.get(deviceId);
|
|
|
|
}
|
|
|
|
if (device != null) {
|
|
|
|
|
|
|
|
// 获取设备参数
|
|
|
|
|
|
|
|
List<DeviceContactModelDO> deviceParams = paramsByDeviceId.getOrDefault(device.getId(), new ArrayList<>());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查设备和参数是否匹配关键词
|
|
|
|
|
|
|
|
boolean shouldIncludeDevice = false;
|
|
|
|
|
|
|
|
List<DeviceContactModelDO> filteredParams = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hasKeyword) {
|
|
|
|
|
|
|
|
String lowerKeyword = keyword.toLowerCase();
|
|
|
|
|
|
|
|
// 检查当前节点是否匹配关键词(组织名称匹配)
|
|
|
|
|
|
|
|
boolean isNodeNameMatched = node.getName() != null &&
|
|
|
|
|
|
|
|
node.getName().toLowerCase().contains(lowerKeyword);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isNodeNameMatched) {
|
|
|
|
|
|
|
|
// 有关键词但不是组织名称匹配的情况
|
|
|
|
|
|
|
|
boolean deviceNameMatches = device.getDeviceName() != null &&
|
|
|
|
|
|
|
|
device.getDeviceName().toLowerCase().contains(lowerKeyword);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查参数是否匹配
|
|
|
|
|
|
|
|
filteredParams = deviceParams.stream()
|
|
|
|
|
|
|
|
.filter(param -> param.getAttributeName() != null &&
|
|
|
|
|
|
|
|
param.getAttributeName().toLowerCase().contains(lowerKeyword))
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否有匹配的参数
|
|
|
|
boolean hasMatchingParam = !filteredParams.isEmpty();
|
|
|
|
boolean hasMatchingParam = deviceParams.stream()
|
|
|
|
|
|
|
|
.anyMatch(param -> isParameterMatch(param, lowerKeyword));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!hasMatchingParam) {
|
|
|
|
// 如果设备名称或参数匹配,则包含设备
|
|
|
|
return null;
|
|
|
|
if (deviceNameMatches || hasMatchingParam) {
|
|
|
|
|
|
|
|
shouldIncludeDevice = true;
|
|
|
|
|
|
|
|
// 如果设备名称匹配但参数不匹配,包含所有参数
|
|
|
|
|
|
|
|
if (deviceNameMatches && filteredParams.isEmpty()) {
|
|
|
|
|
|
|
|
filteredParams = new ArrayList<>(deviceParams);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 是组织名称匹配的情况:包含所有设备和参数
|
|
|
|
|
|
|
|
shouldIncludeDevice = true;
|
|
|
|
|
|
|
|
filteredParams = new ArrayList<>(deviceParams);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 无关键词的情况:包含所有设备和参数
|
|
|
|
|
|
|
|
shouldIncludeDevice = true;
|
|
|
|
|
|
|
|
filteredParams = new ArrayList<>(deviceParams);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 只显示匹配的参数
|
|
|
|
if (shouldIncludeDevice) {
|
|
|
|
List<LineAnalysisTreeDTO.ParameterNode> parameterNodes = deviceParams.stream()
|
|
|
|
List<LineAnalysisTreeDTO.ParameterNode> paramInfos = filteredParams.stream()
|
|
|
|
.filter(param -> isParameterMatch(param, lowerKeyword))
|
|
|
|
.map(this::convertToSimpleInfo)
|
|
|
|
.map(this::buildParameterNode)
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return LineAnalysisTreeDTO.EquipmentNode.builder()
|
|
|
|
// 检查设备是否已添加(避免重复)
|
|
|
|
|
|
|
|
boolean alreadyAdded = equipmentNodes.stream()
|
|
|
|
|
|
|
|
.anyMatch(e -> e.getId().equals(device.getId()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!alreadyAdded) {
|
|
|
|
|
|
|
|
equipmentNodes.add(LineAnalysisTreeDTO.EquipmentNode.builder()
|
|
|
|
.id(device.getId())
|
|
|
|
.id(device.getId())
|
|
|
|
.name(device.getDeviceName())
|
|
|
|
.name(device.getDeviceName())
|
|
|
|
.parameters(parameterNodes)
|
|
|
|
.parameters(paramInfos)
|
|
|
|
.build();
|
|
|
|
.build());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
}
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return LineAnalysisTreeDTO.LineNode.builder()
|
|
|
|
}
|
|
|
|
.id(line.getId())
|
|
|
|
|
|
|
|
.name(line.getName())
|
|
|
|
|
|
|
|
.parentId(parentId)
|
|
|
|
|
|
|
|
.equipments(equipmentNodes)
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
LineAnalysisTreeDTO.LineNode lineNode = LineAnalysisTreeDTO.LineNode.builder()
|
|
|
|
// * 检查产线下是否有匹配的设备或参数
|
|
|
|
.id(node.getId())
|
|
|
|
// */
|
|
|
|
.name(node.getName())
|
|
|
|
// private boolean checkIfLineHasMatchingDeviceOrParam(OrganizationRespVO line,
|
|
|
|
.orgClass(lineOrgClassMap.getOrDefault(node.getId(), null))
|
|
|
|
// Map<Long, List<DeviceDO>> devicesByLineId,
|
|
|
|
.parentId(node.getParentId())
|
|
|
|
// Map<Long, List<DeviceContactModelDO>> paramsByDeviceId,
|
|
|
|
.equipments(equipmentNodes)
|
|
|
|
// String lowerKeyword,
|
|
|
|
.children(new ArrayList<>())
|
|
|
|
// Map<Long, Boolean> deviceMatchedMap) {
|
|
|
|
.build();
|
|
|
|
//
|
|
|
|
|
|
|
|
// List<DeviceDO> lineDevices = devicesByLineId.getOrDefault(line.getId(), new ArrayList<>());
|
|
|
|
nodeMap.put(node.getId(), lineNode);
|
|
|
|
//
|
|
|
|
}
|
|
|
|
// for (DeviceDO device : lineDevices) {
|
|
|
|
|
|
|
|
// // 检查设备是否匹配
|
|
|
|
// 构建父子关系
|
|
|
|
// boolean deviceMatch = deviceMatchedMap.getOrDefault(device.getId(), false);
|
|
|
|
List<LineAnalysisTreeDTO.LineNode> result = new ArrayList<>();
|
|
|
|
// if (deviceMatch) {
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
for (LineAnalysisTreeDTO.LineNode lineNode : nodeMap.values()) {
|
|
|
|
// }
|
|
|
|
if (lineNode.getParentId() == null || lineNode.getParentId() == 0L) {
|
|
|
|
//
|
|
|
|
// 根节点
|
|
|
|
// // 检查设备下的参数是否匹配
|
|
|
|
result.add(lineNode);
|
|
|
|
// List<DeviceContactModelDO> deviceParams = paramsByDeviceId.getOrDefault(device.getId(), new ArrayList<>());
|
|
|
|
} else {
|
|
|
|
// boolean hasMatchingParam = deviceParams.stream()
|
|
|
|
// 查找父节点
|
|
|
|
// .anyMatch(param -> isParameterMatch(param, lowerKeyword));
|
|
|
|
LineAnalysisTreeDTO.LineNode parentNode = nodeMap.get(lineNode.getParentId());
|
|
|
|
// if (hasMatchingParam) {
|
|
|
|
if (parentNode != null) {
|
|
|
|
// return true;
|
|
|
|
parentNode.getChildren().add(lineNode);
|
|
|
|
// }
|
|
|
|
} else {
|
|
|
|
// }
|
|
|
|
// 父节点不在当前构建的节点中,但当前节点是匹配的
|
|
|
|
//
|
|
|
|
// 这种情况下,当前节点应该作为根节点展示
|
|
|
|
// return false;
|
|
|
|
result.add(lineNode);
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
//
|
|
|
|
}
|
|
|
|
// /**
|
|
|
|
}
|
|
|
|
// * 检查设备下是否有匹配的参数
|
|
|
|
|
|
|
|
// */
|
|
|
|
|
|
|
|
// private boolean checkIfDeviceHasMatchingParam(DeviceDO device,
|
|
|
|
|
|
|
|
// Map<Long, List<DeviceContactModelDO>> paramsByDeviceId,
|
|
|
|
|
|
|
|
// String lowerKeyword) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// List<DeviceContactModelDO> deviceParams = paramsByDeviceId.getOrDefault(device.getId(), new ArrayList<>());
|
|
|
|
|
|
|
|
// return deviceParams.stream()
|
|
|
|
|
|
|
|
// .anyMatch(param -> isParameterMatch(param, lowerKeyword));
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 过滤:只保留顶层节点
|
|
|
|
|
|
|
|
List<LineAnalysisTreeDTO.LineNode> filteredResult = new ArrayList<>();
|
|
|
|
|
|
|
|
Set<Long> topLevelNodeIds = topLevelNodes.stream()
|
|
|
|
|
|
|
|
.map(OrganizationRespVO::getId)
|
|
|
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (LineAnalysisTreeDTO.LineNode node : result) {
|
|
|
|
|
|
|
|
if (topLevelNodeIds.contains(node.getId())) {
|
|
|
|
|
|
|
|
filteredResult.add(node);
|
|
|
|
|
|
|
|
} else if (node.getParentId() == null || node.getParentId() == 0L) {
|
|
|
|
|
|
|
|
// 或者是没有父节点的根节点
|
|
|
|
|
|
|
|
filteredResult.add(node);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return filteredResult;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 判断参数是否匹配关键词
|
|
|
|
* 获取当前节点自身的设备ID
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private boolean isParameterMatch(DeviceContactModelDO param, String lowerKeyword) {
|
|
|
|
private List<Long> getCurrentDeviceId(OrganizationRespVO node, Map<Long, OrganizationRespVO> allNodesMap) {
|
|
|
|
if (StringUtils.isBlank(lowerKeyword)) {
|
|
|
|
List<Long> deviceIds = new ArrayList<>();
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前节点
|
|
|
|
|
|
|
|
OrganizationRespVO currentNode = allNodesMap.get(node.getId());
|
|
|
|
|
|
|
|
if (currentNode != null && currentNode.getMachineId() != null) {
|
|
|
|
|
|
|
|
deviceIds.add(currentNode.getMachineId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (param.getAttributeName() != null && param.getAttributeName().toLowerCase().contains(lowerKeyword));
|
|
|
|
return deviceIds;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取节点及其子孙节点的设备ID
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private List<Long> getAllDeviceIdsForNode(Long nodeId,
|
|
|
|
|
|
|
|
Map<Long, List<OrganizationRespVO>> childrenByParentId,
|
|
|
|
|
|
|
|
Map<Long, OrganizationRespVO> allNodesMap,
|
|
|
|
|
|
|
|
Set<Long> matchedNodeIds) {
|
|
|
|
|
|
|
|
Set<Long> deviceIds = new HashSet<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 先检查当前节点是否有设备
|
|
|
|
|
|
|
|
OrganizationRespVO currentNode = allNodesMap.get(nodeId);
|
|
|
|
|
|
|
|
if (currentNode != null && currentNode.getMachineId() != null) {
|
|
|
|
|
|
|
|
deviceIds.add(currentNode.getMachineId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 使用队列迭代获取所有子孙节点
|
|
|
|
|
|
|
|
Queue<Long> queue = new LinkedList<>();
|
|
|
|
|
|
|
|
queue.offer(nodeId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (!queue.isEmpty()) {
|
|
|
|
|
|
|
|
Long currentId = queue.poll();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前节点的子节点
|
|
|
|
|
|
|
|
List<OrganizationRespVO> children = childrenByParentId.get(currentId);
|
|
|
|
|
|
|
|
if (children != null) {
|
|
|
|
|
|
|
|
for (OrganizationRespVO child : children) {
|
|
|
|
|
|
|
|
if (matchedNodeIds.contains(child.getId())) {
|
|
|
|
|
|
|
|
// 如果子节点有设备,添加到设备列表
|
|
|
|
|
|
|
|
if (child.getMachineId() != null) {
|
|
|
|
|
|
|
|
deviceIds.add(child.getMachineId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 继续处理子节点的子节点
|
|
|
|
|
|
|
|
queue.offer(child.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new ArrayList<>(deviceIds);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 构建参数节点
|
|
|
|
* 将设备参数转换为简化的参数信息
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private LineAnalysisTreeDTO.ParameterNode buildParameterNode(DeviceContactModelDO param) {
|
|
|
|
private LineAnalysisTreeDTO.ParameterNode convertToSimpleInfo(DeviceContactModelDO param) {
|
|
|
|
return LineAnalysisTreeDTO.ParameterNode.builder()
|
|
|
|
return LineAnalysisTreeDTO.ParameterNode.builder()
|
|
|
|
.id(param.getId())
|
|
|
|
.id(param.getId())
|
|
|
|
.name(param.getAttributeName())
|
|
|
|
.name(param.getAttributeName())
|
|
|
|
@ -636,29 +667,4 @@ public class OrganizationServiceImpl implements OrganizationService {
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<DeviceContactModelDO> getAllParameters(List<DeviceDO> devices) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (devices.isEmpty()) {
|
|
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Long> deviceIds = devices.stream()
|
|
|
|
|
|
|
|
.map(DeviceDO::getId)
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<DeviceContactModelDO> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
|
|
|
wrapper.in(DeviceContactModelDO::getDeviceId, deviceIds)
|
|
|
|
|
|
|
|
.orderByAsc(DeviceContactModelDO::getSort); // 按排序字段排序
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<DeviceContactModelDO> result = deviceContactModelMapper.selectList(wrapper);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 调试日志
|
|
|
|
|
|
|
|
System.out.println("查询条件: 设备IDs=" + deviceIds);
|
|
|
|
|
|
|
|
System.out.println("查询结果数量: " + result.size());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|