feat(dept): 添加根据部门ID查询所有子部门功能

- 在 ISysDeptService 中新增 selectChildDeptsById 方法定义
- 在 SysDeptController 中新增 listWithChildren 接口用于查询部门及子部门
- 在 SysDeptServiceImpl 中实现 selectChildDeptsById 方法,使用 ancestors 字段递归查询
- 使用注解权限控制确保接口安全性
- 返回完整的部门树形结构数据
This commit is contained in:
2026-01-27 10:04:26 +08:00
parent 91156d8e20
commit fb203d7eb8
3 changed files with 30 additions and 0 deletions

View File

@@ -116,4 +116,16 @@ public class SysDeptController extends BaseController {
deptService.checkDeptDataScope(deptId); deptService.checkDeptDataScope(deptId);
return toAjax(deptService.deleteDeptById(deptId)); return toAjax(deptService.deleteDeptById(deptId));
} }
/**
* 查询部门及其所有子部门
*
* @param deptId 部门ID
*/
@SaCheckPermission("system:dept:list")
@GetMapping("/list/{deptId}")
public R<List<SysDept>> listWithChildren(@PathVariable Long deptId) {
List<SysDept> depts = deptService.selectChildDeptsById(deptId);
return R.ok(depts);
}
} }

View File

@@ -113,4 +113,12 @@ public interface ISysDeptService {
* @return 结果 * @return 结果
*/ */
int deleteDeptById(Long deptId); int deleteDeptById(Long deptId);
/**
* 根据部门ID查询所有子部门递归
*
* @param deptId 部门ID
* @return 所有子部门列表
*/
List<SysDept> selectChildDeptsById(Long deptId);
} }

View File

@@ -270,6 +270,16 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
.in(SysDept::getDeptId, Arrays.asList(deptIds))); .in(SysDept::getDeptId, Arrays.asList(deptIds)));
} }
@Override
public List<SysDept> selectChildDeptsById(Long deptId) {
// 创建查询条件查找祖先列表中包含指定部门ID的所有部门
LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>();
lqw.eq(SysDept::getDelFlag, "0")
.apply(DataBaseHelper.findInSet(deptId, "ancestors"));
return baseMapper.selectList(lqw);
}
/** /**
* 修改子元素关系 * 修改子元素关系
* *