mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-06 17:36:47 +08:00
feat: AI消息查询功能完善
This commit is contained in:
@@ -4,6 +4,7 @@ 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.CaseAiMsgLikeDto;
|
||||||
|
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;
|
||||||
@@ -18,7 +19,6 @@ 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.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -121,6 +121,22 @@ public class CaseAiChatApi extends ApiBaseController {
|
|||||||
return error("保存失败", e.getMessage());
|
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查看会话内消息记录
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ 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.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;
|
||||||
@@ -81,4 +82,11 @@ public interface ICaseAiChatService {
|
|||||||
* @param caseAiMsgLikeDto
|
* @param caseAiMsgLikeDto
|
||||||
*/
|
*/
|
||||||
boolean msgFeedback(CaseAiMsgLikeDto caseAiMsgLikeDto);
|
boolean msgFeedback(CaseAiMsgLikeDto caseAiMsgLikeDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取消息
|
||||||
|
*
|
||||||
|
* @param getCaseAiMsgDto
|
||||||
|
*/
|
||||||
|
List<CaseAiMessageVo> getCaseAiMsg(GetCaseAiMsgDto getCaseAiMsgDto);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,4 +48,12 @@ public interface IElasticSearchIndexService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
boolean updateData(String docId, AiChatConversationData data);
|
boolean updateData(String docId, AiChatConversationData data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过docId查询数据
|
||||||
|
*
|
||||||
|
* @param docId ES docId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<CaseAiMessageVo> queryDataByDocId(String docId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ 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.entity.AiChatConversationData;
|
||||||
import com.xboe.module.boecase.dto.CaseAiMsgLikeDto;
|
import com.xboe.module.boecase.dto.CaseAiMsgLikeDto;
|
||||||
import com.xboe.module.boecase.entity.CaseAiConversations;
|
import com.xboe.module.boecase.entity.CaseAiConversations;
|
||||||
@@ -45,10 +46,8 @@ 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.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.jms.JmsException;
|
import org.springframework.jms.JmsException;
|
||||||
import org.springframework.jms.annotation.JmsListener;
|
|
||||||
import org.springframework.jms.core.JmsTemplate;
|
import org.springframework.jms.core.JmsTemplate;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -827,6 +826,29 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
return elasticSearchIndexService.updateData(caseAiMsgLikeDto.getDocId() ,aiChatConversationData);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断Throwable是否为超时类异常
|
* 判断Throwable是否为超时类异常
|
||||||
* @param e
|
* @param e
|
||||||
|
|||||||
@@ -257,6 +257,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);
|
||||||
@@ -296,6 +305,46 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过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索引的字段映射配置
|
* 获取ai_chat_messages索引的字段映射配置
|
||||||
* 根据项目中的会话消息数据结构规范定义映射
|
* 根据项目中的会话消息数据结构规范定义映射
|
||||||
|
|||||||
@@ -40,4 +40,18 @@ public class CaseAiMessageVo {
|
|||||||
* 建议列表
|
* 建议列表
|
||||||
*/
|
*/
|
||||||
private List<String> suggestions;
|
private List<String> suggestions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户点赞状态
|
||||||
|
* -1: 踩
|
||||||
|
* 1:赞
|
||||||
|
* 0/null 无操作
|
||||||
|
*/
|
||||||
|
private String likeStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户踩的时候, 可以填写反馈意见
|
||||||
|
* 反馈意见
|
||||||
|
*/
|
||||||
|
private String feedback;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user