mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	update 优化 部门树多基点展示问题 支持相同名称节点并排展示
This commit is contained in:
		@@ -43,6 +43,23 @@ public class TreeBuildUtils extends TreeUtil {
 | 
				
			|||||||
        return TreeUtil.build(list, k, DEFAULT_CONFIG, nodeParser);
 | 
					        return TreeUtil.build(list, k, DEFAULT_CONFIG, nodeParser);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 构建树形结构
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param <T>        输入节点的类型
 | 
				
			||||||
 | 
					     * @param <K>        节点ID的类型
 | 
				
			||||||
 | 
					     * @param parentId   顶级节点
 | 
				
			||||||
 | 
					     * @param list       节点列表,其中包含了要构建树形结构的所有节点
 | 
				
			||||||
 | 
					     * @param nodeParser 解析器,用于将输入节点转换为树节点
 | 
				
			||||||
 | 
					     * @return 构建好的树形结构列表
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static <T, K> List<Tree<K>> build(List<T> list, K parentId, NodeParser<T, K> nodeParser) {
 | 
				
			||||||
 | 
					        if (CollUtil.isEmpty(list)) {
 | 
				
			||||||
 | 
					            return CollUtil.newArrayList();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return TreeUtil.build(list, parentId, DEFAULT_CONFIG, nodeParser);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 获取节点列表中所有节点的叶子节点
 | 
					     * 获取节点列表中所有节点的叶子节点
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -102,11 +102,22 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
 | 
				
			|||||||
        if (CollUtil.isEmpty(depts)) {
 | 
					        if (CollUtil.isEmpty(depts)) {
 | 
				
			||||||
            return CollUtil.newArrayList();
 | 
					            return CollUtil.newArrayList();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return TreeBuildUtils.build(depts, (dept, tree) ->
 | 
					        // 获取当前列表中每一个节点的parentId,然后在列表中查找是否有id与其parentId对应,若无对应,则表明此时节点列表中,该节点在当前列表中属于顶级节点
 | 
				
			||||||
            tree.setId(dept.getDeptId())
 | 
					        List<Tree<Long>> treeList = CollUtil.newArrayList();
 | 
				
			||||||
                .setParentId(dept.getParentId())
 | 
					        for (SysDeptVo d : depts) {
 | 
				
			||||||
                .setName(dept.getDeptName())
 | 
					            Long parentId = d.getParentId();
 | 
				
			||||||
                .setWeight(dept.getOrderNum()));
 | 
					            SysDeptVo sysDeptVo = depts.stream().filter(it -> it.getDeptId().longValue() == parentId).findFirst().orElse(null);
 | 
				
			||||||
 | 
					            if (sysDeptVo == null) {
 | 
				
			||||||
 | 
					                List<Tree<Long>> trees = TreeBuildUtils.build(depts, parentId, (dept, tree) ->
 | 
				
			||||||
 | 
					                    tree.setId(dept.getDeptId())
 | 
				
			||||||
 | 
					                        .setParentId(dept.getParentId())
 | 
				
			||||||
 | 
					                        .setName(dept.getDeptName())
 | 
				
			||||||
 | 
					                        .setWeight(dept.getOrderNum()));
 | 
				
			||||||
 | 
					                Tree<Long> tree = trees.stream().filter(it -> it.getId().longValue() == d.getDeptId()).findFirst().get();
 | 
				
			||||||
 | 
					                treeList.add(tree);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return treeList;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user