解决 sonar问题
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -173,3 +173,4 @@ spring-boot-*.jar
|
|||||||
# Kubernetes
|
# Kubernetes
|
||||||
*.yaml.bak
|
*.yaml.bak
|
||||||
*.yml.bak
|
*.yml.bak
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
package com.volvo.ai.analytic.center.service.impl;
|
package com.volvo.ai.analytic.center.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.date.DatePattern;
|
import cn.hutool.core.date.DatePattern;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
@@ -27,15 +26,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 铭牌语料表-同步表
|
* @description 铭牌语料表-同步表
|
||||||
* @author rz
|
* @author rz
|
||||||
|
|||||||
@@ -134,8 +134,6 @@ public class TmOdsVdqwMessagearchivingServiceImpl extends ServiceImpl<TmOdsVdqwM
|
|||||||
int offset = (i - 1) * pageSize;
|
int offset = (i - 1) * pageSize;
|
||||||
List<OdsVdqwMessageOTD> messageList = tmOdsVdqwMessagearchivingMapper.queryOdsVdqwMessageByData(statTime, endTime, offset, pageSize, retry);
|
List<OdsVdqwMessageOTD> messageList = tmOdsVdqwMessagearchivingMapper.queryOdsVdqwMessageByData(statTime, endTime, offset, pageSize, retry);
|
||||||
// 处理查询到的数据
|
// 处理查询到的数据
|
||||||
// 使用多线程并行执行两个业务场景
|
|
||||||
ExecutorService executorService = Executors.newFixedThreadPool(1);
|
|
||||||
log.info("待处理企微聊天列表messageList",messageList.toString());
|
log.info("待处理企微聊天列表messageList",messageList.toString());
|
||||||
// 使用 CompletableFuture 并行处理
|
// 使用 CompletableFuture 并行处理
|
||||||
messageList.forEach(item -> {
|
messageList.forEach(item -> {
|
||||||
@@ -151,7 +149,7 @@ public class TmOdsVdqwMessagearchivingServiceImpl extends ServiceImpl<TmOdsVdqwM
|
|||||||
log.error("处理企微语料失败: FromUserId={}, AcceptUserId={}, 异常: {}",
|
log.error("处理企微语料失败: FromUserId={}, AcceptUserId={}, 异常: {}",
|
||||||
item.getFromUserId(), item.getAcceptUserId(), e.getMessage(), e);
|
item.getFromUserId(), item.getAcceptUserId(), e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}, executorService);
|
}, executor);
|
||||||
|
|
||||||
log.info("处理企微语料 调用完成: 结束时间:{}, 总用时: {}", System.currentTimeMillis(), System.currentTimeMillis() - startTime2);
|
log.info("处理企微语料 调用完成: 结束时间:{}, 总用时: {}", System.currentTimeMillis(), System.currentTimeMillis() - startTime2);
|
||||||
|
|
||||||
@@ -235,61 +233,22 @@ public class TmOdsVdqwMessagearchivingServiceImpl extends ServiceImpl<TmOdsVdqwM
|
|||||||
|
|
||||||
|
|
||||||
// 使用多线程并行执行两个业务场景
|
// 使用多线程并行执行两个业务场景
|
||||||
ExecutorService executorService = Executors.newFixedThreadPool(2);
|
|
||||||
log.info("第1个业务场景, 优先执行。 ");
|
log.info("第1个业务场景, 优先执行。 ");
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture<Void> summaryTask = CompletableFuture.runAsync(() -> {
|
||||||
// 获取配置
|
executeSummaryTask(diFyImageReq, corpusReportDTO, item, maxMsgTimeItem);
|
||||||
JSONObject execDifyFlow = diFyService.executeDifyFlow(diFyImageReq, BusinessTypeEnum.SMART_ASSISTANT_QIWEI.getCode(), JSONObject.toJSONString(corpusReportDTO),null);
|
}, executor);
|
||||||
log.info("runDify execDifyFlow , 企微场景,总结需求的dify返回 :{}", execDifyFlow);
|
|
||||||
if (null != execDifyFlow && execDifyFlow.get("status").equals("succeeded")) {
|
|
||||||
JSONObject text = execDifyFlow.getJSONObject("outputs");
|
|
||||||
// 发送MQ
|
|
||||||
log.info("send mq企微总结 {}", text);
|
|
||||||
tmTelephoneCorpusService.sendMq( CategoryEnum.ENTERPRISE_WECHAT.getCode(), text.toJSONString());
|
|
||||||
|
|
||||||
try {
|
|
||||||
ttVdqwRecordMapper.insert(TtVdqwRecord.builder().acceptUserId(item.getFromUserId()).fromUserId(item.getAcceptUserId()).msgTime(maxMsgTimeItem.getMsgTime()).from_accept_user_id(item.getFromAcceptUserId()).build());
|
|
||||||
aiAnalysisRequestLogsService.saveOrUpdateAiAnalysisRequestLogs(AiAnalysisRequestLogs.builder().aiAnalysisRequestId(execDifyFlow.getString("aiAnalysisRequestId")).businessResponse(text.toJSONString()).build());
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.info(" 企业语料处理保存报告异常processItem:{} ", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.info("runDify execDifyFlow ,企微语料 ,总结和分类业务,返回: {}", execDifyFlow);
|
|
||||||
}, executorService);
|
|
||||||
long endTime1 = System.currentTimeMillis();
|
|
||||||
log.info("第一个业务场景(总结和分类)执行时间: {} ms", (endTime1 - startTime));
|
|
||||||
//第一个业务场景, 结束
|
|
||||||
|
|
||||||
long startTime2 = System.currentTimeMillis();
|
long startTime2 = System.currentTimeMillis();
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture<Void> portraitTask = CompletableFuture.runAsync(() -> {
|
||||||
//"analysisScene": "分析类型", // 1、企微会话 2、AI通话录音 3、AI铭牌(客流) 4、AI铭牌(试驾)
|
executePortraitTask(unionId, maxMsgTimeItem, chatList, corpusReportDTO);
|
||||||
DiFyReq diFyImageReq2 = new DiFyReq();
|
}, executor);
|
||||||
diFyImageReq2.setUser(ConstantStr.corpus_user);
|
|
||||||
Map<String, Object> inputMap2 = new HashMap<>();
|
|
||||||
inputMap2.put("businessId", unionId);
|
|
||||||
inputMap2.put("communicateDate", DateUtil.format(maxMsgTimeItem.getMsgTime(), DatePattern.NORM_DATETIME_PATTERN));
|
|
||||||
inputMap2.put("analysisScene", "1");
|
|
||||||
inputMap2.put("version", 2);
|
|
||||||
inputMap2.put("chat", chatList.toString());
|
|
||||||
diFyImageReq2.setInputs(inputMap2);
|
|
||||||
// 创建新的DiFyReq对象以避免线程安全问题
|
|
||||||
diFyImageReq2.setFlowId(oneTokenPortrait);
|
|
||||||
log.info("runDify execDifyFlow ,客户画像场景 ,token-{} , 对象: {}", oneTokenPortrait, diFyImageReq2);
|
|
||||||
JSONObject execDifyFlowForPortrait = diFyService.executeDifyFlow(diFyImageReq2, BusinessTypeEnum.CORPUS_PORTRAIT_NAMEPLATE.getCode(),
|
|
||||||
JSONObject.toJSONString(corpusReportDTO), null);
|
|
||||||
log.info("runDify execDifyFlow ,客户画像场景 ,返回-{} ", execDifyFlowForPortrait);
|
|
||||||
|
|
||||||
JSONObject text = execDifyFlowForPortrait.getJSONObject("outputs");
|
// 等待两个任务完成
|
||||||
// 发送MQ
|
CompletableFuture.allOf(summaryTask, portraitTask).join();
|
||||||
log.info("send mq企微客户画像 {}", text);
|
|
||||||
tmTelephoneCorpusService.sendMq( CategoryEnum.ENTERPRISE_WECHAT.getCode(), text.toJSONString());
|
|
||||||
|
|
||||||
aiAnalysisRequestLogsService.saveOrUpdateAiAnalysisRequestLogs(AiAnalysisRequestLogs.builder().aiAnalysisRequestId(execDifyFlowForPortrait.getString("aiAnalysisRequestId")).businessResponse(text.toJSONString()).build());
|
long endTime1 = System.currentTimeMillis();
|
||||||
|
log.info("第一个业务场景(总结和分类)执行时间: {} ms", (endTime1 - startTime));
|
||||||
log.info("runDify execDifyFlow ,企微语料 ,客户画像场景,返回: {}", execDifyFlowForPortrait);
|
|
||||||
|
|
||||||
}, executorService);
|
|
||||||
long endTime2 = System.currentTimeMillis();
|
long endTime2 = System.currentTimeMillis();
|
||||||
log.info("第二个业务场景(用户画像)执行时间: {} ms", (endTime2 - startTime2));
|
log.info("第二个业务场景(用户画像)执行时间: {} ms", (endTime2 - startTime2));
|
||||||
|
|
||||||
@@ -318,5 +277,67 @@ public class TmOdsVdqwMessagearchivingServiceImpl extends ServiceImpl<TmOdsVdqwM
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行总结任务
|
||||||
|
*/
|
||||||
|
private void executeSummaryTask(DiFyReq diFyImageReq, CorpusReportDTO corpusReportDTO, OdsVdqwMessageOTD item, OdsVdqwMessageOTD maxMsgTimeItem) {
|
||||||
|
try {
|
||||||
|
// 获取配置
|
||||||
|
JSONObject execDifyFlow = diFyService.executeDifyFlow(diFyImageReq, BusinessTypeEnum.SMART_ASSISTANT_QIWEI.getCode(), JSONObject.toJSONString(corpusReportDTO),null);
|
||||||
|
log.info("runDify execDifyFlow , 企微场景,总结需求的dify返回 :{}", execDifyFlow);
|
||||||
|
if (null != execDifyFlow && execDifyFlow.get("status").equals("succeeded")) {
|
||||||
|
JSONObject text = execDifyFlow.getJSONObject("outputs");
|
||||||
|
// 发送MQ
|
||||||
|
log.info("send mq企微总结 {}", text);
|
||||||
|
tmTelephoneCorpusService.sendMq( CategoryEnum.ENTERPRISE_WECHAT.getCode(), text.toJSONString());
|
||||||
|
|
||||||
|
try {
|
||||||
|
ttVdqwRecordMapper.insert(TtVdqwRecord.builder().acceptUserId(item.getFromUserId()).fromUserId(item.getAcceptUserId()).msgTime(maxMsgTimeItem.getMsgTime()).from_accept_user_id(item.getFromAcceptUserId()).build());
|
||||||
|
aiAnalysisRequestLogsService.saveOrUpdateAiAnalysisRequestLogs(AiAnalysisRequestLogs.builder().aiAnalysisRequestId(execDifyFlow.getString("aiAnalysisRequestId")).businessResponse(text.toJSONString()).build());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info(" 企业语料处理保存报告异常processItem:{} ", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info("runDify execDifyFlow ,企微语料 ,总结和分类业务,返回: {}", execDifyFlow);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("执行总结任务异常", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行客户画像任务
|
||||||
|
*/
|
||||||
|
private void executePortraitTask(String unionId, OdsVdqwMessageOTD maxMsgTimeItem, StringBuffer chatList, CorpusReportDTO corpusReportDTO) {
|
||||||
|
try {
|
||||||
|
//"analysisScene": "分析类型", // 1、企微会话 2、AI通话录音 3、AI铭牌(客流) 4、AI铭牌(试驾)
|
||||||
|
DiFyReq diFyImageReq2 = new DiFyReq();
|
||||||
|
diFyImageReq2.setUser(ConstantStr.corpus_user);
|
||||||
|
Map<String, Object> inputMap2 = new HashMap<>();
|
||||||
|
inputMap2.put("businessId", unionId);
|
||||||
|
inputMap2.put("communicateDate", DateUtil.format(maxMsgTimeItem.getMsgTime(), DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
inputMap2.put("analysisScene", "1");
|
||||||
|
inputMap2.put("version", 2);
|
||||||
|
inputMap2.put("chat", chatList.toString());
|
||||||
|
diFyImageReq2.setInputs(inputMap2);
|
||||||
|
// 创建新的DiFyReq对象以避免线程安全问题
|
||||||
|
diFyImageReq2.setFlowId(oneTokenPortrait);
|
||||||
|
log.info("runDify execDifyFlow ,客户画像场景 ,token-{} , 对象: {}", oneTokenPortrait, diFyImageReq2);
|
||||||
|
JSONObject execDifyFlowForPortrait = diFyService.executeDifyFlow(diFyImageReq2, BusinessTypeEnum.CORPUS_PORTRAIT_NAMEPLATE.getCode(),
|
||||||
|
JSONObject.toJSONString(corpusReportDTO), null);
|
||||||
|
log.info("runDify execDifyFlow ,客户画像场景 ,返回-{} ", execDifyFlowForPortrait);
|
||||||
|
|
||||||
|
JSONObject text = execDifyFlowForPortrait.getJSONObject("outputs");
|
||||||
|
// 发送MQ
|
||||||
|
log.info("send mq企微客户画像 {}", text);
|
||||||
|
tmTelephoneCorpusService.sendMq( CategoryEnum.ENTERPRISE_WECHAT.getCode(), text.toJSONString());
|
||||||
|
|
||||||
|
aiAnalysisRequestLogsService.saveOrUpdateAiAnalysisRequestLogs(AiAnalysisRequestLogs.builder().aiAnalysisRequestId(execDifyFlowForPortrait.getString("aiAnalysisRequestId")).businessResponse(text.toJSONString()).build());
|
||||||
|
|
||||||
|
log.info("runDify execDifyFlow ,企微语料 ,客户画像场景,返回: {}", execDifyFlowForPortrait);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("执行客户画像任务异常", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user