liu
21 小时以前 81d74afadcc07e846d6feabf98bfd026d23b898c
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java
@@ -42,6 +42,8 @@
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
@@ -62,6 +64,10 @@
    @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);
    }
@@ -70,6 +76,10 @@
    @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);
    }
@@ -157,15 +167,19 @@
    }
    @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());
        }