Commit f5b0750899872daa456b71d59eea16354f2428c9
1 parent
18967215
♻️ refactor(im): 将 ImUserController 迁移到 system UserController
- 删除 ImUserController、ImUserRespVO(get-self 复用 UserProfileController#getUserProfile) - UserController 新增 /get-simple、/list-by-nickname 免鉴权接口(用于 IM 点头像弹名片、加好友搜索),整理到类末尾并用分隔注释标识 - UserSimpleRespVO 补充 avatar、sex 字段
Showing
6 changed files
with
80 additions
and
127 deletions
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/group/vo/member/ImGroupMemberCreateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.im.controller.admin.group.vo.member; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import jakarta.validation.constraints.NotNull; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | +@Schema(description = "管理后台 - 群成员邀请 Request VO") | ||
| 8 | +@Data | ||
| 9 | +public class ImGroupMemberCreateReqVO { | ||
| 10 | + | ||
| 11 | + @Schema(description = "群编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13279") | ||
| 12 | + @NotNull(message = "群编号不能为空") | ||
| 13 | + private Long groupId; | ||
| 14 | + | ||
| 15 | + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21730") | ||
| 16 | + @NotNull(message = "用户编号不能为空") | ||
| 17 | + private Long userId; | ||
| 18 | + | ||
| 19 | +} |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/message/vo/privates/ImPrivateMessagePageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.im.controller.admin.message.vo.privates; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.EqualsAndHashCode; | ||
| 7 | +import lombok.ToString; | ||
| 8 | + | ||
| 9 | +import jakarta.validation.constraints.NotNull; | ||
| 10 | + | ||
| 11 | +@Schema(description = "管理后台 - 私聊消息分页 Request VO") | ||
| 12 | +@Data | ||
| 13 | +@EqualsAndHashCode(callSuper = true) | ||
| 14 | +@ToString(callSuper = true) | ||
| 15 | +public class ImPrivateMessagePageReqVO extends PageParam { | ||
| 16 | + | ||
| 17 | + @Schema(description = "接收人编号(对方)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | ||
| 18 | + @NotNull(message = "接收人编号不能为空") | ||
| 19 | + private Long receiverId; | ||
| 20 | + | ||
| 21 | +} |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/user/ImUserController.java deleted
| 1 | -package cn.iocoder.yudao.module.im.controller.admin.user; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 4 | -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 5 | -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 6 | -import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; | ||
| 7 | -import cn.iocoder.yudao.module.im.controller.admin.user.vo.ImUserRespVO; | ||
| 8 | -import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 9 | -import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | ||
| 10 | -import io.swagger.v3.oas.annotations.Operation; | ||
| 11 | -import io.swagger.v3.oas.annotations.Parameter; | ||
| 12 | -import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 13 | -import jakarta.annotation.Resource; | ||
| 14 | -import org.springframework.validation.annotation.Validated; | ||
| 15 | -import org.springframework.web.bind.annotation.GetMapping; | ||
| 16 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 17 | -import org.springframework.web.bind.annotation.RequestParam; | ||
| 18 | -import org.springframework.web.bind.annotation.RestController; | ||
| 19 | - | ||
| 20 | -import java.util.Collections; | ||
| 21 | -import java.util.List; | ||
| 22 | - | ||
| 23 | -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 24 | - | ||
| 25 | -@Tag(name = "管理后台 - IM 用户查询") | ||
| 26 | -@RestController | ||
| 27 | -@RequestMapping("/im/user") | ||
| 28 | -@Validated | ||
| 29 | -public class ImUserController { | ||
| 30 | - | ||
| 31 | - @Resource | ||
| 32 | - private AdminUserApi adminUserApi; | ||
| 33 | - | ||
| 34 | - @GetMapping("/get-self") | ||
| 35 | - @Operation(summary = "获取当前登录用户信息") | ||
| 36 | - public CommonResult<ImUserRespVO> getSelfInfo() { | ||
| 37 | - Long userId = SecurityFrameworkUtils.getLoginUserId(); | ||
| 38 | - AdminUserRespDTO user = adminUserApi.getUser(userId); | ||
| 39 | - return success(BeanUtils.toBean(user, ImUserRespVO.class)); | ||
| 40 | - } | ||
| 41 | - | ||
| 42 | - @GetMapping("/get") | ||
| 43 | - @Operation(summary = "按用户编号查询用户(用于点头像弹名片)") | ||
| 44 | - @Parameter(name = "id", description = "用户编号", required = true, example = "2048") | ||
| 45 | - public CommonResult<ImUserRespVO> getUser(@RequestParam("id") Long id) { | ||
| 46 | - AdminUserRespDTO user = adminUserApi.getUser(id); | ||
| 47 | - if (user == null) { | ||
| 48 | - return success(null); | ||
| 49 | - } | ||
| 50 | - return success(BeanUtils.toBean(user, ImUserRespVO.class)); | ||
| 51 | - } | ||
| 52 | - | ||
| 53 | - @GetMapping("/list-by-name") | ||
| 54 | - @Operation(summary = "按昵称模糊搜索用户(用于加好友场景)") | ||
| 55 | - @Parameter(name = "name", description = "昵称关键词", required = true, example = "芋道") | ||
| 56 | - public CommonResult<List<ImUserRespVO>> getUserListByName(@RequestParam("name") String name) { | ||
| 57 | - if (name == null || name.trim().isEmpty()) { | ||
| 58 | - return success(Collections.emptyList()); | ||
| 59 | - } | ||
| 60 | - List<AdminUserRespDTO> users = adminUserApi.getUserListByNickname(name.trim()); | ||
| 61 | - // TODO @芋艿:【对齐】这里需要支持按「用户名 or 昵称」搜索; | ||
| 62 | - // AdminUser 按用户名模糊的接口暂未暴露,先仅按昵称。后续可扩 AdminUserApi 加一个 | ||
| 63 | - // `getUserListByUsernameOrNickname(keyword)` 或让前端输入时选搜索模式。 | ||
| 64 | - return success(CollectionUtils.convertList(users, u -> BeanUtils.toBean(u, ImUserRespVO.class))); | ||
| 65 | - } | ||
| 66 | - | ||
| 67 | -} |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/user/vo/ImUserRespVO.java deleted
| 1 | -package cn.iocoder.yudao.module.im.controller.admin.user.vo; | ||
| 2 | - | ||
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | -import lombok.Data; | ||
| 5 | - | ||
| 6 | -/** | ||
| 7 | - * IM 用户 Response VO(对 AdminUser 的字段窄投影) | ||
| 8 | - * <p> | ||
| 9 | - * 面向 IM 场景,主要关注 id / userName / nickName / headImage / sex / signature 这些字段; | ||
| 10 | - * 但 yudao 侧 AdminUser 没有 signature 字段,暂不返回(TODO @芋艿:【对齐】后续可加用户扩展表承载)。 | ||
| 11 | - * | ||
| 12 | - * @author 芋道源码 | ||
| 13 | - */ | ||
| 14 | -@Schema(description = "管理后台 - IM 用户 Response VO") | ||
| 15 | -@Data | ||
| 16 | -public class ImUserRespVO { | ||
| 17 | - | ||
| 18 | - @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 19 | - private Long id; | ||
| 20 | - | ||
| 21 | - @Schema(description = "用户名", example = "admin") | ||
| 22 | - private String username; | ||
| 23 | - | ||
| 24 | - @Schema(description = "昵称", example = "芋道") | ||
| 25 | - private String nickname; | ||
| 26 | - | ||
| 27 | - @Schema(description = "头像") | ||
| 28 | - private String avatar; | ||
| 29 | - | ||
| 30 | - @Schema(description = "性别 0=未知 1=男 2=女", example = "1") | ||
| 31 | - private Integer sex; | ||
| 32 | - | ||
| 33 | - @Schema(description = "手机号") | ||
| 34 | - private String mobile; | ||
| 35 | - | ||
| 36 | - /** | ||
| 37 | - * TODO @芋艿:【对齐】个性签名(signature)字段当前缺失,yudao AdminUser 无此字段; | ||
| 38 | - * 如果要对齐,可走 system 模块的用户扩展表,或 IM 模块独立存。 | ||
| 39 | - */ | ||
| 40 | - | ||
| 41 | -} |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java
| 1 | package cn.iocoder.yudao.module.system.controller.admin.user; | 1 | package cn.iocoder.yudao.module.system.controller.admin.user; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.hutool.core.util.StrUtil; | ||
| 4 | import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; | 5 | import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; |
| 5 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 7 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| @@ -27,7 +28,10 @@ import org.springframework.web.bind.annotation.*; | @@ -27,7 +28,10 @@ import org.springframework.web.bind.annotation.*; | ||
| 27 | import org.springframework.web.multipart.MultipartFile; | 28 | import org.springframework.web.multipart.MultipartFile; |
| 28 | 29 | ||
| 29 | import java.io.IOException; | 30 | import java.io.IOException; |
| 30 | -import java.util.*; | 31 | +import java.util.Arrays; |
| 32 | +import java.util.Collections; | ||
| 33 | +import java.util.List; | ||
| 34 | +import java.util.Map; | ||
| 31 | 35 | ||
| 32 | import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; | 36 | import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; |
| 33 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 37 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| @@ -110,27 +114,10 @@ public class UserController { | @@ -110,27 +114,10 @@ public class UserController { | ||
| 110 | pageResult.getTotal())); | 114 | pageResult.getTotal())); |
| 111 | } | 115 | } |
| 112 | 116 | ||
| 113 | - // TODO @dylan:可以服用 getSimpleUserList 呀。 | ||
| 114 | - @GetMapping("/all") | ||
| 115 | - @Operation(summary = "获得所有用户列表") | ||
| 116 | - @PreAuthorize("@ss.hasPermission('system:user:list')") | ||
| 117 | - public CommonResult<List<UserRespVO>> getUserAll() { | ||
| 118 | - List<AdminUserDO> result = userService.getUserListAll(); | ||
| 119 | - if (CollUtil.isEmpty(result)) { | ||
| 120 | - return success(null); | ||
| 121 | - } | ||
| 122 | - // 拼接数据 | ||
| 123 | - Map<Long, DeptDO> deptMap = deptService.getDeptMap( | ||
| 124 | - convertList(result, AdminUserDO::getDeptId)); | ||
| 125 | - return success(UserConvert.INSTANCE.convertList(result, deptMap)); | ||
| 126 | - } | ||
| 127 | - | ||
| 128 | - | ||
| 129 | @GetMapping({"/list-all-simple", "/simple-list"}) | 117 | @GetMapping({"/list-all-simple", "/simple-list"}) |
| 130 | @Operation(summary = "获取用户精简信息列表", description = "只包含被开启的用户,主要用于前端的下拉选项") | 118 | @Operation(summary = "获取用户精简信息列表", description = "只包含被开启的用户,主要用于前端的下拉选项") |
| 131 | public CommonResult<List<UserSimpleRespVO>> getSimpleUserList(@RequestParam("id") Long deptId) { | 119 | public CommonResult<List<UserSimpleRespVO>> getSimpleUserList(@RequestParam("id") Long deptId) { |
| 132 | List<AdminUserDO> list; | 120 | List<AdminUserDO> list; |
| 133 | - | ||
| 134 | if (deptId != null) { | 121 | if (deptId != null) { |
| 135 | List<Long> deptIds = Collections.singletonList(deptId); | 122 | List<Long> deptIds = Collections.singletonList(deptId); |
| 136 | list = userService.getDeptUsers(deptIds); | 123 | list = userService.getDeptUsers(deptIds); |
| @@ -141,7 +128,6 @@ public class UserController { | @@ -141,7 +128,6 @@ public class UserController { | ||
| 141 | // 拼接数据 | 128 | // 拼接数据 |
| 142 | Map<Long, DeptDO> deptMap = deptService.getDeptMap( | 129 | Map<Long, DeptDO> deptMap = deptService.getDeptMap( |
| 143 | convertList(list, AdminUserDO::getDeptId)); | 130 | convertList(list, AdminUserDO::getDeptId)); |
| 144 | - | ||
| 145 | return success(UserConvert.INSTANCE.convertSimpleList(list, deptMap)); | 131 | return success(UserConvert.INSTANCE.convertSimpleList(list, deptMap)); |
| 146 | } | 132 | } |
| 147 | 133 | ||
| @@ -201,4 +187,34 @@ public class UserController { | @@ -201,4 +187,34 @@ public class UserController { | ||
| 201 | return success(userService.importUserList(list, updateSupport)); | 187 | return success(userService.importUserList(list, updateSupport)); |
| 202 | } | 188 | } |
| 203 | 189 | ||
| 190 | + // ==================== 免鉴权接口(用于 IM 点头像弹名片、加好友搜索等场景) ==================== | ||
| 191 | + | ||
| 192 | + @GetMapping("/get-simple") | ||
| 193 | + @Operation(summary = "获得用户精简信息", description = "用于点头像弹名片等场景;免鉴权") | ||
| 194 | + @Parameter(name = "id", description = "用户编号", required = true, example = "1024") | ||
| 195 | + public CommonResult<UserSimpleRespVO> getSimpleUser(@RequestParam("id") Long id) { | ||
| 196 | + AdminUserDO user = userService.getUser(id); | ||
| 197 | + if (user == null) { | ||
| 198 | + return success(null); | ||
| 199 | + } | ||
| 200 | + // 拼接数据 | ||
| 201 | + DeptDO dept = user.getDeptId() != null ? deptService.getDept(user.getDeptId()) : null; | ||
| 202 | + Map<Long, DeptDO> deptMap = dept != null ? Collections.singletonMap(dept.getId(), dept) : Collections.emptyMap(); | ||
| 203 | + return success(CollUtil.getFirst(UserConvert.INSTANCE.convertSimpleList( | ||
| 204 | + Collections.singletonList(user), deptMap))); | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + @GetMapping("/list-by-nickname") | ||
| 208 | + @Operation(summary = "按昵称模糊搜索用户精简信息", description = "用于加好友等场景;免鉴权;当前仅按昵称匹配") | ||
| 209 | + @Parameter(name = "nickname", description = "昵称关键词", required = true, example = "芋道") | ||
| 210 | + public CommonResult<List<UserSimpleRespVO>> getSimpleUserListByNickname(@RequestParam("nickname") String nickname) { | ||
| 211 | + if (StrUtil.isBlank(nickname)) { | ||
| 212 | + return success(Collections.emptyList()); | ||
| 213 | + } | ||
| 214 | + // 拼接数据 | ||
| 215 | + List<AdminUserDO> list = userService.getUserListByNickname(nickname.trim()); | ||
| 216 | + Map<Long, DeptDO> deptMap = deptService.getDeptMap(convertList(list, AdminUserDO::getDeptId)); | ||
| 217 | + return success(UserConvert.INSTANCE.convertSimpleList(list, deptMap)); | ||
| 218 | + } | ||
| 219 | + | ||
| 204 | } | 220 | } |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserSimpleRespVO.java
| @@ -17,6 +17,11 @@ public class UserSimpleRespVO { | @@ -17,6 +17,11 @@ public class UserSimpleRespVO { | ||
| 17 | @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") | 17 | @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") |
| 18 | private String nickname; | 18 | private String nickname; |
| 19 | 19 | ||
| 20 | + @Schema(description = "头像") | ||
| 21 | + private String avatar; | ||
| 22 | + @Schema(description = "性别", example = "1") | ||
| 23 | + private Integer sex; | ||
| 24 | + | ||
| 20 | @Schema(description = "部门ID", example = "我是一个用户") | 25 | @Schema(description = "部门ID", example = "我是一个用户") |
| 21 | private Long deptId; | 26 | private Long deptId; |
| 22 | @Schema(description = "部门名称", example = "IT 部") | 27 | @Schema(description = "部门名称", example = "IT 部") |