diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/DeptController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/DeptController.java index cf5c2aa8e0..29babc9c17 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/DeptController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/DeptController.java @@ -82,5 +82,12 @@ public class DeptController { return success(BeanUtils.toBean(dept, DeptRespVO.class)); } + @GetMapping("/listByDeptId") + @Operation(summary = "根据部门ID查询部门列表") + @Parameter(name = "deptId", description = "部门编号", required = true, example = "1024") + public CommonResult> getDeptListByDeptId(@RequestParam("deptId") Long deptId) { + List list = deptService.getDeptListByDeptId(deptId); + return success(BeanUtils.toBean(list, DeptRespVO.class)); + } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java index 3ddb741717..38ec1126fa 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java @@ -118,4 +118,12 @@ public interface DeptService { */ void validateDeptList(Collection ids); + /** + * 根据部门ID查询部门列表 + * + * @param deptId 部门编号 + * @return 部门列表 + */ + List getDeptListByDeptId(Long deptId); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java index 13b0765418..2a36cd1cfb 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java @@ -235,4 +235,24 @@ public class DeptServiceImpl implements DeptService { }); } + @Override + public List getDeptListByDeptId(Long deptId) { + // 如果部门ID为1或1001,返回所有部门列表 + if (deptId == 100L || deptId == 1001L) { + return deptMapper.selectList(new DeptListReqVO()); + } + // 获取当前部门 + DeptDO dept = getDept(deptId); + if (dept == null) { + return Collections.emptyList(); + } + // 获取所有子部门 + List childDepts = getChildDeptList(deptId); + // 将当前部门添加到列表中 + List result = new ArrayList<>(); + result.add(dept); + result.addAll(childDepts); + return result; + } + }