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