提交 61026bc9 作者: 925993793@qq.com

新版事件分析功能开发:大模型配置、ppt导出等

上级 2b32b387
...@@ -16,6 +16,7 @@ public class Constants { ...@@ -16,6 +16,7 @@ public class Constants {
public static final String SUBJECT_ANALYSIS_PRE = "SUBJECT_ANALYSIS::"; public static final String SUBJECT_ANALYSIS_PRE = "SUBJECT_ANALYSIS::";
//传播路径 //传播路径
public static final String PROPAGATION_KEY = "PROPAGATION_PATH::"; public static final String PROPAGATION_KEY = "PROPAGATION_PATH::";
public static final String CO_OCCURRENCE = "CO_OCCURRENCE::";
public static String[] FETCH_FIELDS_STATISTIC = {"id", "subjectId","title","origin", "publishDate", "sourceAddress"}; public static String[] FETCH_FIELDS_STATISTIC = {"id", "subjectId","title","origin", "publishDate", "sourceAddress"};
public static String[] FETCH_FIELDS_DATA = {"id", "subjectId", "title", "content", "publishDate", "origin", "sourceAddress"}; public static String[] FETCH_FIELDS_DATA = {"id", "subjectId", "title", "content", "publishDate", "origin", "sourceAddress"};
......
...@@ -22,7 +22,6 @@ import com.zzsn.event.util.user.UserUtil; ...@@ -22,7 +22,6 @@ import com.zzsn.event.util.user.UserUtil;
import com.zzsn.event.util.user.UserVo; import com.zzsn.event.util.user.UserVo;
import com.zzsn.event.vo.CoOccurrenceVO; import com.zzsn.event.vo.CoOccurrenceVO;
import com.zzsn.event.vo.CountVO; import com.zzsn.event.vo.CountVO;
import com.zzsn.event.vo.EventVO;
import com.zzsn.event.vo.EventViewVO; import com.zzsn.event.vo.EventViewVO;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
...@@ -31,6 +30,8 @@ import org.apache.commons.lang3.StringUtils; ...@@ -31,6 +30,8 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -51,8 +52,6 @@ import java.util.stream.Collectors; ...@@ -51,8 +52,6 @@ import java.util.stream.Collectors;
public class EventAnalysisController { public class EventAnalysisController {
@Autowired @Autowired
private IEventService eventService;
@Autowired
private EsStatisticsService esStatisticsService; private EsStatisticsService esStatisticsService;
@Autowired @Autowired
private LabelEntityService labelEntityService; private LabelEntityService labelEntityService;
...@@ -65,8 +64,6 @@ public class EventAnalysisController { ...@@ -65,8 +64,6 @@ public class EventAnalysisController {
@Autowired @Autowired
private RedisUtil redisUtil; private RedisUtil redisUtil;
@Autowired @Autowired
private LlmService llmService;
@Autowired
private EventCollectMapService eventCollectMapService; private EventCollectMapService eventCollectMapService;
@Autowired @Autowired
private EventContextService eventContextService; private EventContextService eventContextService;
...@@ -74,6 +71,8 @@ public class EventAnalysisController { ...@@ -74,6 +71,8 @@ public class EventAnalysisController {
private EventAnalysisVersionService eventAnalysisVersionService; private EventAnalysisVersionService eventAnalysisVersionService;
@Autowired @Autowired
private EventAnalysisVersionRecordService eventAnalysisVersionRecordService; private EventAnalysisVersionRecordService eventAnalysisVersionRecordService;
@Autowired
private CommonService commonService;
/** /**
...@@ -106,32 +105,6 @@ public class EventAnalysisController { ...@@ -106,32 +105,6 @@ public class EventAnalysisController {
/** /**
* 核心摘要
*
* @param eventId 事件id
* @param versionId 版本id
* @param model LLM模型
* @author lkg
* @date 2025/7/10
*/
@GetMapping("/coreSummary")
public Result<?> coreSummary(@RequestParam String eventId,
@RequestParam(required = false) String versionId,
@RequestParam(required = false) String model) {
EventVO eventVO = eventService.queryInfo(eventId);
String eventDescribe = eventVO.getEventDescribe();
if (StringUtils.isEmpty(eventDescribe)) {
String prompt = "根据提供的事件名称【name】和对应的关键词【keyword】,关键词【keyword】中'|'表示或;'+'表示与;括号表示优先计算,再结合网络上的相关资讯,生成一段200字左右的核心摘要";
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", eventVO.getEventName());
jsonObject.put("keyword", eventVO.getKeywordsVO().getKeyword());
eventDescribe = llmService.model(model, prompt, jsonObject.toJSONString());
}
return Result.OK(eventDescribe);
}
/**
* 3.4 总体分析 * 3.4 总体分析
* *
* @param eventId 事件id * @param eventId 事件id
...@@ -183,7 +156,8 @@ public class EventAnalysisController { ...@@ -183,7 +156,8 @@ public class EventAnalysisController {
public Result<?> eventContext(@RequestParam String eventId, public Result<?> eventContext(@RequestParam String eventId,
@RequestParam(required = false) String versionId) { @RequestParam(required = false) String versionId) {
if (StringUtils.isNotEmpty(versionId)) { if (StringUtils.isNotEmpty(versionId)) {
return getVersionData(versionId, AnalysisColumnEnum.EVENT_CONTEXT.getCode()); String versionData = getVersionData(versionId, AnalysisColumnEnum.EVENT_CONTEXT.getCode());
return Result.OK(versionData);
} }
List<Map<String, Object>> eventContext = eventContextService.eventContext(eventId); List<Map<String, Object>> eventContext = eventContextService.eventContext(eventId);
return Result.OK(eventContext); return Result.OK(eventContext);
...@@ -273,7 +247,8 @@ public class EventAnalysisController { ...@@ -273,7 +247,8 @@ public class EventAnalysisController {
@RequestParam(required = false) String endTime, @RequestParam(required = false) String endTime,
@RequestParam(required = false) String versionId) { @RequestParam(required = false) String versionId) {
if (StringUtils.isNotEmpty(versionId)) { if (StringUtils.isNotEmpty(versionId)) {
return getVersionData(versionId, AnalysisColumnEnum.KEYWORD_TREND.getCode()); String versionData = getVersionData(versionId, AnalysisColumnEnum.KEYWORD_TREND.getCode());
return Result.OK(versionData);
} }
List<CountVO> countVOS = analysisService.wordTrend(eventId, startTime, endTime); List<CountVO> countVOS = analysisService.wordTrend(eventId, startTime, endTime);
return Result.OK(countVOS); return Result.OK(countVOS);
...@@ -294,11 +269,22 @@ public class EventAnalysisController { ...@@ -294,11 +269,22 @@ public class EventAnalysisController {
@RequestParam(required = false) String endTime, @RequestParam(required = false) String endTime,
@RequestParam(required = false) String versionId) { @RequestParam(required = false) String versionId) {
if (StringUtils.isNotEmpty(versionId)) { if (StringUtils.isNotEmpty(versionId)) {
return getVersionData(versionId, AnalysisColumnEnum.CO_OCCURRENCE.getCode()); String versionData = getVersionData(versionId, AnalysisColumnEnum.CO_OCCURRENCE.getCode());
return Result.OK(versionData);
} }
//增加缓存逻辑,提升查询效率
String key = Constants.SUBJECT_ANALYSIS_PRE + Constants.CO_OCCURRENCE + eventId;
Object cacheObject = redisUtil.get(key);
if (cacheObject != null) {
return Result.OK(cacheObject);
} else {
List<CoOccurrenceVO> coOccurrenceVOS = analysisService.coOccurrence(eventId, startTime, endTime); List<CoOccurrenceVO> coOccurrenceVOS = analysisService.coOccurrence(eventId, startTime, endTime);
if (CollectionUtils.isNotEmpty(coOccurrenceVOS)) {
redisUtil.set(key, coOccurrenceVOS,3600 * 24);
}
return Result.OK(coOccurrenceVOS); return Result.OK(coOccurrenceVOS);
} }
}
/** /**
* 事件下情感类标签下资讯数量统计 * 事件下情感类标签下资讯数量统计
...@@ -446,10 +432,11 @@ public class EventAnalysisController { ...@@ -446,10 +432,11 @@ public class EventAnalysisController {
@RequestParam(required = false) String endTime, @RequestParam(required = false) String endTime,
@RequestParam(required = false) String versionId) { @RequestParam(required = false) String versionId) {
if (StringUtils.isNotEmpty(versionId)) { if (StringUtils.isNotEmpty(versionId)) {
return getVersionData(versionId, AnalysisColumnEnum.IMPACT_ASSESSMENT.getCode()); String versionData = getVersionData(versionId, AnalysisColumnEnum.IMPACT_ASSESSMENT.getCode());
return Result.OK(versionData);
} }
//todo String result = analysisService.llmResult(eventId, startTime, endTime, AnalysisColumnEnum.IMPACT_ASSESSMENT.getCode());
return Result.OK(); return Result.OK(result);
} }
/** /**
...@@ -467,10 +454,11 @@ public class EventAnalysisController { ...@@ -467,10 +454,11 @@ public class EventAnalysisController {
@RequestParam(required = false) String endTime, @RequestParam(required = false) String endTime,
@RequestParam(required = false) String versionId) { @RequestParam(required = false) String versionId) {
if (StringUtils.isNotEmpty(versionId)) { if (StringUtils.isNotEmpty(versionId)) {
return getVersionData(versionId, AnalysisColumnEnum.MEASURE_SUGGEST.getCode()); String versionData = getVersionData(versionId, AnalysisColumnEnum.MEASURE_SUGGEST.getCode());
return Result.OK(versionData);
} }
//todo String result = analysisService.llmResult(eventId, startTime, endTime, AnalysisColumnEnum.MEASURE_SUGGEST.getCode());
return Result.OK(); return Result.OK(result);
} }
/** /**
...@@ -488,10 +476,11 @@ public class EventAnalysisController { ...@@ -488,10 +476,11 @@ public class EventAnalysisController {
@RequestParam(required = false) String endTime, @RequestParam(required = false) String endTime,
@RequestParam(required = false) String versionId) { @RequestParam(required = false) String versionId) {
if (StringUtils.isNotEmpty(versionId)) { if (StringUtils.isNotEmpty(versionId)) {
return getVersionData(versionId, AnalysisColumnEnum.KNOWLEDGE_ENTRY.getCode()); String versionData = getVersionData(versionId, AnalysisColumnEnum.KNOWLEDGE_ENTRY.getCode());
return Result.OK(versionData);
} }
//todo String result = analysisService.llmResult(eventId, startTime, endTime, AnalysisColumnEnum.KNOWLEDGE_ENTRY.getCode());
return Result.OK(); return Result.OK(result);
} }
/** /**
...@@ -509,10 +498,11 @@ public class EventAnalysisController { ...@@ -509,10 +498,11 @@ public class EventAnalysisController {
@RequestParam(required = false) String endTime, @RequestParam(required = false) String endTime,
@RequestParam(required = false) String versionId) { @RequestParam(required = false) String versionId) {
if (StringUtils.isNotEmpty(versionId)) { if (StringUtils.isNotEmpty(versionId)) {
return getVersionData(versionId, AnalysisColumnEnum.ENTERPRISE_CASE.getCode()); String versionData = getVersionData(versionId, AnalysisColumnEnum.ENTERPRISE_CASE.getCode());
return Result.OK(versionData);
} }
//todo String result = analysisService.llmResult(eventId, startTime, endTime, AnalysisColumnEnum.ENTERPRISE_CASE.getCode());
return Result.OK(); return Result.OK(result);
} }
/** /**
...@@ -530,10 +520,11 @@ public class EventAnalysisController { ...@@ -530,10 +520,11 @@ public class EventAnalysisController {
@RequestParam(required = false) String endTime, @RequestParam(required = false) String endTime,
@RequestParam(required = false) String versionId) { @RequestParam(required = false) String versionId) {
if (StringUtils.isNotEmpty(versionId)) { if (StringUtils.isNotEmpty(versionId)) {
return getVersionData(versionId, AnalysisColumnEnum.COUNTRY_POLICY.getCode()); String versionData = getVersionData(versionId, AnalysisColumnEnum.COUNTRY_POLICY.getCode());
return Result.OK(versionData);
} }
//todo String result = analysisService.llmResult(eventId, startTime, endTime, AnalysisColumnEnum.COUNTRY_POLICY.getCode());
return Result.OK(); return Result.OK(result);
} }
/** /**
...@@ -551,10 +542,11 @@ public class EventAnalysisController { ...@@ -551,10 +542,11 @@ public class EventAnalysisController {
@RequestParam(required = false) String endTime, @RequestParam(required = false) String endTime,
@RequestParam(required = false) String versionId) { @RequestParam(required = false) String versionId) {
if (StringUtils.isNotEmpty(versionId)) { if (StringUtils.isNotEmpty(versionId)) {
return getVersionData(versionId, AnalysisColumnEnum.DOMESTIC_SIMILAR_EVENT.getCode()); String versionData = getVersionData(versionId, AnalysisColumnEnum.DOMESTIC_SIMILAR_EVENT.getCode());
return Result.OK(versionData);
} }
//todo String result = analysisService.llmResult(eventId, startTime, endTime, AnalysisColumnEnum.DOMESTIC_SIMILAR_EVENT.getCode());
return Result.OK(); return Result.OK(result);
} }
/** /**
...@@ -572,10 +564,11 @@ public class EventAnalysisController { ...@@ -572,10 +564,11 @@ public class EventAnalysisController {
@RequestParam(required = false) String endTime, @RequestParam(required = false) String endTime,
@RequestParam(required = false) String versionId) { @RequestParam(required = false) String versionId) {
if (StringUtils.isNotEmpty(versionId)) { if (StringUtils.isNotEmpty(versionId)) {
return getVersionData(versionId, AnalysisColumnEnum.FOREIGN_SIMILAR_EVENT.getCode()); String versionData = getVersionData(versionId, AnalysisColumnEnum.FOREIGN_SIMILAR_EVENT.getCode());
return Result.OK(versionData);
} }
//todo String result = analysisService.llmResult(eventId, startTime, endTime, AnalysisColumnEnum.FOREIGN_SIMILAR_EVENT.getCode());
return Result.OK(); return Result.OK(result);
} }
...@@ -610,6 +603,18 @@ public class EventAnalysisController { ...@@ -610,6 +603,18 @@ public class EventAnalysisController {
} }
@PostMapping("/exportPPT")
public void exportPPT(@RequestBody JSONObject params, HttpServletResponse response) throws IOException {
String eventId = params.getString("eventId");
JSONArray content = params.getJSONArray("content");
String ppt = analysisService.exportPPT(eventId, content);
if (ppt == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "PPT文件生成失败");
return;
}
commonService.downloadTemplate(response, ppt);
}
/** /**
* 获取事件分析报告详细信息 * 获取事件分析报告详细信息
* *
...@@ -647,23 +652,16 @@ public class EventAnalysisController { ...@@ -647,23 +652,16 @@ public class EventAnalysisController {
* @author lkg * @author lkg
* @date 2025/7/16 * @date 2025/7/16
*/ */
private Result<?> getVersionData(String versionId, Integer columnCode) { private String getVersionData(String versionId, Integer columnCode) {
String result = null;
LambdaQueryWrapper<EventAnalysisVersionRecord> queryWrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<EventAnalysisVersionRecord> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(EventAnalysisVersionRecord::getVersionId, versionId) queryWrapper.eq(EventAnalysisVersionRecord::getVersionId, versionId)
.eq(EventAnalysisVersionRecord::getColumnCode, columnCode); .eq(EventAnalysisVersionRecord::getColumnCode, columnCode);
EventAnalysisVersionRecord eventAnalysisVersionRecord = eventAnalysisVersionRecordService.getOne(queryWrapper); EventAnalysisVersionRecord eventAnalysisVersionRecord = eventAnalysisVersionRecordService.getOne(queryWrapper);
if (eventAnalysisVersionRecord != null) { if (eventAnalysisVersionRecord != null) {
String resType = eventAnalysisVersionRecord.getResType(); result = eventAnalysisVersionRecord.getReturnData();
String returnData = eventAnalysisVersionRecord.getReturnData();
if (resType.equalsIgnoreCase("string")) {
return Result.OK(returnData);
} else if (resType.equalsIgnoreCase("object")) {
return Result.OK(JSONObject.parseObject(returnData));
} else if (resType.equalsIgnoreCase("array")) {
return Result.OK(JSONArray.parseArray(returnData));
}
} }
return Result.OK(); return result;
} }
......
package com.zzsn.event.controller; package com.zzsn.event.controller;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
...@@ -35,7 +34,6 @@ import org.springframework.kafka.core.KafkaTemplate; ...@@ -35,7 +34,6 @@ import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
...@@ -311,7 +309,7 @@ public class EventManageController { ...@@ -311,7 +309,7 @@ public class EventManageController {
/** /**
* 1.7 发布 * 发布
* *
* @return * @return
*/ */
...@@ -325,6 +323,20 @@ public class EventManageController { ...@@ -325,6 +323,20 @@ public class EventManageController {
return Result.OK(); return Result.OK();
} }
/**
* 审核公开状态
*
* @param event 参数
* @author lkg
* @date 2025/7/22
*/
@PostMapping(value = "/checkFacePublic")
public Result<?> checkFacePublic(@RequestBody Event event) {
eventService.update(Wrappers.<Event>lambdaUpdate().eq(Event::getId, event.getId())
.set(Event::getFacePublic, event.getFacePublic()));
return Result.OK();
}
/** /**
......
...@@ -22,14 +22,12 @@ import com.zzsn.event.service.*; ...@@ -22,14 +22,12 @@ import com.zzsn.event.service.*;
import com.zzsn.event.util.tree.Node; import com.zzsn.event.util.tree.Node;
import com.zzsn.event.vo.*; import com.zzsn.event.vo.*;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
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; import java.util.stream.Collectors;
......
...@@ -11,11 +11,9 @@ import com.zzsn.event.constant.Constants; ...@@ -11,11 +11,9 @@ import com.zzsn.event.constant.Constants;
import com.zzsn.event.constant.Result; import com.zzsn.event.constant.Result;
import com.zzsn.event.entity.Event; import com.zzsn.event.entity.Event;
import com.zzsn.event.entity.KeyWords; import com.zzsn.event.entity.KeyWords;
import com.zzsn.event.entity.SysDictItem;
import com.zzsn.event.es.EsService; import com.zzsn.event.es.EsService;
import com.zzsn.event.service.EventSimpleService; import com.zzsn.event.service.*;
import com.zzsn.event.service.IEventService;
import com.zzsn.event.service.IKeyWordsService;
import com.zzsn.event.service.InformationService;
import com.zzsn.event.service.impl.ConfigurationMessageService; import com.zzsn.event.service.impl.ConfigurationMessageService;
import com.zzsn.event.util.*; import com.zzsn.event.util.*;
import com.zzsn.event.util.user.UserUtil; import com.zzsn.event.util.user.UserUtil;
...@@ -37,6 +35,7 @@ import javax.annotation.Resource; ...@@ -37,6 +35,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
/** /**
* 事件 * 事件
...@@ -72,6 +71,8 @@ public class EventDataController { ...@@ -72,6 +71,8 @@ public class EventDataController {
private EsOpUtil esOpUtil; private EsOpUtil esOpUtil;
@Autowired @Autowired
private ObsUtil obsUtil; private ObsUtil obsUtil;
@Autowired
private SysDictItemService dictItemService;
@Value("${translate.url:}") @Value("${translate.url:}")
private String TRANSLATE_URL; private String TRANSLATE_URL;
...@@ -415,6 +416,14 @@ public class EventDataController { ...@@ -415,6 +416,14 @@ public class EventDataController {
} }
@GetMapping("/labelList")
public Result<?> labelList(){
List<SysDictItem> dictItemList = dictItemService.listByDictCode("eventView");
List<SysDictItem> collect = dictItemList.stream().filter(e -> !e.getItemText().equals("无观点")).collect(Collectors.toList());
return Result.OK(collect);
}
/** /**
* 事件资讯分页列表 * 事件资讯分页列表
* *
...@@ -441,8 +450,7 @@ public class EventDataController { ...@@ -441,8 +450,7 @@ public class EventDataController {
@RequestParam(name = "column", defaultValue = "publishDate") String column, @RequestParam(name = "column", defaultValue = "publishDate") String column,
@RequestParam(name = "order", defaultValue = "desc") String order, @RequestParam(name = "order", defaultValue = "desc") String order,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
HttpServletRequest request) {
UserVo currentUser = UserUtil.getLoginUser(); UserVo currentUser = UserUtil.getLoginUser();
String username = currentUser.getUsername(); String username = currentUser.getUsername();
List<String> subjectIdList = new ArrayList<>(); List<String> subjectIdList = new ArrayList<>();
......
package com.zzsn.event.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* 事件大模型信息配置表
* @TableName event_llm_config
*/
@Data
@TableName("event_llm_config")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class EventLlmConfig implements Serializable {
/**
* 主键id
*/
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**
* 事件id
*/
private String eventId;
/**
* 栏目编码
*/
private Integer columnCode;
/**
* 栏目名称
*/
private String columnName;
/**
* 大模型
*/
private String llmName;
/**
* 角色
*/
private String llmRole;
/**
* 提示词
*/
private String llmPrompt;
/**
* 资讯筛选条件
*/
private String articleCondition;
/**
* 是否默认(1-是;0-否)
*/
private Integer ynDefault;
/**
* 创建人
*/
private String createBy;
/**
* 创建时间
*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date createTime;
/**
* 更新人
*/
private String updateBy;
/**
* 更新时间
*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}
...@@ -33,6 +33,10 @@ public enum AnalysisColumnEnum { ...@@ -33,6 +33,10 @@ public enum AnalysisColumnEnum {
FOREIGN_SIMILAR_EVENT(11,"各国类似事件","array", 1), FOREIGN_SIMILAR_EVENT(11,"各国类似事件","array", 1),
//GENERATE_OUTLINE(12,"生成大纲","array", 1),
//GENERATE_PPT(13,"生成ppt","array", 1),
; ;
//栏目编码 //栏目编码
...@@ -76,4 +80,13 @@ public enum AnalysisColumnEnum { ...@@ -76,4 +80,13 @@ public enum AnalysisColumnEnum {
} }
return list; return list;
} }
public static AnalysisColumnEnum getByCode(Integer code) {
for (AnalysisColumnEnum value : AnalysisColumnEnum.values()) {
if (value.code.equals(code)) {
return value;
}
}
return null;
}
} }
package com.zzsn.event.llm; package com.zzsn.event.llm;
import cn.hutool.http.HttpException;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.dashscope.aigc.generation.Generation; import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam; import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult; import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.common.Message; import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role; import com.alibaba.dashscope.common.Role;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -41,6 +46,18 @@ public class LlmServiceImpl implements LlmService { ...@@ -41,6 +46,18 @@ public class LlmServiceImpl implements LlmService {
@Value("${model.qwen.apiKey:}") @Value("${model.qwen.apiKey:}")
private String QWEN_APIKEY; private String QWEN_APIKEY;
@Value("${model.deepseek.url:}")
private String DEEP_SEEK_URL;
@Value("${model.deepseek.api-key:}")
private String DEEP_SEEK_APIKEY;
@Value("${model.doubao.url:}")
private String DOU_BAO_URL;
@Value("${model.doubao.api-key:}")
private String DOU_BAO_APIKEY;
@Value("${model.doubao.default-model:}")
private String DOU_BAO_MODEL;
@Override @Override
public String model(String model, String system, String content) { public String model(String model, String system, String content) {
if (StringUtils.isNotEmpty(model)) { if (StringUtils.isNotEmpty(model)) {
...@@ -48,6 +65,10 @@ public class LlmServiceImpl implements LlmService { ...@@ -48,6 +65,10 @@ public class LlmServiceImpl implements LlmService {
return glmModel(model.replace("glm:", ""), system, content); return glmModel(model.replace("glm:", ""), system, content);
} else if (model.startsWith("qwen")) { } else if (model.startsWith("qwen")) {
return qwenModel(model.replace("qwen:", ""), system, content); return qwenModel(model.replace("qwen:", ""), system, content);
} else if (model.startsWith("deepseek")) {
return deepSeekModel(system, content);
} else if (model.startsWith("doubao")) {
return douBaoModel(system, content);
} }
} }
//默认调用模型 //默认调用模型
...@@ -120,7 +141,65 @@ public class LlmServiceImpl implements LlmService { ...@@ -120,7 +141,65 @@ public class LlmServiceImpl implements LlmService {
return ""; return "";
} }
public String glmPost(String urlstr, JSONObject jsonObject) { public String deepSeekModel(String system, String content) {
try {
Map<String, Object> params = new HashMap<>();
params.put("model", "deepseek-chat");
params.put("stream", false);
Message systemMsg = Message.builder()
.role(Role.SYSTEM.getValue())
.content(system)
.build();
Message userMsg = Message.builder()
.role(Role.USER.getValue())
.content(content)
.build();
List<Message> messages = Arrays.asList(systemMsg, userMsg);
params.put("messages", messages);
HttpResponse execute = HttpUtil.createPost(DEEP_SEEK_URL)
.header("Content-Type", "application/json")
.header("Authorization", "Bearer " + DEEP_SEEK_APIKEY)
.body(JSONUtil.toJsonStr(params))
.execute();
return execute.body();
} catch (HttpException e) {
log.error("deepseek error:{}", e.getMessage(), e);
}
return null;
}
public String douBaoModel(String system, String content) {
try {
Map<String, Object> params = new HashMap<>();
params.put("model", DOU_BAO_MODEL);
Message systemMsg = Message.builder()
.role(Role.SYSTEM.getValue())
.content(system)
.build();
Message userMsg = Message.builder()
.role(Role.USER.getValue())
.content(content)
.build();
List<Message> messages = Arrays.asList(systemMsg, userMsg);
params.put("messages", messages);
HttpResponse execute = HttpUtil.createPost(DOU_BAO_URL)
.header("Content-Type", "application/json")
.header("Authorization", "Bearer " + DOU_BAO_APIKEY)
.body(JSONUtil.toJsonStr(params))
.execute();
String body = execute.body();
JSONObject jsonObject = JSONObject.parseObject(body);
JSONArray choices = jsonObject.getJSONArray("choices");
JSONObject choice = choices.getJSONObject(0);
JSONObject message = choice.getJSONObject("message");
return message.getString("content");
} catch (HttpException e) {
log.error("doubao error:{}", e.getMessage(), e);
}
return null;
}
private String glmPost(String urlstr, JSONObject jsonObject) {
String responseStr = null; String responseStr = null;
try { try {
URL url = new URL(urlstr); URL url = new URL(urlstr);
......
package com.zzsn.event.mapper;
import com.zzsn.event.entity.EventLlmConfig;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* @author lenovo
* @description 针对表【event_llm_config(事件大模型信息配置表)】的数据库操作Mapper
* @createDate 2025-07-21 14:17:40
* @Entity com.zzsn.event.entity.EventLlmConfig
*/
@Mapper
public interface EventLlmConfigMapper extends BaseMapper<EventLlmConfig> {
}
...@@ -352,7 +352,6 @@ ...@@ -352,7 +352,6 @@
order by t1.publish_date desc order by t1.publish_date desc
</otherwise> </otherwise>
</choose> </choose>
limit #{offset}, #{pageSize}
</select> </select>
......
package com.zzsn.event.service; package com.zzsn.event.service;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.zzsn.event.entity.EventLlmConfig;
import com.zzsn.event.entity.SubjectAnalysis; import com.zzsn.event.entity.SubjectAnalysis;
import com.zzsn.event.vo.CoOccurrenceVO; import com.zzsn.event.vo.CoOccurrenceVO;
import com.zzsn.event.vo.CountVO; import com.zzsn.event.vo.CountVO;
...@@ -81,88 +83,34 @@ public interface AnalysisService { ...@@ -81,88 +83,34 @@ public interface AnalysisService {
PropagationPathVo propagationPath(String eventId); PropagationPathVo propagationPath(String eventId);
/** /**
* 影响评估 * 利用大模型生成的结果
* *
* @param eventId 事件id * @param eventName 事件名称
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2025/7/17
*/
Object impactAssessment(String eventId,String startTime,String endTime);
/**
* 决策建议
*
* @param eventId 事件id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2025/7/17
*/
Object measureSuggest(String eventId,String startTime,String endTime);
/**
* 知识词条
*
* @param eventId 事件id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2025/7/17
*/
Object knowledgeEntry(String eventId,String startTime,String endTime);
/**
* 企业案例
*
* @param eventId 事件id
* @param startTime 开始时间 * @param startTime 开始时间
* @param endTime 结束时间 * @param endTime 结束时间
* @param llmConfig 模型配置信息
* @author lkg * @author lkg
* @date 2025/7/17 * @date 2025/7/17
*/ */
Object enterpriseCase(String eventId,String startTime,String endTime); String llmResult(String eventName, String startTime, String endTime, EventLlmConfig llmConfig);
String llmResult(String eventId, String startTime, String endTime, Integer columnCode);
/** /**
* 各国政策 * 重新生成
*
* @param eventId 事件id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2025/7/17
*/
Object countryPolicy(String eventId,String startTime,String endTime);
/**
* 本国类似事件
*
* @param eventId 事件id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2025/7/17
*/
Object domesticSimilarEvent(String eventId,String startTime,String endTime);
/**
* 各国类似事件
* *
* @param eventId 事件id * @param eventId 事件id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg * @author lkg
* @date 2025/7/17 * @date 2025/7/7
*/ */
Object foreignSimilarEvent(String eventId,String startTime,String endTime); void regenerate(String eventId);
/** /**
* 重新生成 * 导出ppt
* *
* @param eventId 事件id * @param eventId 事件id
* @param content 导出内容
* @author lkg * @author lkg
* @date 2025/7/7 * @date 2025/7/19
*/ */
void regenerate(String eventId); String exportPPT(String eventId, JSONArray content);
} }
package com.zzsn.event.service;
import com.zzsn.event.entity.EventLlmConfig;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* @author lenovo
* @description 针对表【event_llm_config(事件大模型信息配置表)】的数据库操作Service
* @createDate 2025-07-21 14:17:40
*/
public interface EventLlmConfigService extends IService<EventLlmConfig> {
List<EventLlmConfig> getConfigList(String eventId);
EventLlmConfig getConfig(String eventId,Integer columnCode);
}
package com.zzsn.event.service.impl; package com.zzsn.event.service.impl;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.obs.services.model.PutObjectResult;
import com.zzsn.event.constant.Constants; import com.zzsn.event.constant.Constants;
import com.zzsn.event.entity.Event; import com.zzsn.event.entity.*;
import com.zzsn.event.entity.EventAnalysisVersion;
import com.zzsn.event.entity.EventAnalysisVersionRecord;
import com.zzsn.event.entity.SubjectAnalysis;
import com.zzsn.event.enums.AnalysisColumnEnum; import com.zzsn.event.enums.AnalysisColumnEnum;
import com.zzsn.event.es.EsService; import com.zzsn.event.es.EsService;
import com.zzsn.event.llm.LlmService; import com.zzsn.event.llm.LlmService;
import com.zzsn.event.service.*; import com.zzsn.event.service.*;
import com.zzsn.event.util.DateUtil; import com.zzsn.event.util.DateUtil;
import com.zzsn.event.util.HotWordUtil; import com.zzsn.event.util.HotWordUtil;
import com.zzsn.event.util.ObsUtil;
import com.zzsn.event.util.ppt.ApiAuthAlgorithm;
import com.zzsn.event.util.ppt.CreateResponse;
import com.zzsn.event.util.ppt.PPTUtil;
import com.zzsn.event.util.ppt.ProgressResponse;
import com.zzsn.event.vo.*; import com.zzsn.event.vo.*;
import com.zzsn.event.vo.es.SpecialInformation; import com.zzsn.event.vo.es.SpecialInformation;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.implementation.bytecode.Throw;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
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 org.springframework.transaction.annotation.Transactional;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -31,6 +41,7 @@ import java.util.stream.Collectors; ...@@ -31,6 +41,7 @@ import java.util.stream.Collectors;
* @description: * @description:
* @date 2022/7/20 11:32 * @date 2022/7/20 11:32
*/ */
@Slf4j
@Service @Service
public class AnalysisServiceImpl implements AnalysisService { public class AnalysisServiceImpl implements AnalysisService {
...@@ -50,6 +61,12 @@ public class AnalysisServiceImpl implements AnalysisService { ...@@ -50,6 +61,12 @@ public class AnalysisServiceImpl implements AnalysisService {
private EventAnalysisVersionRecordService eventAnalysisVersionRecordService; private EventAnalysisVersionRecordService eventAnalysisVersionRecordService;
@Autowired @Autowired
private EventContextService eventContextService; private EventContextService eventContextService;
@Autowired
private SysDictItemService dictItemService;
@Autowired
private ObsUtil obsUtil;
@Autowired
private EventLlmConfigService eventLlmConfigService;
/* /*
* 优先级:事件脉络 > 伪事件脉络 > 资讯 * 优先级:事件脉络 > 伪事件脉络 > 资讯
...@@ -276,96 +293,130 @@ public class AnalysisServiceImpl implements AnalysisService { ...@@ -276,96 +293,130 @@ public class AnalysisServiceImpl implements AnalysisService {
} }
@Override @Override
public Object impactAssessment(String eventId, String startTime, String endTime) { public String llmResult(String eventName, String startTime, String endTime, EventLlmConfig llmConfig) {
return null; return llmService.model(llmConfig.getLlmName(), llmConfig.getLlmPrompt(), eventName);
}
@Override
public Object measureSuggest(String eventId, String startTime, String endTime) {
return null;
}
@Override
public Object knowledgeEntry(String eventId, String startTime, String endTime) {
return null;
}
@Override
public Object enterpriseCase(String eventId, String startTime, String endTime) {
return null;
}
@Override
public Object countryPolicy(String eventId, String startTime, String endTime) {
return null;
} }
@Override @Override
public Object domesticSimilarEvent(String eventId, String startTime, String endTime) { public String llmResult(String eventId, String startTime, String endTime, Integer columnCode) {
return null; Event event = eventService.getById(eventId);
} EventLlmConfig llmConfig = eventLlmConfigService.getConfig(eventId,columnCode);
return llmService.model(llmConfig.getLlmName(), llmConfig.getLlmPrompt(), event.getEventName());
@Override
public Object foreignSimilarEvent(String eventId, String startTime, String endTime) {
return null;
} }
@Override @Override
public void regenerate(String eventId) { public void regenerate(String eventId) {
//todo 获取模型配置信息(包含模型、提示词、角色等条件) List<EventLlmConfig> configList = eventLlmConfigService.getConfigList(eventId);
List<EventAnalysisVersionRecord> records = new ArrayList<>(); List<EventAnalysisVersionRecord> records = new ArrayList<>();
String today = DateUtil.dateToString(new Date()); String today = DateUtil.dateToString(new Date());
//保存版本信息 //保存版本信息
String versionId = saveVersion(eventId, today); String versionId = saveVersion(eventId, today);
EventVO eventVO = eventService.queryInfo(eventId); Event event = eventService.getById(eventId);
String eventName = event.getEventName();
String eventDescribe = event.getEventDescribe();
//核心摘要 //核心摘要
Integer ynManualEdit = eventVO.getYnManualEdit(); Integer ynManualEdit = event.getYnManualEdit();
if (ynManualEdit == 0) { if (ynManualEdit == 0) {
String prompt = "根据提供的事件名称【name】和对应的关键词【keyword】,关键词【keyword】中'|'表示或;'+'表示与;括号表示优先计算,再结合网络上的相关资讯,生成一段200字左右的核心摘要"; //历史核心摘要是否为空
JSONObject jsonObject = new JSONObject(); boolean empty = StringUtils.isEmpty(eventDescribe);
jsonObject.put("name", eventVO.getEventName()); EventLlmConfig config = configList.stream().filter(e -> e.getColumnCode().equals(AnalysisColumnEnum.CORE_SUMMARY.getCode())).findFirst().orElse(new EventLlmConfig());
jsonObject.put("keyword", eventVO.getKeywordsVO().getKeyword()); eventDescribe = this.llmResult(eventName, null, null, config);
String eventDescribe = llmService.model(null, prompt, jsonObject.toJSONString()); if (empty) {
EventAnalysisVersionRecord record = EventAnalysisVersionRecord.of(versionId, AnalysisColumnEnum.CORE_SUMMARY, eventDescribe); event.setEventDescribe(eventDescribe);
records.add(record); eventService.updateById(event);
}
} }
EventAnalysisVersionRecord coreSummaryRecord = EventAnalysisVersionRecord.of(versionId, AnalysisColumnEnum.CORE_SUMMARY, eventDescribe);
records.add(coreSummaryRecord);
//事件脉络 //事件脉络
List<Map<String, Object>> eventContext = eventContextService.eventContext(eventId); List<Map<String, Object>> eventContext = eventContextService.eventContext(eventId);
if (CollectionUtils.isNotEmpty(eventContext)) { if (CollectionUtils.isNotEmpty(eventContext)) {
EventAnalysisVersionRecord record = EventAnalysisVersionRecord.of(versionId, AnalysisColumnEnum.EVENT_CONTEXT, JSON.toJSONString(eventContext)); EventAnalysisVersionRecord record = EventAnalysisVersionRecord.of(versionId, AnalysisColumnEnum.EVENT_CONTEXT, JSON.toJSONString(eventContext));
records.add(record); records.add(record);
log.info("{}-事件分析【{}】重新生成逻辑完成。",eventName,"事件脉络");
} }
//关键词趋势分析 //关键词趋势分析
List<CountVO> wordTrend = this.wordTrend(eventId, null, null); List<CountVO> wordTrend = this.wordTrend(eventId, null, null);
if (CollectionUtils.isNotEmpty(wordTrend)) { if (CollectionUtils.isNotEmpty(wordTrend)) {
EventAnalysisVersionRecord record = EventAnalysisVersionRecord.of(versionId, AnalysisColumnEnum.KEYWORD_TREND, JSON.toJSONString(wordTrend)); EventAnalysisVersionRecord record = EventAnalysisVersionRecord.of(versionId, AnalysisColumnEnum.KEYWORD_TREND, JSON.toJSONString(wordTrend));
records.add(record); records.add(record);
log.info("{}-事件分析【{}】重新生成逻辑完成。",eventName,"关键词趋势分析");
} }
//关键词共现关系 //关键词共现关系
List<CoOccurrenceVO> coOccurrenceVOS = this.coOccurrence(eventId, null, null); /*List<CoOccurrenceVO> coOccurrenceVOS = this.coOccurrence(eventId, null, null);
if (CollectionUtils.isNotEmpty(coOccurrenceVOS)) { if (CollectionUtils.isNotEmpty(coOccurrenceVOS)) {
EventAnalysisVersionRecord record = EventAnalysisVersionRecord.of(versionId, AnalysisColumnEnum.CO_OCCURRENCE, JSON.toJSONString(coOccurrenceVOS)); EventAnalysisVersionRecord record = EventAnalysisVersionRecord.of(versionId, AnalysisColumnEnum.CO_OCCURRENCE, JSON.toJSONString(coOccurrenceVOS));
records.add(record); records.add(record);
log.info("{}-事件分析【{}】重新生成逻辑完成。",eventName,"关键词共现关系");
}*/
//大模型相关逻辑生成的结果(影响评估,举措建议等)
List<EventLlmConfig> collect = configList.stream().filter(e -> !e.getColumnCode().equals(AnalysisColumnEnum.CORE_SUMMARY.getCode())).collect(Collectors.toList());
for (EventLlmConfig config : collect) {
String llmResult = this.llmResult(eventName, null, null, config);
EventAnalysisVersionRecord record = EventAnalysisVersionRecord.of(versionId, Objects.requireNonNull(AnalysisColumnEnum.getByCode(config.getColumnCode())), llmResult);
records.add(record);
log.info("{}-事件分析【{}】重新生成逻辑完成。",eventName,config.getColumnName());
} }
//todo 大模型相关逻辑
//影响评估
this.impactAssessment(eventId, null, null);
//举措建议
this.measureSuggest(eventId, null, null);
//知识词条
this.knowledgeEntry(eventId, null, null);
//企业案例
this.enterpriseCase(eventId, null, null);
//各国政策
this.countryPolicy(eventId, null, null);
//本国类似事件
this.domesticSimilarEvent(eventId, null, null);
//各国类似事件
this.foreignSimilarEvent(eventId, null, null);
//保存版本记录信息 //保存版本记录信息
eventAnalysisVersionRecordService.saveBatch(records); eventAnalysisVersionRecordService.saveBatch(records);
log.info("{}-事件分析重新生成逻辑完成。",eventName);
} }
@Override
public String exportPPT(String eventId, JSONArray content) {
String pptFile = null;
Event event = eventService.getById(eventId);
String eventName = event.getEventName();
Map<String, Object> params = new HashMap<>();
params.put("eventName", eventName);
params.put("dataList", content);
List<SysDictItem> dictItemList = dictItemService.listByDictCode("xunfei_ppt");
long timestamp = System.currentTimeMillis() / 1000;
try {
for (SysDictItem dictItem : dictItemList) {
String appId = dictItem.getItemText();
String secret = dictItem.getItemValue();
String signature = ApiAuthAlgorithm.getSignature(appId, secret, timestamp);
//获取接口得到的大纲
String outlinePrompt = "请基于提供的json数据,生成大纲。数据如下:" + JSON.toJSONString(params);
CreateResponse outlineResponse = PPTUtil.createOutline(appId, String.valueOf(timestamp), signature, outlinePrompt);
if (outlineResponse != null && !outlineResponse.isFlag()) {
continue;
}
String outline = outlineResponse.getData().getOutline();
log.info("大纲生成完毕:{}", outline);
String pptPrompt = "结合大纲及以下正文内容生成ppt。正文内容:";
CreateResponse pptResponse = PPTUtil.createByOutline(appId, String.valueOf(timestamp), signature, pptPrompt, outline);
if (pptResponse != null && !pptResponse.isFlag()) {
continue;
}
String sid = pptResponse.getData().getSid();
log.info("PPT生成接口返回的sid:{}", sid);
String pptUrl = null;
boolean flag = true;
while (flag) {
Thread.sleep(3000);
ProgressResponse progressResponse = PPTUtil.checkProgress(appId, String.valueOf(timestamp), signature, sid);
if (progressResponse == null || !progressResponse.isFlag()) {
continue;
}
if (progressResponse.isFlag() && progressResponse.getData().getPptStatus().equals("done")) {
pptUrl = progressResponse.getData().getPptUrl();
flag = false;
}
}
URL urlPath = new URL(pptUrl);
URLConnection connection = urlPath.openConnection();
InputStream inputStream = connection.getInputStream();
PutObjectResult putObjectResult = obsUtil.uploadFile("event_ppt/" + eventId + "_" + timestamp + ".pptx", inputStream);
pptFile = putObjectResult.getObjectKey();
break;
}
} catch (Exception e) {
e.printStackTrace();
}
return pptFile;
}
private String saveVersion(String eventId, String time) { private String saveVersion(String eventId, String time) {
EventAnalysisVersion version = new EventAnalysisVersion(); EventAnalysisVersion version = new EventAnalysisVersion();
......
package com.zzsn.event.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.event.entity.EventLlmConfig;
import com.zzsn.event.service.EventLlmConfigService;
import com.zzsn.event.mapper.EventLlmConfigMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author lenovo
* @description 针对表【event_llm_config(事件大模型信息配置表)】的数据库操作Service实现
* @createDate 2025-07-21 14:17:40
*/
@Service
public class EventLlmConfigServiceImpl extends ServiceImpl<EventLlmConfigMapper, EventLlmConfig> implements EventLlmConfigService{
@Override
public List<EventLlmConfig> getConfigList(String eventId) {
LambdaQueryWrapper<EventLlmConfig> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(EventLlmConfig::getEventId, eventId).orderByAsc(EventLlmConfig::getColumnCode);
List<EventLlmConfig> configList = this.list(queryWrapper);
if (CollectionUtils.isEmpty(configList)) {
LambdaQueryWrapper<EventLlmConfig> query = Wrappers.lambdaQuery();
query.eq(EventLlmConfig::getYnDefault, 1).orderByAsc(EventLlmConfig::getColumnCode);
configList = this.list(query);
}
return configList;
}
@Override
public EventLlmConfig getConfig(String eventId, Integer columnCode) {
LambdaQueryWrapper<EventLlmConfig> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(EventLlmConfig::getEventId, eventId).eq(EventLlmConfig::getColumnCode, columnCode);
EventLlmConfig config = this.getOne(queryWrapper);
if (ObjectUtils.isNull(config)) {
LambdaQueryWrapper<EventLlmConfig> query = Wrappers.lambdaQuery();
query.eq(EventLlmConfig::getYnDefault, 1).eq(EventLlmConfig::getColumnCode, columnCode);
config = this.getOne(query);
}
return config;
}
}
...@@ -64,7 +64,7 @@ public class AnalysisTask { ...@@ -64,7 +64,7 @@ public class AnalysisTask {
* @author lkg * @author lkg
* @date 2025/7/9 * @date 2025/7/9
*/ */
@Scheduled(cron = "0 0 0/3 * * ?") //@Scheduled(cron = "0 0 0/3 * * ?")
public void eventContext() { public void eventContext() {
Date today = new Date(); Date today = new Date();
Date disableDate = DateUtil.addDate(today, -1); Date disableDate = DateUtil.addDate(today, -1);
......
package com.zzsn.event.task;
import com.zzsn.event.constant.Constants;
import com.zzsn.event.service.AnalysisService;
import com.zzsn.event.service.IEventService;
import com.zzsn.event.util.DateUtil;
import com.zzsn.event.util.RedisUtil;
import com.zzsn.event.vo.CoOccurrenceVO;
import com.zzsn.event.vo.SubjectKafkaVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
* 热词共现数据缓存
*
* @author lkg
* @date 2025/7/22
*/
@Slf4j
@Component
public class CoOccurrenceTask {
@Autowired
private IEventService eventService;
@Autowired
private RedisUtil redisUtil;
@Autowired
private AnalysisService analysisService;
/**
* 定时缓存热词共现关系数据
* 每天凌晨1点执行一次
*/
@Scheduled(cron = "0 0 1 * * ?")
public void propagationPath() {
Date today = new Date();
Date deadlineDate = DateUtil.addDate(today, -1);
List<SubjectKafkaVo> events = eventService.eventSubjectList();
for (SubjectKafkaVo event : events) {
CompletableFuture.runAsync(() -> {
String eventId = event.getId();
String key = Constants.SUBJECT_ANALYSIS_PRE + Constants.CO_OCCURRENCE + eventId;
Date timeDisable = event.getTimeDisable();
if (timeDisable != null && deadlineDate.compareTo(timeDisable) > 0) {
Object cacheObject = redisUtil.get(key);
if (cacheObject == null) {
List<CoOccurrenceVO> occurrenceList = analysisService.coOccurrence(eventId, null, null);
if (CollectionUtils.isNotEmpty(occurrenceList)) {
redisUtil.set(key, occurrenceList);
log.info("专题-{},热词共现关系数据【永久】缓存成功!", event.getSubjectName());
}
}
} else {
List<CoOccurrenceVO> occurrenceList = analysisService.coOccurrence(eventId, null, null);
if (CollectionUtils.isNotEmpty(occurrenceList)) {
redisUtil.set(key, occurrenceList, 3600 * 24);
log.info("专题-{},热词共现关系数据缓存成功!", event.getSubjectName());
}
}
});
}
}
}
package com.zzsn.event.util.ppt;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class ApiAuthAlgorithm {
/**
* Gets the signature for the given appId and secret.
*
* @param appId The appId used as a key for the signature.
* @param apiSecret The secret key used for the signature.
* @param ts The timestamp.
* @return The generated signature.
*/
public static String getSignature(String appId, String apiSecret, long ts) {
try {
String auth = md5(appId + ts);
return hmacSHA1Encrypt(auth, apiSecret);
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
// Log the exception for debugging
e.printStackTrace();
return null;
}
}
/**
* HMAC SHA1 encryption.
*
* @param encryptText The text to be encrypted.
* @param encryptKey The encryption key.
* @return The encrypted string.
* @throws NoSuchAlgorithmException If the algorithm is not available.
* @throws InvalidKeyException If the key is invalid.
*/
private static String hmacSHA1Encrypt(String encryptText, String encryptKey)
throws NoSuchAlgorithmException, InvalidKeyException {
SecretKeySpec keySpec = new SecretKeySpec(
encryptKey.getBytes(StandardCharsets.UTF_8), "HmacSHA1");
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(keySpec);
byte[] result = mac.doFinal(encryptText.getBytes(StandardCharsets.UTF_8));
return Base64.encodeBase64String(result);
}
/**
* Generates MD5 hash of the given text.
*
* @param text The text to be hashed.
* @return The MD5 hash of the text.
* @throws NoSuchAlgorithmException If the MD5 algorithm is not available.
*/
private static String md5(String text) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(text.getBytes(StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
for (byte b : digest) {
sb.append(String.format("%02x", b));
}
return sb.toString();
}
}
package com.zzsn.event.util.ppt;
import lombok.Data;
@Data
public class CreateResponse {
private boolean flag;
private int code;
private String desc;
private Integer count;
private Data data;
@lombok.Data
public static class Data {
private String sid;
private String coverImgSrc;
private String title;
private String subTitle;
private String outline;
}
}
package com.zzsn.event.util.ppt;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
/**
* ppt工具类
*
* @author lkg
* @date 2025/7/19
*/
@Slf4j
public class PPTUtil {
//讯飞-智能PPT
public static final String baseUrl = "https://zwapi.xfyun.cn/api/ppt/v2";
//默认模板id
public static final String templateId = "20240807EA3CB30";
private final static OkHttpClient client = new OkHttpClient().newBuilder()
.connectionPool(new ConnectionPool(100, 5, TimeUnit.MINUTES))
.readTimeout(60 * 10, TimeUnit.SECONDS)
.build();
/**
* 生成大纲
*
* @param appId 应用id
* @param timestamp 时间戳
* @param signature 签名
* @param query 大模型提问
* @author lkg
* @date 2025/7/19
*/
public static CreateResponse createOutline(String appId, String timestamp, String signature, String query) {
MultipartBody.Builder builder = new MultipartBody.Builder();
builder.setType(MultipartBody.FORM);
builder.addFormDataPart("query", query);
RequestBody requestBody = builder.build();
Request request = new Request.Builder().url(baseUrl + "/createOutline")
.addHeader("appId", appId)
.addHeader("timestamp", timestamp)
.addHeader("signature", signature)
.post(requestBody)
.build();
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
String string = Objects.requireNonNull(response.body()).string();
return JSONObject.parseObject(string, CreateResponse.class);
} else {
log.info("PPT大纲生成异常:{}", Objects.requireNonNull(response.body()).string());
return null;
}
} catch (IOException e) {
log.info("PPT生成进度查询异常:{}", e.getMessage());
}
return null;
}
/**
* 根据大纲生成ppt
*
* @param appId 应用id
* @param timestamp 时间戳
* @param signature 签名
* @param query 大模型提问
* @param outline ppt大纲
* @author lkg
* @date 2025/7/19
*/
public static CreateResponse createByOutline(String appId, String timestamp, String signature, String query, String outline) {
JSONObject jsonObject = new JSONObject();
JSONObject outlineJson = JSONObject.parseObject(outline);
jsonObject.put("outline", outlineJson);
jsonObject.put("query", query);
jsonObject.put("templateId", templateId);
RequestBody requestBody = RequestBody.create(jsonObject.toString(), MediaType.get("application/json; charset=utf-8"));
Request request = new Request.Builder()
.url(baseUrl + "/createPptByOutline")
.addHeader("appId", appId)
.addHeader("timestamp", timestamp)
.addHeader("signature", signature)
.post(requestBody)
.build();
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
String string = Objects.requireNonNull(response.body()).string();
return JSONObject.parseObject(string, CreateResponse.class);
} else {
log.info("PPT生成异常:{}", Objects.requireNonNull(response.body()).string());
return null;
}
} catch (IOException e) {
log.info("PPT生成进度查询异常:{}", e.getMessage());
}
return null;
}
/**
* 查看ppt生成进度
*
* @param appId 应用id
* @param timestamp 时间戳
* @param signature 签名
* @param sid 请求大纲唯一id
* @author lkg
* @date 2025/7/19
*/
public static ProgressResponse checkProgress(String appId, String timestamp, String signature, String sid) {
String url = baseUrl + "/progress?sid=" + sid;
Request request = new Request.Builder()
.url(url)
.addHeader("appId", appId)
.addHeader("timestamp", timestamp)
.addHeader("signature", signature)
.get()
.build();
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
String string = Objects.requireNonNull(response.body()).string();
return JSON.parseObject(string,ProgressResponse.class);
} else {
log.info("PPT生成进度查询异常:{}", Objects.requireNonNull(response.body()).string());
return null;
}
} catch (IOException e) {
log.info("PPT生成进度查询异常:{}", e.getMessage());
}
return null;
}
}
package com.zzsn.event.util.ppt;
import lombok.Data;
@Data
public class ProgressResponse {
private boolean flag;
private int code;
private String desc;
private Integer count;
private Data data;
@lombok.Data
public static class Data {
private String pptStatus;
private String aiImageStatus;
private String cardNoteStatus;
private String pptUrl;
private String errMsg;
private Integer totalPages;
private Integer donePages;
}
}
...@@ -155,7 +155,7 @@ python: ...@@ -155,7 +155,7 @@ python:
hot-crawler: http://139.9.144.106:5000/data?option=OPTION hot-crawler: http://139.9.144.106:5000/data?option=OPTION
jeecg: jeecg:
shiro: shiro:
excludeUrls: info/subjectPageListGroupByLabel,/subject/simple/queryInfoNoSign,/subject/manage/visiblePageListNoSign excludeUrls: info/subjectPageListGroupByLabel,/subject/simple/**,/subject/manage/visiblePageListNoSign,/test/**
kafka: kafka:
topic: topic:
subject: subject:
...@@ -184,4 +184,14 @@ model: ...@@ -184,4 +184,14 @@ model:
url: https://open.bigmodel.cn/api/paas/v4/chat/completions url: https://open.bigmodel.cn/api/paas/v4/chat/completions
authorization: Bearer 3262d41a17a9490a8528eaf52a2be6a0.LNbHPCRmnzFgPHRp authorization: Bearer 3262d41a17a9490a8528eaf52a2be6a0.LNbHPCRmnzFgPHRp
cookie: acw_tc=2760822c17247248406261468e6c541507ba9035f95078363549469047ee74 cookie: acw_tc=2760822c17247248406261468e6c541507ba9035f95078363549469047ee74
qwen:
apiKey: sk-01ee9a6efa394178993a950b768e3753
deepseek:
url: https://api.deepseek.com/v1/chat/completions
# api-key: sk-0e374c2ff9a147a2822c36d1c971fda1
api-key: sk-656a8ec451dc47aaad3dacf24fe36f20
doubao:
url: https://ark.cn-beijing.volces.com/api/v3/chat/completions
api-key: ab54c534-4f3c-41b9-9b27-132cb7954b6f
default-model: doubao-1-5-pro-32k-250115 # Doubao-1.5-pro-32k # 收费
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论