Commit 29a3ad42b62e867aca9e2d835bf7c1a6bffbfcec
1 parent
40be6ed7
TODO处理
Showing
5 changed files
with
30 additions
and
45 deletions
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/conversation/ImConversationController.java
| @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversatio | @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversatio | ||
| 6 | import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationRespVO; | 6 | import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationRespVO; |
| 7 | import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationUpdatePinnedReqVO; | 7 | import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationUpdatePinnedReqVO; |
| 8 | import cn.iocoder.yudao.module.im.controller.admin.message.vo.ImMessageListByNoReqVO; | 8 | import cn.iocoder.yudao.module.im.controller.admin.message.vo.ImMessageListByNoReqVO; |
| 9 | +import cn.iocoder.yudao.module.im.controller.admin.message.vo.ImMessageListReqVO; | ||
| 9 | import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ImConversationDO; | 10 | import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ImConversationDO; |
| 10 | import cn.iocoder.yudao.module.im.dal.dataobject.message.ImMessageDO; | 11 | import cn.iocoder.yudao.module.im.dal.dataobject.message.ImMessageDO; |
| 11 | import cn.iocoder.yudao.module.im.enums.message.ImMessageContentTypeEnum; | 12 | import cn.iocoder.yudao.module.im.enums.message.ImMessageContentTypeEnum; |
| @@ -56,28 +57,6 @@ public class ImConversationController { | @@ -56,28 +57,6 @@ public class ImConversationController { | ||
| 56 | item.setNickname(receiverUser.getNickname()); | 57 | item.setNickname(receiverUser.getNickname()); |
| 57 | } | 58 | } |
| 58 | 59 | ||
| 59 | - // 处理未读消息条数【TODO:】 | ||
| 60 | - | ||
| 61 | - | ||
| 62 | - // 处理最后一条消息描述 | ||
| 63 | - ImMessageListByNoReqVO imMessageListByNoReqVO = new ImMessageListByNoReqVO(); | ||
| 64 | - imMessageListByNoReqVO.setConversationNo(item.getNo()); | ||
| 65 | - List<ImMessageDO> listMessage = imMessageService.getMessageListByConversationNo(imMessageListByNoReqVO); | ||
| 66 | - | ||
| 67 | - if (!listMessage.isEmpty()) { | ||
| 68 | - ImMessageDO lastMessage = listMessage.get(listMessage.size() - 1); | ||
| 69 | - if (lastMessage != null) { | ||
| 70 | - if (Objects.equals(lastMessage.getContentType(), ImMessageContentTypeEnum.TEXT.getType())) { | ||
| 71 | - item.setLastMessageDescription(lastMessage.getContent()); | ||
| 72 | - } else if (Objects.equals(lastMessage.getContentType(), ImMessageContentTypeEnum.PICTURE.getType())) { | ||
| 73 | - item.setLastMessageDescription("[图片]"); | ||
| 74 | - } else { | ||
| 75 | - item.setLastMessageDescription("[未知类型]"); | ||
| 76 | - } | ||
| 77 | - } | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | - | ||
| 81 | }); | 60 | }); |
| 82 | return success(imConversationRespVOList); | 61 | return success(imConversationRespVOList); |
| 83 | } | 62 | } |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/message/ImMessageController.java
| @@ -51,11 +51,4 @@ public class ImMessageController { | @@ -51,11 +51,4 @@ public class ImMessageController { | ||
| 51 | return success(BeanUtils.toBean(messagePage, ImMessageRespVO.class)); | 51 | return success(BeanUtils.toBean(messagePage, ImMessageRespVO.class)); |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | - @GetMapping("/listByNo") | ||
| 55 | - @Operation(summary = "消息列表-根据接收人和发送时间进行分页查询") | ||
| 56 | - public CommonResult<List<ImMessageRespVO>> getMessageListByNo(@Valid ImMessageListByNoReqVO listReqVO) { | ||
| 57 | - List<ImMessageDO> messagePage = imMessageService.getMessageListByConversationNo(listReqVO); | ||
| 58 | - return success(BeanUtils.toBean(messagePage, ImMessageRespVO.class)); | ||
| 59 | - } | ||
| 60 | - | ||
| 61 | } | 54 | } |
| 62 | \ No newline at end of file | 55 | \ No newline at end of file |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/message/vo/ImMessageListReqVO.java
| @@ -15,14 +15,13 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ | @@ -15,14 +15,13 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ | ||
| 15 | @Data | 15 | @Data |
| 16 | public class ImMessageListReqVO { | 16 | public class ImMessageListReqVO { |
| 17 | 17 | ||
| 18 | - // TODO @dylan:是不是 receiverId 和 senderId 保留一个 receiverId 就行。这样,A + 自己(调用接口,从 getLoginUserId 拿),然后 conversationType,最终可以拼接出 conversationNo | ||
| 19 | @Schema(description = "接收人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "32494") | 18 | @Schema(description = "接收人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "32494") |
| 20 | @NotNull(message = "接收人编号不能为空") | 19 | @NotNull(message = "接收人编号不能为空") |
| 21 | private Long receiverId; | 20 | private Long receiverId; |
| 22 | 21 | ||
| 23 | - @Schema(description = "发送人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "32494") | ||
| 24 | - @NotNull(message = "发送人编号不能为空") | ||
| 25 | - private Long senderId; | 22 | + @Schema(description = "会话所属人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "32494") |
| 23 | + @NotNull(message = "会话所属人编号不能为空") | ||
| 24 | + private Long userId; | ||
| 26 | 25 | ||
| 27 | @Schema(description = "会话类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | 26 | @Schema(description = "会话类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") |
| 28 | @InEnum(value = ImConversationTypeEnum.class,message = "会话类型必须是 {value}") | 27 | @InEnum(value = ImConversationTypeEnum.class,message = "会话类型必须是 {value}") |
| @@ -33,9 +32,4 @@ public class ImMessageListReqVO { | @@ -33,9 +32,4 @@ public class ImMessageListReqVO { | ||
| 33 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY) | 32 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY) |
| 34 | private LocalDateTime sendTime; | 33 | private LocalDateTime sendTime; |
| 35 | 34 | ||
| 36 | - // TODO @dylan:这个,可以根据 receiverId、senderId、conversationType 推导的,建议可以去掉。 | ||
| 37 | - @Schema(description = "会话编号编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "32494") | ||
| 38 | - @NotNull(message = "会话编号不能为空") | ||
| 39 | - private String conversationNo; | ||
| 40 | - | ||
| 41 | } | 35 | } |
| 42 | \ No newline at end of file | 36 | \ No newline at end of file |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/message/vo/ImMessageSendReqVO.java
| @@ -24,10 +24,9 @@ public class ImMessageSendReqVO { | @@ -24,10 +24,9 @@ public class ImMessageSendReqVO { | ||
| 24 | @NotNull(message = "会话类型不能为空") | 24 | @NotNull(message = "会话类型不能为空") |
| 25 | private Integer conversationType; | 25 | private Integer conversationType; |
| 26 | 26 | ||
| 27 | - // TODO @dylan:这个 conversationNo,直接计算哈。不用传递 | ||
| 28 | - @Schema(description = "会话编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | ||
| 29 | - @NotNull(message = "会话编号不能为空") | ||
| 30 | - private String conversationNo; | 27 | + @Schema(description = "会话所属用户id", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") |
| 28 | + @NotNull(message = "会话所属用户id") | ||
| 29 | + private Long conversationUserId; | ||
| 31 | 30 | ||
| 32 | @Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | 31 | @Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 33 | @InEnum(ImMessageContentTypeEnum.class) | 32 | @InEnum(ImMessageContentTypeEnum.class) |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/service/message/ImMessageServiceImpl.java
| @@ -23,9 +23,12 @@ import org.springframework.validation.annotation.Validated; | @@ -23,9 +23,12 @@ import org.springframework.validation.annotation.Validated; | ||
| 23 | import java.time.LocalDateTime; | 23 | import java.time.LocalDateTime; |
| 24 | import java.util.Collections; | 24 | import java.util.Collections; |
| 25 | import java.util.List; | 25 | import java.util.List; |
| 26 | +import java.util.Objects; | ||
| 26 | 27 | ||
| 27 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 28 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 29 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | ||
| 28 | import static cn.iocoder.yudao.module.im.enums.ErrorCodeConstants.MESSAGE_RECEIVER_NOT_EXISTS; | 30 | import static cn.iocoder.yudao.module.im.enums.ErrorCodeConstants.MESSAGE_RECEIVER_NOT_EXISTS; |
| 31 | +import static cn.iocoder.yudao.module.im.enums.conversation.ImConversationTypeEnum.generateConversationNo; | ||
| 29 | 32 | ||
| 30 | /** | 33 | /** |
| 31 | * 消息 Service 实现类 | 34 | * 消息 Service 实现类 |
| @@ -48,8 +51,16 @@ public class ImMessageServiceImpl implements ImMessageService { | @@ -48,8 +51,16 @@ public class ImMessageServiceImpl implements ImMessageService { | ||
| 48 | 51 | ||
| 49 | @Override | 52 | @Override |
| 50 | public List<ImMessageDO> getMessageList(ImMessageListReqVO listReqVO) { | 53 | public List<ImMessageDO> getMessageList(ImMessageListReqVO listReqVO) { |
| 54 | + | ||
| 51 | // 1. 获得会话编号 | 55 | // 1. 获得会话编号 |
| 52 | - String no = ImConversationTypeEnum.generateConversationNo(listReqVO.getSenderId(), listReqVO.getReceiverId(), listReqVO.getConversationType()); | 56 | + String no = ""; |
| 57 | + Long loginUserId = getLoginUserId(); | ||
| 58 | + if (Objects.equals(loginUserId, listReqVO.getUserId())) { | ||
| 59 | + no = generateConversationNo(loginUserId, listReqVO.getReceiverId(), listReqVO.getConversationType()); | ||
| 60 | + } else { | ||
| 61 | + no = generateConversationNo(listReqVO.getReceiverId(),loginUserId , listReqVO.getConversationType()); | ||
| 62 | + } | ||
| 63 | + | ||
| 53 | // 2. 查询历史消息 | 64 | // 2. 查询历史消息 |
| 54 | ImMessageDO message = new ImMessageDO() | 65 | ImMessageDO message = new ImMessageDO() |
| 55 | .setSendTime(listReqVO.getSendTime()) | 66 | .setSendTime(listReqVO.getSendTime()) |
| @@ -92,11 +103,20 @@ public class ImMessageServiceImpl implements ImMessageService { | @@ -92,11 +103,20 @@ public class ImMessageServiceImpl implements ImMessageService { | ||
| 92 | validateReceiverIdExists(message); | 103 | validateReceiverIdExists(message); |
| 93 | // 2. 查询发送人信息 | 104 | // 2. 查询发送人信息 |
| 94 | AdminUserRespDTO fromUser = adminUserApi.getUser(fromUserId); | 105 | AdminUserRespDTO fromUser = adminUserApi.getUser(fromUserId); |
| 95 | - // 3. 保存消息 | 106 | + |
| 107 | + // 3. 生成conversationNo | ||
| 108 | + String conversationNo = ""; | ||
| 109 | + if (fromUserId == message.getConversationUserId()) { | ||
| 110 | + conversationNo = generateConversationNo(fromUserId, message.getReceiverId(), message.getConversationType()); | ||
| 111 | + } else { | ||
| 112 | + conversationNo = generateConversationNo(message.getReceiverId(), fromUserId, message.getConversationType()); | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + // 4. 保存消息 | ||
| 96 | ImMessageDO imMessageDO = BeanUtil.copyProperties(message, ImMessageDO.class) | 116 | ImMessageDO imMessageDO = BeanUtil.copyProperties(message, ImMessageDO.class) |
| 97 | .setSenderNickname(fromUser.getNickname()).setSenderAvatar(fromUser.getAvatar()) | 117 | .setSenderNickname(fromUser.getNickname()).setSenderAvatar(fromUser.getAvatar()) |
| 98 | .setSenderId(fromUserId) | 118 | .setSenderId(fromUserId) |
| 99 | - .setConversationNo(message.getConversationNo()) | 119 | + .setConversationNo(conversationNo) |
| 100 | .setSendFrom(ImMessageSourceEnum.USER_SEND.getSource()) | 120 | .setSendFrom(ImMessageSourceEnum.USER_SEND.getSource()) |
| 101 | .setMessageStatus(ImMessageStatusEnum.SENDING.getStatus()) | 121 | .setMessageStatus(ImMessageStatusEnum.SENDING.getStatus()) |
| 102 | .setSendTime(LocalDateTime.now()); | 122 | .setSendTime(LocalDateTime.now()); |