Bladeren bron

feat(ai): 添加客服类型参数支持AI和运营客服区分

- 在AiUserSessionController中添加type参数验证,支持AI客服(0)和运营客服(1)
- 修改getUserSessions方法签名,增加type参数并实现类型转换逻辑
- 更新请求参数校验,确保type值为0或1
- 扩展日志记录,包含type参数便于调试追踪
- 更新API调用,将type参数传递给后端服务
fcw 2 maanden geleden
bovenliggende
commit
e8d58403c4

+ 28 - 1
alien-store/src/main/java/shop/alien/store/controller/AiUserSessionController.java

@@ -35,6 +35,10 @@ public class AiUserSessionController {
             if (request == null || !request.containsKey("user_id")) {
                 return R.fail("用户ID不能为空");
             }
+            //type: 0是ai客服,1是运营客服
+            if (!request.containsKey("type")) {
+                return R.fail("type不能为空");
+            }
 
             Object userIdObj = request.get("user_id");
             if (userIdObj == null) {
@@ -58,7 +62,30 @@ public class AiUserSessionController {
                 return R.fail("用户ID必须大于0");
             }
 
-            JSONObject result = aiUserSessionUtil.getUserSessions(userId);
+            Object typeObj = request.get("type");
+            if (typeObj == null) {
+                return R.fail("type不能为空");
+            }
+
+            Integer type;
+            if (typeObj instanceof Integer) {
+                type = (Integer) typeObj;
+            } else if (typeObj instanceof Number) {
+                type = ((Number) typeObj).intValue();
+            } else {
+                try {
+                    type = Integer.parseInt(typeObj.toString());
+                } catch (NumberFormatException e) {
+                    return R.fail("type格式错误");
+                }
+            }
+
+            // type: 0是ai客服,1是运营客服
+            if (type != 0 && type != 1) {
+                return R.fail("type必须为0或1,0是ai客服,1是运营客服");
+            }
+
+            JSONObject result = aiUserSessionUtil.getUserSessions(userId, type);
             if (result != null) {
                 Boolean success = result.getBoolean("success");
                 if (Boolean.TRUE.equals(success)) {

+ 17 - 10
alien-store/src/main/java/shop/alien/store/util/ai/AiUserSessionUtil.java

@@ -54,14 +54,20 @@ public class AiUserSessionUtil {
      * 获取用户会话列表
      *
      * @param userId 用户ID
+     * @param type 会话类型,0是ai客服,1是运营客服
      * @return 用户会话列表响应,包含 success, user_id, total, limit, offset, sessions
      */
-    public JSONObject getUserSessions(Integer userId) {
+    public JSONObject getUserSessions(Integer userId, Integer type) {
         if (userId == null || userId <= 0) {
             log.warn("用户ID为空或无效,无法查询会话列表");
             return buildErrorResponse("用户ID不能为空");
         }
 
+        if (type == null) {
+            log.warn("type参数为空,无法查询会话列表");
+            return buildErrorResponse("type不能为空");
+        }
+
         // 获取AI服务访问令牌
         String accessToken = aiAuthTokenUtil.getAccessToken();
         if (!StringUtils.hasText(accessToken)) {
@@ -73,6 +79,7 @@ public class AiUserSessionUtil {
             // 构建请求体
             Map<String, Object> requestBody = new HashMap<>();
             requestBody.put("user_id", userId);
+            requestBody.put("type", type);
 
             // 构建请求头,添加Authorization
             HttpHeaders headers = new HttpHeaders();
@@ -81,7 +88,7 @@ public class AiUserSessionUtil {
 
             HttpEntity<Map<String, Object>> request = new HttpEntity<>(requestBody, headers);
 
-            log.info("调用AI用户会话接口,用户ID: {}", userId);
+            log.info("调用AI用户会话接口,用户ID: {}, type: {}", userId, type);
             ResponseEntity<String> response = restTemplate.postForEntity(userSessionUrl, request, String.class);
 
             if (response != null && response.getStatusCode() == HttpStatus.OK) {
@@ -93,12 +100,12 @@ public class AiUserSessionUtil {
                     if (jsonObject != null) {
                         Boolean success = jsonObject.getBoolean("success");
                         if (Boolean.TRUE.equals(success)) {
-                            log.info("成功获取用户会话列表,用户ID: {}, 总会话数: {}", 
-                                    userId, jsonObject.getInteger("total"));
+                            log.info("成功获取用户会话列表,用户ID: {}, type: {}, 总会话数: {}", 
+                                    userId, type, jsonObject.getInteger("total"));
                             return jsonObject;
                         } else {
                             String message = jsonObject.getString("message");
-                            log.warn("AI接口返回失败,用户ID: {}, message: {}", userId, message);
+                            log.warn("AI接口返回失败,用户ID: {}, type: {}, message: {}", userId, type, message);
                             return jsonObject;
                         }
                     }
@@ -109,15 +116,15 @@ public class AiUserSessionUtil {
                 return buildErrorResponse("AI用户会话接口调用失败");
             }
         } catch (HttpClientErrorException e) {
-            log.error("调用AI用户会话接口失败,HTTP客户端错误,状态码: {}, 响应体: {}, 用户ID: {}", 
-                    e.getStatusCode(), e.getResponseBodyAsString(), userId, e);
+            log.error("调用AI用户会话接口失败,HTTP客户端错误,状态码: {}, 响应体: {}, 用户ID: {}, type: {}", 
+                    e.getStatusCode(), e.getResponseBodyAsString(), userId, type, e);
             return buildErrorResponse("调用AI用户会话接口失败: " + e.getMessage());
         } catch (HttpServerErrorException e) {
-            log.error("调用AI用户会话接口失败,HTTP服务器错误,状态码: {}, 响应体: {}, 用户ID: {}", 
-                    e.getStatusCode(), e.getResponseBodyAsString(), userId, e);
+            log.error("调用AI用户会话接口失败,HTTP服务器错误,状态码: {}, 响应体: {}, 用户ID: {}, type: {}", 
+                    e.getStatusCode(), e.getResponseBodyAsString(), userId, type, e);
             return buildErrorResponse("调用AI用户会话接口失败: " + e.getMessage());
         } catch (Exception e) {
-            log.error("调用AI用户会话接口异常,用户ID: {}", userId, e);
+            log.error("调用AI用户会话接口异常,用户ID: {}, type: {}", userId, type, e);
             return buildErrorResponse("调用AI用户会话接口异常: " + e.getMessage());
         }