From 19e7763440974aa6d5570e2c59fdfc73af3e481e Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 5 Jul 2024 16:30:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?MALL-KEFU:=20=E4=BC=98=E5=8C=96=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=B7=B2=E8=AF=BB=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dal/mysql/kefu/KeFuMessageMapper.java | 6 ++++-- .../service/kefu/KeFuMessageServiceImpl.java | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/kefu/KeFuMessageMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/kefu/KeFuMessageMapper.java index 3de68fe0f..f565fd7f0 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/kefu/KeFuMessageMapper.java +++ b/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 { .orderByDesc(KeFuMessageDO::getCreateTime)); } - default List selectListByConversationIdAndReadStatus(Long conversationId, Boolean readStatus) { + default List selectListByConversationIdAndUserTypeAndReadStatus(Long conversationId, Integer userType, + Boolean readStatus) { return selectList(new LambdaQueryWrapper() .eq(KeFuMessageDO::getConversationId, conversationId) + .ne(KeFuMessageDO::getSenderType, userType) // 管理员:查询出未读的会员消息,会员:查询出未读的客服消息 .eq(KeFuMessageDO::getReadStatus, readStatus)); } @@ -38,7 +40,7 @@ public interface KeFuMessageMapper extends BaseMapperX { .in(KeFuMessageDO::getId, ids)); } - default PageResult selectPage(AppKeFuMessagePageReqVO pageReqVO){ + default PageResult selectPage(AppKeFuMessagePageReqVO pageReqVO) { return selectPage(pageReqVO, new LambdaQueryWrapperX() .eqIfPresent(KeFuMessageDO::getConversationId, pageReqVO.getConversationId()) .orderByDesc(KeFuMessageDO::getCreateTime)); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageServiceImpl.java index e11474f91..125628347 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageServiceImpl.java +++ b/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 { conversationService.updateConversationLastMessage(kefuMessage); // 3. 发送消息 - getSelf().sendAsyncMessage(UserTypeEnum.MEMBER.getValue(), conversation.getUserId(), kefuMessage); + getSelf().sendAsyncMessageToMember(conversation.getUserId(), KEFU_MESSAGE_TYPE, kefuMessage); return kefuMessage.getId(); } @@ -83,7 +83,7 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { // 2. 更新会话消息冗余 conversationService.updateConversationLastMessage(kefuMessage); // 3. 发送消息 - getSelf().sendAsyncMessageToAdmin(kefuMessage); + getSelf().sendAsyncMessageToAdmin(KEFU_MESSAGE_TYPE, kefuMessage); return kefuMessage.getId(); } @@ -97,7 +97,7 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { throw exception(KEFU_CONVERSATION_NOT_EXISTS); } // 1.3 查询会话所有的未读消息 (tips: 多个客服,一个人点了,就都点了) - List messageList = keFuMessageMapper.selectListByConversationIdAndReadStatus(conversationId, Boolean.FALSE); + List messageList = keFuMessageMapper.selectListByConversationIdAndUserTypeAndReadStatus(conversationId, userType, Boolean.FALSE); if (CollUtil.isEmpty(messageList)) { return; } @@ -109,10 +109,11 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { conversationService.updateAdminUnreadMessageCountToZero(conversationId); // 2.3 发送消息通知会员,管理员已读 -> 会员更新发送的消息状态 - // TODO @puhui999:待定~ KeFuMessageDO keFuMessage = getFirst(filterList(messageList, message -> UserTypeEnum.MEMBER.getValue().equals(message.getSenderType()))); 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) { @@ -125,13 +126,13 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { } @Async - public void sendAsyncMessage(Integer userType, Long userId, Object content) { - webSocketSenderApi.sendObject(userType, userId, KEFU_MESSAGE_TYPE, content); + public void sendAsyncMessageToMember(Long userId, String messageType, Object content) { + webSocketSenderApi.sendObject(UserTypeEnum.MEMBER.getValue(), userId, messageType, content); } @Async - public void sendAsyncMessageToAdmin(Object content) { - webSocketSenderApi.sendObject(UserTypeEnum.ADMIN.getValue(), KEFU_MESSAGE_TYPE, content); + public void sendAsyncMessageToAdmin(String messageType, Object content) { + webSocketSenderApi.sendObject(UserTypeEnum.ADMIN.getValue(), messageType, content); } @Override From 4a395955769ca03baeff3820f4829a5f78864a60 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 5 Jul 2024 17:59:47 +0800 Subject: [PATCH 2/2] =?UTF-8?q?MALL-KEFU:=20=E4=BC=98=E5=8C=96=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98=E4=BC=9A=E8=AF=9D=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/kefu/KeFuConversationController.java | 4 ++-- .../promotion/service/kefu/KeFuConversationServiceImpl.java | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuConversationController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuConversationController.java index 705118142..8d286a36a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuConversationController.java +++ b/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 { @Resource private MemberUserApi memberUserApi; - @PostMapping("/update-conversation-pinned") - @Operation(summary = "置顶客服会话") + @PutMapping("/update-conversation-pinned") + @Operation(summary = "置顶/取消置顶客服会话") @PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:update')") public CommonResult updateConversationPinned(@Valid @RequestBody KeFuConversationUpdatePinnedReqVO updateReqVO) { conversationService.updateConversationPinnedByAdmin(updateReqVO); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationServiceImpl.java index 57df13d76..fbc658abc 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationServiceImpl.java +++ b/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 { @Override public void updateConversationPinnedByAdmin(KeFuConversationUpdatePinnedReqVO updateReqVO) { + // 校验存在 + validateKefuConversationExists(updateReqVO.getId()); + + // 更新管理员会话置顶状态 conversationMapper.updateById(new KeFuConversationDO().setId(updateReqVO.getId()).setAdminPinned(updateReqVO.getAdminPinned())); }