private static List<Long> getChildDept(Long deptId, List<SystemDept> allDeptList) {
Set<Long> childDeptIds = new HashSet<>();
childDeptIds.add(deptId);
List<SystemDept> returnList = new ArrayList<>();
allDeptList.stream().filter(f -> f.getDeptId().compareTo(deptId) == 0).findFirst().ifPresent(p -> returnList.add(p));
List<SystemDept> allChildList = allDeptList.stream().filter(f -> Objects.nonNull(f.getParentId()) && f.getParentId().compareTo(deptId) == 0).collect(Collectors.toList());
for (SystemDept dept : allChildList) {
childDeptIds.add(dept.getDeptId());
returnList.add(dept);
recursiveTree2(dept, allDeptList, childDeptIds, returnList);
}
log.info("全集》》》{}", JSONObject.toJSONString(childDeptIds));
return returnList.stream().map(SystemDept::getDeptId).collect(Collectors.toList());
}
public static SystemDept recursiveTree2(SystemDept parent, List<SystemDept> allDeptList, Set<Long> childDeptIds, List<SystemDept> returnList) {
for (SystemDept dept : allDeptList) {
if (Objects.nonNull(dept.getParentId()) && parent.getDeptId().compareTo(dept.getParentId()) == 0) {
childDeptIds.add(dept.getDeptId());
returnList.add(dept);
recursiveTree2(dept, allDeptList, childDeptIds, returnList);
}
}
return parent;
}
获取本部门及所有子部门
最新推荐文章于 2024-05-17 13:43:01 发布