提交 88b6c9b3 作者: 925993793@qq.com

事件分析bug修改

上级 7ae25444
......@@ -83,13 +83,14 @@ public class EventAnalysisController {
/**
* 重新生成
*
* @param eventId 事件id
* @param eventId 事件id
* @param versionId 版本id
* @author lkg
* @date 2025/7/17
*/
@GetMapping("/regenerate")
public Result<?> regenerate(@RequestParam String eventId) {
CompletableFuture.runAsync(() -> analysisService.regenerate(eventId));
public Result<?> regenerate(@RequestParam String eventId, @RequestParam(required = false) String versionId) {
CompletableFuture.runAsync(() -> analysisService.regenerate(eventId, versionId));
return Result.OK("重新生成中,请稍后查看", null);
}
......
......@@ -184,7 +184,7 @@ public class EventManageController {
e.printStackTrace();
}
//立马执行一次事件分析
analysisService.regenerate(event.getId());
analysisService.regenerate(event.getId(),null);
});
return Result.OK();
} else {
......
package com.zzsn.event.controller.common;
import cn.hutool.core.bean.BeanException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zzsn.event.constant.Result;
import com.zzsn.event.entity.Event;
import com.zzsn.event.entity.EventAnalysisVersion;
import com.zzsn.event.entity.EventAnalysisVersionRecord;
import com.zzsn.event.entity.EventLlmConfig;
import com.zzsn.event.enums.AnalysisColumnEnum;
import com.zzsn.event.service.*;
import com.zzsn.event.util.DateUtil;
import com.zzsn.event.vo.EventLlmConfigModifyVO;
import com.zzsn.event.vo.EventVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
......@@ -68,49 +74,42 @@ public class LLmConfigController {
/**
* 编辑事件栏目的大模型配置信息,同时触发大模型更新结果
*
* @param eventLlmConfig 大模型配置信息
* @param eventLlmConfigModifyVO 大模型配置信息
* @author lkg
* @date 2025/7/28
*/
@PostMapping("/modifySingle")
public Result<?> modifySingle(@RequestBody EventLlmConfig eventLlmConfig) {
llmConfigService.modifySingle(eventLlmConfig);
CompletableFuture.runAsync(() ->{
public Result<?> modifySingle(@RequestBody EventLlmConfigModifyVO eventLlmConfigModifyVO) {
String llmResult = null;
String versionId = eventLlmConfigModifyVO.getVersionId();
if (StringUtils.isEmpty(versionId)) {
return Result.FAIL("请选择要修改的版本");
}
try {
EventLlmConfig eventLlmConfig = new EventLlmConfig();
BeanUtils.copyProperties(eventLlmConfigModifyVO, eventLlmConfig);
llmConfigService.modifySingle(eventLlmConfig);
AnalysisColumnEnum analysisColumnEnum = AnalysisColumnEnum.getByCode(eventLlmConfig.getColumnCode());
if (analysisColumnEnum != null) {
String eventId = eventLlmConfig.getEventId();
EventVO event = eventService.queryInfo(eventId);
Event event = eventService.getById(eventId);
String eventName = event.getEventName();
log.info("{}-事件分析【{}】重新生成逻辑完成。", eventName, analysisColumnEnum.getName());
String content = "事件标题;" + eventName + "\n事件摘要:" + event.getEventDescribe();
//调用大模型更细结果
String llmResult = analysisService.llmResult(eventId,content, null, null, eventLlmConfig.getColumnCode());
EventAnalysisVersion eventAnalysisVersion = eventAnalysisVersionService.latestVersion(eventId);
String versionId;
if (eventAnalysisVersion == null) {
eventAnalysisVersion = new EventAnalysisVersion();
eventAnalysisVersion.setEventId(eventId);
eventAnalysisVersion.setVersionName("版本" + DateUtil.dateToString(new Date()));
eventAnalysisVersionService.save(eventAnalysisVersion);
versionId = eventAnalysisVersion.getId();
} else {
versionId = eventAnalysisVersion.getId();
}
EventAnalysisVersionRecord versionRecord = EventAnalysisVersionRecord.of(versionId, analysisColumnEnum, llmResult);
LambdaQueryWrapper<EventAnalysisVersionRecord> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(EventAnalysisVersionRecord::getVersionId, versionId).eq(EventAnalysisVersionRecord::getColumnCode, eventLlmConfig.getColumnCode());
EventAnalysisVersionRecord oldVersionRecord = eventAnalysisVersionRecordService.getOne(queryWrapper);
if (oldVersionRecord != null) {
oldVersionRecord.setReturnData(llmResult);
eventAnalysisVersionRecordService.updateById(oldVersionRecord);
} else {
eventAnalysisVersionRecordService.save(versionRecord);
}
llmResult = analysisService.llmResult(eventId,content, null, null, eventLlmConfig.getColumnCode());
log.info("{}-事件分析【{}】重新生成逻辑完成。", eventName, analysisColumnEnum.getName());
} else {
log.info("未找到对应的事件栏目【{}】", eventLlmConfig.getColumnCode());
}
});
return Result.OK();
//更新返回结果
String finalLlmResult = llmResult;
CompletableFuture.runAsync(() ->{
eventAnalysisVersionRecordService.modify(versionId, analysisColumnEnum, finalLlmResult);
});
} catch (Exception e) {
log.info("事件栏目【{}】,结果更新失败", eventLlmConfigModifyVO.getColumnCode());
e.printStackTrace();
}
return Result.OK(llmResult);
}
}
......@@ -291,7 +291,7 @@ public class EventDataController {
e.printStackTrace();
}
//立马执行一次事件分析
analysisService.regenerate(event.getId());
analysisService.regenerate(event.getId(),null);
});
return Result.OK();
} else {
......
......@@ -2,7 +2,6 @@ package com.zzsn.event.external.controller;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
......@@ -23,9 +22,13 @@ import com.zzsn.event.service.SubjectSimpleService;
import com.zzsn.event.util.HttpUtil;
import com.zzsn.event.util.ObjectUtil;
import com.zzsn.event.util.RedisUtil;
import com.zzsn.event.vo.*;
import com.zzsn.event.vo.InfoDataSearchCondition;
import com.zzsn.event.vo.SubjectDetailVO;
import com.zzsn.event.vo.SubjectSimpleVO;
import com.zzsn.event.vo.TranslateVO;
import com.zzsn.event.vo.es.DisplayInfo;
import com.zzsn.event.xxljob.service.IXxlJobInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
......@@ -48,6 +51,7 @@ import java.util.concurrent.CompletableFuture;
* @author lkg
* @date 2025/8/12
*/
@Slf4j
@RestController
@RequestMapping("/external")
public class ExternalController {
......@@ -278,6 +282,7 @@ public class ExternalController {
subjectInfoVO.setInfoSourceList(externalSubjectInfoSourceMapService.list(queryWrapper));
try {
HttpUtil.doPost(keywordCrawlerUrl, JSONObject.from(subjectInfoVO), 30000);
log.info("【{}】-通知元搜索采集数据",subjectDetailVO.getSubjectName());
} catch (IOException e) {
e.printStackTrace();
}
......@@ -312,9 +317,9 @@ public class ExternalController {
Subject subject = subjectService.getById(subjectId);
params.put("subject", subject.getSubjectName());
params.put("summaryList", summaryList);
String languageCN = "中文";
String languageCN = "中文简体";
if ("zh-CN".equals(language)) {
languageCN = "中文";
languageCN = "中文简体";
} else if ("en".equals(language)) {
languageCN = "英文";
} else if ("ja".equals(language)) {
......
......@@ -101,7 +101,7 @@ public interface AnalysisService {
* @author lkg
* @date 2025/7/7
*/
void regenerate(String eventId);
void regenerate(String eventId,String versionId);
/**
* 导出ppt
......
......@@ -2,14 +2,34 @@ package com.zzsn.event.service;
import com.zzsn.event.entity.EventAnalysisVersionRecord;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.event.enums.AnalysisColumnEnum;
/**
* @author lenovo
* @description 针对表【event_analysis_version_record(事件分析版本记录表)】的数据库操作Service
* @createDate 2025-07-16 16:34:46
*/
* @author lenovo
* @description 针对表【event_analysis_version_record(事件分析版本记录表)】的数据库操作Service
* @createDate 2025-07-16 16:34:46
*/
public interface EventAnalysisVersionRecordService extends IService<EventAnalysisVersionRecord> {
/**
* 获取版本下的数据
*
* @param versionId 版本id
* @param columnCode 栏目编码
* @author lkg
* @date 2025/8/19
*/
String getVersionData(String versionId, Integer columnCode);
/**
* 新增/编辑版本数据
*
* @param versionId 版本id
* @param analysisColumnEnum 栏目枚举
* @param data 结果数据
* @author lkg
* @date 2025/8/19
*/
void modify(String versionId, AnalysisColumnEnum analysisColumnEnum, String data);
}
......@@ -342,6 +342,7 @@ public class AnalysisServiceImpl implements AnalysisService {
params.put("impactOutline", impact);
String impactDetail = llmService.model(detailConfig.getLlmName(),null, detailConfig.getLlmPrompt(), params.toJSONString());
impact.put("impactDetail", impactDetail);
log.info("{}-事件分析【{}-{}详情】重新生成逻辑完成。", event.getEventName(), AnalysisColumnEnum.IMPACT_ASSESSMENT.getName(),impact.getString("theme"));
}
result = JSON.toJSONString(impactList);
} else if (llmConfig.getColumnCode().equals(AnalysisColumnEnum.DRIVING_FACTORS.getCode())) {
......@@ -360,14 +361,45 @@ public class AnalysisServiceImpl implements AnalysisService {
}
@Override
public void regenerate(String eventId) {
List<EventLlmConfig> configList = eventLlmConfigService.getConfigList(eventId);
public void regenerate(String eventId,String versionId) {
final List<EventLlmConfig> configList = eventLlmConfigService.getConfigList(eventId);
String today = DateUtil.dateToString(new Date());
//保存版本信息
String versionId = saveVersion(eventId, today);
EventVO event = eventService.queryInfo(eventId);
if (StringUtils.isEmpty(versionId)) {
versionId = saveVersion(eventId, today);
}
final EventVO event = eventService.queryInfo(eventId);
String eventName = event.getEventName();
log.info("{}-事件分析重新生成逻辑开始。。。", eventName);
int attempts = 0;
do {
String finalVersionId = versionId;
Thread thread = new Thread(() -> {
generate(event, finalVersionId, configList);
});
thread.start();
try {
Thread.sleep(1000 * 30);
} catch (InterruptedException e) {
e.printStackTrace();
}
LambdaQueryWrapper<EventAnalysisVersionRecord> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(EventAnalysisVersionRecord::getVersionId, versionId);
List<EventAnalysisVersionRecord> list = eventAnalysisVersionRecordService.list(queryWrapper);
if (list.size() < 1) {
thread.interrupt();
attempts ++;
} else {
break;
}
} while (attempts < 3);
log.info("{}-事件分析重新生成逻辑完成。", eventName);
}
private void generate(EventVO event,String versionId,List<EventLlmConfig> configList){
String eventId = event.getId();
String eventName = event.getEventName();
String eventDescribe = event.getEventDescribe();
//核心摘要
Integer ynManualEdit = event.getYnManualEdit();
......@@ -384,33 +416,8 @@ public class AnalysisServiceImpl implements AnalysisService {
eventService.update(update);
}
}
EventAnalysisVersionRecord coreSummaryRecord = EventAnalysisVersionRecord.of(versionId, AnalysisColumnEnum.CORE_SUMMARY, eventDescribe);
eventAnalysisVersionRecordService.save(coreSummaryRecord);
eventAnalysisVersionRecordService.modify(versionId,AnalysisColumnEnum.CORE_SUMMARY, eventDescribe);
log.info("{}-事件分析【{}】重新生成逻辑完成。", eventName, AnalysisColumnEnum.CORE_SUMMARY.getName());
//事件脉络
//List<Map<String, Object>> eventContext = eventContextService.eventContext(eventId);
//if (CollectionUtils.isNotEmpty(eventContext)) {
// EventAnalysisVersionRecord record = EventAnalysisVersionRecord.of(versionId, AnalysisColumnEnum.EVENT_CONTEXT, JSON.toJSONString(eventContext));
// records.add(record);
// log.info("{}-事件分析【{}】重新生成逻辑完成。", eventName, AnalysisColumnEnum.EVENT_CONTEXT.getName());
//}
//关键词趋势分析
/*int count = esService.count(eventId, null, null);
if (count > 0) {
List<CountVO> wordTrend = this.wordTrend(eventId, null, null);
if (CollectionUtils.isNotEmpty(wordTrend)) {
EventAnalysisVersionRecord record = EventAnalysisVersionRecord.of(versionId, AnalysisColumnEnum.KEYWORD_TREND, JSON.toJSONString(wordTrend));
eventAnalysisVersionRecordService.save(record);
log.info("{}-事件分析【{}】重新生成逻辑完成。", eventName, AnalysisColumnEnum.KEYWORD_TREND.getName());
}
//关键词共现关系
List<CoOccurrenceVO> coOccurrenceVOS = this.coOccurrence(eventId, null, null);
if (CollectionUtils.isNotEmpty(coOccurrenceVOS)) {
EventAnalysisVersionRecord record = EventAnalysisVersionRecord.of(versionId, AnalysisColumnEnum.CO_OCCURRENCE, JSON.toJSONString(coOccurrenceVOS));
eventAnalysisVersionRecordService.save(record);
log.info("{}-事件分析【{}】重新生成逻辑完成。", eventName, AnalysisColumnEnum.CO_OCCURRENCE.getName());
}
}*/
//大模型相关逻辑生成的结果(影响评估,举措建议等)
List<EventLlmConfig> collect = configList.stream()
.filter(e -> !e.getColumnCode().equals(AnalysisColumnEnum.CORE_SUMMARY.getCode())
......@@ -422,17 +429,16 @@ public class AnalysisServiceImpl implements AnalysisService {
AnalysisColumnEnum analysisColumnEnum = AnalysisColumnEnum.getByCode(config.getColumnCode());
if (analysisColumnEnum != null) {
String llmResult = this.llmResult(event,content, null, null, config);
EventAnalysisVersionRecord record = EventAnalysisVersionRecord.of(versionId, analysisColumnEnum, llmResult);
eventAnalysisVersionRecordService.save(record);
eventAnalysisVersionRecordService.modify(versionId, analysisColumnEnum, llmResult);
}
log.info("{}-事件分析【{}】重新生成逻辑完成。", eventName, config.getColumnName());
} catch (Exception e) {
e.printStackTrace();
}
}
log.info("{}-事件分析重新生成逻辑完成。", eventName);
}
@Override
public String exportPPT(String eventId,String versionId, JSONArray content) {
String pptFile = null;
......
......@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.event.entity.EventAnalysisVersionRecord;
import com.zzsn.event.enums.AnalysisColumnEnum;
import com.zzsn.event.service.EventAnalysisVersionRecordService;
import com.zzsn.event.mapper.EventAnalysisVersionRecordMapper;
import org.springframework.stereotype.Service;
......@@ -29,6 +30,20 @@ public class EventAnalysisVersionRecordServiceImpl extends ServiceImpl<EventAnal
}
return result;
}
@Override
public void modify(String versionId, AnalysisColumnEnum analysisColumnEnum, String data) {
EventAnalysisVersionRecord versionRecord = EventAnalysisVersionRecord.of(versionId, analysisColumnEnum, data);
LambdaQueryWrapper<EventAnalysisVersionRecord> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(EventAnalysisVersionRecord::getVersionId, versionId)
.eq(EventAnalysisVersionRecord::getColumnCode, analysisColumnEnum.getCode());
int count = this.count(queryWrapper);
if (count > 0) {
this.update(versionRecord, queryWrapper);
} else {
this.save(versionRecord);
}
}
}
......
......@@ -64,7 +64,7 @@ public class AnalysisTask {
if (StringUtils.isNotBlank(estimateStatus)
&& !estimateStatus.equals("已完成") && !estimateStatus.equals("未启用")) {
if (DateUtil.stringToDate(estimateStatus, "yyyy-MM-dd HH:mm:ss").compareTo(deadlineDate) > 0) {
analysisService.regenerate(eventId);
analysisService.regenerate(eventId,null);
}
}
});
......
package com.zzsn.event.vo;
import com.zzsn.event.entity.EventLlmConfig;
import lombok.Data;
/**
* 模型配置编辑对象
*
* @author lkg
* @date 2025/8/19
*/
@Data
public class EventLlmConfigModifyVO extends EventLlmConfig {
private String versionId;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论