添加getAllChildDeptIds方法获取所有子部门ID

This commit is contained in:
Your Name 2026-01-20 13:50:04 +08:00
parent c839bba7b6
commit 3e74be7087

View File

@ -592,6 +592,30 @@ public class DepartmentService {
return children;
}
/**
* 获取部门的所有子部门ID(递归)
*/
public List<Long> getAllChildDeptIds(Long deptId) {
List<Long> result = new ArrayList<>();
if (deptId == null) {
return result;
}
// 查找直接子部门
List<Department> children = departmentMapper.selectList(
new LambdaQueryWrapper<Department>()
.eq(Department::getParentId, deptId)
);
// 递归获取所有子部门
for (Department child : children) {
result.add(child.getId());
result.addAll(getAllChildDeptIds(child.getId()));
}
return result;
}
/**
* 检查用户是否为任何部门的负责人
*/