本文最后更新于 2026年5月15日 下午
获取角色部门ID集合接口的实现
获取角色部门ID集合接口的需求
获取角色id
根据角色id查出该角色有属于哪些部门(通过角色部门联表)
封装成 部门id列表
代码实现
其实这和前面的 获取角色菜单ID集合接口 是差不多的 就改个联表而已
SysRoleController
1 2 3 4 5 6 7
| @GetMapping("/{roleId}/dept-ids") @SystemLog(businessName = "获取角色部门ID集合") @ApiOperation(value = "角色部门ID集合", notes = "获取角色部门ID集合", responseContainer = "List") public ResponseResult<List<Long>> getRoleDeptList(@PathVariable Long roleId) { return sysRoleService.getRoleDeptList(roleId); }
|
在 SysRoleServiceImpl 中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| @Autowired private SysRoleDeptService sysRoleDeptService;
@Override public ResponseResult<List<Long>> getRoleDeptList(Long roleId) { SysRole sysRole = sysRoleService.getById(roleId); if (sysRole == null) { return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR, "该角色不存在!"); }
LambdaQueryWrapper<SysRoleDept> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SysRoleDept::getRoleId, roleId) .select(SysRoleDept::getDeptId);
List<SysRoleDept> roleDeptList = sysRoleDeptService.list(wrapper);
List<Long> deptIds = roleDeptList.stream() .map(SysRoleDept::getDeptId) .toList();
return ResponseResult.okResult(deptIds); }
|
PS:该系列只做为作者学习开发项目做的笔记用
不一定符合读者来学习,仅供参考
预告
后续会记录博客的开发过程
每次学习会做一份笔记来进行发表
“一花一世界,一叶一菩提”
版权所有 © 2026 云梦泽
欢迎访问我的个人网站:https://hgt12.github.io/