云
2026-10-27 0520581c65a2d93c1d02359180c77b8fb911dc55
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);
    }
@@ -110,7 +120,6 @@
    @GetMapping("/page")
    @Operation(summary = "获得用户分页列表")
    @PreAuthorize("@ss.hasPermission('system:user:query')")
    public CommonResult<PageResult<UserRespVO>> getUserPage(@Valid UserPageReqVO pageReqVO) {
        // 获得用户分页列表
        PageResult<AdminUserDO> pageResult = userService.getUserPage(pageReqVO);
@@ -127,7 +136,6 @@
    @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)) {
@@ -157,15 +165,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());
        }
@@ -181,7 +193,6 @@
    @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) {