| | |
| | | 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("/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()); |
| | | } |