批处理增加入参;

问答增加历史
This commit is contained in:
liu.zixi
2025-11-05 15:42:39 +08:00
parent c701fae5ef
commit 89860eb080
2 changed files with 67 additions and 11 deletions

View File

@@ -108,6 +108,9 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
public SseEmitter chat(CaseAiChatDto caseAiChatDto, CurrentUser currentUser) {
// 1. 获取conversationId
String conversationId = getOrCreateConversationId(caseAiChatDto, currentUser);
// 2. 查询历史
List<CaseAiMessageVo> historyMessages = elasticSearchIndexService.queryData(conversationId);
// 3. 构建请求参数
String userId = currentUser.getCode();
@@ -120,6 +123,20 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
chatParam.put("query", caseAiChatDto.getQuery());
chatParam.put("conversationId", conversationId);
chatParam.put("enableThinking", Objects.equals(caseAiChatDto.getEnableThinking(), 1));
if (historyMessages != null && !historyMessages.isEmpty()) {
// 最多10条历史从后往前
JSONArray historyList = new JSONArray();
int size = historyMessages.size();
int startIndex = Math.max(0, size - 10);
for (int i = startIndex; i < size; i++) {
JSONObject conversationDetail = new JSONObject();
CaseAiMessageVo message = historyMessages.get(i);
conversationDetail.put("query", message.getQuery());
conversationDetail.put("content", message.getAnswer());
historyList.add(conversationDetail);
}
chatParam.put("historyList", historyList);
}
String chatParamStr = chatParam.toJSONString();
log.info("案例问答接口请求参数: [{}]", chatParamStr);

View File

@@ -8,6 +8,7 @@ import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
@Component
@Slf4j
@@ -22,17 +23,55 @@ public class CaseAiChatDataTask {
* cron: 0/10 * * * * ?
*/
@XxlJob("chatDataExcelDownloadJob")
public void chatDataExcelDownload() {
LocalDateTime now = LocalDateTime.now();
// 取上个月的1号00:00:00到上个月最后一天的23:59:59
YearMonth lastMonth = YearMonth.from(now).minusMonths(1);
LocalDateTime startTime = now.minusMonths(1)
.withDayOfMonth(1)
.withHour(0)
.withMinute(0)
.withSecond(0);
LocalDateTime endTime = lastMonth.atEndOfMonth().atTime(23, 59, 59);
public void chatDataExcelDownload(String param) {
LocalDateTime startTime;
LocalDateTime endTime;
if (param != null && !param.isEmpty()) {
// 解析参数,格式应为 "startTime,endTime",例如 "2023-01-01T00:00:00,2023-01-31T23:59:59"
String[] times = param.split(",");
if (times.length == 2) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
try {
startTime = LocalDateTime.parse(times[0], formatter);
endTime = LocalDateTime.parse(times[1], formatter);
log.info("使用参数指定的时间范围: {} 到 {}", startTime, endTime);
} catch (Exception e) {
log.error("解析时间参数失败,使用默认时间范围", e);
// 使用默认逻辑
LocalDateTime now = LocalDateTime.now();
YearMonth lastMonth = YearMonth.from(now).minusMonths(1);
startTime = now.minusMonths(1)
.withDayOfMonth(1)
.withHour(0)
.withMinute(0)
.withSecond(0);
endTime = lastMonth.atEndOfMonth().atTime(23, 59, 59);
}
} else {
// 使用默认逻辑
LocalDateTime now = LocalDateTime.now();
YearMonth lastMonth = YearMonth.from(now).minusMonths(1);
startTime = now.minusMonths(1)
.withDayOfMonth(1)
.withHour(0)
.withMinute(0)
.withSecond(0);
endTime = lastMonth.atEndOfMonth().atTime(23, 59, 59);
}
} else {
// 使用默认逻辑
LocalDateTime now = LocalDateTime.now();
YearMonth lastMonth = YearMonth.from(now).minusMonths(1);
startTime = now.minusMonths(1)
.withDayOfMonth(1)
.withHour(0)
.withMinute(0)
.withSecond(0);
endTime = lastMonth.atEndOfMonth().atTime(23, 59, 59);
}
// 执行
caseAiChatService.downloadConversationExcel(startTime, endTime);
}
}
}