mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-11 03:46:50 +08:00
Compare commits
33 Commits
fceb6ac805
...
250930-fea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6474c29a60 | ||
|
|
85dbefee3e | ||
|
|
99c95f0cfe | ||
|
|
300fa7ab06 | ||
|
|
784fe062bf | ||
|
|
c233260250 | ||
|
|
4015e461b2 | ||
|
|
b07b620d14 | ||
|
|
e54f184a16 | ||
|
|
3abe5365b4 | ||
|
|
e5cb156e64 | ||
|
|
68e610c222 | ||
|
|
457339a385 | ||
|
|
b9fc27f4fb | ||
|
|
ee0a853b1b | ||
|
|
b128187e31 | ||
|
|
4412563208 | ||
|
|
7bee2e3c45 | ||
|
|
5c43dffb4f | ||
|
|
a045f470e6 | ||
|
|
92aaf2bed7 | ||
|
|
cc9d4b7bb9 | ||
|
|
dd0760a32b | ||
|
|
38c2784f51 | ||
|
|
49d3ad5999 | ||
|
|
4f4fd64a6d | ||
|
|
07bf665220 | ||
|
|
8a3899dfd1 | ||
|
|
c17a594393 | ||
|
|
09d61ceb9d | ||
|
|
106fde8e6b | ||
|
|
3bf0534d77 | ||
|
|
dd0e10539f |
@@ -0,0 +1,39 @@
|
|||||||
|
package com.xboe.config;
|
||||||
|
|
||||||
|
import org.apache.activemq.command.ActiveMQTopic;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.jms.annotation.EnableJms;
|
||||||
|
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
|
||||||
|
import org.springframework.jms.config.JmsListenerContainerFactory;
|
||||||
|
|
||||||
|
import javax.jms.ConnectionFactory;
|
||||||
|
import javax.jms.Topic;
|
||||||
|
|
||||||
|
@EnableJms
|
||||||
|
@Configuration
|
||||||
|
public class MqConfig {
|
||||||
|
|
||||||
|
@Value("${activemq.topic.name}")
|
||||||
|
private String topicName;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置topic
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public Topic broadcastTopic() {
|
||||||
|
return new ActiveMQTopic(topicName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 配置JmsListenerContainerFactory为发布/订阅模式
|
||||||
|
@Bean
|
||||||
|
public JmsListenerContainerFactory<?> jmsListenerContainerFactory(ConnectionFactory connectionFactory) {
|
||||||
|
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
|
||||||
|
factory.setConnectionFactory(connectionFactory);
|
||||||
|
factory.setPubSubDomain(true); // 设置为发布/订阅模式
|
||||||
|
factory.setSubscriptionDurable(false); // 非持久订阅
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,6 +65,24 @@ public class ThreadPoolConfig {
|
|||||||
return executor;
|
return executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异步存会话数据线程池
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Bean(name = "esChatExecutor")
|
||||||
|
public ThreadPoolTaskExecutor esChatExecutor() {
|
||||||
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||||
|
executor.setCorePoolSize(10);
|
||||||
|
executor.setMaxPoolSize(500);
|
||||||
|
executor.setQueueCapacity(10);
|
||||||
|
executor.setThreadNamePrefix("es-chat-");
|
||||||
|
executor.setKeepAliveSeconds(300);
|
||||||
|
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
|
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||||
|
executor.initialize();
|
||||||
|
return executor;
|
||||||
|
}
|
||||||
|
|
||||||
@Bean(name = "customDispatcher")
|
@Bean(name = "customDispatcher")
|
||||||
public Dispatcher customDispatcher(@Qualifier("eventStreamExecutor") ThreadPoolTaskExecutor eventStreamExecutor) {
|
public Dispatcher customDispatcher(@Qualifier("eventStreamExecutor") ThreadPoolTaskExecutor eventStreamExecutor) {
|
||||||
return new Dispatcher(eventStreamExecutor.getThreadPoolExecutor());
|
return new Dispatcher(eventStreamExecutor.getThreadPoolExecutor());
|
||||||
|
|||||||
@@ -7,4 +7,8 @@ public class CaseAiConstants {
|
|||||||
public static final String CASE_DOC_UPLOAD_INTERFACE_NAME = "文档上传";
|
public static final String CASE_DOC_UPLOAD_INTERFACE_NAME = "文档上传";
|
||||||
|
|
||||||
public static final String CASE_DOC_DELETE_INTERFACE_NAME = "文档删除";
|
public static final String CASE_DOC_DELETE_INTERFACE_NAME = "文档删除";
|
||||||
|
|
||||||
|
public static final String CHAT_SYS_ERR_MSG = "当前无法获取回答,请稍后重试";
|
||||||
|
|
||||||
|
public static final String CHAT_NET_ERR_MSG = "网络异常,请稍后再试";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.xboe.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误码枚举
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum CaseAiChatErrCodeEnum {
|
||||||
|
|
||||||
|
SUCCESS(0, "成功"),
|
||||||
|
|
||||||
|
INTERNAL_ERROR(1, "内部错误"),
|
||||||
|
|
||||||
|
AIOT_ERROR(2, "AIoT平台错误"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
|
||||||
|
private final String label;
|
||||||
|
|
||||||
|
CaseAiChatErrCodeEnum(int code, String label) {
|
||||||
|
this.code = code;
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CaseAiChatErrCodeEnum getByCode(int code) {
|
||||||
|
return Arrays.stream(values()).filter(e -> e.code == code)
|
||||||
|
.findFirst().orElse(SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,9 @@ package com.xboe.module.boecase.api;
|
|||||||
import com.xboe.core.api.ApiBaseController;
|
import com.xboe.core.api.ApiBaseController;
|
||||||
import com.xboe.core.JsonResponse;
|
import com.xboe.core.JsonResponse;
|
||||||
import com.xboe.module.boecase.dto.CaseAiChatDto;
|
import com.xboe.module.boecase.dto.CaseAiChatDto;
|
||||||
|
import com.xboe.module.boecase.dto.CaseAiMsgLikeDto;
|
||||||
|
import com.xboe.module.boecase.dto.EsFieldDTO;
|
||||||
|
import com.xboe.module.boecase.dto.GetCaseAiMsgDto;
|
||||||
import com.xboe.module.boecase.entity.AiChatConversationData;
|
import com.xboe.module.boecase.entity.AiChatConversationData;
|
||||||
import com.xboe.module.boecase.service.ICaseAiChatService;
|
import com.xboe.module.boecase.service.ICaseAiChatService;
|
||||||
import com.xboe.module.boecase.service.ICaseAiPermissionService;
|
import com.xboe.module.boecase.service.ICaseAiPermissionService;
|
||||||
@@ -17,7 +20,7 @@ import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,13 +61,13 @@ public class CaseAiChatApi extends ApiBaseController {
|
|||||||
// 获取当前用户
|
// 获取当前用户
|
||||||
return caseAiChatService.chat(caseAiChatDto, getCurrent());
|
return caseAiChatService.chat(caseAiChatDto, getCurrent());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 停止当前聊天输出
|
* 停止当前聊天输出
|
||||||
* @param conversationId 会话ID
|
* @param conversationId 会话ID
|
||||||
* @return 是否成功停止
|
* @return 是否成功停止
|
||||||
*/
|
*/
|
||||||
@PostMapping("/stop")
|
@GetMapping("/stop")
|
||||||
public JsonResponse<Boolean> stopChat(@RequestParam String conversationId) {
|
public JsonResponse<Boolean> stopChat(@RequestParam String conversationId) {
|
||||||
try {
|
try {
|
||||||
boolean result = caseAiChatService.stopChatOutput(conversationId);
|
boolean result = caseAiChatService.stopChatOutput(conversationId);
|
||||||
@@ -78,7 +81,64 @@ public class CaseAiChatApi extends ApiBaseController {
|
|||||||
return error("停止输出失败", e.getMessage());
|
return error("停止输出失败", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 赞消息
|
||||||
|
* @param caseAiMsgLikeDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/likeMsg")
|
||||||
|
public JsonResponse<Boolean> likeMsg(@RequestBody CaseAiMsgLikeDto caseAiMsgLikeDto) {
|
||||||
|
try {
|
||||||
|
caseAiMsgLikeDto.setOperation(true);
|
||||||
|
if (caseAiChatService.msgFeedback(caseAiMsgLikeDto)) {
|
||||||
|
return success(true, "保存成功");
|
||||||
|
} else {
|
||||||
|
return success(false, "保存失败");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("消息赞/踩操作保存异常", e);
|
||||||
|
return error("保存失败", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息问题反馈保存
|
||||||
|
* @param caseAiMsgLikeDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/msgFeedback")
|
||||||
|
public JsonResponse<Boolean> msgFeedback(@RequestBody CaseAiMsgLikeDto caseAiMsgLikeDto) {
|
||||||
|
try {
|
||||||
|
caseAiMsgLikeDto.setOperation(false);
|
||||||
|
if (caseAiChatService.msgFeedback(caseAiMsgLikeDto)) {
|
||||||
|
return success(true, "保存成功");
|
||||||
|
} else {
|
||||||
|
return success(false, "保存失败");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("消息问题反馈保存异常", e);
|
||||||
|
return error("保存失败", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取消息
|
||||||
|
*
|
||||||
|
* @param getCaseAiMsgDto
|
||||||
|
*/
|
||||||
|
@PostMapping("/getCaseAiMsg")
|
||||||
|
public JsonResponse<List<CaseAiMessageVo>> getCaseAiMsgDetail(@RequestBody GetCaseAiMsgDto getCaseAiMsgDto) {
|
||||||
|
try {
|
||||||
|
List<CaseAiMessageVo> caseAiMessageVoList = caseAiChatService.getCaseAiMsg(getCaseAiMsgDto);
|
||||||
|
return success(caseAiMessageVoList);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取消息详情异常", e);
|
||||||
|
return error("获取失败", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据conversationId查看会话内消息记录
|
* 根据conversationId查看会话内消息记录
|
||||||
* @param conversationId 会话ID
|
* @param conversationId 会话ID
|
||||||
@@ -105,8 +165,9 @@ public class CaseAiChatApi extends ApiBaseController {
|
|||||||
public void downloadConversationExcel(@RequestParam String startTime,
|
public void downloadConversationExcel(@RequestParam String startTime,
|
||||||
@RequestParam String endTime,
|
@RequestParam String endTime,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
LocalDate startDate = LocalDate.parse(startTime);
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
LocalDate endDate = LocalDate.parse(endTime);
|
LocalDate startDate = LocalDate.parse(startTime, formatter);
|
||||||
|
LocalDate endDate = LocalDate.parse(endTime, formatter);
|
||||||
caseAiChatService.getConversationExcel(startDate.atStartOfDay(), endDate.atTime(23, 59, 59), response);
|
caseAiChatService.getConversationExcel(startDate.atStartOfDay(), endDate.atTime(23, 59, 59), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,6 +208,17 @@ public class CaseAiChatApi extends ApiBaseController {
|
|||||||
return error("刷新失败");
|
return error("刷新失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加索引字段
|
||||||
|
* @param esFieldDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/index/add_field")
|
||||||
|
public JsonResponse<String> addField(@RequestBody EsFieldDTO esFieldDTO) {
|
||||||
|
boolean result = elasticSearchIndexService.updateIndex(esFieldDTO.getFieldName(), esFieldDTO.getIndexProperties());
|
||||||
|
return result ? success("添加成功") : error("添加失败");
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/es/create")
|
@PostMapping("/es/create")
|
||||||
public JsonResponse<String> createNewConversation(@RequestBody CaseAiMessageVo caseAiMessageVo,
|
public JsonResponse<String> createNewConversation(@RequestBody CaseAiMessageVo caseAiMessageVo,
|
||||||
@RequestParam String conversationId,
|
@RequestParam String conversationId,
|
||||||
@@ -158,7 +230,7 @@ public class CaseAiChatApi extends ApiBaseController {
|
|||||||
aiChatConversationData.setCaseRefers(caseAiMessageVo.getCaseRefer());
|
aiChatConversationData.setCaseRefers(caseAiMessageVo.getCaseRefer());
|
||||||
aiChatConversationData.setSuggestions(caseAiMessageVo.getSuggestions());
|
aiChatConversationData.setSuggestions(caseAiMessageVo.getSuggestions());
|
||||||
aiChatConversationData.setUserId(userId);
|
aiChatConversationData.setUserId(userId);
|
||||||
if (elasticSearchIndexService.createData(aiChatConversationData)) {
|
if (elasticSearchIndexService.createData(aiChatConversationData) != null) {
|
||||||
return success("创建成功");
|
return success("创建成功");
|
||||||
}
|
}
|
||||||
return error("创建失败");
|
return error("创建失败");
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.xboe.module.boecase.api;
|
package com.xboe.module.boecase.api;
|
||||||
|
|
||||||
|
import com.xboe.module.boecase.task.CaseUploadTask;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
@@ -20,14 +21,21 @@ public class CaseUploadTaskApi {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private StringRedisTemplate stringRedisTemplate;
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
private static final String CASE_UPLOAD_LAST_ID_KEY = "case:upload:last:id";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清除处理位置标记,使下次任务从头开始执行
|
* 清除处理位置标记,使下次任务从头开始执行
|
||||||
*/
|
*/
|
||||||
@PostMapping("/reset")
|
@PostMapping("/reset")
|
||||||
public void resetLastProcessedId() {
|
public void resetLastProcessedId() {
|
||||||
stringRedisTemplate.delete(CASE_UPLOAD_LAST_ID_KEY);
|
stringRedisTemplate.delete(CaseUploadTask.CASE_UPLOAD_LAST_ID_KEY);
|
||||||
|
log.info("已清除上次处理位置标记");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除处理位置标记,使下次任务从头开始执行
|
||||||
|
*/
|
||||||
|
@PostMapping("/reload/reset")
|
||||||
|
public void resetReloadProcessedId() {
|
||||||
|
stringRedisTemplate.delete(CaseUploadTask.CASE_RELOAD_LAST_ID_KEY);
|
||||||
log.info("已清除上次处理位置标记");
|
log.info("已清除上次处理位置标记");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.xboe.module.boecase.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CaseAiMsgLikeDto {
|
||||||
|
/**
|
||||||
|
* 文档id
|
||||||
|
*/
|
||||||
|
private String docId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点赞状态:
|
||||||
|
* -1 踩
|
||||||
|
* 1 赞
|
||||||
|
* 0/null 无操作
|
||||||
|
*/
|
||||||
|
private String likeStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 反馈
|
||||||
|
*/
|
||||||
|
private String feedback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作
|
||||||
|
* true: 点踩
|
||||||
|
* false: 反馈
|
||||||
|
* 为空:其他情况
|
||||||
|
*/
|
||||||
|
private Boolean operation;
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.xboe.module.boecase.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class EsFieldDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段名称
|
||||||
|
*/
|
||||||
|
private String fieldName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段属性
|
||||||
|
*/
|
||||||
|
private Properties properties;
|
||||||
|
|
||||||
|
public Map<String, Object> getIndexProperties() {
|
||||||
|
Map<String, Object> indexProperties = new HashMap<>();
|
||||||
|
if (properties != null) {
|
||||||
|
indexProperties.put("type", properties.type);
|
||||||
|
if (properties.index != null) {
|
||||||
|
indexProperties.put("index", properties.index);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(properties.analyzer)) {
|
||||||
|
indexProperties.put("analyzer", properties.analyzer);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(properties.searchAnalyzer)) {
|
||||||
|
indexProperties.put("search_analyzer", properties.searchAnalyzer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return indexProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Properties {
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
private Boolean index;
|
||||||
|
|
||||||
|
private String analyzer;
|
||||||
|
|
||||||
|
private String searchAnalyzer;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.xboe.module.boecase.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class GetCaseAiMsgDto {
|
||||||
|
/**
|
||||||
|
* 会话Id
|
||||||
|
*/
|
||||||
|
private String conversationId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ES DocId
|
||||||
|
*/
|
||||||
|
private String docId;
|
||||||
|
}
|
||||||
@@ -34,6 +34,19 @@ public class AiChatConversationData {
|
|||||||
*/
|
*/
|
||||||
private StringBuilder answer = new StringBuilder();
|
private StringBuilder answer = new StringBuilder();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
* 0-正常
|
||||||
|
* 1-系统错误
|
||||||
|
* 2-AIoT平台错误
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误信息
|
||||||
|
*/
|
||||||
|
private String errorMsg;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 案例引用列表
|
* 案例引用列表
|
||||||
*/
|
*/
|
||||||
@@ -44,6 +57,20 @@ public class AiChatConversationData {
|
|||||||
*/
|
*/
|
||||||
private List<String> suggestions = new ArrayList<>();
|
private List<String> suggestions = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户点赞状态
|
||||||
|
* -1: 踩
|
||||||
|
* 1:赞
|
||||||
|
* 0/null 无操作
|
||||||
|
*/
|
||||||
|
private String likeStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户踩的时候, 可以填写反馈意见
|
||||||
|
* 反馈意见
|
||||||
|
*/
|
||||||
|
private String feedback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户ID
|
* 用户ID
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -93,4 +93,12 @@ public class CaseDocumentLog extends BaseEntity {
|
|||||||
*/
|
*/
|
||||||
@Column(name = "execute_duration")
|
@Column(name = "execute_duration")
|
||||||
private Long executeDuration;
|
private Long executeDuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 元数据处理状态
|
||||||
|
* 0-未处理
|
||||||
|
* 1-已处理
|
||||||
|
*/
|
||||||
|
@Column(name = "metadata_status")
|
||||||
|
private Integer metadataStatus;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.xboe.module.boecase.mq;
|
||||||
|
|
||||||
|
|
||||||
|
import com.xboe.module.boecase.service.ICaseAiChatService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.jms.annotation.JmsListener;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class BroadcastMessageConsumer {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ICaseAiChatService iCaseAiChatService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接收会话终止广播消息
|
||||||
|
*
|
||||||
|
* @param conversationId 会话ID
|
||||||
|
*/
|
||||||
|
@JmsListener(destination = "${activemq.topic.name}")
|
||||||
|
public void receiveSessionTerminationBroadcastMessage(String conversationId) {
|
||||||
|
log.info("收到会话终止广播消息:{}", conversationId);
|
||||||
|
iCaseAiChatService.eventSourceCancel(conversationId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@ package com.xboe.module.boecase.service;
|
|||||||
|
|
||||||
import com.xboe.core.CurrentUser;
|
import com.xboe.core.CurrentUser;
|
||||||
import com.xboe.module.boecase.dto.CaseAiChatDto;
|
import com.xboe.module.boecase.dto.CaseAiChatDto;
|
||||||
|
import com.xboe.module.boecase.dto.CaseAiMsgLikeDto;
|
||||||
|
import com.xboe.module.boecase.dto.GetCaseAiMsgDto;
|
||||||
import com.xboe.module.boecase.entity.CaseAiConversations;
|
import com.xboe.module.boecase.entity.CaseAiConversations;
|
||||||
import com.xboe.module.boecase.vo.CaseAiMessageVo;
|
import com.xboe.module.boecase.vo.CaseAiMessageVo;
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
@@ -64,4 +66,27 @@ public interface ICaseAiChatService {
|
|||||||
* @return 是否成功停止
|
* @return 是否成功停止
|
||||||
*/
|
*/
|
||||||
boolean stopChatOutput(String conversationId);
|
boolean stopChatOutput(String conversationId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消eventSource
|
||||||
|
*
|
||||||
|
* @param conversationId 会话ID
|
||||||
|
*/
|
||||||
|
void eventSourceCancel(String conversationId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息反馈保存
|
||||||
|
* likeStatus: 踩/赞
|
||||||
|
* feedBack: 反馈消息内容
|
||||||
|
*
|
||||||
|
* @param caseAiMsgLikeDto
|
||||||
|
*/
|
||||||
|
boolean msgFeedback(CaseAiMsgLikeDto caseAiMsgLikeDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取消息
|
||||||
|
*
|
||||||
|
* @param getCaseAiMsgDto
|
||||||
|
*/
|
||||||
|
List<CaseAiMessageVo> getCaseAiMsg(GetCaseAiMsgDto getCaseAiMsgDto);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.xboe.module.boecase.entity.AiChatConversationData;
|
|||||||
import com.xboe.module.boecase.vo.CaseAiMessageVo;
|
import com.xboe.module.boecase.vo.CaseAiMessageVo;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* es索引
|
* es索引
|
||||||
@@ -27,12 +28,20 @@ public interface IElasticSearchIndexService {
|
|||||||
*/
|
*/
|
||||||
boolean deleteIndex();
|
boolean deleteIndex();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新索引:添加索引字段
|
||||||
|
* @param fieldName
|
||||||
|
* @param fieldProperties
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean updateIndex(String fieldName, Map<String, Object> fieldProperties);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增数据
|
* 新增数据
|
||||||
* @param data
|
* @param data
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
boolean createData(AiChatConversationData data);
|
String createData(AiChatConversationData data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询数据
|
* 查询数据
|
||||||
@@ -40,4 +49,20 @@ public interface IElasticSearchIndexService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<CaseAiMessageVo> queryData(String conversationId);
|
List<CaseAiMessageVo> queryData(String conversationId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新数据
|
||||||
|
* @param docId
|
||||||
|
* @param data
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean updateData(String docId, AiChatConversationData data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过docId查询数据
|
||||||
|
*
|
||||||
|
* @param docId ES docId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<CaseAiMessageVo> queryDataByDocId(String docId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
@EnableConfigurationProperties({CaseAiProperties.class})
|
@EnableConfigurationProperties({CaseAiProperties.class})
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j(topic = "caseAiChatLogger")
|
||||||
public class AiAccessTokenServiceImpl implements IAiAccessTokenService {
|
public class AiAccessTokenServiceImpl implements IAiAccessTokenService {
|
||||||
|
|
||||||
private static final String ACCESS_TOKEN_CACHE_KEY = "case_ai_access_token";
|
private static final String ACCESS_TOKEN_CACHE_KEY = "case_ai_access_token";
|
||||||
|
|||||||
@@ -2,13 +2,19 @@ package com.xboe.module.boecase.service.impl;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.xboe.constants.CaseAiConstants;
|
||||||
import com.xboe.core.CurrentUser;
|
import com.xboe.core.CurrentUser;
|
||||||
import com.xboe.core.orm.FieldFilters;
|
import com.xboe.core.orm.FieldFilters;
|
||||||
|
import com.xboe.enums.CaseAiChatErrCodeEnum;
|
||||||
import com.xboe.enums.CaseAiChatStatusEnum;
|
import com.xboe.enums.CaseAiChatStatusEnum;
|
||||||
import com.xboe.module.boecase.dao.CaseAiConversationsDao;
|
import com.xboe.module.boecase.dao.CaseAiConversationsDao;
|
||||||
import com.xboe.module.boecase.dao.CaseDocumentLogDao;
|
import com.xboe.module.boecase.dao.CaseDocumentLogDao;
|
||||||
import com.xboe.module.boecase.dao.CasesDao;
|
import com.xboe.module.boecase.dao.CasesDao;
|
||||||
import com.xboe.module.boecase.dto.CaseAiChatDto;
|
import com.xboe.module.boecase.dto.CaseAiChatDto;
|
||||||
|
import com.xboe.module.boecase.dto.GetCaseAiMsgDto;
|
||||||
|
import com.xboe.module.boecase.entity.AiChatConversationData;
|
||||||
|
import com.xboe.module.boecase.dto.CaseAiMsgLikeDto;
|
||||||
import com.xboe.module.boecase.entity.CaseAiConversations;
|
import com.xboe.module.boecase.entity.CaseAiConversations;
|
||||||
import com.xboe.module.boecase.entity.CaseDocumentLog;
|
import com.xboe.module.boecase.entity.CaseDocumentLog;
|
||||||
import com.xboe.module.boecase.entity.Cases;
|
import com.xboe.module.boecase.entity.Cases;
|
||||||
@@ -18,17 +24,15 @@ import com.xboe.module.boecase.service.ICaseAiChatService;
|
|||||||
import com.xboe.module.boecase.service.IElasticSearchIndexService;
|
import com.xboe.module.boecase.service.IElasticSearchIndexService;
|
||||||
import com.xboe.module.boecase.vo.CaseAiMessageVo;
|
import com.xboe.module.boecase.vo.CaseAiMessageVo;
|
||||||
import com.xboe.module.boecase.vo.CaseReferVo;
|
import com.xboe.module.boecase.vo.CaseReferVo;
|
||||||
import com.xboe.module.boecase.entity.AiChatConversationData;
|
|
||||||
import com.xboe.module.boecase.vo.ConversationExcelVo;
|
import com.xboe.module.boecase.vo.ConversationExcelVo;
|
||||||
import com.xboe.system.organization.vo.OrgSimpleVo;
|
import com.xboe.system.organization.vo.OrgSimpleVo;
|
||||||
import com.xboe.system.user.service.IUserService;
|
import com.xboe.system.user.service.IUserService;
|
||||||
import lombok.Data;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import okhttp3.*;
|
import okhttp3.*;
|
||||||
import okhttp3.sse.EventSource;
|
import okhttp3.sse.EventSource;
|
||||||
import okhttp3.sse.EventSourceListener;
|
import okhttp3.sse.EventSourceListener;
|
||||||
import okhttp3.sse.EventSources;
|
import okhttp3.sse.EventSources;
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
@@ -40,32 +44,23 @@ import org.apache.poi.ss.usermodel.Sheet;
|
|||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.elasticsearch.action.index.IndexRequest;
|
|
||||||
import org.elasticsearch.action.index.IndexResponse;
|
|
||||||
import org.elasticsearch.action.search.SearchRequest;
|
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
|
||||||
import org.elasticsearch.client.RequestOptions;
|
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
|
||||||
import org.elasticsearch.search.SearchHit;
|
|
||||||
import org.elasticsearch.search.SearchHits;
|
|
||||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.jms.JmsException;
|
||||||
|
import org.springframework.jms.core.JmsTemplate;
|
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
|
|
||||||
|
import javax.jms.Topic;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.SocketTimeoutException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@@ -81,11 +76,13 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Slf4j(topic = "caseAiChatLogger")
|
@Slf4j(topic = "caseAiChatLogger")
|
||||||
public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||||
|
|
||||||
private static final String SYS_ERR_MSG = "服务繁忙,请稍后再试。";
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CaseAiProperties caseAiProperties;
|
private CaseAiProperties caseAiProperties;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("esChatExecutor")
|
||||||
|
private ThreadPoolTaskExecutor esChatExecutor;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("customDispatcher")
|
@Qualifier("customDispatcher")
|
||||||
private Dispatcher dispatcher;
|
private Dispatcher dispatcher;
|
||||||
@@ -107,7 +104,13 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CasesDao casesDao;
|
private CasesDao casesDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JmsTemplate jmsTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Topic topic;
|
||||||
|
|
||||||
// 用于存储会话ID与EventSource的映射关系,以便能够中断特定会话
|
// 用于存储会话ID与EventSource的映射关系,以便能够中断特定会话
|
||||||
private final Map<String, EventSource> conversationEventSourceMap = new ConcurrentHashMap<>();
|
private final Map<String, EventSource> conversationEventSourceMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@@ -122,16 +125,24 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
conversationId = getOrCreateConversationId(caseAiChatDto, currentUser);
|
conversationId = getOrCreateConversationId(caseAiChatDto, currentUser);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("获取会话ID失败", e);
|
log.error("获取会话ID失败", e);
|
||||||
errMessage(sseEmitter, SYS_ERR_MSG);
|
errMessage(sseEmitter, null, CaseAiConstants.CHAT_SYS_ERR_MSG);
|
||||||
sseEmitter.complete();
|
sseEmitter.complete();
|
||||||
return sseEmitter;
|
return sseEmitter;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 查询历史
|
// 2. 查询历史
|
||||||
List<CaseAiMessageVo> historyMessages = elasticSearchIndexService.queryData(conversationId);
|
List<CaseAiMessageVo> historyMessages = elasticSearchIndexService.queryData(conversationId);
|
||||||
|
|
||||||
// 3. 构建请求参数
|
// 3. 构建请求参数
|
||||||
String userId = currentUser.getCode();
|
String userId = currentUser.getCode();
|
||||||
|
|
||||||
|
// 6. 用于收集对话数据的容器
|
||||||
|
AiChatConversationData conversationData = new AiChatConversationData();
|
||||||
|
conversationData.setQuery(caseAiChatDto.getQuery());
|
||||||
|
conversationData.setConversationId(conversationId);
|
||||||
|
conversationData.setUserId(userId);
|
||||||
|
conversationData.setStatus(CaseAiChatErrCodeEnum.SUCCESS.getCode());
|
||||||
|
|
||||||
String kId = caseAiProperties.getCaseKnowledgeId();
|
String kId = caseAiProperties.getCaseKnowledgeId();
|
||||||
JSONObject chatParam = new JSONObject();
|
JSONObject chatParam = new JSONObject();
|
||||||
chatParam.put("userId", userId);
|
chatParam.put("userId", userId);
|
||||||
@@ -157,14 +168,29 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
}
|
}
|
||||||
String chatParamStr = chatParam.toJSONString();
|
String chatParamStr = chatParam.toJSONString();
|
||||||
log.info("案例问答接口请求参数: [{}]", chatParamStr);
|
log.info("案例问答接口请求参数: [{}]", chatParamStr);
|
||||||
|
|
||||||
// 4. 设置请求头
|
// 4. 设置请求头
|
||||||
String accessToken;
|
String accessToken;
|
||||||
try {
|
try {
|
||||||
accessToken = aiAccessTokenService.getAccessToken();
|
accessToken = aiAccessTokenService.getAccessToken();
|
||||||
|
if (org.apache.commons.lang3.StringUtils.isBlank(accessToken)) {
|
||||||
|
errMessage(sseEmitter, conversationId, CaseAiConstants.CHAT_SYS_ERR_MSG);
|
||||||
|
// 先响应给前端
|
||||||
|
conversationData.setStatus(CaseAiChatErrCodeEnum.AIOT_ERROR.getCode());
|
||||||
|
conversationData.setErrorMsg("获取AccessToken时发生异常");
|
||||||
|
conversationData.appendAnswer(CaseAiConstants.CHAT_SYS_ERR_MSG);
|
||||||
|
saveConversationData(sseEmitter, conversationData);
|
||||||
|
sseEmitter.complete();
|
||||||
|
return sseEmitter;
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("获取access_token失败", e);
|
log.error("获取access_token失败", e);
|
||||||
errMessage(sseEmitter, SYS_ERR_MSG);
|
errMessage(sseEmitter, conversationId, CaseAiConstants.CHAT_SYS_ERR_MSG);
|
||||||
|
// 先响应给前端
|
||||||
|
conversationData.setStatus(CaseAiChatErrCodeEnum.AIOT_ERROR.getCode());
|
||||||
|
conversationData.setErrorMsg("获取AccessToken时发生异常" + e.getMessage());
|
||||||
|
conversationData.appendAnswer(CaseAiConstants.CHAT_SYS_ERR_MSG);
|
||||||
|
saveConversationData(sseEmitter, conversationData);
|
||||||
sseEmitter.complete();
|
sseEmitter.complete();
|
||||||
return sseEmitter;
|
return sseEmitter;
|
||||||
}
|
}
|
||||||
@@ -177,18 +203,52 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
builder.post(bodyRequestBody);
|
builder.post(bodyRequestBody);
|
||||||
Request request = builder.build();
|
Request request = builder.build();
|
||||||
|
|
||||||
|
|
||||||
// 6. 用于收集对话数据的容器
|
|
||||||
AiChatConversationData conversationData = new AiChatConversationData();
|
|
||||||
conversationData.setQuery(caseAiChatDto.getQuery());
|
|
||||||
conversationData.setConversationId(conversationId);
|
|
||||||
conversationData.setUserId(userId);
|
|
||||||
|
|
||||||
// 7. 创建事件监听器
|
// 7. 创建事件监听器
|
||||||
EventSourceListener listener = new EventSourceListener() {
|
EventSourceListener listener = new EventSourceListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onOpen(@NotNull EventSource eventSource, @NotNull Response response) {
|
public void onOpen(@NotNull EventSource eventSource, @NotNull Response response) {
|
||||||
log.info("调用接口 [{}] 接口开始监听", request.url());
|
log.info("调用接口 [{}] 接口开始监听", request.url());
|
||||||
|
// 检查contentType
|
||||||
|
String contentType = response.header("Content-Type");
|
||||||
|
if (contentType == null || !contentType.contains("text/event-stream")) {
|
||||||
|
// 服务器返回的不是SSE流,需要额外处理
|
||||||
|
log.error("调用接口 [{}] 返回的Content-Type不是text/event-stream,实际ContentType: {}", request.url(), contentType);
|
||||||
|
String sseContent;
|
||||||
|
try {
|
||||||
|
ResponseBody responseBody = response.body();
|
||||||
|
if (responseBody == null) {
|
||||||
|
sseContent = CaseAiConstants.CHAT_SYS_ERR_MSG;
|
||||||
|
} else {
|
||||||
|
String responseBodyStr = responseBody.string();
|
||||||
|
log.error("调用 [{}] 返回值: {}", request.url(), responseBodyStr);
|
||||||
|
// 判断是否为json
|
||||||
|
if (contentType != null && contentType.contains("application/json")) {
|
||||||
|
JSONObject responseData = JSONObject.parseObject(responseBodyStr);
|
||||||
|
if (responseData.containsKey("message") && StringUtils.isNotBlank(responseData.getString("message"))) {
|
||||||
|
sseContent = responseData.getString("message");
|
||||||
|
} else {
|
||||||
|
sseContent = CaseAiConstants.CHAT_SYS_ERR_MSG;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sseContent = CaseAiConstants.CHAT_SYS_ERR_MSG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("解析接口响应失败", e);
|
||||||
|
// 处理失败的情况
|
||||||
|
sseContent = CaseAiConstants.CHAT_SYS_ERR_MSG;
|
||||||
|
}
|
||||||
|
|
||||||
|
errMessage(sseEmitter, conversationId, sseContent);
|
||||||
|
conversationData.setStatus(CaseAiChatErrCodeEnum.AIOT_ERROR.getCode());
|
||||||
|
conversationData.setErrorMsg(sseContent);
|
||||||
|
conversationData.appendAnswer(sseContent);
|
||||||
|
saveConversationData(sseEmitter, conversationData);
|
||||||
|
sseEmitter.complete();
|
||||||
|
// 关闭eventSource
|
||||||
|
eventSource.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 将EventSource存储到Map中,以便后续可以中断
|
// 将EventSource存储到Map中,以便后续可以中断
|
||||||
conversationEventSourceMap.put(conversationId, eventSource);
|
conversationEventSourceMap.put(conversationId, eventSource);
|
||||||
}
|
}
|
||||||
@@ -197,7 +257,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
public void onClosed(@NotNull EventSource eventSource) {
|
public void onClosed(@NotNull EventSource eventSource) {
|
||||||
log.info("调用接口 [{}] 接口关闭", request.url());
|
log.info("调用接口 [{}] 接口关闭", request.url());
|
||||||
// 对话完成,保存到ES
|
// 对话完成,保存到ES
|
||||||
elasticSearchIndexService.createData(conversationData);
|
saveConversationData(sseEmitter, conversationData);
|
||||||
// 从Map中移除已完成的会话
|
// 从Map中移除已完成的会话
|
||||||
conversationEventSourceMap.remove(conversationId);
|
conversationEventSourceMap.remove(conversationId);
|
||||||
sseEmitter.complete();
|
sseEmitter.complete();
|
||||||
@@ -206,14 +266,14 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
@Override
|
@Override
|
||||||
public void onEvent(@NotNull EventSource eventSource, @Nullable String id, @Nullable String type, @NotNull String data) {
|
public void onEvent(@NotNull EventSource eventSource, @Nullable String id, @Nullable String type, @NotNull String data) {
|
||||||
log.info("调用接口 [{}] 监听数据 id: [{}] type: [{}] data: [{}]", request.url(), id, type, data);
|
log.info("调用接口 [{}] 监听数据 id: [{}] type: [{}] data: [{}]", request.url(), id, type, data);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 解析返回的数据
|
// 解析返回的数据
|
||||||
JSONObject jsonData = JSONObject.parseObject(data);
|
JSONObject jsonData = JSONObject.parseObject(data);
|
||||||
if (jsonData.getBooleanValue("success") && jsonData.getIntValue("code") == 0) {
|
if (jsonData.getBooleanValue("success") && jsonData.getIntValue("code") == 0) {
|
||||||
JSONObject responseData = jsonData.getJSONObject("data");
|
JSONObject responseData = jsonData.getJSONObject("data");
|
||||||
Integer status = responseData.getInteger("status");
|
Integer status = responseData.getInteger("status");
|
||||||
|
|
||||||
if (status != null) {
|
if (status != null) {
|
||||||
CaseAiChatStatusEnum statusEnum = CaseAiChatStatusEnum.getByCode(status);
|
CaseAiChatStatusEnum statusEnum = CaseAiChatStatusEnum.getByCode(status);
|
||||||
if (statusEnum == CaseAiChatStatusEnum.REFERS) { // 返回引用文件
|
if (statusEnum == CaseAiChatStatusEnum.REFERS) { // 返回引用文件
|
||||||
@@ -236,7 +296,9 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
} else {
|
} else {
|
||||||
// 异常问题,取message内容
|
// 异常问题,取message内容
|
||||||
String message = jsonData.getString("message");
|
String message = jsonData.getString("message");
|
||||||
errMessage(sseEmitter, message);
|
errMessage(sseEmitter, conversationId, message);
|
||||||
|
conversationData.setStatus(CaseAiChatErrCodeEnum.AIOT_ERROR.getCode());
|
||||||
|
conversationData.setErrorMsg(jsonData.toJSONString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -258,46 +320,53 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NotNull EventSource eventSource, @Nullable Throwable e, @Nullable Response response) {
|
public void onFailure(@NotNull EventSource eventSource, @Nullable Throwable e, @Nullable Response response) {
|
||||||
if (e == null) {
|
// 只要有异常,必打日志
|
||||||
sseEmitter.completeWithError(new RuntimeException("调用接口异常, 异常未捕获"));
|
if (e != null) {
|
||||||
return;
|
log.error("调用接口 [{}] 时发生错误,捕获到异常", request.url(), e);
|
||||||
|
} else {
|
||||||
|
log.error("调用接口 [{}] 时发生错误,未捕获到异常", request.url());
|
||||||
}
|
}
|
||||||
log.error("调用接口 [{}] 接口异常", request.url(), e);
|
String errorMessage = CaseAiConstants.CHAT_SYS_ERR_MSG;
|
||||||
if (isTimeoutException(e)) {
|
// 优先处理错误响应
|
||||||
log.warn("接口调用超时,conversationId: {}", conversationId);
|
if (response != null) {
|
||||||
errMessage(sseEmitter, SYS_ERR_MSG);
|
try {
|
||||||
sseEmitter.complete();
|
log.error("调用接口 [{}] 时发生错误,响应码: {}", request.url(), response.code());
|
||||||
// 从Map中移除失败的会话
|
if (response.body() != null) {
|
||||||
conversationEventSourceMap.remove(conversationId);
|
String body = response.body().string();
|
||||||
|
log.error("调用接口 [{}] 时的错误响应内容: {}", request.url(), body);
|
||||||
// 即使失败,也要将已有的对话数据保存到ES
|
// 将错误内容发送至SseEmitter
|
||||||
elasticSearchIndexService.createData(conversationData);
|
if (StringUtils.contains(response.header("Content-Type"), "application/json")) {
|
||||||
return;
|
// json解析
|
||||||
}
|
JSONObject jsonData = JSONObject.parseObject(body);
|
||||||
|
if (jsonData.containsKey("message") && StringUtils.isNotBlank(jsonData.getString("message"))) {
|
||||||
// 如果是 content-type 错误,尝试作为普通 HTTP 请求处理
|
errorMessage = jsonData.getString("message");
|
||||||
if (e instanceof IllegalStateException && e.getMessage() != null && e.getMessage().contains("Invalid content-type")) {
|
}
|
||||||
log.warn("服务器返回的 Content-Type 不是 text/event-stream,尝试作为普通 HTTP 请求处理");
|
}
|
||||||
handleAsRegularHttpRequest(request, sseEmitter, conversationData);
|
}
|
||||||
// 从Map中移除失败的会话
|
} catch (IOException ex) {
|
||||||
conversationEventSourceMap.remove(conversationId);
|
log.error("解析异常请求时错误", ex);
|
||||||
// 即使失败,也要将已有的对话数据保存到ES
|
}
|
||||||
elasticSearchIndexService.createData(conversationData);
|
} else if (e != null) {
|
||||||
return;
|
if (isTimeoutException(e)) {
|
||||||
|
errorMessage = CaseAiConstants.CHAT_NET_ERR_MSG;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sseEmitter.completeWithError(e);
|
errMessage(sseEmitter, conversationId, errorMessage);
|
||||||
// 从Map中移除失败的会话
|
// 从Map中移除失败的会话
|
||||||
conversationEventSourceMap.remove(conversationId);
|
conversationEventSourceMap.remove(conversationId);
|
||||||
|
|
||||||
// 即使失败,也要将已有的对话数据保存到ES
|
// 即使失败,也要将已有的对话数据保存到ES
|
||||||
elasticSearchIndexService.createData(conversationData);
|
conversationData.setStatus(CaseAiChatErrCodeEnum.AIOT_ERROR.getCode());
|
||||||
|
conversationData.setErrorMsg(errorMessage);
|
||||||
|
conversationData.appendAnswer(errorMessage);
|
||||||
|
saveConversationData(sseEmitter, conversationData);
|
||||||
|
sseEmitter.complete();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 8. 执行HTTP请求
|
// 8. 执行HTTP请求
|
||||||
OkHttpClient client = new OkHttpClient.Builder()
|
OkHttpClient client = new OkHttpClient.Builder()
|
||||||
.connectTimeout(60, TimeUnit.SECONDS)
|
.connectTimeout(600, TimeUnit.SECONDS)
|
||||||
.writeTimeout(600, TimeUnit.SECONDS)
|
.writeTimeout(600, TimeUnit.SECONDS)
|
||||||
.readTimeout(600, TimeUnit.SECONDS)
|
.readTimeout(600, TimeUnit.SECONDS)
|
||||||
.callTimeout(600, TimeUnit.SECONDS)
|
.callTimeout(600, TimeUnit.SECONDS)
|
||||||
@@ -305,16 +374,16 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
.build();
|
.build();
|
||||||
EventSource.Factory factory = EventSources.createFactory(client);
|
EventSource.Factory factory = EventSources.createFactory(client);
|
||||||
factory.newEventSource(request, listener);
|
factory.newEventSource(request, listener);
|
||||||
|
|
||||||
return sseEmitter;
|
return sseEmitter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取或创建会话ID
|
* 获取或创建会话ID
|
||||||
*/
|
*/
|
||||||
private String getOrCreateConversationId(CaseAiChatDto caseAiChatDto, CurrentUser currentUser) {
|
private String getOrCreateConversationId(CaseAiChatDto caseAiChatDto, CurrentUser currentUser) {
|
||||||
String conversationId = caseAiChatDto.getConversationId();
|
String conversationId = caseAiChatDto.getConversationId();
|
||||||
|
|
||||||
if (StringUtils.isEmpty(conversationId)) {
|
if (StringUtils.isEmpty(conversationId)) {
|
||||||
// 新会话,调用创建会话接口
|
// 新会话,调用创建会话接口
|
||||||
String conversationName = "AI案例咨询-" + LocalDateTime.now().toString();
|
String conversationName = "AI案例咨询-" + LocalDateTime.now().toString();
|
||||||
@@ -332,39 +401,40 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
||||||
String url = caseAiProperties.getBaseUrl() + "/apigateway/knowledge/v1/conversation";
|
String url = caseAiProperties.getBaseUrl() + "/apigateway/knowledge/v1/conversation";
|
||||||
HttpPost httpPost = new HttpPost(url);
|
HttpPost httpPost = new HttpPost(url);
|
||||||
|
|
||||||
// 设置请求头
|
// 设置请求头
|
||||||
String accessToken = aiAccessTokenService.getAccessToken();
|
String accessToken = aiAccessTokenService.getAccessToken();
|
||||||
String apiCode = caseAiProperties.getChatApiCode();
|
String apiCode = caseAiProperties.getChatApiCode();
|
||||||
httpPost.setHeader("access_token", accessToken);
|
httpPost.setHeader("access_token", accessToken);
|
||||||
httpPost.setHeader("X-AI-ApiCode", apiCode);
|
httpPost.setHeader("X-AI-ApiCode", apiCode);
|
||||||
httpPost.setHeader("Content-Type", "application/json");
|
httpPost.setHeader("Content-Type", "application/json");
|
||||||
|
httpPost.setHeader("X-AI-ApiRawResponse", "true");
|
||||||
|
|
||||||
// 设置请求体
|
// 设置请求体
|
||||||
JSONObject requestBody = new JSONObject();
|
JSONObject requestBody = new JSONObject();
|
||||||
requestBody.put("userId", userId);
|
requestBody.put("userId", userId);
|
||||||
requestBody.put("name", conversationName);
|
requestBody.put("name", conversationName);
|
||||||
StringEntity entity = new StringEntity(requestBody.toJSONString(), StandardCharsets.UTF_8);
|
StringEntity entity = new StringEntity(requestBody.toJSONString(), StandardCharsets.UTF_8);
|
||||||
httpPost.setEntity(entity);
|
httpPost.setEntity(entity);
|
||||||
|
|
||||||
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
|
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
|
String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
|
||||||
|
|
||||||
if (statusCode == 200) {
|
if (statusCode == 200) {
|
||||||
JSONObject result = JSONObject.parseObject(responseBody);
|
JSONObject result = JSONObject.parseObject(responseBody);
|
||||||
if (result.getIntValue("code") == 0 && result.getBooleanValue("success")) {
|
if (result.getIntValue("code") == 0 && result.getBooleanValue("success")) {
|
||||||
JSONObject data = result.getJSONObject("data");
|
JSONObject data = result.getJSONObject("data");
|
||||||
String aiConversationId = data.getString("id");
|
String aiConversationId = data.getString("id");
|
||||||
String name = data.getString("name");
|
String name = data.getString("name");
|
||||||
|
|
||||||
// 保存到数据库
|
// 保存到数据库
|
||||||
CaseAiConversations conversation = new CaseAiConversations();
|
CaseAiConversations conversation = new CaseAiConversations();
|
||||||
conversation.setAiConversationId(aiConversationId);
|
conversation.setAiConversationId(aiConversationId);
|
||||||
conversation.setConversationName(name);
|
conversation.setConversationName(name);
|
||||||
conversation.setConversationUser(userId);
|
conversation.setConversationUser(userId);
|
||||||
caseAiConversationsDao.save(conversation);
|
caseAiConversationsDao.save(conversation);
|
||||||
|
|
||||||
log.info("创建AI会话成功,aiConversationId: {}, name: {}", aiConversationId, name);
|
log.info("创建AI会话成功,aiConversationId: {}, name: {}", aiConversationId, name);
|
||||||
return conversation;
|
return conversation;
|
||||||
} else {
|
} else {
|
||||||
@@ -435,52 +505,56 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 从 ES 数据中解析消息对象
|
* 从 ES 数据中解析消息对象
|
||||||
|
* 已迁移
|
||||||
|
* @see IElasticSearchIndexService
|
||||||
|
*
|
||||||
* @param sourceMap ES数据
|
* @param sourceMap ES数据
|
||||||
* @return 消息对象
|
* @return 消息对象
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
private CaseAiMessageVo parseMessageFromES(Map<String, Object> sourceMap) {
|
private CaseAiMessageVo parseMessageFromES(Map<String, Object> sourceMap) {
|
||||||
try {
|
try {
|
||||||
CaseAiMessageVo messageVo = new CaseAiMessageVo();
|
CaseAiMessageVo messageVo = new CaseAiMessageVo();
|
||||||
messageVo.setQuery((String) sourceMap.get("query"));
|
messageVo.setQuery((String) sourceMap.get("query"));
|
||||||
messageVo.setAnswer((String) sourceMap.get("answer"));
|
messageVo.setAnswer((String) sourceMap.get("answer"));
|
||||||
|
|
||||||
// 解析 suggestions
|
// 解析 suggestions
|
||||||
Object suggestionsObj = sourceMap.get("suggestions");
|
Object suggestionsObj = sourceMap.get("suggestions");
|
||||||
if (suggestionsObj instanceof List) {
|
if (suggestionsObj instanceof List) {
|
||||||
messageVo.setSuggestions((List<String>) suggestionsObj);
|
messageVo.setSuggestions((List<String>) suggestionsObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析 caseRefer
|
// 解析 caseRefer
|
||||||
Object caseReferObj = sourceMap.get("caseRefer");
|
Object caseReferObj = sourceMap.get("caseRefer");
|
||||||
if (caseReferObj instanceof List) {
|
if (caseReferObj instanceof List) {
|
||||||
List<CaseReferVo> caseReferList = new ArrayList<>();
|
List<CaseReferVo> caseReferList = new ArrayList<>();
|
||||||
List<Map<String, Object>> caseReferMaps = (List<Map<String, Object>>) caseReferObj;
|
List<Map<String, Object>> caseReferMaps = (List<Map<String, Object>>) caseReferObj;
|
||||||
|
|
||||||
for (Map<String, Object> caseReferMap : caseReferMaps) {
|
for (Map<String, Object> caseReferMap : caseReferMaps) {
|
||||||
CaseReferVo caseRefer = new CaseReferVo();
|
CaseReferVo caseRefer = new CaseReferVo();
|
||||||
caseRefer.setCaseId((String) caseReferMap.get("caseId"));
|
caseRefer.setCaseId((String) caseReferMap.get("caseId"));
|
||||||
caseRefer.setTitle((String) caseReferMap.get("title"));
|
caseRefer.setTitle((String) caseReferMap.get("title"));
|
||||||
caseRefer.setAuthorName((String) caseReferMap.get("authorName"));
|
caseRefer.setAuthorName((String) caseReferMap.get("authorName"));
|
||||||
caseRefer.setContent((String) caseReferMap.get("content"));
|
caseRefer.setContent((String) caseReferMap.get("content"));
|
||||||
|
|
||||||
// 解析 keywords
|
// 解析 keywords
|
||||||
Object keywordsObj = caseReferMap.get("keywords");
|
Object keywordsObj = caseReferMap.get("keywords");
|
||||||
if (keywordsObj instanceof List) {
|
if (keywordsObj instanceof List) {
|
||||||
caseRefer.setKeywords((List<String>) keywordsObj);
|
caseRefer.setKeywords((List<String>) keywordsObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
caseReferList.add(caseRefer);
|
caseReferList.add(caseRefer);
|
||||||
}
|
}
|
||||||
messageVo.setCaseRefer(caseReferList);
|
messageVo.setCaseRefer(caseReferList);
|
||||||
}
|
}
|
||||||
|
|
||||||
return messageVo;
|
return messageVo;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("解析ES消息数据异常", e);
|
log.error("解析ES消息数据异常", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理文件引用并构建返给前端的响应数据
|
* 处理文件引用并构建返给前端的响应数据
|
||||||
*/
|
*/
|
||||||
@@ -489,7 +563,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
// 先处理文件引用,收集CaseReferVo数据
|
// 先处理文件引用,收集CaseReferVo数据
|
||||||
List<CaseReferVo> currentCaseRefers = new ArrayList<>();
|
List<CaseReferVo> currentCaseRefers = new ArrayList<>();
|
||||||
Set<String> docIds = new HashSet<>();
|
Set<String> docIds = new HashSet<>();
|
||||||
|
|
||||||
JSONObject fileRefer = responseData.getJSONObject("fileRefer");
|
JSONObject fileRefer = responseData.getJSONObject("fileRefer");
|
||||||
if (fileRefer != null && fileRefer.containsKey("files")) {
|
if (fileRefer != null && fileRefer.containsKey("files")) {
|
||||||
JSONArray files = fileRefer.getJSONArray("files");
|
JSONArray files = fileRefer.getJSONArray("files");
|
||||||
@@ -507,13 +581,13 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建返给前端的数据结构
|
// 构建返给前端的数据结构
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
data.put("status", 0);
|
data.put("status", 0);
|
||||||
data.put("conversationId", conversationData.getConversationId());
|
data.put("conversationId", conversationData.getConversationId());
|
||||||
data.put("content", responseData.getString("content"));
|
data.put("content", responseData.getString("content"));
|
||||||
|
|
||||||
// 添加处理后的案例引用数据
|
// 添加处理后的案例引用数据
|
||||||
JSONArray caseReferArray = new JSONArray();
|
JSONArray caseReferArray = new JSONArray();
|
||||||
for (CaseReferVo caseRefer : currentCaseRefers) {
|
for (CaseReferVo caseRefer : currentCaseRefers) {
|
||||||
@@ -529,11 +603,11 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
|
|
||||||
caseReferArray.add(caseReferObj);
|
caseReferArray.add(caseReferObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建新的fileRefer结构,包含案例引用
|
// 构建新的fileRefer结构,包含案例引用
|
||||||
JSONObject newFileRefer = new JSONObject();
|
JSONObject newFileRefer = new JSONObject();
|
||||||
newFileRefer.put("caseRefers", caseReferArray);
|
newFileRefer.put("caseRefers", caseReferArray);
|
||||||
|
|
||||||
// 保留原始的docs和files信息(如果需要)
|
// 保留原始的docs和files信息(如果需要)
|
||||||
if (fileRefer != null) {
|
if (fileRefer != null) {
|
||||||
if (fileRefer.containsKey("docs")) {
|
if (fileRefer.containsKey("docs")) {
|
||||||
@@ -543,22 +617,23 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
newFileRefer.put("files", fileRefer.get("files"));
|
newFileRefer.put("files", fileRefer.get("files"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data.put("fileRefer", newFileRefer);
|
data.put("fileRefer", newFileRefer);
|
||||||
data.put("suggestions", responseData.get("suggestions"));
|
data.put("suggestions", responseData.get("suggestions"));
|
||||||
|
|
||||||
log.info("处理文件引用成功,返回 {} 个案例引用", currentCaseRefers.size());
|
log.info("处理文件引用成功,返回 {} 个案例引用", currentCaseRefers.size());
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("处理文件引用并构建响应数据异常", e);
|
log.error("处理文件引用并构建响应数据异常", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理文件引用(原方法,保留用于数据收集)
|
* 处理文件引用(原方法,保留用于数据收集)
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
private void handleFileRefer(JSONObject responseData, AiChatConversationData conversationData) {
|
private void handleFileRefer(JSONObject responseData, AiChatConversationData conversationData) {
|
||||||
try {
|
try {
|
||||||
JSONObject fileRefer = responseData.getJSONObject("fileRefer");
|
JSONObject fileRefer = responseData.getJSONObject("fileRefer");
|
||||||
@@ -580,7 +655,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
log.error("处理文件引用异常", e);
|
log.error("处理文件引用异常", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理建议
|
* 处理建议
|
||||||
*/
|
*/
|
||||||
@@ -599,7 +674,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
log.error("处理建议异常", e);
|
log.error("处理建议异常", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据docId查询案例引用信息
|
* 根据docId查询案例引用信息
|
||||||
*/
|
*/
|
||||||
@@ -610,7 +685,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
if (docLog == null) {
|
if (docLog == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据 case_id 查询案例详情
|
// 根据 case_id 查询案例详情
|
||||||
Cases caseEntity = casesDao.get(docLog.getCaseId());
|
Cases caseEntity = casesDao.get(docLog.getCaseId());
|
||||||
if (caseEntity == null) {
|
if (caseEntity == null) {
|
||||||
@@ -627,7 +702,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
caseRefer.setContent(caseEntity.getSummary());
|
caseRefer.setContent(caseEntity.getSummary());
|
||||||
caseRefer.setUploadTime(caseEntity.getSysCreateTime());
|
caseRefer.setUploadTime(caseEntity.getSysCreateTime());
|
||||||
caseRefer.setOrgInfo(authorOrg.getName());
|
caseRefer.setOrgInfo(authorOrg.getName());
|
||||||
|
|
||||||
// 构建关键词列表
|
// 构建关键词列表
|
||||||
List<String> keywords = new ArrayList<>();
|
List<String> keywords = new ArrayList<>();
|
||||||
if (caseEntity.getKeyword1() != null) keywords.add(caseEntity.getKeyword1());
|
if (caseEntity.getKeyword1() != null) keywords.add(caseEntity.getKeyword1());
|
||||||
@@ -636,17 +711,19 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
if (caseEntity.getKeyword4() != null) keywords.add(caseEntity.getKeyword4());
|
if (caseEntity.getKeyword4() != null) keywords.add(caseEntity.getKeyword4());
|
||||||
if (caseEntity.getKeyword5() != null) keywords.add(caseEntity.getKeyword5());
|
if (caseEntity.getKeyword5() != null) keywords.add(caseEntity.getKeyword5());
|
||||||
caseRefer.setKeywords(keywords);
|
caseRefer.setKeywords(keywords);
|
||||||
|
|
||||||
return caseRefer;
|
return caseRefer;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("根据docId查询案例引用信息异常", e);
|
log.error("根据docId查询案例引用信息异常", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当 SSE 失败时,作为普通 HTTP 请求处理
|
* 当 SSE 失败时,作为普通 HTTP 请求处理
|
||||||
|
* 不再使用
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
private void handleAsRegularHttpRequest(Request request, SseEmitter sseEmitter, AiChatConversationData conversationData) {
|
private void handleAsRegularHttpRequest(Request request, SseEmitter sseEmitter, AiChatConversationData conversationData) {
|
||||||
try {
|
try {
|
||||||
OkHttpClient client = new OkHttpClient.Builder()
|
OkHttpClient client = new OkHttpClient.Builder()
|
||||||
@@ -654,16 +731,16 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
.writeTimeout(60, TimeUnit.SECONDS)
|
.writeTimeout(60, TimeUnit.SECONDS)
|
||||||
.readTimeout(60, TimeUnit.SECONDS)
|
.readTimeout(60, TimeUnit.SECONDS)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
String responseBody = response.body().string();
|
String responseBody = response.body().string();
|
||||||
log.info("作为普通 HTTP 请求处理成功,将响应原封不动推送给前端");
|
log.info("作为普通 HTTP 请求处理成功,将响应原封不动推送给前端");
|
||||||
|
|
||||||
// 将响应内容原封不动地推送到 SseEmitter
|
// 将响应内容原封不动地推送到 SseEmitter
|
||||||
JSONObject responseData = JSONObject.parseObject(responseBody);
|
JSONObject responseData = JSONObject.parseObject(responseBody);
|
||||||
if (responseBody.contains("message")) {
|
if (responseBody.contains("message")) {
|
||||||
errMessage(sseEmitter, responseData.getString("message"));
|
errMessage(sseEmitter, conversationData.getConversationId(), responseData.getString("message"));
|
||||||
sseEmitter.complete();
|
sseEmitter.complete();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -679,12 +756,26 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void errMessage(SseEmitter sseEmitter, String message) {
|
/**
|
||||||
|
* 发送错误信息
|
||||||
|
*/
|
||||||
|
private void errMessage(SseEmitter sseEmitter, String conversationId, String message) {
|
||||||
|
JSONObject conversationData = new JSONObject();
|
||||||
|
conversationData.put("conversationId", conversationId);
|
||||||
|
conversationData.put("content", "");
|
||||||
|
conversationData.put("status", 0);
|
||||||
|
|
||||||
JSONObject jsonData = new JSONObject();
|
JSONObject jsonData = new JSONObject();
|
||||||
jsonData.put("status", 1);
|
jsonData.put("status", 1);
|
||||||
jsonData.put("content", message);
|
jsonData.put("content", message);
|
||||||
|
|
||||||
|
JSONObject finishData = new JSONObject();
|
||||||
|
finishData.put("status", 4);
|
||||||
|
finishData.put("content", "");
|
||||||
try {
|
try {
|
||||||
|
sseEmitter.send(conversationData.toJSONString());
|
||||||
sseEmitter.send(jsonData.toJSONString());
|
sseEmitter.send(jsonData.toJSONString());
|
||||||
|
sseEmitter.send(finishData.toJSONString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("发送错误信息异常", e);
|
log.error("发送错误信息异常", e);
|
||||||
sseEmitter.completeWithError(e);
|
sseEmitter.completeWithError(e);
|
||||||
@@ -693,6 +784,22 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean stopChatOutput(String conversationId) {
|
public boolean stopChatOutput(String conversationId) {
|
||||||
|
log.info("收到停止会话 {} 的指令", conversationId);
|
||||||
|
// 发送广播消息,通知中断连接
|
||||||
|
try {
|
||||||
|
jmsTemplate.convertAndSend(topic, conversationId);
|
||||||
|
} catch (JmsException e) {
|
||||||
|
log.error("发送停止会话 {} 输出时发生异常", conversationId, e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消eventSource
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void eventSourceCancel(String conversationId) {
|
||||||
EventSource eventSource = conversationEventSourceMap.get(conversationId);
|
EventSource eventSource = conversationEventSourceMap.get(conversationId);
|
||||||
if (eventSource != null) {
|
if (eventSource != null) {
|
||||||
try {
|
try {
|
||||||
@@ -700,17 +807,61 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
eventSource.cancel();
|
eventSource.cancel();
|
||||||
// 注意:cancel()会触发onFailure回调,在onFailure中会清理资源
|
// 注意:cancel()会触发onFailure回调,在onFailure中会清理资源
|
||||||
log.info("成功发送停止会话 {} 的指令", conversationId);
|
log.info("成功发送停止会话 {} 的指令", conversationId);
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("停止会话 {} 输出时发生异常", conversationId, e);
|
log.error("停止会话 {} 输出时发生异常", conversationId, e);
|
||||||
// 即使出现异常,也从Map中移除,避免内存泄漏
|
// 即使出现异常,也从Map中移除,避免内存泄漏
|
||||||
conversationEventSourceMap.remove(conversationId);
|
conversationEventSourceMap.remove(conversationId);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.warn("未找到会话 {} 对应的事件源,可能已经完成或不存在", conversationId);
|
log.info("未找到会话 {} 对应的事件源,可能已经完成或不存在", conversationId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean msgFeedback(CaseAiMsgLikeDto caseAiMsgLikeDto) {
|
||||||
|
AiChatConversationData aiChatConversationData = new AiChatConversationData();
|
||||||
|
if (StringUtils.isBlank(caseAiMsgLikeDto.getDocId())) {
|
||||||
|
log.error("操作失败,docId为空");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (Boolean.TRUE.equals(caseAiMsgLikeDto.getOperation())) {
|
||||||
|
String likeStatus = caseAiMsgLikeDto.getLikeStatus();
|
||||||
|
if (!StringUtils.equals(likeStatus, "1") && !StringUtils.equals(likeStatus, "0") && !StringUtils.equals(likeStatus, "-1")) {
|
||||||
|
log.error("操作失败,参数错误");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (Boolean.FALSE.equals(caseAiMsgLikeDto.getOperation())) {
|
||||||
|
if (StringUtils.isBlank(caseAiMsgLikeDto.getFeedback())) {
|
||||||
|
log.error("操作失败,参数错误");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
aiChatConversationData.setLikeStatus(caseAiMsgLikeDto.getLikeStatus());
|
||||||
|
aiChatConversationData.setFeedback(caseAiMsgLikeDto.getFeedback());
|
||||||
|
return elasticSearchIndexService.updateData(caseAiMsgLikeDto.getDocId() ,aiChatConversationData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取消息详情
|
||||||
|
*
|
||||||
|
* @param getCaseAiMsgDto
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<CaseAiMessageVo> getCaseAiMsg(GetCaseAiMsgDto getCaseAiMsgDto) {
|
||||||
|
String conversationId = getCaseAiMsgDto.getConversationId();
|
||||||
|
String docId = getCaseAiMsgDto.getDocId();
|
||||||
|
if (StringUtils.isBlank(conversationId) && StringUtils.isBlank(docId)) {
|
||||||
|
log.error("获取消息详情失败,会话id与docId不可同时为空");
|
||||||
|
throw new RuntimeException("获取消息详情失败,会话id与docId不可同时为空");
|
||||||
|
}
|
||||||
|
List<CaseAiMessageVo> list = new ArrayList<>();
|
||||||
|
if (StringUtils.isNotBlank(conversationId)) {
|
||||||
|
return elasticSearchIndexService.queryData(conversationId);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(docId)) {
|
||||||
|
return elasticSearchIndexService.queryDataByDocId(conversationId);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -792,6 +943,8 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
headerRow.createCell(4).setCellValue("回答");
|
headerRow.createCell(4).setCellValue("回答");
|
||||||
headerRow.createCell(5).setCellValue("开始时间");
|
headerRow.createCell(5).setCellValue("开始时间");
|
||||||
headerRow.createCell(6).setCellValue("问答时长(秒)");
|
headerRow.createCell(6).setCellValue("问答时长(秒)");
|
||||||
|
headerRow.createCell(7).setCellValue("消息状态");
|
||||||
|
headerRow.createCell(8).setCellValue("错误信息");
|
||||||
|
|
||||||
// 内容行
|
// 内容行
|
||||||
if (!excelDataList.isEmpty()) {
|
if (!excelDataList.isEmpty()) {
|
||||||
@@ -812,8 +965,22 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
row.createCell(2).setCellValue(excelData.getUser());
|
row.createCell(2).setCellValue(excelData.getUser());
|
||||||
row.createCell(3).setCellValue(message.getQuery() != null ? message.getQuery() : "");
|
row.createCell(3).setCellValue(message.getQuery() != null ? message.getQuery() : "");
|
||||||
row.createCell(4).setCellValue(message.getAnswer() != null ? message.getAnswer() : "");
|
row.createCell(4).setCellValue(message.getAnswer() != null ? message.getAnswer() : "");
|
||||||
row.createCell(5).setCellValue(""); // 开始时间字段暂留空
|
LocalDateTime messageStartTime = message.getStartTime();
|
||||||
|
if (messageStartTime != null) {
|
||||||
|
String startTimeStr = messageStartTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||||
|
row.createCell(5).setCellValue(startTimeStr);
|
||||||
|
} else {
|
||||||
|
row.createCell(5).setCellValue("");
|
||||||
|
}
|
||||||
row.createCell(6).setCellValue(message.getDurationSeconds() != null ? message.getDurationSeconds() : 0);
|
row.createCell(6).setCellValue(message.getDurationSeconds() != null ? message.getDurationSeconds() : 0);
|
||||||
|
if (message.getStatus() != null) {
|
||||||
|
int status = message.getStatus();
|
||||||
|
CaseAiChatErrCodeEnum errCodeEnum = CaseAiChatErrCodeEnum.getByCode(status);
|
||||||
|
row.createCell(7).setCellValue(errCodeEnum.getLabel());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(message.getErrorMsg())) {
|
||||||
|
row.createCell(8).setCellValue(message.getErrorMsg());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 合并单元格(会话ID、会话名称、用户三列)
|
// 合并单元格(会话ID、会话名称、用户三列)
|
||||||
@@ -835,4 +1002,19 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
|
|
||||||
return workbook;
|
return workbook;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异步存储会话数据
|
||||||
|
* @param conversationData
|
||||||
|
*/
|
||||||
|
private void saveConversationData(SseEmitter sseEmitter, AiChatConversationData conversationData) {
|
||||||
|
try {
|
||||||
|
String docId = elasticSearchIndexService.createData(conversationData);
|
||||||
|
if (docId != null) {
|
||||||
|
sseEmitter.send(JSON.toJSONString(Collections.singletonMap("docId", docId)));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("docId消息发送失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,7 +205,8 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.addTextBody("fileMetaData", fileMetaData.toJSONString(), ContentType.TEXT_PLAIN);
|
ContentType contentType = ContentType.create("text/plain", StandardCharsets.UTF_8);
|
||||||
|
builder.addTextBody("fileMetaData", fileMetaData.toJSONString(), contentType);
|
||||||
requestBody.put("fileMetaData", fileMetaData);
|
requestBody.put("fileMetaData", fileMetaData);
|
||||||
// 由于接口权限,目前采用不回调,而是通过批处理的方式,处理文件状态
|
// 由于接口权限,目前采用不回调,而是通过批处理的方式,处理文件状态
|
||||||
if (caseAiProperties.isFileUploadUseCallback()) {
|
if (caseAiProperties.isFileUploadUseCallback()) {
|
||||||
@@ -542,7 +543,8 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.addTextBody("fileMetaData", fileMetaData.toJSONString(), ContentType.TEXT_PLAIN);
|
ContentType contentType = ContentType.create("text/plain", StandardCharsets.UTF_8);
|
||||||
|
builder.addTextBody("fileMetaData", fileMetaData.toJSONString(), contentType);
|
||||||
requestBody.put("fileMetaData", fileMetaData);
|
requestBody.put("fileMetaData", fileMetaData);
|
||||||
// 由于接口权限,目前采用不回调,而是通过批处理的方式,处理文件状态
|
// 由于接口权限,目前采用不回调,而是通过批处理的方式,处理文件状态
|
||||||
if (caseAiProperties.isFileUploadUseCallback()) {
|
if (caseAiProperties.isFileUploadUseCallback()) {
|
||||||
@@ -650,7 +652,8 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
|||||||
.findList(CaseDocumentLog.class, 1,
|
.findList(CaseDocumentLog.class, 1,
|
||||||
OrderCondition.desc("sysCreateTime"),
|
OrderCondition.desc("sysCreateTime"),
|
||||||
FieldFilters.eq("caseId", caseId),
|
FieldFilters.eq("caseId", caseId),
|
||||||
FieldFilters.eq("requestUrl", CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME));
|
FieldFilters.eq("requestUrl", CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME),
|
||||||
|
FieldFilters.eq("caseStatus", CaseDocumentLogCaseStatusEnum.SUCCESS.getCode()));
|
||||||
|
|
||||||
if (logList.isEmpty()) {
|
if (logList.isEmpty()) {
|
||||||
log.info("删除案例文档失败,未找到相关的日志记录,caseId: {}", caseId);
|
log.info("删除案例文档失败,未找到相关的日志记录,caseId: {}", caseId);
|
||||||
@@ -856,7 +859,8 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.addTextBody("fileMetaData", fileMetaData.toJSONString(), ContentType.TEXT_PLAIN);
|
ContentType contentType = ContentType.create("text/plain", StandardCharsets.UTF_8);
|
||||||
|
builder.addTextBody("fileMetaData", fileMetaData.toJSONString(), contentType);
|
||||||
requestBody.put("fileMetaData", fileMetaData);
|
requestBody.put("fileMetaData", fileMetaData);
|
||||||
// 由于接口权限,目前采用不回调,而是通过批处理的方式,处理文件状态
|
// 由于接口权限,目前采用不回调,而是通过批处理的方式,处理文件状态
|
||||||
if (caseAiProperties.isFileUploadUseCallback()) {
|
if (caseAiProperties.isFileUploadUseCallback()) {
|
||||||
@@ -1358,6 +1362,7 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
|||||||
caseLog.setRunStatus(CaseDocumentLogRunStatusEnum.COMPLETED.getCode());
|
caseLog.setRunStatus(CaseDocumentLogRunStatusEnum.COMPLETED.getCode());
|
||||||
caseLog.setOptStatus(CaseDocumentLogOptStatusEnum.SUCCESS.getCode());
|
caseLog.setOptStatus(CaseDocumentLogOptStatusEnum.SUCCESS.getCode());
|
||||||
caseLog.setCaseStatus(CaseDocumentLogCaseStatusEnum.SUCCESS.getCode());
|
caseLog.setCaseStatus(CaseDocumentLogCaseStatusEnum.SUCCESS.getCode());
|
||||||
|
caseLog.setMetadataStatus(1);
|
||||||
needUpdate = true;
|
needUpdate = true;
|
||||||
// log.info("文档向量化成功,更新状态,taskId: {}, caseId: {}", caseLog.getTaskId(), caseLog.getCaseId());
|
// log.info("文档向量化成功,更新状态,taskId: {}, caseId: {}", caseLog.getTaskId(), caseLog.getCaseId());
|
||||||
} else if ("failed".equals(fileStatus)) {
|
} else if ("failed".equals(fileStatus)) {
|
||||||
|
|||||||
@@ -8,32 +8,43 @@ import com.xboe.module.boecase.service.IElasticSearchIndexService;
|
|||||||
import com.xboe.module.boecase.vo.CaseAiMessageVo;
|
import com.xboe.module.boecase.vo.CaseAiMessageVo;
|
||||||
import com.xboe.module.boecase.vo.CaseReferVo;
|
import com.xboe.module.boecase.vo.CaseReferVo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
||||||
import org.elasticsearch.action.index.IndexRequest;
|
import org.elasticsearch.action.index.IndexRequest;
|
||||||
import org.elasticsearch.action.index.IndexResponse;
|
import org.elasticsearch.action.index.IndexResponse;
|
||||||
import org.elasticsearch.action.search.SearchRequest;
|
import org.elasticsearch.action.search.SearchRequest;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
||||||
|
import org.elasticsearch.action.update.UpdateRequest;
|
||||||
import org.elasticsearch.client.RequestOptions;
|
import org.elasticsearch.client.RequestOptions;
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
import org.elasticsearch.client.indices.CreateIndexRequest;
|
import org.elasticsearch.client.indices.CreateIndexRequest;
|
||||||
import org.elasticsearch.client.indices.CreateIndexResponse;
|
import org.elasticsearch.client.indices.CreateIndexResponse;
|
||||||
import org.elasticsearch.client.indices.GetIndexRequest;
|
import org.elasticsearch.client.indices.GetIndexRequest;
|
||||||
|
import org.elasticsearch.client.indices.PutMappingRequest;
|
||||||
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
|
import org.elasticsearch.rest.RestStatus;
|
||||||
import org.elasticsearch.search.SearchHit;
|
import org.elasticsearch.search.SearchHit;
|
||||||
import org.elasticsearch.search.SearchHits;
|
import org.elasticsearch.search.SearchHits;
|
||||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -122,10 +133,40 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean createData(AiChatConversationData conversationData) {
|
public boolean updateIndex(String fieldName, Map<String, Object> fieldProperties) {
|
||||||
|
if (elasticsearchClient == null) {
|
||||||
|
log.error("ElasticSearch客户端未配置");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 执行新增字段请求
|
||||||
|
JSONObject newField = new JSONObject();
|
||||||
|
newField.put(fieldName, fieldProperties);
|
||||||
|
|
||||||
|
JSONObject properties = new JSONObject();
|
||||||
|
properties.put("properties", newField);
|
||||||
|
|
||||||
|
PutMappingRequest request = new PutMappingRequest(CaseAiConstants.CASE_AI_INDEX_NAME);
|
||||||
|
request.source(properties.toJSONString(), XContentType.JSON);
|
||||||
|
try {
|
||||||
|
AcknowledgedResponse response = elasticsearchClient.indices().putMapping(request, RequestOptions.DEFAULT);
|
||||||
|
if (response.isAcknowledged()) {
|
||||||
|
log.info("成功更新Elasticsearch索引: {}, 新增字段: {}", CaseAiConstants.CASE_AI_INDEX_NAME, fieldName);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
log.error("更新索引 [{}] 未被确认(可能部分节点未响应)", CaseAiConstants.CASE_AI_INDEX_NAME);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("更新ElasticSearch索引时发生异常", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String createData(AiChatConversationData conversationData) {
|
||||||
if (elasticsearchClient == null) {
|
if (elasticsearchClient == null) {
|
||||||
log.error("未配置Elasticsearch客户端,无法保存对话记录");
|
log.error("未配置Elasticsearch客户端,无法保存对话记录");
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -141,6 +182,9 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
|
|||||||
esData.put("timestamp", now.toString());
|
esData.put("timestamp", now.toString());
|
||||||
esData.put("durationSeconds", Duration.between(conversationData.getStartTime(), now).getSeconds());
|
esData.put("durationSeconds", Duration.between(conversationData.getStartTime(), now).getSeconds());
|
||||||
|
|
||||||
|
esData.put("status", conversationData.getStatus());
|
||||||
|
esData.put("errorMsg", conversationData.getErrorMsg());
|
||||||
|
|
||||||
// 构建 caseRefer 数据
|
// 构建 caseRefer 数据
|
||||||
JSONArray caseReferArray = new JSONArray();
|
JSONArray caseReferArray = new JSONArray();
|
||||||
for (CaseReferVo caseRefer : conversationData.getCaseRefers()) {
|
for (CaseReferVo caseRefer : conversationData.getCaseRefers()) {
|
||||||
@@ -165,10 +209,10 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
|
|||||||
|
|
||||||
IndexResponse indexResponse = elasticsearchClient.index(indexRequest, RequestOptions.DEFAULT);
|
IndexResponse indexResponse = elasticsearchClient.index(indexRequest, RequestOptions.DEFAULT);
|
||||||
log.info("保存对话记录到ES成功,文档ID: {}", indexResponse.getId());
|
log.info("保存对话记录到ES成功,文档ID: {}", indexResponse.getId());
|
||||||
return true;
|
return indexResponse.getId();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("保存对话记录到ES异常", e);
|
log.error("保存对话记录到ES异常", e);
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,6 +238,7 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
|
|||||||
Map<String, Object> sourceMap = hit.getSourceAsMap();
|
Map<String, Object> sourceMap = hit.getSourceAsMap();
|
||||||
CaseAiMessageVo data = parseMessageFromES(sourceMap);
|
CaseAiMessageVo data = parseMessageFromES(sourceMap);
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
|
data.setDocId(hit.getId());
|
||||||
list.add(data);
|
list.add(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,6 +254,7 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
|
|||||||
private CaseAiMessageVo parseMessageFromES(Map<String, Object> sourceMap) {
|
private CaseAiMessageVo parseMessageFromES(Map<String, Object> sourceMap) {
|
||||||
try {
|
try {
|
||||||
CaseAiMessageVo messageVo = new CaseAiMessageVo();
|
CaseAiMessageVo messageVo = new CaseAiMessageVo();
|
||||||
|
messageVo.setConversationId((String) sourceMap.get("conversationId"));
|
||||||
messageVo.setQuery((String) sourceMap.get("query"));
|
messageVo.setQuery((String) sourceMap.get("query"));
|
||||||
messageVo.setAnswer((String) sourceMap.get("answer"));
|
messageVo.setAnswer((String) sourceMap.get("answer"));
|
||||||
if (sourceMap.containsKey("startTime")) {
|
if (sourceMap.containsKey("startTime")) {
|
||||||
@@ -216,7 +262,7 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
|
|||||||
messageVo.setStartTime(LocalDateTime.parse(startTimeStr));
|
messageVo.setStartTime(LocalDateTime.parse(startTimeStr));
|
||||||
}
|
}
|
||||||
if (sourceMap.containsKey("durationSeconds")) {
|
if (sourceMap.containsKey("durationSeconds")) {
|
||||||
messageVo.setDurationSeconds((Long) sourceMap.get("durationSeconds"));
|
messageVo.setDurationSeconds((Integer) sourceMap.get("durationSeconds"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析 suggestions
|
// 解析 suggestions
|
||||||
@@ -227,6 +273,20 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sourceMap.containsKey("status")) {
|
||||||
|
Object statusObj = sourceMap.get("status");
|
||||||
|
if (statusObj != null) {
|
||||||
|
messageVo.setStatus(Integer.valueOf(statusObj.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sourceMap.containsKey("errorMsg")) {
|
||||||
|
Object errorMsgObj = sourceMap.get("errorMsg");
|
||||||
|
if (errorMsgObj != null) {
|
||||||
|
messageVo.setErrorMsg(errorMsgObj.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 解析 caseRefer
|
// 解析 caseRefer
|
||||||
if (sourceMap.containsKey("caseRefer")) {
|
if (sourceMap.containsKey("caseRefer")) {
|
||||||
Object caseReferObj = sourceMap.get("caseRefer");
|
Object caseReferObj = sourceMap.get("caseRefer");
|
||||||
@@ -253,6 +313,15 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 解析点赞状态
|
||||||
|
if (sourceMap.containsKey("likeStatus")) {
|
||||||
|
messageVo.setLikeStatus((String) sourceMap.get("likeStatus"));
|
||||||
|
}
|
||||||
|
// 解析反馈信息
|
||||||
|
if (sourceMap.containsKey("feedback")) {
|
||||||
|
messageVo.setFeedback((String) sourceMap.get("feedback"));
|
||||||
|
}
|
||||||
|
|
||||||
return messageVo;
|
return messageVo;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("解析ES消息数据异常", e);
|
log.error("解析ES消息数据异常", e);
|
||||||
@@ -260,6 +329,79 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateData(String docId, AiChatConversationData data) {
|
||||||
|
if (elasticsearchClient == null) {
|
||||||
|
log.error("未配置Elasticsearch客户端,无法更新对话记录");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
UpdateRequest updateRequest = new UpdateRequest(CaseAiConstants.CASE_AI_INDEX_NAME, docId);
|
||||||
|
JSONObject esData = new JSONObject();
|
||||||
|
// 目前只支持更新点赞状态和反馈信息
|
||||||
|
if (StringUtils.isNotBlank(data.getLikeStatus())) {
|
||||||
|
// 进行点赞/踩或取消操作是, 将feedback字段置空
|
||||||
|
esData.put("likeStatus", data.getLikeStatus());
|
||||||
|
esData.put("feedback", "");
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(data.getFeedback())) {
|
||||||
|
esData.put("feedback", data.getFeedback());
|
||||||
|
}
|
||||||
|
updateRequest.doc(esData.toJSONString(), XContentType.JSON);
|
||||||
|
elasticsearchClient.update(updateRequest, RequestOptions.DEFAULT);
|
||||||
|
return true;
|
||||||
|
} catch (ElasticsearchException e) {
|
||||||
|
if (e.status() == RestStatus.NOT_FOUND) {
|
||||||
|
log.error("文档不存在", e);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("更新对话记录异常", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过docId查询数据
|
||||||
|
*
|
||||||
|
* @param docId 会话ID
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<CaseAiMessageVo> queryDataByDocId(String docId) {
|
||||||
|
List<CaseAiMessageVo> list = new ArrayList<>();
|
||||||
|
if (elasticsearchClient == null) {
|
||||||
|
log.error("未配置Elasticsearch客户端,无法查询消息记录");
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
SearchRequest searchRequest = new SearchRequest(CaseAiConstants.CASE_AI_INDEX_NAME);
|
||||||
|
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||||
|
searchSourceBuilder.query(QueryBuilders.matchQuery("_id", docId));
|
||||||
|
searchSourceBuilder.size(1000); // 设置最大返回数量
|
||||||
|
searchRequest.source(searchSourceBuilder);
|
||||||
|
|
||||||
|
|
||||||
|
SearchResponse searchResponse = elasticsearchClient.search(searchRequest, RequestOptions.DEFAULT);
|
||||||
|
SearchHits hits = searchResponse.getHits();
|
||||||
|
|
||||||
|
for (SearchHit hit : hits) {
|
||||||
|
Map<String, Object> sourceMap = hit.getSourceAsMap();
|
||||||
|
CaseAiMessageVo data = parseMessageFromES(sourceMap);
|
||||||
|
if (data != null) {
|
||||||
|
data.setDocId(hit.getId());
|
||||||
|
list.add(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("从 ES 中查询到 {} 条消息记录", list.size());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("从 ES 查询消息异常", e);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取ai_chat_messages索引的字段映射配置
|
* 获取ai_chat_messages索引的字段映射配置
|
||||||
* 根据项目中的会话消息数据结构规范定义映射
|
* 根据项目中的会话消息数据结构规范定义映射
|
||||||
@@ -267,70 +409,15 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
|
|||||||
* @return JSON格式的映射配置
|
* @return JSON格式的映射配置
|
||||||
*/
|
*/
|
||||||
private String getAiChatMessagesMapping() {
|
private String getAiChatMessagesMapping() {
|
||||||
return "{\n" +
|
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("case_ai_index.json");
|
||||||
" \"properties\": {\n" +
|
if (inputStream != null) {
|
||||||
" \"conversationId\": {\n" +
|
try (InputStreamReader isr = new InputStreamReader(inputStream);
|
||||||
" \"type\": \"keyword\",\n" +
|
BufferedReader reader = new BufferedReader(isr)) {
|
||||||
" \"index\": true\n" +
|
return reader.lines().collect(Collectors.joining(System.lineSeparator()));
|
||||||
" },\n" +
|
} catch (IOException e) {
|
||||||
" \"query\": {\n" +
|
throw new RuntimeException("Resource read error: case_ai_index.json", e);
|
||||||
" \"type\": \"text\",\n" +
|
}
|
||||||
" \"analyzer\": \"ik_max_word\",\n" +
|
}
|
||||||
" \"search_analyzer\": \"ik_smart\",\n" +
|
throw new RuntimeException("Resource not found: case_ai_index.json");
|
||||||
" \"fields\": {\n" +
|
|
||||||
" \"keyword\": {\n" +
|
|
||||||
" \"type\": \"keyword\",\n" +
|
|
||||||
" \"ignore_above\": 256\n" +
|
|
||||||
" }\n" +
|
|
||||||
" }\n" +
|
|
||||||
" },\n" +
|
|
||||||
" \"answer\": {\n" +
|
|
||||||
" \"type\": \"text\",\n" +
|
|
||||||
" \"analyzer\": \"ik_max_word\",\n" +
|
|
||||||
" \"search_analyzer\": \"ik_smart\"\n" +
|
|
||||||
" },\n" +
|
|
||||||
" \"caseRefer\": {\n" +
|
|
||||||
" \"type\": \"nested\",\n" +
|
|
||||||
" \"properties\": {\n" +
|
|
||||||
" \"caseId\": {\n" +
|
|
||||||
" \"type\": \"keyword\",\n" +
|
|
||||||
" \"index\": true\n" +
|
|
||||||
" },\n" +
|
|
||||||
" \"title\": {\n" +
|
|
||||||
" \"type\": \"text\",\n" +
|
|
||||||
" \"analyzer\": \"ik_max_word\",\n" +
|
|
||||||
" \"search_analyzer\": \"ik_smart\"\n" +
|
|
||||||
" },\n" +
|
|
||||||
" \"authorName\": {\n" +
|
|
||||||
" \"type\": \"keyword\",\n" +
|
|
||||||
" \"index\": true\n" +
|
|
||||||
" },\n" +
|
|
||||||
" \"keywords\": {\n" +
|
|
||||||
" \"type\": \"text\",\n" +
|
|
||||||
" \"analyzer\": \"ik_max_word\",\n" +
|
|
||||||
" \"search_analyzer\": \"ik_smart\"\n" +
|
|
||||||
" },\n" +
|
|
||||||
" \"content\": {\n" +
|
|
||||||
" \"type\": \"text\",\n" +
|
|
||||||
" \"analyzer\": \"ik_max_word\",\n" +
|
|
||||||
" \"search_analyzer\": \"ik_smart\"\n" +
|
|
||||||
" }\n" +
|
|
||||||
" }\n" +
|
|
||||||
" },\n" +
|
|
||||||
" \"suggestions\": {\n" +
|
|
||||||
" \"type\": \"text\",\n" +
|
|
||||||
" \"analyzer\": \"ik_max_word\",\n" +
|
|
||||||
" \"search_analyzer\": \"ik_smart\"\n" +
|
|
||||||
" },\n" +
|
|
||||||
" \"userId\": {\n" +
|
|
||||||
" \"type\": \"keyword\",\n" +
|
|
||||||
" \"index\": true\n" +
|
|
||||||
" },\n" +
|
|
||||||
" \"timestamp\": {\n" +
|
|
||||||
" \"type\": \"date\",\n" +
|
|
||||||
" \"format\": \"yyyy-MM-dd HH:mm:ss||yyyy-MM-dd'T'HH:mm:ss||yyyy-MM-dd'T'HH:mm:ss.SSS||yyyy-MM-dd'T'HH:mm:ss.SSS'Z'||epoch_millis\"\n" +
|
|
||||||
" }\n" +
|
|
||||||
" }\n" +
|
|
||||||
"}";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package com.xboe.module.boecase.task;
|
package com.xboe.module.boecase.task;
|
||||||
|
|
||||||
|
import com.xboe.common.OrderCondition;
|
||||||
import com.xboe.constants.CaseAiConstants;
|
import com.xboe.constants.CaseAiConstants;
|
||||||
|
import com.xboe.core.orm.FieldFilters;
|
||||||
|
import com.xboe.core.orm.QueryBuilder;
|
||||||
import com.xboe.enums.CaseDocumentLogCaseStatusEnum;
|
import com.xboe.enums.CaseDocumentLogCaseStatusEnum;
|
||||||
import com.xboe.enums.CaseDocumentLogOptStatusEnum;
|
import com.xboe.enums.CaseDocumentLogOptStatusEnum;
|
||||||
import com.xboe.enums.CaseDocumentLogOptTypeEnum;
|
import com.xboe.enums.CaseDocumentLogOptTypeEnum;
|
||||||
@@ -43,7 +46,39 @@ public class CaseUploadTask {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private StringRedisTemplate stringRedisTemplate;
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
private static final String CASE_UPLOAD_LAST_ID_KEY = "case:upload:last:id";
|
public static final String CASE_UPLOAD_LAST_ID_KEY = "case:upload:last:id";
|
||||||
|
|
||||||
|
public static final String CASE_RELOAD_LAST_ID_KEY = "case:reload:last:id";
|
||||||
|
|
||||||
|
@XxlJob("reloadJob")
|
||||||
|
public void reloadJob() {
|
||||||
|
String currentLastId = null;
|
||||||
|
try {
|
||||||
|
// 从Redis获取上次处理的最后一条记录ID
|
||||||
|
String lastProcessedId = stringRedisTemplate.opsForValue().get(CASE_RELOAD_LAST_ID_KEY);
|
||||||
|
// 查询需要重新加载的案例
|
||||||
|
List<CaseDocumentLog> logsToReload = listToReload(lastProcessedId);
|
||||||
|
if (logsToReload.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
currentLastId = logsToReload.get(logsToReload.size() - 1).getId();
|
||||||
|
for (CaseDocumentLog log : logsToReload) {
|
||||||
|
String caseId = log.getCaseId();
|
||||||
|
Cases cases = casesDao.get(caseId);
|
||||||
|
if (cases != null && StringUtils.isNotBlank(cases.getFilePath())) {
|
||||||
|
// 更新
|
||||||
|
caseAiDocumentAsyncHandler.process(CaseDocumentLogOptTypeEnum.UPDATE, cases);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("[reload]执行重新上传任务时发生异常", e);
|
||||||
|
} finally {
|
||||||
|
if (currentLastId != null) {
|
||||||
|
stringRedisTemplate.opsForValue().set(CASE_RELOAD_LAST_ID_KEY, currentLastId);
|
||||||
|
log.info("[reload] 已重新上传案例,最后一条caseDocumentLogId 已更新为: {}", currentLastId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@XxlJob("oldDataUploadJob")
|
@XxlJob("oldDataUploadJob")
|
||||||
public void oldDataUploadJob() {
|
public void oldDataUploadJob() {
|
||||||
@@ -142,25 +177,44 @@ public class CaseUploadTask {
|
|||||||
* @return 案例列表
|
* @return 案例列表
|
||||||
*/
|
*/
|
||||||
private List<Cases> findCasesToProcess(String lastProcessedId) {
|
private List<Cases> findCasesToProcess(String lastProcessedId) {
|
||||||
com.xboe.core.orm.QueryBuilder queryBuilder = com.xboe.core.orm.QueryBuilder.from(Cases.class);
|
QueryBuilder queryBuilder = QueryBuilder.from(Cases.class);
|
||||||
queryBuilder.addFilter(com.xboe.core.orm.FieldFilters.eq("deleted", false));
|
queryBuilder.addFilter(FieldFilters.eq("deleted", false));
|
||||||
// 只处理有文件路径的案例
|
// 只处理有文件路径的案例
|
||||||
queryBuilder.addFilter(com.xboe.core.orm.FieldFilters.isNotNull("filePath"));
|
queryBuilder.addFilter(FieldFilters.isNotNull("filePath"));
|
||||||
queryBuilder.addFilter(com.xboe.core.orm.FieldFilters.ne("filePath", ""));
|
queryBuilder.addFilter(FieldFilters.ne("filePath", ""));
|
||||||
|
|
||||||
// 如果有上次处理的ID,则从该ID之后开始查询
|
// 如果有上次处理的ID,则从该ID之后开始查询
|
||||||
if (lastProcessedId != null && !lastProcessedId.isEmpty()) {
|
if (lastProcessedId != null && !lastProcessedId.isEmpty()) {
|
||||||
queryBuilder.addFilter(com.xboe.core.orm.FieldFilters.gt("id", lastProcessedId));
|
queryBuilder.addFilter(FieldFilters.gt("id", lastProcessedId));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按创建时间升序排序
|
// 按创建时间升序排序
|
||||||
queryBuilder.addOrder(com.xboe.common.OrderCondition.asc("id"));
|
queryBuilder.addOrder(OrderCondition.asc("id"));
|
||||||
// 限制每次处理的数量,避免一次性处理太多数据
|
// 限制每次处理的数量,避免一次性处理太多数据
|
||||||
queryBuilder.setPageSize(100);
|
queryBuilder.setPageSize(100);
|
||||||
|
|
||||||
return casesDao.findList(queryBuilder.builder());
|
return casesDao.findList(queryBuilder.builder());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取需要重新加载的案例
|
||||||
|
* @param lastProcessedId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private List<CaseDocumentLog> listToReload(String lastProcessedId) {
|
||||||
|
QueryBuilder queryBuilder = QueryBuilder.from(CaseDocumentLog.class);
|
||||||
|
queryBuilder.addFilter(FieldFilters.eq("deleted", false));
|
||||||
|
queryBuilder.addFilter(FieldFilters.eq("requestUrl", CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME));
|
||||||
|
queryBuilder.addFilter(FieldFilters.eq("caseStatus", CaseDocumentLogCaseStatusEnum.SUCCESS.getCode()));
|
||||||
|
queryBuilder.addFilter(FieldFilters.eq("metadataStatus", 0));
|
||||||
|
if (lastProcessedId != null && !lastProcessedId.isEmpty()) {
|
||||||
|
queryBuilder.addFilter(FieldFilters.gt("id", lastProcessedId));
|
||||||
|
}
|
||||||
|
queryBuilder.addOrder(OrderCondition.asc("id"));
|
||||||
|
queryBuilder.setPageSize(100);
|
||||||
|
return caseDocumentLogDao.findList(queryBuilder.builder());
|
||||||
|
}
|
||||||
|
|
||||||
private void fixOnLastCase(String currentLastId) {
|
private void fixOnLastCase(String currentLastId) {
|
||||||
stringRedisTemplate.opsForValue().set(CASE_UPLOAD_LAST_ID_KEY, currentLastId);
|
stringRedisTemplate.opsForValue().set(CASE_UPLOAD_LAST_ID_KEY, currentLastId);
|
||||||
log.info("已处理案例,最后一条记录ID已更新为: {}", currentLastId);
|
log.info("已处理案例,最后一条记录ID已更新为: {}", currentLastId);
|
||||||
|
|||||||
@@ -10,6 +10,15 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class CaseAiMessageVo {
|
public class CaseAiMessageVo {
|
||||||
|
/**
|
||||||
|
* ES docId
|
||||||
|
*/
|
||||||
|
private String docId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会话ID
|
||||||
|
*/
|
||||||
|
private String conversationId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户提问内容
|
* 用户提问内容
|
||||||
@@ -29,7 +38,7 @@ public class CaseAiMessageVo {
|
|||||||
/**
|
/**
|
||||||
* 会话时长(秒)
|
* 会话时长(秒)
|
||||||
*/
|
*/
|
||||||
private Long durationSeconds;
|
private Integer durationSeconds;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 案例引用列表
|
* 案例引用列表
|
||||||
@@ -40,4 +49,31 @@ public class CaseAiMessageVo {
|
|||||||
* 建议列表
|
* 建议列表
|
||||||
*/
|
*/
|
||||||
private List<String> suggestions;
|
private List<String> suggestions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
* 0-正常
|
||||||
|
* 1-系统错误
|
||||||
|
* 2-AIoT平台错误
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误信息
|
||||||
|
*/
|
||||||
|
private String errorMsg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户点赞状态
|
||||||
|
* -1: 踩
|
||||||
|
* 1:赞
|
||||||
|
* 0/null 无操作
|
||||||
|
*/
|
||||||
|
private String likeStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户踩的时候, 可以填写反馈意见
|
||||||
|
* 反馈意见
|
||||||
|
*/
|
||||||
|
private String feedback;
|
||||||
}
|
}
|
||||||
@@ -11,22 +11,22 @@ spring:
|
|||||||
cloud:
|
cloud:
|
||||||
nacos:
|
nacos:
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: 192.168.0.253:8848
|
server-addr: 192.168.10.74:8848
|
||||||
config:
|
config:
|
||||||
server-addr: 192.168.0.253:8848
|
server-addr: 192.168.10.74:8848
|
||||||
redis:
|
redis:
|
||||||
database: 1
|
database: 2
|
||||||
host: 192.168.0.253
|
host: 39.104.123.58
|
||||||
password: boe@123
|
password: Ebiz2020
|
||||||
port: 6379
|
port: 6378
|
||||||
jpa:
|
jpa:
|
||||||
hibernate:
|
hibernate:
|
||||||
ddl-auto: none
|
ddl-auto: none
|
||||||
datasource:
|
datasource:
|
||||||
driverClassName: com.mysql.jdbc.Driver
|
driverClassName: com.mysql.jdbc.Driver
|
||||||
url: jdbc:mysql://192.168.0.253:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull
|
url: jdbc:mysql://rm-hp3cpkk0u50q90eu9vo.mysql.huhehaote.rds.aliyuncs.com:3306/ebiz_doc_manage?characterEncoding=utf8&useUnicode=true&serverTimezone=Asia/Shanghai&useSSL=false&allowMultiQueries=true
|
||||||
username: root
|
username: ebiz_ai
|
||||||
password: boe#1234A
|
password: ebiz_ai123
|
||||||
type: com.zaxxer.hikari.HikariDataSource
|
type: com.zaxxer.hikari.HikariDataSource
|
||||||
hikari:
|
hikari:
|
||||||
auto-commit: true
|
auto-commit: true
|
||||||
@@ -35,6 +35,12 @@ spring:
|
|||||||
connection-timeout: 30000
|
connection-timeout: 30000
|
||||||
max-lifetime: 1800000
|
max-lifetime: 1800000
|
||||||
maximum-pool-size: 20
|
maximum-pool-size: 20
|
||||||
|
activemq:
|
||||||
|
broker-url: tcp://192.168.10.74:61616
|
||||||
|
user: admin
|
||||||
|
password: admin
|
||||||
|
jms:
|
||||||
|
pub-sub-domain: true
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
org:
|
org:
|
||||||
@@ -107,7 +113,7 @@ aop-log-record:
|
|||||||
#不进行拦截的包或者类
|
#不进行拦截的包或者类
|
||||||
excludeClassNames:
|
excludeClassNames:
|
||||||
activemq:
|
activemq:
|
||||||
broker-url: tcp://192.168.0.253:61616
|
broker-url: tcp://192.168.10.74:61616
|
||||||
user: admin
|
user: admin
|
||||||
password: admin
|
password: admin
|
||||||
elasticsearch:
|
elasticsearch:
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ spring:
|
|||||||
web:
|
web:
|
||||||
resources:
|
resources:
|
||||||
static-locations: file:E:/Projects/BOE/10/static
|
static-locations: file:E:/Projects/BOE/10/static
|
||||||
|
activemq:
|
||||||
|
broker-url: tcp://10.251.129.51:61616
|
||||||
|
user: admin
|
||||||
|
password: admin
|
||||||
|
jms:
|
||||||
|
pub-sub-domain: true
|
||||||
server:
|
server:
|
||||||
port: 9090
|
port: 9090
|
||||||
tomcat:
|
tomcat:
|
||||||
|
|||||||
@@ -33,6 +33,12 @@ spring:
|
|||||||
connection-timeout: 30000
|
connection-timeout: 30000
|
||||||
max-lifetime: 1800000
|
max-lifetime: 1800000
|
||||||
maximum-pool-size: 20
|
maximum-pool-size: 20
|
||||||
|
activemq:
|
||||||
|
broker-url: tcp://10.251.113.100:61616
|
||||||
|
user: admin
|
||||||
|
password: admin
|
||||||
|
jms:
|
||||||
|
pub-sub-domain: true
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
org:
|
org:
|
||||||
@@ -113,6 +119,204 @@ xboe:
|
|||||||
- "10827857"
|
- "10827857"
|
||||||
- "11339772"
|
- "11339772"
|
||||||
- "pctest06"
|
- "pctest06"
|
||||||
|
# 20251202 新增天使用户
|
||||||
|
- "30103141"
|
||||||
|
- "60001391"
|
||||||
|
- "61001278"
|
||||||
|
- "30101301"
|
||||||
|
- "10444837"
|
||||||
|
- "50102190"
|
||||||
|
- "10745030"
|
||||||
|
- "11417101"
|
||||||
|
- "11305432"
|
||||||
|
- "10103037"
|
||||||
|
- "10035168"
|
||||||
|
- "30118060"
|
||||||
|
- "11490910"
|
||||||
|
- "11402931"
|
||||||
|
- "50102196"
|
||||||
|
- "00004896"
|
||||||
|
- "98050025"
|
||||||
|
- "15014359"
|
||||||
|
- "98000758"
|
||||||
|
- "10111538"
|
||||||
|
- "62000137"
|
||||||
|
- "10621476"
|
||||||
|
- "11698996"
|
||||||
|
- "10626304"
|
||||||
|
- "1215826"
|
||||||
|
- "30101887"
|
||||||
|
- "10111915"
|
||||||
|
- "11456852"
|
||||||
|
- "126458"
|
||||||
|
- "30141438"
|
||||||
|
- "10209179"
|
||||||
|
- "22BT15420"
|
||||||
|
- "21BB2053"
|
||||||
|
- "10449861"
|
||||||
|
- "130325"
|
||||||
|
- "11331818"
|
||||||
|
- "10117022"
|
||||||
|
- "10105891"
|
||||||
|
- "121649"
|
||||||
|
- "110338"
|
||||||
|
- "1217784"
|
||||||
|
- "30105038"
|
||||||
|
- "98000792"
|
||||||
|
- "60001146"
|
||||||
|
- "11698607"
|
||||||
|
- "11493629"
|
||||||
|
- "10164819"
|
||||||
|
- "11463452"
|
||||||
|
- "10412122"
|
||||||
|
- "11677116"
|
||||||
|
- "98000780"
|
||||||
|
- "61004269"
|
||||||
|
- "1218902"
|
||||||
|
- "111038"
|
||||||
|
- "10056775"
|
||||||
|
- "50125311"
|
||||||
|
- "50100445"
|
||||||
|
- "00003320"
|
||||||
|
- "11672602"
|
||||||
|
- "30129421"
|
||||||
|
- "11433296"
|
||||||
|
- "11759796"
|
||||||
|
- "10063656"
|
||||||
|
- "10829939"
|
||||||
|
- "98050190"
|
||||||
|
- "10061076"
|
||||||
|
- "60001460"
|
||||||
|
- "10415155"
|
||||||
|
- "60000626"
|
||||||
|
- "110791"
|
||||||
|
- "60000984"
|
||||||
|
- "62000025"
|
||||||
|
- "11794394"
|
||||||
|
- "11681568"
|
||||||
|
- "00002915"
|
||||||
|
- "1210874"
|
||||||
|
- "132046"
|
||||||
|
- "10157955"
|
||||||
|
- "00004409"
|
||||||
|
- "10773520"
|
||||||
|
- "102403"
|
||||||
|
- "10119108"
|
||||||
|
- "10062300"
|
||||||
|
- "10334899"
|
||||||
|
- "10111689"
|
||||||
|
- "10258267"
|
||||||
|
- "60000327"
|
||||||
|
- "50100096"
|
||||||
|
- "10075741"
|
||||||
|
- "1000477"
|
||||||
|
- "1218405"
|
||||||
|
- "132666"
|
||||||
|
- "10183064"
|
||||||
|
- "50101990"
|
||||||
|
- "120869"
|
||||||
|
- "11291711"
|
||||||
|
- "11670020"
|
||||||
|
- "11321710"
|
||||||
|
- "10855714"
|
||||||
|
- "11331449"
|
||||||
|
- "50108923"
|
||||||
|
- "66001553"
|
||||||
|
- "81011081"
|
||||||
|
- "11098405"
|
||||||
|
- "10158509"
|
||||||
|
- "11327800"
|
||||||
|
- "10065717"
|
||||||
|
- "10897206"
|
||||||
|
- "30135784"
|
||||||
|
- "1200373"
|
||||||
|
- "10048566"
|
||||||
|
- "10059710"
|
||||||
|
- "11834720"
|
||||||
|
- "1200384"
|
||||||
|
- "60000973"
|
||||||
|
- "11282207"
|
||||||
|
- "40865"
|
||||||
|
- "10811920"
|
||||||
|
- "00003324"
|
||||||
|
- "00003937"
|
||||||
|
- "10031853"
|
||||||
|
- "1201730"
|
||||||
|
- "00004615"
|
||||||
|
- "10613607"
|
||||||
|
- "10166435"
|
||||||
|
- "11407507"
|
||||||
|
- "21BB0031"
|
||||||
|
- "00002198"
|
||||||
|
- "30104243"
|
||||||
|
- "10840493"
|
||||||
|
- "10046158"
|
||||||
|
- "132164"
|
||||||
|
- "11257354"
|
||||||
|
- "11753398"
|
||||||
|
- "10230265"
|
||||||
|
- "11293165"
|
||||||
|
- "10114925"
|
||||||
|
- "S638"
|
||||||
|
- "10833174"
|
||||||
|
- "10926203"
|
||||||
|
- "124046"
|
||||||
|
- "201181"
|
||||||
|
- "11319329"
|
||||||
|
- "10884794"
|
||||||
|
- "10331955"
|
||||||
|
- "60000847"
|
||||||
|
- "1411"
|
||||||
|
- "126581"
|
||||||
|
- "00003375"
|
||||||
|
- "132539"
|
||||||
|
- "98050455"
|
||||||
|
- "10053666"
|
||||||
|
- "11697194"
|
||||||
|
- "61002398"
|
||||||
|
- "00002971"
|
||||||
|
- "14157"
|
||||||
|
- "132989"
|
||||||
|
- "50103467"
|
||||||
|
- "37315"
|
||||||
|
- "10088583"
|
||||||
|
- "11048954"
|
||||||
|
- "110202"
|
||||||
|
- "30141433"
|
||||||
|
- "1000079"
|
||||||
|
- "11783149"
|
||||||
|
- "10025448"
|
||||||
|
- "98000579"
|
||||||
|
- "10614158"
|
||||||
|
- "30104381"
|
||||||
|
- "60000122"
|
||||||
|
- "11074875"
|
||||||
|
- "10009047"
|
||||||
|
- "10228087"
|
||||||
|
- "10875722"
|
||||||
|
- "10041401"
|
||||||
|
- "110679"
|
||||||
|
- "11167945"
|
||||||
|
- "11288196"
|
||||||
|
- "00003111"
|
||||||
|
- "11780879"
|
||||||
|
- "10836255"
|
||||||
|
- "10753364"
|
||||||
|
- "50102132"
|
||||||
|
- "10711537"
|
||||||
|
- "15001329"
|
||||||
|
- "11733703"
|
||||||
|
- "10450632"
|
||||||
|
- "98050011"
|
||||||
|
- "10224644"
|
||||||
|
- "120931"
|
||||||
|
- "10743223"
|
||||||
|
- "107873"
|
||||||
|
- "11141942"
|
||||||
|
- "120434"
|
||||||
|
- "126466"
|
||||||
|
- "98050020"
|
||||||
|
- "10928732"
|
||||||
alert-email-recipients:
|
alert-email-recipients:
|
||||||
- chengmeng@boe.com.cn
|
- chengmeng@boe.com.cn
|
||||||
- liyubing@boe.com.cn
|
- liyubing@boe.com.cn
|
||||||
@@ -141,4 +345,11 @@ aop-log-record:
|
|||||||
password: admin
|
password: admin
|
||||||
elasticsearch:
|
elasticsearch:
|
||||||
host: 10.251.88.218
|
host: 10.251.88.218
|
||||||
port: 9200
|
port: 9200
|
||||||
|
ok:
|
||||||
|
http:
|
||||||
|
connect-timeout: 300
|
||||||
|
read-timeout: 300
|
||||||
|
write-timeout: 300
|
||||||
|
max-idle-connections: 200
|
||||||
|
keep-alive-duration: 300
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ spring:
|
|||||||
web:
|
web:
|
||||||
resources:
|
resources:
|
||||||
static-locations: file:E:/Projects/BOE/10/static
|
static-locations: file:E:/Projects/BOE/10/static
|
||||||
|
activemq:
|
||||||
|
broker-url: tcp://10.251.129.25:61616
|
||||||
|
user: admin
|
||||||
|
password: admin
|
||||||
|
jms:
|
||||||
|
pub-sub-domain: true
|
||||||
server:
|
server:
|
||||||
port: 9090
|
port: 9090
|
||||||
tomcat:
|
tomcat:
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ ok:
|
|||||||
write-timeout: 300
|
write-timeout: 300
|
||||||
max-idle-connections: 200
|
max-idle-connections: 200
|
||||||
keep-alive-duration: 300
|
keep-alive-duration: 300
|
||||||
|
activemq:
|
||||||
|
topic:
|
||||||
|
name: case_ai_chat_stop_topic
|
||||||
boe:
|
boe:
|
||||||
domain: http://127.0.0.1
|
domain: http://127.0.0.1
|
||||||
orgTree:
|
orgTree:
|
||||||
|
|||||||
82
servers/boe-server-all/src/main/resources/case_ai_index.json
Normal file
82
servers/boe-server-all/src/main/resources/case_ai_index.json
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"conversationId": {
|
||||||
|
"type": "keyword",
|
||||||
|
"index": true
|
||||||
|
},
|
||||||
|
"query": {
|
||||||
|
"type": "text",
|
||||||
|
"analyzer": "ik_max_word",
|
||||||
|
"search_analyzer": "ik_smart",
|
||||||
|
"fields": {
|
||||||
|
"keyword": {
|
||||||
|
"type": "keyword",
|
||||||
|
"ignore_above": 256
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"answer": {
|
||||||
|
"type": "text",
|
||||||
|
"analyzer": "ik_max_word",
|
||||||
|
"search_analyzer": "ik_smart"
|
||||||
|
},
|
||||||
|
"caseRefer": {
|
||||||
|
"type": "nested",
|
||||||
|
"properties": {
|
||||||
|
"caseId": {
|
||||||
|
"type": "keyword",
|
||||||
|
"index": true
|
||||||
|
},
|
||||||
|
"title": {
|
||||||
|
"type": "text",
|
||||||
|
"analyzer": "ik_max_word",
|
||||||
|
"search_analyzer": "ik_smart"
|
||||||
|
},
|
||||||
|
"authorName": {
|
||||||
|
"type": "keyword",
|
||||||
|
"index": true
|
||||||
|
},
|
||||||
|
"keywords": {
|
||||||
|
"type": "text",
|
||||||
|
"analyzer": "ik_max_word",
|
||||||
|
"search_analyzer": "ik_smart"
|
||||||
|
},
|
||||||
|
"content": {
|
||||||
|
"type": "text",
|
||||||
|
"analyzer": "ik_max_word",
|
||||||
|
"search_analyzer": "ik_smart"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"suggestions": {
|
||||||
|
"type": "text",
|
||||||
|
"analyzer": "ik_max_word",
|
||||||
|
"search_analyzer": "ik_smart"
|
||||||
|
},
|
||||||
|
"userId": {
|
||||||
|
"type": "keyword",
|
||||||
|
"index": true
|
||||||
|
},
|
||||||
|
"timestamp": {
|
||||||
|
"type": "date",
|
||||||
|
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd'T'HH:mm:ss||yyyy-MM-dd'T'HH:mm:ss.SSS||yyyy-MM-dd'T'HH:mm:ss.SSS'Z'||epoch_millis"
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"errorMsg": {
|
||||||
|
"type": "text",
|
||||||
|
"analyzer": "ik_max_word",
|
||||||
|
"search_analyzer": "ik_smart"
|
||||||
|
},
|
||||||
|
"likeStatus": {
|
||||||
|
"type": "keyword",
|
||||||
|
"index": true
|
||||||
|
},
|
||||||
|
"feedback": {
|
||||||
|
"type": "text",
|
||||||
|
"analyzer": "ik_max_word",
|
||||||
|
"search_analyzer": "ik_smart"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,37 +31,33 @@
|
|||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!-- Log file error output -->
|
<appender name="caseAiChat"
|
||||||
<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
<file>${log.path}/error.log</file>
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
|
||||||
<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
|
||||||
<maxFileSize>50MB</maxFileSize>
|
|
||||||
<maxHistory>30</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||||
|
<charset>UTF-8</charset>
|
||||||
</encoder>
|
</encoder>
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
<file>${log.path}/caseAiChat.log</file>
|
||||||
<level>ERROR</level>
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
</filter>
|
<fileNamePattern>${log.path}/caseAiChat.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
</rollingPolicy>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!-- Log file error output -->
|
<!-- Log file error output -->
|
||||||
<appender name="caseAiChat" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
<!-- <appender name="caseAiChat" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
|
||||||
<file>${log.path}/caseAiChat.log</file>
|
<!-- <file>${log.path}/caseAiChat.log</file>-->
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
<!-- <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">-->
|
||||||
<fileNamePattern>${log.path}/%d{yyyy-MM}/caseAiChat.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
<!-- <fileNamePattern>${log.path}/%d{yyyy-MM}/caseAiChat.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>-->
|
||||||
<maxFileSize>50MB</maxFileSize>
|
<!-- <maxFileSize>50MB</maxFileSize>-->
|
||||||
<maxHistory>30</maxHistory>
|
<!-- <maxHistory>30</maxHistory>-->
|
||||||
</rollingPolicy>
|
<!-- </rollingPolicy>-->
|
||||||
<encoder>
|
<!-- <encoder>-->
|
||||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
<!-- <pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>-->
|
||||||
</encoder>
|
<!-- </encoder>-->
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
<!-- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">-->
|
||||||
<level>ERROR</level>
|
<!-- <level>ERROR</level>-->
|
||||||
</filter>
|
<!-- </filter>-->
|
||||||
</appender>
|
<!-- </appender>-->
|
||||||
|
|
||||||
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
||||||
<root level="INFO">
|
<root level="INFO">
|
||||||
|
|||||||
@@ -47,20 +47,16 @@
|
|||||||
</filter>
|
</filter>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!-- Log file error output -->
|
<appender name="caseAiChat"
|
||||||
<appender name="caseAiChat" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
<file>${log.path}/caseAiChat.log</file>
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
|
||||||
<fileNamePattern>${log.path}/%d{yyyy-MM}/caseAiChat.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
|
||||||
<maxFileSize>50MB</maxFileSize>
|
|
||||||
<maxHistory>30</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||||
|
<charset>UTF-8</charset>
|
||||||
</encoder>
|
</encoder>
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
<File>${log.path}/caseAiChat.log</File>
|
||||||
<level>ERROR</level>
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
</filter>
|
<FileNamePattern>${log.path}/caseAiChat.%d{yyyy-MM-dd}.log</FileNamePattern>
|
||||||
|
</rollingPolicy>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
||||||
|
|||||||
Reference in New Issue
Block a user