Commit f510ae5c168c3fbd13dee5c8377a2bbdc608cbfa
Committed by
Gitee
!1008 MALL-KEFU: 优化消息已读处理逻辑
Merge pull request !1008 from puhui999/develop
Showing
4 changed files
with
20 additions
and
13 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuConversationController.java
| ... | ... | @@ -34,8 +34,8 @@ public class KeFuConversationController { |
| 34 | 34 | @Resource |
| 35 | 35 | private MemberUserApi memberUserApi; |
| 36 | 36 | |
| 37 | - @PostMapping("/update-conversation-pinned") | |
| 38 | - @Operation(summary = "置顶客服会话") | |
| 37 | + @PutMapping("/update-conversation-pinned") | |
| 38 | + @Operation(summary = "置顶/取消置顶客服会话") | |
| 39 | 39 | @PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:update')") |
| 40 | 40 | public CommonResult<Boolean> updateConversationPinned(@Valid @RequestBody KeFuConversationUpdatePinnedReqVO updateReqVO) { |
| 41 | 41 | conversationService.updateConversationPinnedByAdmin(updateReqVO); | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/kefu/KeFuMessageMapper.java
| ... | ... | @@ -27,9 +27,11 @@ public interface KeFuMessageMapper extends BaseMapperX<KeFuMessageDO> { |
| 27 | 27 | .orderByDesc(KeFuMessageDO::getCreateTime)); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - default List<KeFuMessageDO> selectListByConversationIdAndReadStatus(Long conversationId, Boolean readStatus) { | |
| 30 | + default List<KeFuMessageDO> selectListByConversationIdAndUserTypeAndReadStatus(Long conversationId, Integer userType, | |
| 31 | + Boolean readStatus) { | |
| 31 | 32 | return selectList(new LambdaQueryWrapper<KeFuMessageDO>() |
| 32 | 33 | .eq(KeFuMessageDO::getConversationId, conversationId) |
| 34 | + .ne(KeFuMessageDO::getSenderType, userType) // 管理员:查询出未读的会员消息,会员:查询出未读的客服消息 | |
| 33 | 35 | .eq(KeFuMessageDO::getReadStatus, readStatus)); |
| 34 | 36 | } |
| 35 | 37 | |
| ... | ... | @@ -38,7 +40,7 @@ public interface KeFuMessageMapper extends BaseMapperX<KeFuMessageDO> { |
| 38 | 40 | .in(KeFuMessageDO::getId, ids)); |
| 39 | 41 | } |
| 40 | 42 | |
| 41 | - default PageResult<KeFuMessageDO> selectPage(AppKeFuMessagePageReqVO pageReqVO){ | |
| 43 | + default PageResult<KeFuMessageDO> selectPage(AppKeFuMessagePageReqVO pageReqVO) { | |
| 42 | 44 | return selectPage(pageReqVO, new LambdaQueryWrapperX<KeFuMessageDO>() |
| 43 | 45 | .eqIfPresent(KeFuMessageDO::getConversationId, pageReqVO.getConversationId()) |
| 44 | 46 | .orderByDesc(KeFuMessageDO::getCreateTime)); | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationServiceImpl.java
| ... | ... | @@ -41,6 +41,10 @@ public class KeFuConversationServiceImpl implements KeFuConversationService { |
| 41 | 41 | |
| 42 | 42 | @Override |
| 43 | 43 | public void updateConversationPinnedByAdmin(KeFuConversationUpdatePinnedReqVO updateReqVO) { |
| 44 | + // 校验存在 | |
| 45 | + validateKefuConversationExists(updateReqVO.getId()); | |
| 46 | + | |
| 47 | + // 更新管理员会话置顶状态 | |
| 44 | 48 | conversationMapper.updateById(new KeFuConversationDO().setId(updateReqVO.getId()).setAdminPinned(updateReqVO.getAdminPinned())); |
| 45 | 49 | } |
| 46 | 50 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageServiceImpl.java
| ... | ... | @@ -67,7 +67,7 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { |
| 67 | 67 | conversationService.updateConversationLastMessage(kefuMessage); |
| 68 | 68 | |
| 69 | 69 | // 3. 发送消息 |
| 70 | - getSelf().sendAsyncMessage(UserTypeEnum.MEMBER.getValue(), conversation.getUserId(), kefuMessage); | |
| 70 | + getSelf().sendAsyncMessageToMember(conversation.getUserId(), KEFU_MESSAGE_TYPE, kefuMessage); | |
| 71 | 71 | return kefuMessage.getId(); |
| 72 | 72 | } |
| 73 | 73 | |
| ... | ... | @@ -83,7 +83,7 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { |
| 83 | 83 | // 2. 更新会话消息冗余 |
| 84 | 84 | conversationService.updateConversationLastMessage(kefuMessage); |
| 85 | 85 | // 3. 发送消息 |
| 86 | - getSelf().sendAsyncMessageToAdmin(kefuMessage); | |
| 86 | + getSelf().sendAsyncMessageToAdmin(KEFU_MESSAGE_TYPE, kefuMessage); | |
| 87 | 87 | return kefuMessage.getId(); |
| 88 | 88 | } |
| 89 | 89 | |
| ... | ... | @@ -97,7 +97,7 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { |
| 97 | 97 | throw exception(KEFU_CONVERSATION_NOT_EXISTS); |
| 98 | 98 | } |
| 99 | 99 | // 1.3 查询会话所有的未读消息 (tips: 多个客服,一个人点了,就都点了) |
| 100 | - List<KeFuMessageDO> messageList = keFuMessageMapper.selectListByConversationIdAndReadStatus(conversationId, Boolean.FALSE); | |
| 100 | + List<KeFuMessageDO> messageList = keFuMessageMapper.selectListByConversationIdAndUserTypeAndReadStatus(conversationId, userType, Boolean.FALSE); | |
| 101 | 101 | if (CollUtil.isEmpty(messageList)) { |
| 102 | 102 | return; |
| 103 | 103 | } |
| ... | ... | @@ -109,10 +109,11 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { |
| 109 | 109 | conversationService.updateAdminUnreadMessageCountToZero(conversationId); |
| 110 | 110 | |
| 111 | 111 | // 2.3 发送消息通知会员,管理员已读 -> 会员更新发送的消息状态 |
| 112 | - // TODO @puhui999:待定~ | |
| 113 | 112 | KeFuMessageDO keFuMessage = getFirst(filterList(messageList, message -> UserTypeEnum.MEMBER.getValue().equals(message.getSenderType()))); |
| 114 | 113 | assert keFuMessage != null; // 断言避免警告 |
| 115 | - webSocketSenderApi.sendObject(UserTypeEnum.MEMBER.getValue(), keFuMessage.getSenderId(), KEFU_MESSAGE_ADMIN_READ, StrUtil.EMPTY); | |
| 114 | + getSelf().sendAsyncMessageToMember(keFuMessage.getSenderId(), KEFU_MESSAGE_ADMIN_READ, StrUtil.EMPTY); | |
| 115 | + // 2.4 通知所有管理员消息已读 | |
| 116 | + getSelf().sendAsyncMessageToAdmin(KEFU_MESSAGE_ADMIN_READ, StrUtil.EMPTY); | |
| 116 | 117 | } |
| 117 | 118 | |
| 118 | 119 | private void validateReceiverExist(Long receiverId, Integer receiverType) { |
| ... | ... | @@ -125,13 +126,13 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { |
| 125 | 126 | } |
| 126 | 127 | |
| 127 | 128 | @Async |
| 128 | - public void sendAsyncMessage(Integer userType, Long userId, Object content) { | |
| 129 | - webSocketSenderApi.sendObject(userType, userId, KEFU_MESSAGE_TYPE, content); | |
| 129 | + public void sendAsyncMessageToMember(Long userId, String messageType, Object content) { | |
| 130 | + webSocketSenderApi.sendObject(UserTypeEnum.MEMBER.getValue(), userId, messageType, content); | |
| 130 | 131 | } |
| 131 | 132 | |
| 132 | 133 | @Async |
| 133 | - public void sendAsyncMessageToAdmin(Object content) { | |
| 134 | - webSocketSenderApi.sendObject(UserTypeEnum.ADMIN.getValue(), KEFU_MESSAGE_TYPE, content); | |
| 134 | + public void sendAsyncMessageToAdmin(String messageType, Object content) { | |
| 135 | + webSocketSenderApi.sendObject(UserTypeEnum.ADMIN.getValue(), messageType, content); | |
| 135 | 136 | } |
| 136 | 137 | |
| 137 | 138 | @Override | ... | ... |