mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-09-17 19:06:39 +08:00
!36 解决deparement中返回树形列表SelfAndAllChildrenIdList只返回本节点id的问题
Merge pull request !36 from C-ccc/N/A
This commit is contained in:
commit
d702e6cca4
@ -143,10 +143,12 @@ public class DepartmentCacheManager {
|
||||
|
||||
/**
|
||||
* 构建所有根节点的下级树形结构
|
||||
*
|
||||
* 返回值为层序遍历结果
|
||||
* [由于departmentDao中listAll给出数据根据Sort降序 所以同一层中Sort值较大的优先遍历]
|
||||
*/
|
||||
private void recursiveBuildTree(List<DepartmentTreeVO> nodeList, List<DepartmentVO> allDepartmentList) {
|
||||
private List<Long> recursiveBuildTree(List<DepartmentTreeVO> nodeList, List<DepartmentVO> allDepartmentList) {
|
||||
int nodeSize = nodeList.size();
|
||||
List<Long> childIdList = new ArrayList<>();
|
||||
for(int i = 0; i < nodeSize; i++) {
|
||||
int preIndex = i - 1;
|
||||
int nextIndex = i + 1;
|
||||
@ -158,16 +160,34 @@ public class DepartmentCacheManager {
|
||||
node.setNextId(nodeList.get(nextIndex).getDepartmentId());
|
||||
}
|
||||
|
||||
ArrayList<Long> selfAndAllChildrenIdList = Lists.newArrayList();
|
||||
selfAndAllChildrenIdList.add(node.getDepartmentId());
|
||||
node.setSelfAndAllChildrenIdList(selfAndAllChildrenIdList);
|
||||
|
||||
List<DepartmentTreeVO> children = getChildren(node.getDepartmentId(), allDepartmentList);
|
||||
|
||||
List<Long> tempChildIdList = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(children)) {
|
||||
node.setChildren(children);
|
||||
this.recursiveBuildTree(children, allDepartmentList);
|
||||
tempChildIdList = this.recursiveBuildTree(children, allDepartmentList);
|
||||
}
|
||||
|
||||
if(CollectionUtils.isEmpty(node.getSelfAndAllChildrenIdList())) {
|
||||
node.setSelfAndAllChildrenIdList(
|
||||
new ArrayList<>()
|
||||
);
|
||||
}
|
||||
node.getSelfAndAllChildrenIdList().add(node.getDepartmentId());
|
||||
|
||||
if(CollectionUtils.isNotEmpty(tempChildIdList)) {
|
||||
node.getSelfAndAllChildrenIdList().addAll(tempChildIdList);
|
||||
childIdList.addAll(tempChildIdList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 保证本层遍历顺序
|
||||
for(int i = nodeSize - 1; i >= 0; i--) {
|
||||
childIdList.add(0, nodeList.get(i).getDepartmentId());
|
||||
}
|
||||
|
||||
return childIdList;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user