Commit 1f58fd2be488203bb18a1515bc2921a2e527f53d
1 parent
d6736204
【代码评审】IM:消息相关接口
Showing
6 changed files
with
8 additions
and
13 deletions
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/conversation/ImConversationController.java
| 1 | 1 | package cn.iocoder.yudao.module.im.controller.admin.conversation; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 4 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | -import cn.iocoder.yudao.framework.websocket.core.sender.WebSocketMessageSender; | |
| 7 | 5 | import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationCreateReqVO; |
| 8 | 6 | import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationUpdateLastReadTimeReqVO; |
| 9 | 7 | import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationRespVO; |
| 10 | 8 | import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationUpdatePinnedReqVO; |
| 11 | -import cn.iocoder.yudao.module.im.controller.admin.message.vo.ImMessageListByNoReqVO; | |
| 12 | -import cn.iocoder.yudao.module.im.controller.admin.message.vo.ImMessageListReqVO; | |
| 13 | 9 | import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ImConversationDO; |
| 14 | -import cn.iocoder.yudao.module.im.dal.dataobject.message.ImMessageDO; | |
| 15 | -import cn.iocoder.yudao.module.im.enums.message.ImMessageContentTypeEnum; | |
| 16 | 10 | import cn.iocoder.yudao.module.im.service.conversation.ImConversationService; |
| 17 | 11 | import cn.iocoder.yudao.module.im.service.message.ImMessageService; |
| 18 | 12 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| ... | ... | @@ -25,7 +19,6 @@ import org.springframework.validation.annotation.Validated; |
| 25 | 19 | import org.springframework.web.bind.annotation.*; |
| 26 | 20 | |
| 27 | 21 | import java.util.List; |
| 28 | -import java.util.Objects; | |
| 29 | 22 | |
| 30 | 23 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 31 | 24 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | ... | ... |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/message/vo/ImMessageListReqVO.java
| ... | ... | @@ -19,6 +19,7 @@ public class ImMessageListReqVO { |
| 19 | 19 | @NotNull(message = "接收人编号不能为空") |
| 20 | 20 | private Long receiverId; |
| 21 | 21 | |
| 22 | + // TODO @dylan:这个是不是不用传递呀。因为 http 连接,有当前的 userid 呀 | |
| 22 | 23 | @Schema(description = "会话所属人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "32494") |
| 23 | 24 | @NotNull(message = "会话所属人编号不能为空") |
| 24 | 25 | private Long userId; | ... | ... |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/message/vo/ImMessageSendReqVO.java
| ... | ... | @@ -24,6 +24,7 @@ public class ImMessageSendReqVO { |
| 24 | 24 | @NotNull(message = "会话类型不能为空") |
| 25 | 25 | private Integer conversationType; |
| 26 | 26 | |
| 27 | + // TODO @dylan:这个是不是不用传递呀。因为 http 连接,有当前的 userid 呀 | |
| 27 | 28 | @Schema(description = "会话所属用户id", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") |
| 28 | 29 | @NotNull(message = "会话所属用户id") |
| 29 | 30 | private Long conversationUserId; | ... | ... |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/service/conversation/ImConversationServiceImpl.java
| ... | ... | @@ -8,8 +8,6 @@ import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversatio |
| 8 | 8 | import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ImConversationDO; |
| 9 | 9 | import cn.iocoder.yudao.module.im.dal.mysql.conversation.ImConversationMapper; |
| 10 | 10 | import cn.iocoder.yudao.module.im.enums.conversation.ImConversationTypeEnum; |
| 11 | -import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | |
| 12 | -import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | |
| 13 | 11 | import jakarta.annotation.Resource; |
| 14 | 12 | import org.springframework.stereotype.Service; |
| 15 | 13 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -26,6 +24,7 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti |
| 26 | 24 | @Service |
| 27 | 25 | @Validated |
| 28 | 26 | public class ImConversationServiceImpl implements ImConversationService { |
| 27 | + | |
| 29 | 28 | private final String IM_CONVERSATION_ADD = "im-conversation-add"; |
| 30 | 29 | |
| 31 | 30 | @Resource |
| ... | ... | @@ -108,6 +107,7 @@ public class ImConversationServiceImpl implements ImConversationService { |
| 108 | 107 | conversation = insertConversation(no, loginUserId, createReqVO.getTargetId(), createReqVO.getType()); |
| 109 | 108 | } |
| 110 | 109 | |
| 110 | + // TODO @dylan:这个是不是不用 push 呀。对于发送端,它自己肯定知道;对于接收端,貌似收到 message 的时候,再创建更合理一点。 | |
| 111 | 111 | // 发送打开会话的通知,并推送会话实体 |
| 112 | 112 | // 给自己发送创建会话成功的通知 |
| 113 | 113 | webSocketMessageSender.sendObject(UserTypeEnum.ADMIN.getValue(), getLoginUserId(), |
| ... | ... | @@ -116,9 +116,7 @@ public class ImConversationServiceImpl implements ImConversationService { |
| 116 | 116 | // 给接受者发送创建会话的通知 |
| 117 | 117 | webSocketMessageSender.sendObject(UserTypeEnum.ADMIN.getValue(), createReqVO.getTargetId(), |
| 118 | 118 | IM_CONVERSATION_ADD, conversation); |
| 119 | - | |
| 120 | 119 | return conversation; |
| 121 | 120 | } |
| 122 | 121 | |
| 123 | - | |
| 124 | 122 | } |
| 125 | 123 | \ No newline at end of file | ... | ... |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/service/message/ImMessageServiceImpl.java
| ... | ... | @@ -23,7 +23,6 @@ import org.springframework.validation.annotation.Validated; |
| 23 | 23 | import java.time.LocalDateTime; |
| 24 | 24 | import java.util.Collections; |
| 25 | 25 | import java.util.List; |
| 26 | -import java.util.Objects; | |
| 27 | 26 | |
| 28 | 27 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 29 | 28 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| ... | ... | @@ -51,9 +50,10 @@ public class ImMessageServiceImpl implements ImMessageService { |
| 51 | 50 | |
| 52 | 51 | @Override |
| 53 | 52 | public List<ImMessageDO> getMessageList(ImMessageListReqVO listReqVO) { |
| 54 | - | |
| 53 | + // TODO @dylan:userId 从 controller 传递,service 保持无状态 | |
| 55 | 54 | // 1. 获得会话编号 |
| 56 | 55 | Long loginUserId = getLoginUserId(); |
| 56 | + // TODO @dylan:修复下 generateConversationNo 方法,fromUserId、receiverId 需要小的放前面,大的放后面。这样,可以保证一定只生成唯一的。 | |
| 57 | 57 | String no1 = generateConversationNo(loginUserId, listReqVO.getReceiverId(), listReqVO.getConversationType()); |
| 58 | 58 | String no2 = generateConversationNo(listReqVO.getReceiverId(),loginUserId, listReqVO.getConversationType()); |
| 59 | 59 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java
| ... | ... | @@ -101,6 +101,7 @@ public class UserController { |
| 101 | 101 | pageResult.getTotal())); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | + // TODO @dylan:可以服用 getSimpleUserList 呀。 | |
| 104 | 105 | @GetMapping("/all") |
| 105 | 106 | @Operation(summary = "获得所有用户列表") |
| 106 | 107 | @PreAuthorize("@ss.hasPermission('system:user:list')") |
| ... | ... | @@ -115,6 +116,7 @@ public class UserController { |
| 115 | 116 | return success(UserConvert.INSTANCE.convertList(result, deptMap)); |
| 116 | 117 | } |
| 117 | 118 | |
| 119 | + // TODO @dylan:融合到 getSimpleUserList 接口,允许传递 deptId 筛选 | |
| 118 | 120 | @GetMapping("/listByDept") |
| 119 | 121 | @Operation(summary = "获得部门用户列表") |
| 120 | 122 | @PreAuthorize("@ss.hasPermission('system:user:list')") | ... | ... |