浏览代码

【代码评审】MALL:review 客服的实现

YunaiV 10 月之前
父节点
当前提交
866b38535e

+ 2 - 2
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/WebSocketMessageTypeConstants.java

@@ -1,13 +1,13 @@
 package cn.iocoder.yudao.module.promotion.enums;
 
 /**
- * websocket 消息类型枚举类
+ * Promotion 的 WebSocket 消息类型枚举类
  *
  * @author HUIHUI
  */
 public interface WebSocketMessageTypeConstants {
 
-    //======================= mall 客服 =======================
+    // ======================= mall 客服 =======================
 
     String KEFU_MESSAGE_TYPE = "kefu_message_type"; // 客服消息类型
     String KEFU_MESSAGE_ADMIN_READ = "kefu_message_read_status_change"; // 客服消息管理员已读

+ 1 - 0
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/kehu/KeFuMessageContentTypeEnum.java

@@ -20,6 +20,7 @@ public enum KeFuMessageContentTypeEnum implements IntArrayValuable {
     VOICE(3, "语音消息"),
     VIDEO(4, "视频消息"),
     SYSTEM(5, "系统消息"),
+
     // ========== 商城特殊消息 ==========
     PRODUCT(10, "商品消息"),
     ORDER(11, "订单消息");

+ 1 - 1
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuConversationController.java

@@ -31,7 +31,7 @@ public class KeFuConversationController {
     @Operation(summary = "置顶客服会话")
     @PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:update')")
     public CommonResult<Boolean> updateConversationPinned(@Valid @RequestBody KeFuConversationUpdatePinnedReqVO updateReqVO) {
-        conversationService.updateAdminPinned(updateReqVO);
+        conversationService.updateConversationPinnedByAdmin(updateReqVO);
         return success(true);
     }
 

+ 1 - 2
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuMessageController.java

@@ -1,6 +1,5 @@
 package cn.iocoder.yudao.module.promotion.controller.admin.kefu;
 
-import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@@ -37,7 +36,7 @@ public class KeFuMessageController {
     }
 
     @PutMapping("/update-read-status")
-    @Operation(summary = "更新会员客服消息已读状态")
+    @Operation(summary = "更新客服消息已读状态")
     @Parameter(name = "conversationId", description = "会话编号", required = true)
     @PreAuthorize("@ss.hasPermission('promotion:kefu-message:update')")
     public CommonResult<Boolean> updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) {

+ 2 - 1
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/AppKeFuMessageController.java

@@ -33,7 +33,7 @@ public class AppKeFuMessageController {
     @PostMapping("/send")
     @Operation(summary = "发送客服消息")
     @PreAuthenticated
-    public CommonResult<Long> createKefuMessage(@Valid @RequestBody AppKeFuMessageSendReqVO sendReqVO) {
+    public CommonResult<Long> sendKefuMessage(@Valid @RequestBody AppKeFuMessageSendReqVO sendReqVO) {
         sendReqVO.setSenderId(getLoginUserId()).setSenderType(UserTypeEnum.MEMBER.getValue()); // 设置用户编号和类型
         return success(kefuMessageService.sendKefuMessage(sendReqVO));
     }
@@ -43,6 +43,7 @@ public class AppKeFuMessageController {
     @Parameter(name = "conversationId", description = "会话编号", required = true)
     @PreAuthenticated
     public CommonResult<Boolean> updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) {
+        // TODO @puhui999:需要传递 userId;万一用户模拟一个 conversationId
         kefuMessageService.updateKefuMessageReadStatus(conversationId);
         return success(true);
     }

+ 8 - 5
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/vo/message/AppKeFuMessageSendReqVO.java

@@ -9,14 +9,10 @@ import lombok.Data;
 @Data
 public class AppKeFuMessageSendReqVO {
 
+    // TODO @puhui999:应该没有传递编号哈
     @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23202")
     private Long id;
 
-    @Schema(description = "发送人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24571")
-    private Long senderId;
-    @Schema(description = "发送人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
-    private Integer senderType;
-
     @Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
     @NotNull(message = "消息类型不能为空")
     private Integer contentType;
@@ -24,4 +20,11 @@ public class AppKeFuMessageSendReqVO {
     @NotEmpty(message = "消息不能为空")
     private String content;
 
+    // ========== 后端设置的参数,前端无需传递 ==========
+
+    @Schema(description = "发送人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24571", hidden = true)
+    private Long senderId;
+    @Schema(description = "发送人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1", hidden = true)
+    private Integer senderType;
+
 }

+ 2 - 0
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/kefu/KeFuConversationMapper.java

@@ -22,12 +22,14 @@ public interface KeFuConversationMapper extends BaseMapperX<KeFuConversationDO>
                 .orderByDesc(KeFuConversationDO::getCreateTime));
     }
 
+    // TODO @puhui999:这个不用单独搞个方法哈。Service 直接 new 一个对象,然后调用 update 方法。
     default void updateAdminUnreadMessageCountWithZero(Long id) {
         update(new LambdaUpdateWrapper<KeFuConversationDO>()
                 .eq(KeFuConversationDO::getId, id)
                 .set(KeFuConversationDO::getAdminUnreadMessageCount, 0));
     }
 
+    // TODO @puhui999:改成 updateAdminUnreadMessageCountIncrement 增加
     default void updateAdminUnreadMessageCount(Long id) {
         update(new LambdaUpdateWrapper<KeFuConversationDO>()
                 .eq(KeFuConversationDO::getId, id)

+ 1 - 1
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationService.java

@@ -25,7 +25,7 @@ public interface KeFuConversationService {
      *
      * @param updateReqVO 请求
      */
-    void updateAdminPinned(KeFuConversationUpdatePinnedReqVO updateReqVO);
+    void updateConversationPinnedByAdmin(KeFuConversationUpdatePinnedReqVO updateReqVO);
 
     /**
      * 更新会话客服消息冗余信息

+ 5 - 3
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationServiceImpl.java

@@ -40,7 +40,7 @@ public class KeFuConversationServiceImpl implements KeFuConversationService {
     }
 
     @Override
-    public void updateAdminPinned(KeFuConversationUpdatePinnedReqVO updateReqVO) {
+    public void updateConversationPinnedByAdmin(KeFuConversationUpdatePinnedReqVO updateReqVO) {
         conversationMapper.updateById(new KeFuConversationDO().setId(updateReqVO.getId()).setAdminPinned(updateReqVO.getAdminPinned()));
     }
 
@@ -54,11 +54,12 @@ public class KeFuConversationServiceImpl implements KeFuConversationService {
                 .setLastMessageTime(kefuMessage.getCreateTime()).setLastMessageContent(kefuMessage.getContent())
                 .setLastMessageContentType(kefuMessage.getContentType()));
 
-        // 2.2 更新管理员未读消息数
+        // 2.1 更新管理员未读消息数
         if (UserTypeEnum.MEMBER.getValue().equals(kefuMessage.getSenderType())) {
             conversationMapper.updateAdminUnreadMessageCount(kefuMessage.getConversationId());
         }
-        // 2.4 会员用户发送消息时,如果管理员删除过会话则进行恢复
+        // 2.2 会员用户发送消息时,如果管理员删除过会话则进行恢复
+        // TODO @puhui999:其实不用判断用户类型;只要be已删除,就恢复!
         if (UserTypeEnum.MEMBER.getValue().equals(kefuMessage.getSenderType())
                 && Boolean.TRUE.equals(conversation.getAdminDeleted())) {
             updateConversationAdminDeleted(kefuMessage.getConversationId(), Boolean.FALSE);
@@ -106,6 +107,7 @@ public class KeFuConversationServiceImpl implements KeFuConversationService {
 
     @Override
     public KeFuConversationDO getConversationByUserId(Long userId) {
+        // TODO @puhui999:service 不写 dao 的逻辑哈
         return conversationMapper.selectOne(KeFuConversationDO::getUserId, userId);
     }