mirror of
https://gitee.com/log4j/pig.git
synced 2024-12-23 05:00:23 +08:00
🐛 查询用户部门树根据当前用户所在部门上级部门id构建部门树
This commit is contained in:
parent
1c104ec5b1
commit
2de7391840
@ -121,7 +121,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
*/
|
||||
@Override
|
||||
public List<Tree<Long>> listDeptTrees() {
|
||||
return getDeptTree(this.list(Wrappers.emptyWrapper()));
|
||||
return getDeptTree(this.list(Wrappers.emptyWrapper()), 0L);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -136,15 +136,17 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
.map(SysDeptRelation::getDescendant).collect(Collectors.toList());
|
||||
|
||||
List<SysDept> deptList = baseMapper.selectBatchIds(descendantIdList);
|
||||
return getDeptTree(deptList);
|
||||
Optional<SysDept> dept = deptList.stream().filter(item -> item.getDeptId().intValue() == deptId).findFirst();
|
||||
return getDeptTree(deptList, dept.isPresent() ? dept.get().getParentId() : 0L);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建部门树
|
||||
* @param depts 部门
|
||||
* @param parentId 父级id
|
||||
* @return
|
||||
*/
|
||||
private List<Tree<Long>> getDeptTree(List<SysDept> depts) {
|
||||
private List<Tree<Long>> getDeptTree(List<SysDept> depts, Long parentId) {
|
||||
List<TreeNode<Long>> collect = depts.stream().filter(dept -> dept.getDeptId().intValue() != dept.getParentId())
|
||||
.sorted(Comparator.comparingInt(SysDept::getSortOrder)).map(dept -> {
|
||||
TreeNode<Long> treeNode = new TreeNode();
|
||||
@ -159,7 +161,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
return treeNode;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return TreeUtil.build(collect, 0L);
|
||||
return TreeUtil.build(collect, parentId);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user