mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-06 17:36:47 +08:00
fix: 报错时也记录
This commit is contained in:
@@ -132,6 +132,13 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
|
||||
// 3. 构建请求参数
|
||||
String userId = currentUser.getCode();
|
||||
|
||||
// 6. 用于收集对话数据的容器
|
||||
AiChatConversationData conversationData = new AiChatConversationData();
|
||||
conversationData.setQuery(caseAiChatDto.getQuery());
|
||||
conversationData.setConversationId(conversationId);
|
||||
conversationData.setUserId(userId);
|
||||
|
||||
String kId = caseAiProperties.getCaseKnowledgeId();
|
||||
JSONObject chatParam = new JSONObject();
|
||||
chatParam.put("userId", userId);
|
||||
@@ -162,9 +169,18 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
String accessToken;
|
||||
try {
|
||||
accessToken = aiAccessTokenService.getAccessToken();
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(accessToken)) {
|
||||
errMessage(sseEmitter, SYS_ERR_MSG);
|
||||
sseEmitter.complete();
|
||||
conversationData.appendAnswer(SYS_ERR_MSG);
|
||||
elasticSearchIndexService.createData(conversationData);
|
||||
return sseEmitter;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取access_token失败", e);
|
||||
errMessage(sseEmitter, SYS_ERR_MSG);
|
||||
conversationData.appendAnswer(SYS_ERR_MSG);
|
||||
elasticSearchIndexService.createData(conversationData);
|
||||
sseEmitter.complete();
|
||||
return sseEmitter;
|
||||
}
|
||||
@@ -177,13 +193,6 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
builder.post(bodyRequestBody);
|
||||
Request request = builder.build();
|
||||
|
||||
|
||||
// 6. 用于收集对话数据的容器
|
||||
AiChatConversationData conversationData = new AiChatConversationData();
|
||||
conversationData.setQuery(caseAiChatDto.getQuery());
|
||||
conversationData.setConversationId(conversationId);
|
||||
conversationData.setUserId(userId);
|
||||
|
||||
// 7. 创建事件监听器
|
||||
EventSourceListener listener = new EventSourceListener() {
|
||||
@Override
|
||||
@@ -271,6 +280,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
conversationEventSourceMap.remove(conversationId);
|
||||
|
||||
// 即使失败,也要将已有的对话数据保存到ES
|
||||
conversationData.appendAnswer(SYS_ERR_MSG);
|
||||
elasticSearchIndexService.createData(conversationData);
|
||||
return;
|
||||
}
|
||||
@@ -282,16 +292,17 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
// 从Map中移除失败的会话
|
||||
conversationEventSourceMap.remove(conversationId);
|
||||
// 即使失败,也要将已有的对话数据保存到ES
|
||||
conversationData.appendAnswer(SYS_ERR_MSG);
|
||||
elasticSearchIndexService.createData(conversationData);
|
||||
return;
|
||||
}
|
||||
|
||||
sseEmitter.completeWithError(e);
|
||||
// 从Map中移除失败的会话
|
||||
conversationEventSourceMap.remove(conversationId);
|
||||
|
||||
// 即使失败,也要将已有的对话数据保存到ES
|
||||
elasticSearchIndexService.createData(conversationData);
|
||||
sseEmitter.completeWithError(e);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user