mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-09 02:46:50 +08:00
Compare commits
19 Commits
SZX-1194-2
...
release_20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17ada96efb | ||
|
|
271d52ce70 | ||
|
|
73d3c4b7f8 | ||
|
|
ac3465ff92 | ||
|
|
92721b9c17 | ||
|
|
e070c14d70 | ||
|
|
ee2770585c | ||
|
|
f7adb42c8b | ||
|
|
9fb01d7ef2 | ||
|
|
095c483843 | ||
|
|
73174be9e2 | ||
|
|
c9fe597f55 | ||
|
|
10acdbeee2 | ||
|
|
6f82bc7365 | ||
|
|
f65ddb2a2b | ||
|
|
d36f4c19eb | ||
|
|
db6f761b92 | ||
|
|
732269998f | ||
|
|
5844b1d9eb |
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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.JsonResponse;
|
||||
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.service.ICaseAiChatService;
|
||||
import com.xboe.module.boecase.service.ICaseAiPermissionService;
|
||||
@@ -17,7 +20,6 @@ import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
@@ -65,7 +67,7 @@ public class CaseAiChatApi extends ApiBaseController {
|
||||
* @param conversationId 会话ID
|
||||
* @return 是否成功停止
|
||||
*/
|
||||
@PostMapping("/stop")
|
||||
@GetMapping("/stop")
|
||||
public JsonResponse<Boolean> stopChat(@RequestParam String conversationId) {
|
||||
try {
|
||||
boolean result = caseAiChatService.stopChatOutput(conversationId);
|
||||
@@ -80,6 +82,63 @@ public class CaseAiChatApi extends ApiBaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 赞消息
|
||||
* @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查看会话内消息记录
|
||||
* @param conversationId 会话ID
|
||||
@@ -149,6 +208,17 @@ public class CaseAiChatApi extends ApiBaseController {
|
||||
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")
|
||||
public JsonResponse<String> createNewConversation(@RequestBody CaseAiMessageVo caseAiMessageVo,
|
||||
@RequestParam String conversationId,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.xboe.module.boecase.api;
|
||||
|
||||
import com.xboe.module.boecase.task.CaseUploadTask;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
@@ -20,14 +21,21 @@ public class CaseUploadTaskApi {
|
||||
@Autowired
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
private static final String CASE_UPLOAD_LAST_ID_KEY = "case:upload:last:id";
|
||||
|
||||
/**
|
||||
* 清除处理位置标记,使下次任务从头开始执行
|
||||
*/
|
||||
@PostMapping("/reset")
|
||||
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("已清除上次处理位置标记");
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
/**
|
||||
* 状态
|
||||
* 0-正常
|
||||
* 1-系统错误
|
||||
* 2-AIoT平台错误
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
private String errorMsg;
|
||||
|
||||
/**
|
||||
* 案例引用列表
|
||||
*/
|
||||
@@ -44,6 +57,20 @@ public class AiChatConversationData {
|
||||
*/
|
||||
private List<String> suggestions = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 用户点赞状态
|
||||
* -1: 踩
|
||||
* 1:赞
|
||||
* 0/null 无操作
|
||||
*/
|
||||
private String likeStatus;
|
||||
|
||||
/**
|
||||
* 用户踩的时候, 可以填写反馈意见
|
||||
* 反馈意见
|
||||
*/
|
||||
private String feedback;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
|
||||
@@ -93,4 +93,12 @@ public class CaseDocumentLog extends BaseEntity {
|
||||
*/
|
||||
@Column(name = "execute_duration")
|
||||
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.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.vo.CaseAiMessageVo;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
@@ -64,4 +66,27 @@ public interface ICaseAiChatService {
|
||||
* @return 是否成功停止
|
||||
*/
|
||||
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 java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* es索引
|
||||
@@ -27,6 +28,14 @@ public interface IElasticSearchIndexService {
|
||||
*/
|
||||
boolean deleteIndex();
|
||||
|
||||
/**
|
||||
* 更新索引:添加索引字段
|
||||
* @param fieldName
|
||||
* @param fieldProperties
|
||||
* @return
|
||||
*/
|
||||
boolean updateIndex(String fieldName, Map<String, Object> fieldProperties);
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
* @param data
|
||||
@@ -40,4 +49,20 @@ public interface IElasticSearchIndexService {
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -5,11 +5,15 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.xboe.constants.CaseAiConstants;
|
||||
import com.xboe.core.CurrentUser;
|
||||
import com.xboe.core.orm.FieldFilters;
|
||||
import com.xboe.enums.CaseAiChatErrCodeEnum;
|
||||
import com.xboe.enums.CaseAiChatStatusEnum;
|
||||
import com.xboe.module.boecase.dao.CaseAiConversationsDao;
|
||||
import com.xboe.module.boecase.dao.CaseDocumentLogDao;
|
||||
import com.xboe.module.boecase.dao.CasesDao;
|
||||
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.CaseDocumentLog;
|
||||
import com.xboe.module.boecase.entity.Cases;
|
||||
@@ -19,7 +23,6 @@ import com.xboe.module.boecase.service.ICaseAiChatService;
|
||||
import com.xboe.module.boecase.service.IElasticSearchIndexService;
|
||||
import com.xboe.module.boecase.vo.CaseAiMessageVo;
|
||||
import com.xboe.module.boecase.vo.CaseReferVo;
|
||||
import com.xboe.module.boecase.entity.AiChatConversationData;
|
||||
import com.xboe.module.boecase.vo.ConversationExcelVo;
|
||||
import com.xboe.system.organization.vo.OrgSimpleVo;
|
||||
import com.xboe.system.user.service.IUserService;
|
||||
@@ -45,16 +48,18 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
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.transaction.annotation.Transactional;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
import javax.jms.Topic;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -99,6 +104,12 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
@Autowired
|
||||
private CasesDao casesDao;
|
||||
|
||||
@Autowired
|
||||
private JmsTemplate jmsTemplate;
|
||||
|
||||
@Autowired
|
||||
private Topic topic;
|
||||
|
||||
// 用于存储会话ID与EventSource的映射关系,以便能够中断特定会话
|
||||
private final Map<String, EventSource> conversationEventSourceMap = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -129,6 +140,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
conversationData.setQuery(caseAiChatDto.getQuery());
|
||||
conversationData.setConversationId(conversationId);
|
||||
conversationData.setUserId(userId);
|
||||
conversationData.setStatus(CaseAiChatErrCodeEnum.SUCCESS.getCode());
|
||||
|
||||
String kId = caseAiProperties.getCaseKnowledgeId();
|
||||
JSONObject chatParam = new JSONObject();
|
||||
@@ -164,6 +176,8 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
errMessage(sseEmitter, conversationId, CaseAiConstants.CHAT_SYS_ERR_MSG);
|
||||
// 先响应给前端
|
||||
sseEmitter.complete();
|
||||
conversationData.setStatus(CaseAiChatErrCodeEnum.AIOT_ERROR.getCode());
|
||||
conversationData.setErrorMsg("获取AccessToken时发生异常");
|
||||
conversationData.appendAnswer(CaseAiConstants.CHAT_SYS_ERR_MSG);
|
||||
saveConversationData(conversationData);
|
||||
return sseEmitter;
|
||||
@@ -173,6 +187,8 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
errMessage(sseEmitter, conversationId, CaseAiConstants.CHAT_SYS_ERR_MSG);
|
||||
// 先响应给前端
|
||||
sseEmitter.complete();
|
||||
conversationData.setStatus(CaseAiChatErrCodeEnum.AIOT_ERROR.getCode());
|
||||
conversationData.setErrorMsg("获取AccessToken时发生异常" + e.getMessage());
|
||||
conversationData.appendAnswer(CaseAiConstants.CHAT_SYS_ERR_MSG);
|
||||
saveConversationData(conversationData);
|
||||
return sseEmitter;
|
||||
@@ -190,6 +206,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
EventSourceListener listener = new EventSourceListener() {
|
||||
@Override
|
||||
public void onOpen(@NotNull EventSource eventSource, @NotNull Response response) {
|
||||
log.info("调用接口 [{}] 接口开始监听", request.url());
|
||||
// 检查contentType
|
||||
String contentType = response.header("Content-Type");
|
||||
if (contentType == null || !contentType.contains("text/event-stream")) {
|
||||
@@ -223,13 +240,14 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
|
||||
errMessage(sseEmitter, conversationId, sseContent);
|
||||
sseEmitter.complete();
|
||||
conversationData.setStatus(CaseAiChatErrCodeEnum.AIOT_ERROR.getCode());
|
||||
conversationData.setErrorMsg(sseContent);
|
||||
conversationData.appendAnswer(sseContent);
|
||||
saveConversationData(conversationData);
|
||||
// 关闭eventSource
|
||||
eventSource.cancel();
|
||||
return;
|
||||
}
|
||||
log.info("调用接口 [{}] 接口开始监听", request.url());
|
||||
// 将EventSource存储到Map中,以便后续可以中断
|
||||
conversationEventSourceMap.put(conversationId, eventSource);
|
||||
}
|
||||
@@ -278,6 +296,8 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
// 异常问题,取message内容
|
||||
String message = jsonData.getString("message");
|
||||
errMessage(sseEmitter, conversationId, message);
|
||||
conversationData.setStatus(CaseAiChatErrCodeEnum.AIOT_ERROR.getCode());
|
||||
conversationData.setErrorMsg(jsonData.toJSONString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -336,6 +356,8 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
// 从Map中移除失败的会话
|
||||
conversationEventSourceMap.remove(conversationId);
|
||||
// 即使失败,也要将已有的对话数据保存到ES
|
||||
conversationData.setStatus(CaseAiChatErrCodeEnum.AIOT_ERROR.getCode());
|
||||
conversationData.setErrorMsg(errorMessage);
|
||||
conversationData.appendAnswer(errorMessage);
|
||||
saveConversationData(conversationData);
|
||||
}
|
||||
@@ -343,7 +365,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
|
||||
// 8. 执行HTTP请求
|
||||
OkHttpClient client = new OkHttpClient.Builder()
|
||||
.connectTimeout(60, TimeUnit.SECONDS)
|
||||
.connectTimeout(100, TimeUnit.SECONDS)
|
||||
.writeTimeout(600, TimeUnit.SECONDS)
|
||||
.readTimeout(600, TimeUnit.SECONDS)
|
||||
.callTimeout(600, TimeUnit.SECONDS)
|
||||
@@ -746,8 +768,8 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
jsonData.put("content", message);
|
||||
|
||||
JSONObject finishData = new JSONObject();
|
||||
jsonData.put("status", 4);
|
||||
jsonData.put("content", "");
|
||||
finishData.put("status", 4);
|
||||
finishData.put("content", "");
|
||||
try {
|
||||
sseEmitter.send(conversationData.toJSONString());
|
||||
sseEmitter.send(jsonData.toJSONString());
|
||||
@@ -760,6 +782,22 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
|
||||
@Override
|
||||
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);
|
||||
if (eventSource != null) {
|
||||
try {
|
||||
@@ -767,17 +805,61 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
eventSource.cancel();
|
||||
// 注意:cancel()会触发onFailure回调,在onFailure中会清理资源
|
||||
log.info("成功发送停止会话 {} 的指令", conversationId);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error("停止会话 {} 输出时发生异常", conversationId, e);
|
||||
// 即使出现异常,也从Map中移除,避免内存泄漏
|
||||
conversationEventSourceMap.remove(conversationId);
|
||||
return false;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -859,6 +941,8 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
headerRow.createCell(4).setCellValue("回答");
|
||||
headerRow.createCell(5).setCellValue("开始时间");
|
||||
headerRow.createCell(6).setCellValue("问答时长(秒)");
|
||||
headerRow.createCell(7).setCellValue("消息状态");
|
||||
headerRow.createCell(8).setCellValue("错误信息");
|
||||
|
||||
// 内容行
|
||||
if (!excelDataList.isEmpty()) {
|
||||
@@ -879,8 +963,22 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
row.createCell(2).setCellValue(excelData.getUser());
|
||||
row.createCell(3).setCellValue(message.getQuery() != null ? message.getQuery() : "");
|
||||
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);
|
||||
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、会话名称、用户三列)
|
||||
|
||||
@@ -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);
|
||||
// 由于接口权限,目前采用不回调,而是通过批处理的方式,处理文件状态
|
||||
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);
|
||||
// 由于接口权限,目前采用不回调,而是通过批处理的方式,处理文件状态
|
||||
if (caseAiProperties.isFileUploadUseCallback()) {
|
||||
@@ -650,7 +652,8 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
.findList(CaseDocumentLog.class, 1,
|
||||
OrderCondition.desc("sysCreateTime"),
|
||||
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()) {
|
||||
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);
|
||||
// 由于接口权限,目前采用不回调,而是通过批处理的方式,处理文件状态
|
||||
if (caseAiProperties.isFileUploadUseCallback()) {
|
||||
@@ -1358,6 +1362,7 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
caseLog.setRunStatus(CaseDocumentLogRunStatusEnum.COMPLETED.getCode());
|
||||
caseLog.setOptStatus(CaseDocumentLogOptStatusEnum.SUCCESS.getCode());
|
||||
caseLog.setCaseStatus(CaseDocumentLogCaseStatusEnum.SUCCESS.getCode());
|
||||
caseLog.setMetadataStatus(1);
|
||||
needUpdate = true;
|
||||
// log.info("文档向量化成功,更新状态,taskId: {}, caseId: {}", caseLog.getTaskId(), caseLog.getCaseId());
|
||||
} 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.CaseReferVo;
|
||||
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.index.IndexRequest;
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.client.indices.CreateIndexRequest;
|
||||
import org.elasticsearch.client.indices.CreateIndexResponse;
|
||||
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.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -121,6 +132,36 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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 boolean createData(AiChatConversationData conversationData) {
|
||||
if (elasticsearchClient == null) {
|
||||
@@ -141,6 +182,9 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
|
||||
esData.put("timestamp", now.toString());
|
||||
esData.put("durationSeconds", Duration.between(conversationData.getStartTime(), now).getSeconds());
|
||||
|
||||
esData.put("status", conversationData.getStatus());
|
||||
esData.put("errorMsg", conversationData.getErrorMsg());
|
||||
|
||||
// 构建 caseRefer 数据
|
||||
JSONArray caseReferArray = new JSONArray();
|
||||
for (CaseReferVo caseRefer : conversationData.getCaseRefers()) {
|
||||
@@ -227,6 +271,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
|
||||
if (sourceMap.containsKey("caseRefer")) {
|
||||
Object caseReferObj = sourceMap.get("caseRefer");
|
||||
@@ -253,6 +311,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;
|
||||
} catch (Exception e) {
|
||||
log.error("解析ES消息数据异常", e);
|
||||
@@ -260,6 +327,78 @@ 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) {
|
||||
list.add(data);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("从 ES 中查询到 {} 条消息记录", list.size());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("从 ES 查询消息异常", e);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取ai_chat_messages索引的字段映射配置
|
||||
* 根据项目中的会话消息数据结构规范定义映射
|
||||
@@ -267,70 +406,15 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
|
||||
* @return JSON格式的映射配置
|
||||
*/
|
||||
private String getAiChatMessagesMapping() {
|
||||
return "{\n" +
|
||||
" \"properties\": {\n" +
|
||||
" \"conversationId\": {\n" +
|
||||
" \"type\": \"keyword\",\n" +
|
||||
" \"index\": true\n" +
|
||||
" },\n" +
|
||||
" \"query\": {\n" +
|
||||
" \"type\": \"text\",\n" +
|
||||
" \"analyzer\": \"ik_max_word\",\n" +
|
||||
" \"search_analyzer\": \"ik_smart\",\n" +
|
||||
" \"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" +
|
||||
"}";
|
||||
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("case_ai_index.json");
|
||||
if (inputStream != null) {
|
||||
try (InputStreamReader isr = new InputStreamReader(inputStream);
|
||||
BufferedReader reader = new BufferedReader(isr)) {
|
||||
return reader.lines().collect(Collectors.joining(System.lineSeparator()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Resource read error: case_ai_index.json", e);
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Resource not found: case_ai_index.json");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.xboe.module.boecase.task;
|
||||
|
||||
import com.xboe.common.OrderCondition;
|
||||
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.CaseDocumentLogOptStatusEnum;
|
||||
import com.xboe.enums.CaseDocumentLogOptTypeEnum;
|
||||
@@ -43,7 +46,39 @@ public class CaseUploadTask {
|
||||
@Autowired
|
||||
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")
|
||||
public void oldDataUploadJob() {
|
||||
@@ -142,25 +177,44 @@ public class CaseUploadTask {
|
||||
* @return 案例列表
|
||||
*/
|
||||
private List<Cases> findCasesToProcess(String lastProcessedId) {
|
||||
com.xboe.core.orm.QueryBuilder queryBuilder = com.xboe.core.orm.QueryBuilder.from(Cases.class);
|
||||
queryBuilder.addFilter(com.xboe.core.orm.FieldFilters.eq("deleted", false));
|
||||
QueryBuilder queryBuilder = QueryBuilder.from(Cases.class);
|
||||
queryBuilder.addFilter(FieldFilters.eq("deleted", false));
|
||||
// 只处理有文件路径的案例
|
||||
queryBuilder.addFilter(com.xboe.core.orm.FieldFilters.isNotNull("filePath"));
|
||||
queryBuilder.addFilter(com.xboe.core.orm.FieldFilters.ne("filePath", ""));
|
||||
queryBuilder.addFilter(FieldFilters.isNotNull("filePath"));
|
||||
queryBuilder.addFilter(FieldFilters.ne("filePath", ""));
|
||||
|
||||
// 如果有上次处理的ID,则从该ID之后开始查询
|
||||
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);
|
||||
|
||||
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) {
|
||||
stringRedisTemplate.opsForValue().set(CASE_UPLOAD_LAST_ID_KEY, currentLastId);
|
||||
log.info("已处理案例,最后一条记录ID已更新为: {}", currentLastId);
|
||||
|
||||
@@ -40,4 +40,31 @@ public class CaseAiMessageVo {
|
||||
* 建议列表
|
||||
*/
|
||||
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:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 192.168.0.253:8848
|
||||
server-addr: 192.168.10.74:8848
|
||||
config:
|
||||
server-addr: 192.168.0.253:8848
|
||||
server-addr: 192.168.10.74:8848
|
||||
redis:
|
||||
database: 1
|
||||
host: 192.168.0.253
|
||||
password: boe@123
|
||||
port: 6379
|
||||
database: 2
|
||||
host: 39.104.123.58
|
||||
password: Ebiz2020
|
||||
port: 6378
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: none
|
||||
datasource:
|
||||
driverClassName: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://192.168.0.253:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull
|
||||
username: root
|
||||
password: boe#1234A
|
||||
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: ebiz_ai
|
||||
password: ebiz_ai123
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
hikari:
|
||||
auto-commit: true
|
||||
@@ -35,6 +35,12 @@ spring:
|
||||
connection-timeout: 30000
|
||||
max-lifetime: 1800000
|
||||
maximum-pool-size: 20
|
||||
activemq:
|
||||
broker-url: tcp://192.168.10.74:61616
|
||||
user: admin
|
||||
password: admin
|
||||
jms:
|
||||
pub-sub-domain: true
|
||||
logging:
|
||||
level:
|
||||
org:
|
||||
@@ -107,7 +113,7 @@ aop-log-record:
|
||||
#不进行拦截的包或者类
|
||||
excludeClassNames:
|
||||
activemq:
|
||||
broker-url: tcp://192.168.0.253:61616
|
||||
broker-url: tcp://192.168.10.74:61616
|
||||
user: admin
|
||||
password: admin
|
||||
elasticsearch:
|
||||
|
||||
@@ -40,6 +40,12 @@ spring:
|
||||
web:
|
||||
resources:
|
||||
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:
|
||||
port: 9090
|
||||
tomcat:
|
||||
|
||||
@@ -33,6 +33,12 @@ spring:
|
||||
connection-timeout: 30000
|
||||
max-lifetime: 1800000
|
||||
maximum-pool-size: 20
|
||||
activemq:
|
||||
broker-url: tcp://10.251.113.100:61616
|
||||
user: admin
|
||||
password: admin
|
||||
jms:
|
||||
pub-sub-domain: true
|
||||
logging:
|
||||
level:
|
||||
org:
|
||||
@@ -308,6 +314,7 @@ xboe:
|
||||
- "120434"
|
||||
- "126466"
|
||||
- "98050020"
|
||||
- "10928732"
|
||||
alert-email-recipients:
|
||||
- chengmeng@boe.com.cn
|
||||
- liyubing@boe.com.cn
|
||||
|
||||
@@ -40,6 +40,12 @@ spring:
|
||||
web:
|
||||
resources:
|
||||
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:
|
||||
port: 9090
|
||||
tomcat:
|
||||
|
||||
@@ -50,6 +50,9 @@ ok:
|
||||
write-timeout: 300
|
||||
max-idle-connections: 200
|
||||
keep-alive-duration: 300
|
||||
activemq:
|
||||
topic:
|
||||
name: case_ai_chat_stop_topic
|
||||
boe:
|
||||
domain: http://127.0.0.1
|
||||
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"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user