提交 517eeb6a 作者: 925993793@qq.com

接口逻辑调整

上级 a34f4958
...@@ -66,7 +66,7 @@ public class EventManageController { ...@@ -66,7 +66,7 @@ public class EventManageController {
@Autowired @Autowired
private EventAnalysisVersionRecordService eventAnalysisVersionRecordService; private EventAnalysisVersionRecordService eventAnalysisVersionRecordService;
@Autowired @Autowired
private EventAnalysisVersionService eventAnalysisVersionService; private AnalysisService analysisService;
@Value(("${serviceProject.url:}")) @Value(("${serviceProject.url:}"))
private String SERVICE_PROJECT_URL; private String SERVICE_PROJECT_URL;
...@@ -166,6 +166,9 @@ public class EventManageController { ...@@ -166,6 +166,9 @@ public class EventManageController {
//事件分析 //事件分析
log.info("新增事件,事件分析,事件id:{}", event.getId()); log.info("新增事件,事件分析,事件id:{}", event.getId());
kafkaTemplate.send(EVENT_MODEL_KAFKA_CHANNEL, event.getEventCode()); kafkaTemplate.send(EVENT_MODEL_KAFKA_CHANNEL, event.getEventCode());
//立马执行一次事件分析
analysisService.regenerate(event.getId());
}); });
return Result.OK(); return Result.OK();
} else { } else {
......
...@@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
...@@ -359,6 +360,7 @@ public class AnalysisServiceImpl implements AnalysisService { ...@@ -359,6 +360,7 @@ public class AnalysisServiceImpl implements AnalysisService {
String versionId = saveVersion(eventId, today); String versionId = saveVersion(eventId, today);
Event event = eventService.getById(eventId); Event event = eventService.getById(eventId);
String eventName = event.getEventName(); String eventName = event.getEventName();
log.info("{}-事件分析重新生成逻辑开始。。。", eventName);
String eventDescribe = event.getEventDescribe(); String eventDescribe = event.getEventDescribe();
//核心摘要 //核心摘要
Integer ynManualEdit = event.getYnManualEdit(); Integer ynManualEdit = event.getYnManualEdit();
...@@ -418,27 +420,29 @@ public class AnalysisServiceImpl implements AnalysisService { ...@@ -418,27 +420,29 @@ public class AnalysisServiceImpl implements AnalysisService {
params.put("dataList", content); params.put("dataList", content);
List<SysDictItem> dictItemList = dictItemService.listByDictCode("xunfei_ppt"); List<SysDictItem> dictItemList = dictItemService.listByDictCode("xunfei_ppt");
long timestamp = System.currentTimeMillis() / 1000; long timestamp = System.currentTimeMillis() / 1000;
try {
for (SysDictItem dictItem : dictItemList) { for (SysDictItem dictItem : dictItemList) {
String pptUrl = null;
//是否应用异常
boolean appException = false;
try {
String appId = dictItem.getItemText(); String appId = dictItem.getItemText();
String secret = dictItem.getItemValue(); String secret = dictItem.getItemValue();
String signature = ApiAuthAlgorithm.getSignature(appId, secret, timestamp); String signature = ApiAuthAlgorithm.getSignature(appId, secret, timestamp);
//获取接口得到的大纲 //获取接口得到的大纲
String outlinePrompt = "请基于提供的json数据,生成大纲。数据如下:" + JSON.toJSONString(params); String outlinePrompt = "请基于提供的json数据,生成大纲。数据如下:" + JSON.toJSONString(params);
CreateResponse outlineResponse = PPTUtil.createOutline(appId, String.valueOf(timestamp), signature, outlinePrompt); CreateResponse outlineResponse = PPTUtil.createOutline(appId, String.valueOf(timestamp), signature, outlinePrompt);
if (outlineResponse != null && !outlineResponse.isFlag()) { if (outlineResponse == null || !outlineResponse.isFlag()) {
continue; continue;
} }
String outline = outlineResponse.getData().getOutline(); String outline = outlineResponse.getData().getOutline();
log.info("大纲生成完毕:{}", outline); log.info("大纲生成完毕:{}", outline);
String pptPrompt = "结合大纲及以下正文内容生成ppt。正文内容:"; String pptPrompt = "结合大纲及以下正文内容生成ppt。正文内容:";
CreateResponse pptResponse = PPTUtil.createByOutline(appId, String.valueOf(timestamp), signature, pptPrompt, outline); CreateResponse pptResponse = PPTUtil.createByOutline(appId, String.valueOf(timestamp), signature, pptPrompt, outline);
if (pptResponse != null && !pptResponse.isFlag()) { if (pptResponse == null || !pptResponse.isFlag()) {
continue; continue;
} }
String sid = pptResponse.getData().getSid(); String sid = pptResponse.getData().getSid();
log.info("PPT生成接口返回的sid:{}", sid); log.info("PPT生成接口返回的sid:{}", sid);
String pptUrl = null;
boolean flag = true; boolean flag = true;
while (flag) { while (flag) {
Thread.sleep(3000); Thread.sleep(3000);
...@@ -446,20 +450,47 @@ public class AnalysisServiceImpl implements AnalysisService { ...@@ -446,20 +450,47 @@ public class AnalysisServiceImpl implements AnalysisService {
if (progressResponse == null || !progressResponse.isFlag()) { if (progressResponse == null || !progressResponse.isFlag()) {
continue; continue;
} }
if (progressResponse.isFlag() && progressResponse.getData().getPptStatus().equals("done")) { String pptStatus = progressResponse.getData().getPptStatus();
switch (pptStatus) {
case "building":
log.info("PPT正在生成中...");
break;
case "done":
pptUrl = progressResponse.getData().getPptUrl(); pptUrl = progressResponse.getData().getPptUrl();
log.info("应用-{},PPT生成成功: {}", appId,pptUrl);
flag = false; flag = false;
break;
case "build_failed":
log.info("PPT生成失败");
flag = false;
break;
} }
} }
} catch (Exception e) {
e.printStackTrace();
appException = true;
}
if (pptUrl != null) {
try {
URL urlPath = new URL(pptUrl); URL urlPath = new URL(pptUrl);
URLConnection connection = urlPath.openConnection(); URLConnection connection = urlPath.openConnection();
InputStream inputStream = connection.getInputStream(); InputStream inputStream = connection.getInputStream();
PutObjectResult putObjectResult = obsUtil.uploadFile("event_ppt/" + eventId + "_" + timestamp + ".pptx", inputStream); PutObjectResult putObjectResult = obsUtil.uploadFile("event_ppt/" + eventId + "_" + timestamp + ".pptx", inputStream);
pptFile = putObjectResult.getObjectKey(); pptFile = putObjectResult.getObjectKey();
break; break;
} } catch (IOException e) {
} catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.info("PPT上传OBS失败");
break;
}
} else { //pptFile为空时,不是应用异常,说明是数据问题,直接结束循环
if (!appException) {
log.info("数据问题,导致PPT生成失败");
break;
} else {
log.info("应用异常,继续尝试其他应用");
}
}
} }
return pptFile; return pptFile;
} }
......
...@@ -122,8 +122,7 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements ...@@ -122,8 +122,7 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements
private ClbModelArrangeSubjectMapService clbModelArrangeSubjectMapService; private ClbModelArrangeSubjectMapService clbModelArrangeSubjectMapService;
@Autowired @Autowired
private EventCollectMapService eventCollMapService; private EventCollectMapService eventCollMapService;
@Autowired
private AnalysisService analysisService;
@Value("${kafka.topic.event.run:}") @Value("${kafka.topic.event.run:}")
private String EVENT_MODEL_KAFKA_CHANNEL; private String EVENT_MODEL_KAFKA_CHANNEL;
...@@ -427,10 +426,6 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements ...@@ -427,10 +426,6 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}); });
CompletableFuture.runAsync(() -> {
//立马执行一次事件分析
analysisService.regenerate(eventId);
});
return event; return event;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论