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

This commit is contained in:
puhui999 2024-07-05 16:30:38 +08:00
parent b7e4f8e460
commit 19e7763440
2 changed files with 14 additions and 11 deletions

View File

@ -27,9 +27,11 @@ public interface KeFuMessageMapper extends BaseMapperX<KeFuMessageDO> {
.orderByDesc(KeFuMessageDO::getCreateTime)); .orderByDesc(KeFuMessageDO::getCreateTime));
} }
default List<KeFuMessageDO> selectListByConversationIdAndReadStatus(Long conversationId, Boolean readStatus) { default List<KeFuMessageDO> selectListByConversationIdAndUserTypeAndReadStatus(Long conversationId, Integer userType,
Boolean readStatus) {
return selectList(new LambdaQueryWrapper<KeFuMessageDO>() return selectList(new LambdaQueryWrapper<KeFuMessageDO>()
.eq(KeFuMessageDO::getConversationId, conversationId) .eq(KeFuMessageDO::getConversationId, conversationId)
.ne(KeFuMessageDO::getSenderType, userType) // 管理员查询出未读的会员消息会员查询出未读的客服消息
.eq(KeFuMessageDO::getReadStatus, readStatus)); .eq(KeFuMessageDO::getReadStatus, readStatus));
} }
@ -38,7 +40,7 @@ public interface KeFuMessageMapper extends BaseMapperX<KeFuMessageDO> {
.in(KeFuMessageDO::getId, ids)); .in(KeFuMessageDO::getId, ids));
} }
default PageResult<KeFuMessageDO> selectPage(AppKeFuMessagePageReqVO pageReqVO){ default PageResult<KeFuMessageDO> selectPage(AppKeFuMessagePageReqVO pageReqVO) {
return selectPage(pageReqVO, new LambdaQueryWrapperX<KeFuMessageDO>() return selectPage(pageReqVO, new LambdaQueryWrapperX<KeFuMessageDO>()
.eqIfPresent(KeFuMessageDO::getConversationId, pageReqVO.getConversationId()) .eqIfPresent(KeFuMessageDO::getConversationId, pageReqVO.getConversationId())
.orderByDesc(KeFuMessageDO::getCreateTime)); .orderByDesc(KeFuMessageDO::getCreateTime));

View File

@ -67,7 +67,7 @@ public class KeFuMessageServiceImpl implements KeFuMessageService {
conversationService.updateConversationLastMessage(kefuMessage); conversationService.updateConversationLastMessage(kefuMessage);
// 3. 发送消息 // 3. 发送消息
getSelf().sendAsyncMessage(UserTypeEnum.MEMBER.getValue(), conversation.getUserId(), kefuMessage); getSelf().sendAsyncMessageToMember(conversation.getUserId(), KEFU_MESSAGE_TYPE, kefuMessage);
return kefuMessage.getId(); return kefuMessage.getId();
} }
@ -83,7 +83,7 @@ public class KeFuMessageServiceImpl implements KeFuMessageService {
// 2. 更新会话消息冗余 // 2. 更新会话消息冗余
conversationService.updateConversationLastMessage(kefuMessage); conversationService.updateConversationLastMessage(kefuMessage);
// 3. 发送消息 // 3. 发送消息
getSelf().sendAsyncMessageToAdmin(kefuMessage); getSelf().sendAsyncMessageToAdmin(KEFU_MESSAGE_TYPE, kefuMessage);
return kefuMessage.getId(); return kefuMessage.getId();
} }
@ -97,7 +97,7 @@ public class KeFuMessageServiceImpl implements KeFuMessageService {
throw exception(KEFU_CONVERSATION_NOT_EXISTS); throw exception(KEFU_CONVERSATION_NOT_EXISTS);
} }
// 1.3 查询会话所有的未读消息 (tips: 多个客服一个人点了就都点了) // 1.3 查询会话所有的未读消息 (tips: 多个客服一个人点了就都点了)
List<KeFuMessageDO> messageList = keFuMessageMapper.selectListByConversationIdAndReadStatus(conversationId, Boolean.FALSE); List<KeFuMessageDO> messageList = keFuMessageMapper.selectListByConversationIdAndUserTypeAndReadStatus(conversationId, userType, Boolean.FALSE);
if (CollUtil.isEmpty(messageList)) { if (CollUtil.isEmpty(messageList)) {
return; return;
} }
@ -109,10 +109,11 @@ public class KeFuMessageServiceImpl implements KeFuMessageService {
conversationService.updateAdminUnreadMessageCountToZero(conversationId); conversationService.updateAdminUnreadMessageCountToZero(conversationId);
// 2.3 发送消息通知会员管理员已读 -> 会员更新发送的消息状态 // 2.3 发送消息通知会员管理员已读 -> 会员更新发送的消息状态
// TODO @puhui999待定~
KeFuMessageDO keFuMessage = getFirst(filterList(messageList, message -> UserTypeEnum.MEMBER.getValue().equals(message.getSenderType()))); KeFuMessageDO keFuMessage = getFirst(filterList(messageList, message -> UserTypeEnum.MEMBER.getValue().equals(message.getSenderType())));
assert keFuMessage != null; // 断言避免警告 assert keFuMessage != null; // 断言避免警告
webSocketSenderApi.sendObject(UserTypeEnum.MEMBER.getValue(), keFuMessage.getSenderId(), KEFU_MESSAGE_ADMIN_READ, StrUtil.EMPTY); getSelf().sendAsyncMessageToMember(keFuMessage.getSenderId(), KEFU_MESSAGE_ADMIN_READ, StrUtil.EMPTY);
// 2.4 通知所有管理员消息已读
getSelf().sendAsyncMessageToAdmin(KEFU_MESSAGE_ADMIN_READ, StrUtil.EMPTY);
} }
private void validateReceiverExist(Long receiverId, Integer receiverType) { private void validateReceiverExist(Long receiverId, Integer receiverType) {
@ -125,13 +126,13 @@ public class KeFuMessageServiceImpl implements KeFuMessageService {
} }
@Async @Async
public void sendAsyncMessage(Integer userType, Long userId, Object content) { public void sendAsyncMessageToMember(Long userId, String messageType, Object content) {
webSocketSenderApi.sendObject(userType, userId, KEFU_MESSAGE_TYPE, content); webSocketSenderApi.sendObject(UserTypeEnum.MEMBER.getValue(), userId, messageType, content);
} }
@Async @Async
public void sendAsyncMessageToAdmin(Object content) { public void sendAsyncMessageToAdmin(String messageType, Object content) {
webSocketSenderApi.sendObject(UserTypeEnum.ADMIN.getValue(), KEFU_MESSAGE_TYPE, content); webSocketSenderApi.sendObject(UserTypeEnum.ADMIN.getValue(), messageType, content);
} }
@Override @Override