Commit f510ae5c168c3fbd13dee5c8377a2bbdc608cbfa

Authored by 芋道源码
Committed by Gitee
2 parents b7e4f8e4 4a395955

!1008 MALL-KEFU: 优化消息已读处理逻辑

Merge pull request !1008 from puhui999/develop
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,8 +34,8 @@ public class KeFuConversationController {
34 @Resource 34 @Resource
35 private MemberUserApi memberUserApi; 35 private MemberUserApi memberUserApi;
36 36
37 - @PostMapping("/update-conversation-pinned")  
38 - @Operation(summary = "置顶客服会话") 37 + @PutMapping("/update-conversation-pinned")
  38 + @Operation(summary = "置顶/取消置顶客服会话")
39 @PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:update')") 39 @PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:update')")
40 public CommonResult<Boolean> updateConversationPinned(@Valid @RequestBody KeFuConversationUpdatePinnedReqVO updateReqVO) { 40 public CommonResult<Boolean> updateConversationPinned(@Valid @RequestBody KeFuConversationUpdatePinnedReqVO updateReqVO) {
41 conversationService.updateConversationPinnedByAdmin(updateReqVO); 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&lt;KeFuMessageDO&gt; { @@ -27,9 +27,11 @@ public interface KeFuMessageMapper extends BaseMapperX&lt;KeFuMessageDO&gt; {
27 .orderByDesc(KeFuMessageDO::getCreateTime)); 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 return selectList(new LambdaQueryWrapper<KeFuMessageDO>() 32 return selectList(new LambdaQueryWrapper<KeFuMessageDO>()
32 .eq(KeFuMessageDO::getConversationId, conversationId) 33 .eq(KeFuMessageDO::getConversationId, conversationId)
  34 + .ne(KeFuMessageDO::getSenderType, userType) // 管理员:查询出未读的会员消息,会员:查询出未读的客服消息
33 .eq(KeFuMessageDO::getReadStatus, readStatus)); 35 .eq(KeFuMessageDO::getReadStatus, readStatus));
34 } 36 }
35 37
@@ -38,7 +40,7 @@ public interface KeFuMessageMapper extends BaseMapperX&lt;KeFuMessageDO&gt; { @@ -38,7 +40,7 @@ public interface KeFuMessageMapper extends BaseMapperX&lt;KeFuMessageDO&gt; {
38 .in(KeFuMessageDO::getId, ids)); 40 .in(KeFuMessageDO::getId, ids));
39 } 41 }
40 42
41 - default PageResult<KeFuMessageDO> selectPage(AppKeFuMessagePageReqVO pageReqVO){ 43 + default PageResult<KeFuMessageDO> selectPage(AppKeFuMessagePageReqVO pageReqVO) {
42 return selectPage(pageReqVO, new LambdaQueryWrapperX<KeFuMessageDO>() 44 return selectPage(pageReqVO, new LambdaQueryWrapperX<KeFuMessageDO>()
43 .eqIfPresent(KeFuMessageDO::getConversationId, pageReqVO.getConversationId()) 45 .eqIfPresent(KeFuMessageDO::getConversationId, pageReqVO.getConversationId())
44 .orderByDesc(KeFuMessageDO::getCreateTime)); 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,6 +41,10 @@ public class KeFuConversationServiceImpl implements KeFuConversationService {
41 41
42 @Override 42 @Override
43 public void updateConversationPinnedByAdmin(KeFuConversationUpdatePinnedReqVO updateReqVO) { 43 public void updateConversationPinnedByAdmin(KeFuConversationUpdatePinnedReqVO updateReqVO) {
  44 + // 校验存在
  45 + validateKefuConversationExists(updateReqVO.getId());
  46 +
  47 + // 更新管理员会话置顶状态
44 conversationMapper.updateById(new KeFuConversationDO().setId(updateReqVO.getId()).setAdminPinned(updateReqVO.getAdminPinned())); 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,7 +67,7 @@ public class KeFuMessageServiceImpl implements KeFuMessageService {
67 conversationService.updateConversationLastMessage(kefuMessage); 67 conversationService.updateConversationLastMessage(kefuMessage);
68 68
69 // 3. 发送消息 69 // 3. 发送消息
70 - getSelf().sendAsyncMessage(UserTypeEnum.MEMBER.getValue(), conversation.getUserId(), kefuMessage); 70 + getSelf().sendAsyncMessageToMember(conversation.getUserId(), KEFU_MESSAGE_TYPE, kefuMessage);
71 return kefuMessage.getId(); 71 return kefuMessage.getId();
72 } 72 }
73 73
@@ -83,7 +83,7 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { @@ -83,7 +83,7 @@ public class KeFuMessageServiceImpl implements KeFuMessageService {
83 // 2. 更新会话消息冗余 83 // 2. 更新会话消息冗余
84 conversationService.updateConversationLastMessage(kefuMessage); 84 conversationService.updateConversationLastMessage(kefuMessage);
85 // 3. 发送消息 85 // 3. 发送消息
86 - getSelf().sendAsyncMessageToAdmin(kefuMessage); 86 + getSelf().sendAsyncMessageToAdmin(KEFU_MESSAGE_TYPE, kefuMessage);
87 return kefuMessage.getId(); 87 return kefuMessage.getId();
88 } 88 }
89 89
@@ -97,7 +97,7 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { @@ -97,7 +97,7 @@ public class KeFuMessageServiceImpl implements KeFuMessageService {
97 throw exception(KEFU_CONVERSATION_NOT_EXISTS); 97 throw exception(KEFU_CONVERSATION_NOT_EXISTS);
98 } 98 }
99 // 1.3 查询会话所有的未读消息 (tips: 多个客服,一个人点了,就都点了) 99 // 1.3 查询会话所有的未读消息 (tips: 多个客服,一个人点了,就都点了)
100 - List<KeFuMessageDO> messageList = keFuMessageMapper.selectListByConversationIdAndReadStatus(conversationId, Boolean.FALSE); 100 + List<KeFuMessageDO> messageList = keFuMessageMapper.selectListByConversationIdAndUserTypeAndReadStatus(conversationId, userType, Boolean.FALSE);
101 if (CollUtil.isEmpty(messageList)) { 101 if (CollUtil.isEmpty(messageList)) {
102 return; 102 return;
103 } 103 }
@@ -109,10 +109,11 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { @@ -109,10 +109,11 @@ public class KeFuMessageServiceImpl implements KeFuMessageService {
109 conversationService.updateAdminUnreadMessageCountToZero(conversationId); 109 conversationService.updateAdminUnreadMessageCountToZero(conversationId);
110 110
111 // 2.3 发送消息通知会员,管理员已读 -> 会员更新发送的消息状态 111 // 2.3 发送消息通知会员,管理员已读 -> 会员更新发送的消息状态
112 - // TODO @puhui999:待定~  
113 KeFuMessageDO keFuMessage = getFirst(filterList(messageList, message -> UserTypeEnum.MEMBER.getValue().equals(message.getSenderType()))); 112 KeFuMessageDO keFuMessage = getFirst(filterList(messageList, message -> UserTypeEnum.MEMBER.getValue().equals(message.getSenderType())));
114 assert keFuMessage != null; // 断言避免警告 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 private void validateReceiverExist(Long receiverId, Integer receiverType) { 119 private void validateReceiverExist(Long receiverId, Integer receiverType) {
@@ -125,13 +126,13 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { @@ -125,13 +126,13 @@ public class KeFuMessageServiceImpl implements KeFuMessageService {
125 } 126 }
126 127
127 @Async 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 @Async 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 @Override 138 @Override