Ver código fonte

开始对话接口修改

Zhangbw 2 meses atrás
pai
commit
4e93952acc

+ 5 - 6
ruoyi-admin/src/main/resources/application-prod.yml

@@ -4,7 +4,7 @@ spring.servlet.multipart.location: /ruoyi/server/temp
 --- # 监控中心配置
 spring.boot.admin.client:
   # 增加客户端开关
-  enabled: true
+  enabled: false
   url: http://localhost:9090/admin
   instance:
     service-host-type: IP
@@ -16,7 +16,7 @@ spring.boot.admin.client:
 
 --- # snail-job 配置
 snail-job:
-  enabled: true
+  enabled: false
   # 需要在 SnailJob 后台组管理创建对应名称的组,然后创建任务的时候选择对应的组,才能正确分派任务
   group: "ruoyi_group"
   # SnailJob 接入验证令牌 详见 script/sql/ry_job.sql `sj_group_config`表
@@ -50,9 +50,9 @@ spring:
           driverClassName: com.mysql.cj.jdbc.Driver
           # jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
           # rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
-          url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
-          username: root
-          password: root
+          url: jdbc:mysql://localhost:3306/aitalk?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
+          username: aiTalk
+          password: X4CmF85A2M6nDLJt
 #        # 从库数据源
 #        slave:
 #          lazy: true
@@ -105,7 +105,6 @@ spring.data:
     # 数据库索引
     database: 0
     # redis 密码必须配置
-    password: ruoyi123
     # 连接超时时间
     timeout: 10s
     # 是否开启ssl

+ 11 - 56
ruoyi-modules/yp-talk/src/main/java/org/dromara/talk/controller/api/ChatController.java

@@ -86,17 +86,17 @@ public class ChatController {
     }
 
     /**
-     * 开始对话
-     * 用户点击开始对话时,将客服状态改为2(对话中),带并发控制
+     * 开始对话(通用接口)
+     * 支持普通对话和RPA对话场景
      *
      * @param id 客服ID
-     * @return 更新结果
+     * @param request 可选参数,包含customerPhone(RPA场景使用)
+     * @return 开始对话结果,包含sessionId
      */
     @PostMapping("/agent/{id}/start")
-    public Map<String, Object> startChat(@PathVariable Long id) {
+    public Map<String, Object> startChat(@PathVariable Long id, @RequestBody(required = false) Map<String, String> request) {
         boolean success = talkAgentService.changeAgentStatus(id, "2");
         if (success) {
-            // 获取当前登录用户ID
             Long userId = 0L;
             try {
                 userId = LoginHelper.getUserId();
@@ -104,18 +104,20 @@ public class ChatController {
                 log.warn("获取登录用户ID失败,使用默认值", e);
             }
 
-            // 生成临时sessionId
             String tempSessionId = UUID.randomUUID().toString();
+            String customerPhone = request != null ? request.get("customerPhone") : null;
 
-            // 创建会话记录
             TalkSessionBo sessionBo = new TalkSessionBo();
             sessionBo.setSessionId(tempSessionId);
             sessionBo.setAgentId(id);
-            sessionBo.setStartTime(new java.util.Date());
+            sessionBo.setStartTime(new Date());
             sessionBo.setUserId(userId);
+            if (customerPhone != null) {
+                sessionBo.setCustomerPhone(customerPhone);
+            }
             talkSessionService.insertByBo(sessionBo);
 
-            log.info("客服 {} 开始对话,状态已改为对话中,临时sessionId: {}, 创建人: {}", id, tempSessionId, userId);
+            log.info("客服 {} 开始对话,sessionId: {}, customerPhone: {}, 创建人: {}", id, tempSessionId, customerPhone, userId);
             return Map.of("success", true, "code", 200, "sessionId", tempSessionId);
         } else {
             log.warn("客服 {} 开始对话失败,可能已被占用", id);
@@ -196,51 +198,4 @@ public class ChatController {
         return emitter;
     }
 
-    /**
-     * RPA开始对话
-     * 代表客户选择客服并开始对话
-     *
-     * @param request 包含agentId和customerPhone的请求体
-     * @return 开始对话结果,包含临时sessionId
-     */
-    @PostMapping("/rpa/startChat")
-    public Map<String, Object> rpaStartChat(@RequestBody Map<String, String> request) {
-        String agentIdStr = request.get("agentId");
-        String customerPhone = request.get("customerPhone");
-
-        if (agentIdStr == null || customerPhone == null) {
-            return Map.of("success", false, "code", 400, "msg", "agentId和customerPhone不能为空");
-        }
-
-        Long agentId = Long.valueOf(agentIdStr);
-        boolean success = talkAgentService.changeAgentStatus(agentId, "2");
-
-        if (success) {
-            // 生成临时sessionId
-            String tempSessionId = UUID.randomUUID().toString();
-
-            // 获取当前登录用户ID
-            Long userId = 0L;
-            try {
-                userId = org.dromara.common.satoken.utils.LoginHelper.getUserId();
-            } catch (Exception e) {
-                log.warn("获取登录用户ID失败,使用默认值", e);
-            }
-
-            // 创建会话记录
-            TalkSessionBo sessionBo = new TalkSessionBo();
-            sessionBo.setSessionId(tempSessionId);
-            sessionBo.setAgentId(agentId);
-            sessionBo.setCustomerPhone(customerPhone);
-            sessionBo.setStartTime(new Date());
-            sessionBo.setUserId(userId);
-            talkSessionService.insertByBo(sessionBo);
-
-            log.info("RPA代表客户 {} 选择客服 {} 开始对话,临时sessionId: {}, 创建人: {}", customerPhone, agentId, tempSessionId, userId);
-            return Map.of("success", true, "code", 200, "agentId", agentId, "customerPhone", customerPhone, "sessionId", tempSessionId);
-        } else {
-            log.warn("RPA开始对话失败,客服 {} 可能已被占用", agentId);
-            return Map.of("success", false, "code", 400, "msg", "该客服已被其他用户占用,请选择其他客服");
-        }
-    }
 }

+ 0 - 1
ruoyi-modules/yp-talk/src/main/java/org/dromara/talk/service/impl/ChatServiceImpl.java

@@ -1,6 +1,5 @@
 package org.dromara.talk.service.impl;
 
-import cn.dev33.satoken.stp.StpUtil;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;