|
|
@@ -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", "该客服已被其他用户占用,请选择其他客服");
|
|
|
- }
|
|
|
- }
|
|
|
}
|