| | |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_POST_NOT_EMPTY; |
| | | |
| | | @Tag(name = "管理后台 - 用户") |
| | | @RestController |
| | |
| | | @Operation(summary = "新增用户") |
| | | @PreAuthorize("@ss.hasPermission('system:user:create')") |
| | | public CommonResult<Long> createUser(@Valid @RequestBody UserSaveReqVO reqVO) { |
| | | // 校验岗位必填 |
| | | if (CollUtil.isEmpty(reqVO.getPostIds())) { |
| | | throw exception(USER_POST_NOT_EMPTY); |
| | | } |
| | | Long id = userService.createUser(reqVO); |
| | | return success(id); |
| | | } |
| | |
| | | @Operation(summary = "修改用户") |
| | | @PreAuthorize("@ss.hasPermission('system:user:update')") |
| | | public CommonResult<Boolean> updateUser(@Valid @RequestBody UserSaveReqVO reqVO) { |
| | | // 校验岗位必填 |
| | | if (CollUtil.isEmpty(reqVO.getPostIds())) { |
| | | throw exception(USER_POST_NOT_EMPTY); |
| | | } |
| | | userService.updateUser(reqVO); |
| | | return success(true); |
| | | } |
| | |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "获得用户分页列表") |
| | | @PreAuthorize("@ss.hasPermission('system:user:query')") |
| | | public CommonResult<PageResult<UserRespVO>> getUserPage(@Valid UserPageReqVO pageReqVO) { |
| | | // 获得用户分页列表 |
| | | PageResult<AdminUserDO> pageResult = userService.getUserPage(pageReqVO); |
| | |
| | | @GetMapping("/list") |
| | | @Operation(summary = "获得用户详情列表") |
| | | @Parameter(name = "ids", description = "编号列表", required = true, example = "[1024]") |
| | | @PreAuthorize("@ss.hasPermission('system:user:query')") |
| | | public CommonResult<List<UserRespVO>> getUserList(@RequestParam("ids") List<Long> ids) { |
| | | List<AdminUserDO> list = userService.getUserList(ids); |
| | | if (CollUtil.isEmpty(list)) { |
| | |
| | | } |
| | | |
| | | @GetMapping("/list-by-role-code") |
| | | @Operation(summary = "通过角色标识获取用户精简信息列表", description = "只包含拥有该角色的用户,主要用于前端的下拉选项") |
| | | @Parameter(name = "code", description = "角色标识", required = true, example = "admin") |
| | | @Operation(summary = "通过角色标识获取用户精简信息列表", description = "只包含拥有这些角色的用户,主要用于前端的下拉选项。支持逗号分隔的多个角色标识") |
| | | @Parameter(name = "code", description = "角色标识,支持多个,逗号分隔", required = true, example = "admin,user") |
| | | public CommonResult<List<UserSimpleRespVO>> getSimpleUserListByRoleCode( |
| | | @RequestParam("code") String code) { |
| | | RoleDO role = roleService.getRoleByCode(code); |
| | | if (role == null) { |
| | | if (StrUtil.isBlank(code)) { |
| | | return success(Collections.emptyList()); |
| | | } |
| | | Set<Long> userIds = permissionService.getUserRoleIdListByRoleId(Collections.singleton(role.getId())); |
| | | List<String> codes = StrUtil.split(code, ","); |
| | | List<RoleDO> roles = roleService.getRoleListByCodes(codes); |
| | | if (CollUtil.isEmpty(roles)) { |
| | | return success(Collections.emptyList()); |
| | | } |
| | | Set<Long> userIds = permissionService.getUserRoleIdListByRoleId(convertList(roles, RoleDO::getId)); |
| | | if (CollUtil.isEmpty(userIds)) { |
| | | return success(Collections.emptyList()); |
| | | } |
| | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "获得用户详情") |
| | | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| | | @PreAuthorize("@ss.hasPermission('system:user:query')") |
| | | public CommonResult<UserRespVO> getUser(@RequestParam("id") Long id) { |
| | | AdminUserDO user = userService.getUser(id); |
| | | if (user == null) { |