1、修改bug

This commit is contained in:
潘荣晟
2025-10-30 16:15:15 +08:00
parent d6fb9fcb22
commit 9eb7efd088
6 changed files with 40 additions and 19 deletions

View File

@@ -393,12 +393,7 @@ public class TmplTpServiceImpl extends ServiceImpl<TmplTpMapper, TmplTpDO> imple
String nodeId = node.getId().toString();
String parentId = node.getPrnId() != null ? node.getPrnId().toString() : null;
// 如果是查询条件匹配的根节点
if (rootIds.contains(nodeId)) {
roots.add(node);
}
// 如果有父节点且父节点在当前节点集合中,建立父子关系
// 建立父子关系
if (parentId != null && nodeMap.containsKey(parentId)) {
TmplTpTreeVO parent = nodeMap.get(parentId);
if (parent.getChildren() == null) {
@@ -408,14 +403,26 @@ public class TmplTpServiceImpl extends ServiceImpl<TmplTpMapper, TmplTpDO> imple
}
}
// 3. 对所有节点的子节点进行排序
// 3. 只将匹配的节点rootIds且没有父节点在结果集中的作为根节点
for (String rootId : rootIds) {
TmplTpTreeVO node = nodeMap.get(rootId);
if (node != null) {
String parentId = node.getPrnId() != null ? node.getPrnId().toString() : null;
// 如果父节点不在当前结果集中,则作为根节点
if (parentId == null || !nodeMap.containsKey(parentId)) {
roots.add(node);
}
}
}
// 4. 对所有节点的子节点进行排序
nodeMap.values().forEach(node -> {
if (node.getChildren() != null && !node.getChildren().isEmpty()) {
node.getChildren().sort(Comparator.comparing(TmplTpTreeVO::getSrt));
}
});
// 4. 对根节点排序
// 5. 对根节点排序
roots.sort(Comparator.comparing(TmplTpTreeVO::getSrt));
return roots;