update 优化 部门树多基点展示问题 支持相同名称节点并排展示

This commit is contained in:
疯狂的狮子Li
2024-11-04 11:38:45 +08:00
parent 53635da552
commit 2ffdd56301
2 changed files with 33 additions and 5 deletions

View File

@ -102,11 +102,22 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
if (CollUtil.isEmpty(depts)) {
return CollUtil.newArrayList();
}
return TreeBuildUtils.build(depts, (dept, tree) ->
tree.setId(dept.getDeptId())
.setParentId(dept.getParentId())
.setName(dept.getDeptName())
.setWeight(dept.getOrderNum()));
// 获取当前列表中每一个节点的parentId然后在列表中查找是否有id与其parentId对应若无对应则表明此时节点列表中该节点在当前列表中属于顶级节点
List<Tree<Long>> treeList = CollUtil.newArrayList();
for (SysDeptVo d : depts) {
Long parentId = d.getParentId();
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;
}
/**