fix(基础组件): 修复遍历构造树函数的缺陷

Closes 34521
This commit is contained in:
Jianguo-Genius 2024-12-05 15:34:11 +08:00 committed by 建国
parent 02be82aada
commit e83985a2f5
1 changed files with 7 additions and 0 deletions

View File

@ -59,6 +59,13 @@ public abstract class ModuleTreeService {
}
int lastSize = 0;
Map<String, BaseTreeNode> baseTreeNodeMap = new HashMap<>();
// 根节点预先处理
baseTreeNodeList.addAll(traverseList.stream().filter(treeNode -> StringUtils.equalsIgnoreCase(treeNode.getParentId(), ModuleConstants.ROOT_NODE_PARENT_ID)).toList());
baseTreeNodeList.forEach(item -> baseTreeNodeMap.put(item.getId(), item));
traverseList = (List<BaseTreeNode>) CollectionUtils.removeAll(traverseList, baseTreeNodeList);
// 循环处理子节点
while (CollectionUtils.isNotEmpty(traverseList) && traverseList.size() != lastSize) {
lastSize = traverseList.size();
List<BaseTreeNode> notMatchedList = new ArrayList<>();