Переглянути джерело

feat(promotion): 初始化客服消息和优化会话列表

- 新增 initUser 方法用于初始化客服消息- 在获取会话列表时,如果为空则调用 initUser 初始化
- 优化了发送消息的逻辑,确保 conversationId 不为空- 注释掉了 KeFuConversationMapper 中的无效查询条件
zrd 3 місяців тому
батько
коміт
03f482fbac

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

@@ -1,6 +1,7 @@
 package cn.iocoder.yudao.module.promotion.controller.app.kefu;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjUtil;
 import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@@ -141,6 +142,11 @@ public class AppKeFuConversationController {
                     sendReqVO.setContent("{\"text\":\"" + conteng + "\"}");
                     sendReqVO.setContentType(1);
                     sendReqVO.setRelUserId(id);
+                    if (ObjUtil.isNull(sendReqVO.getConversationId())) {
+                        KeFuConversationDO conversation =
+                                conversationService.getOrCreateConversation(sendReqVO.getSenderId());
+                        sendReqVO.setConversationId(conversation.getId());
+                    }
                     kefuMessageService.sendMessage(sendReqVO);
                 }
                 
@@ -149,6 +155,25 @@ public class AppKeFuConversationController {
         }
     }
     
+    private void initUser(String conteng, Long userId) {
+        
+        AppKeFuMessageSendReqVO sendReqVO = new AppKeFuMessageSendReqVO();
+        sendReqVO.setSenderId(userId).setSenderType(UserTypeEnum.ADMIN.getValue()); //
+        // 设置用户编号和类型
+        sendReqVO.setContent("{\"text\":\"" + conteng + "\"}");
+        sendReqVO.setContentType(1);
+        sendReqVO.setRelUserId(SecurityFrameworkUtils.getLoginUserId());
+        if (ObjUtil.isNull(sendReqVO.getConversationId())) {
+            KeFuConversationDO conversation =
+                    conversationService.getOrCreateConversation(sendReqVO.getSenderId(),
+                            SecurityFrameworkUtils.getLoginUserId());
+            sendReqVO.setConversationId(conversation.getId());
+        }
+        kefuMessageService.sendMessage(sendReqVO);
+        
+        
+    }
+    
     @GetMapping("/listNew")
     @Operation(summary = "获得客服会话列表新")
     public CommonResult<List<KeFuConversationRespVO>> getConversationListNew() {
@@ -156,7 +181,15 @@ public class AppKeFuConversationController {
         Long me = SecurityFrameworkUtils.getLoginUserId();
         List<KeFuConversationDO> list =
                 conversationService.getConversationList(me);
-        
+        if (CollUtil.isEmpty(list)) {
+            //初始化 1 2 3 4  发送消息
+            initUser("欢迎!", 1L);
+            initUser("欢迎1!", 2L);
+            initUser("欢迎2!", 3L);
+            initUser("欢迎3!", 4L);
+            list =
+                    conversationService.getConversationList(me);
+        }
         List<KeFuConversationRespVO> respList =
                 BeanUtils.toBean(list,
                 KeFuConversationRespVO.class);

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

@@ -47,7 +47,7 @@ public interface KeFuConversationMapper extends BaseMapperX<KeFuConversationDO>
                 
                 .eq(KeFuConversationDO::getAdminDeleted, Boolean.FALSE)
                 .apply("t.rel_user_id>4")
-                .apply("t.id is null")
+//                .apply("t.id is null")
                 .orderByDesc(KeFuConversationDO::getCreateTime));
     }