通过部门ID递归查询其下所有子部门。
/**
* 获取部门下所有子部门的 ID 集合
*
* @param deptId 传入当前部门id
* @param allSysDeptList 传入所有部门
* @param childDeptList 返回封装后的所有子部门
* @return void
*/
private void getDeptIdList(Long deptId, List<SysDept> allSysDeptList, List<Long> childDeptList) {
// 遍历所有部门,查deptId的所有子部门
allSysDeptList.forEach(e -> {
// deptId=parentId为当前部门的直接子部门
if (deptId.equals(e.getParentId())) {
// 添加子部门
childDeptList.add(e.getId());
// 递归查deptId子部门下的子部门
this.getDeptIdList(e.getId(), allSysDeptList, childDeptList);
}
});
}