加上try
This commit is contained in:
@@ -107,116 +107,117 @@ public class TmTelephoneCorpusServiceImpl extends ServiceImpl<TmTelephoneCorpusM
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runTelephoneCorpusDify(AicorpusTelephoneDTO aicorpusTelephone) {
|
public void runTelephoneCorpusDify(AicorpusTelephoneDTO aicorpusTelephone) {
|
||||||
|
try {
|
||||||
|
if (null != aicorpusTelephone) {
|
||||||
|
|
||||||
if(null != aicorpusTelephone) {
|
List<DataMaskingRule> maskingRuleItems = dataMaskingRuleService.getDataMaskingRuleListByApplicationChannel(BusinessTypeEnum.SMART_ASSISTANT.getCode());
|
||||||
|
|
||||||
List<DataMaskingRule> maskingRuleItems = dataMaskingRuleService.getDataMaskingRuleListByApplicationChannel(BusinessTypeEnum.SMART_ASSISTANT.getCode());
|
RunMaskingRuleInput runMaskingRuleInput = new RunMaskingRuleInput();
|
||||||
|
runMaskingRuleInput.setDataMaskingRules(maskingRuleItems);
|
||||||
|
|
||||||
RunMaskingRuleInput runMaskingRuleInput = new RunMaskingRuleInput();
|
Map<String, Object> inputMap = new HashMap();
|
||||||
runMaskingRuleInput.setDataMaskingRules(maskingRuleItems);
|
DiFyReq diFyImageReq = new DiFyReq();
|
||||||
|
diFyImageReq.setUser(ConstantStr.corpus_user);
|
||||||
Map<String, Object> inputMap = new HashMap();
|
diFyImageReq.setFlowId(telephoneToken);
|
||||||
DiFyReq diFyImageReq = new DiFyReq();
|
JSONObject jsonObject = JSONObject.parseObject(aicorpusTelephone.getDisplay());
|
||||||
diFyImageReq.setUser(ConstantStr.corpus_user);
|
JSONArray segments = jsonObject.getJSONArray("segments");
|
||||||
diFyImageReq.setFlowId(telephoneToken);
|
Long audioDuration = jsonObject.getLong("audio_duration"); // 毫秒
|
||||||
|
if (audioDuration / 1000 <= 10) {
|
||||||
|
log.info("电话语料时长小于10秒,不进行dify处理");
|
||||||
JSONObject jsonObject = JSONObject.parseObject(aicorpusTelephone.getDisplay());
|
return;
|
||||||
JSONArray segments = jsonObject.getJSONArray("segments");
|
|
||||||
Long audioDuration = jsonObject.getLong("audio_duration"); // 毫秒
|
|
||||||
if (audioDuration / 1000 <= 10) {
|
|
||||||
log.info("电话语料时长小于10秒,不进行dify处理");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (segments == null || segments.isEmpty()) {
|
|
||||||
log.info("电话语料内容segments为空,不进行dify处理");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 遍历 segments
|
|
||||||
StringBuffer chatList = new StringBuffer();
|
|
||||||
segments.stream()
|
|
||||||
.map(segment -> (JSONObject) segment)
|
|
||||||
.forEach(segment -> {
|
|
||||||
JSONObject result = segment.getJSONObject("result");
|
|
||||||
String text = result.getString("text");
|
|
||||||
JSONObject analysisInfo = result.getJSONObject("analysis_info");
|
|
||||||
String role = analysisInfo.getString("role");
|
|
||||||
String title = "";
|
|
||||||
if (role.equals("AGENT")) {
|
|
||||||
title = "顾问";
|
|
||||||
} else {
|
|
||||||
title = "客户";
|
|
||||||
}
|
|
||||||
// 拼接 role 和 text
|
|
||||||
String chat = title + ": " + text;
|
|
||||||
runMaskingRuleInput.setOldStr(chat);
|
|
||||||
String corpusChat = dataMaskingRuleService.runMaskingRule(runMaskingRuleInput);
|
|
||||||
chatList.append(corpusChat).append("\n");
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
ZonedDateTime zonedDateTime = ZonedDateTime.parse(jsonObject.getString("start_time"));
|
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
||||||
String formattedDateStartTime = zonedDateTime.format(formatter);
|
|
||||||
String carModel = getCarModelList();
|
|
||||||
inputMap.put("chat", chatList.toString());
|
|
||||||
inputMap.put("model", carModel);
|
|
||||||
inputMap.put("analysisScene", "2");
|
|
||||||
inputMap.put("recordId", aicorpusTelephone.getSourceId());
|
|
||||||
inputMap.put(communicateDateStr, formattedDateStartTime);
|
|
||||||
inputMap.put("version", 2);
|
|
||||||
diFyImageReq.setInputs(inputMap);
|
|
||||||
CorpusReportDTO corpusReportDTO = new CorpusReportDTO();
|
|
||||||
corpusReportDTO.setCorpusTime(formattedDateStartTime);
|
|
||||||
corpusReportDTO.setRecordId(aicorpusTelephone.getSourceId());
|
|
||||||
corpusReportDTO.setAnalysisScene(2l);
|
|
||||||
corpusReportDTO.setCarModel(carModel);
|
|
||||||
// 获取配置
|
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
CompletableFuture.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
diFyImageReq.setFlowId(telephoneToken);
|
|
||||||
log.info("铭牌语料telephoneToken:{}", telephoneToken);
|
|
||||||
JSONObject execDifyFlow = diFyService.executeDifyFlow(diFyImageReq, BusinessTypeEnum.SMART_ASSISTANT.getCode(),
|
|
||||||
JSONObject.toJSONString(corpusReportDTO), aicorpusTelephone.getAiAnalysisRequestId());
|
|
||||||
|
|
||||||
log.info("dcc总结场景,总结和分类 runDify execDifyFlow : {}", execDifyFlow);
|
|
||||||
parseDfiyResult(execDifyFlow, aicorpusTelephone.getSourceId(), formattedDateStartTime, aicorpusTelephone.getAiAnalysisRequestId(),
|
|
||||||
BusinessTypeEnum.SMART_ASSISTANT.getCode());
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("runDify 异常", e);
|
|
||||||
}
|
}
|
||||||
}, executor);
|
if (segments == null || segments.isEmpty()) {
|
||||||
long endTime = System.currentTimeMillis();
|
log.info("电话语料内容segments为空,不进行dify处理");
|
||||||
log.info("第一个业务场景(dcc总结和分类)执行时间: {} ms", (endTime - startTime));
|
return;
|
||||||
//第一个业务场景, 结束
|
|
||||||
|
|
||||||
long startTime2 = System.currentTimeMillis();
|
|
||||||
CompletableFuture.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
|
|
||||||
// 创建新的DiFyReq对象以避免线程安全问题
|
|
||||||
inputMap.put("businessId", aicorpusTelephone.getSourceId());
|
|
||||||
|
|
||||||
diFyImageReq.setInputs(inputMap);
|
|
||||||
|
|
||||||
diFyImageReq.setFlowId(oneTokenPortrait);
|
|
||||||
log.info("dcc总结场景,客户画像runDify execDifyFlow : {}", oneTokenPortrait);
|
|
||||||
JSONObject execDifyFlowForPortrait = diFyService.executeDifyFlow(diFyImageReq, BusinessTypeEnum.CORPUS_PORTRAIT_DCC.getCode(),
|
|
||||||
JSONObject.toJSONString(corpusReportDTO), aicorpusTelephone.getAiAnalysisRequestId());
|
|
||||||
|
|
||||||
log.info("dcc客户画像场景 runDify execDifyFlow 返回 , dcc: {}", execDifyFlowForPortrait);
|
|
||||||
|
|
||||||
parseDfiyResult(execDifyFlowForPortrait, aicorpusTelephone.getSourceId(), formattedDateStartTime,
|
|
||||||
aicorpusTelephone.getAiAnalysisRequestId(), BusinessTypeEnum.CORPUS_PORTRAIT_DCC.getCode());
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("runDify 异常", e);
|
|
||||||
}
|
}
|
||||||
}, executor);
|
// 遍历 segments
|
||||||
long endTime2 = System.currentTimeMillis();
|
StringBuffer chatList = new StringBuffer();
|
||||||
log.info("第二个业务场景(dcc用户画像)执行时间: {} ms", (endTime2 - startTime2));
|
segments.stream()
|
||||||
//第二个业务场景, 结束
|
.map(segment -> (JSONObject) segment)
|
||||||
|
.forEach(segment -> {
|
||||||
|
JSONObject result = segment.getJSONObject("result");
|
||||||
|
String text = result.getString("text");
|
||||||
|
JSONObject analysisInfo = result.getJSONObject("analysis_info");
|
||||||
|
String role = analysisInfo.getString("role");
|
||||||
|
String title = "";
|
||||||
|
if (role.equals("AGENT")) {
|
||||||
|
title = "顾问";
|
||||||
|
} else {
|
||||||
|
title = "客户";
|
||||||
|
}
|
||||||
|
// 拼接 role 和 text
|
||||||
|
String chat = title + ": " + text;
|
||||||
|
runMaskingRuleInput.setOldStr(chat);
|
||||||
|
String corpusChat = dataMaskingRuleService.runMaskingRule(runMaskingRuleInput);
|
||||||
|
chatList.append(corpusChat).append("\n");
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
ZonedDateTime zonedDateTime = ZonedDateTime.parse(jsonObject.getString("start_time"));
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String formattedDateStartTime = zonedDateTime.format(formatter);
|
||||||
|
String carModel = getCarModelList();
|
||||||
|
inputMap.put("chat", chatList.toString());
|
||||||
|
inputMap.put("model", carModel);
|
||||||
|
inputMap.put("analysisScene", "2");
|
||||||
|
inputMap.put("recordId", aicorpusTelephone.getSourceId());
|
||||||
|
inputMap.put(communicateDateStr, formattedDateStartTime);
|
||||||
|
inputMap.put("version", 2);
|
||||||
|
diFyImageReq.setInputs(inputMap);
|
||||||
|
CorpusReportDTO corpusReportDTO = new CorpusReportDTO();
|
||||||
|
corpusReportDTO.setCorpusTime(formattedDateStartTime);
|
||||||
|
corpusReportDTO.setRecordId(aicorpusTelephone.getSourceId());
|
||||||
|
corpusReportDTO.setAnalysisScene(2l);
|
||||||
|
corpusReportDTO.setCarModel(carModel);
|
||||||
|
// 获取配置
|
||||||
|
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
|
try {
|
||||||
|
diFyImageReq.setFlowId(telephoneToken);
|
||||||
|
log.info("铭牌语料telephoneToken:{}", telephoneToken);
|
||||||
|
JSONObject execDifyFlow = diFyService.executeDifyFlow(diFyImageReq, BusinessTypeEnum.SMART_ASSISTANT.getCode(),
|
||||||
|
JSONObject.toJSONString(corpusReportDTO), aicorpusTelephone.getAiAnalysisRequestId());
|
||||||
|
|
||||||
|
log.info("dcc总结场景,总结和分类 runDify execDifyFlow : {}", execDifyFlow);
|
||||||
|
parseDfiyResult(execDifyFlow, aicorpusTelephone.getSourceId(), formattedDateStartTime, aicorpusTelephone.getAiAnalysisRequestId(),
|
||||||
|
BusinessTypeEnum.SMART_ASSISTANT.getCode());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("runDify 异常", e);
|
||||||
|
}
|
||||||
|
}, executor);
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
log.info("第一个业务场景(dcc总结和分类)执行时间: {} ms", (endTime - startTime));
|
||||||
|
//第一个业务场景, 结束
|
||||||
|
|
||||||
|
long startTime2 = System.currentTimeMillis();
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
|
try {
|
||||||
|
|
||||||
|
// 创建新的DiFyReq对象以避免线程安全问题
|
||||||
|
inputMap.put("businessId", aicorpusTelephone.getSourceId());
|
||||||
|
|
||||||
|
diFyImageReq.setInputs(inputMap);
|
||||||
|
|
||||||
|
diFyImageReq.setFlowId(oneTokenPortrait);
|
||||||
|
log.info("dcc总结场景,客户画像runDify execDifyFlow : {}", oneTokenPortrait);
|
||||||
|
JSONObject execDifyFlowForPortrait = diFyService.executeDifyFlow(diFyImageReq, BusinessTypeEnum.CORPUS_PORTRAIT_DCC.getCode(),
|
||||||
|
JSONObject.toJSONString(corpusReportDTO), aicorpusTelephone.getAiAnalysisRequestId());
|
||||||
|
|
||||||
|
log.info("dcc客户画像场景 runDify execDifyFlow 返回 , dcc: {}", execDifyFlowForPortrait);
|
||||||
|
|
||||||
|
parseDfiyResult(execDifyFlowForPortrait, aicorpusTelephone.getSourceId(), formattedDateStartTime,
|
||||||
|
aicorpusTelephone.getAiAnalysisRequestId(), BusinessTypeEnum.CORPUS_PORTRAIT_DCC.getCode());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("runDify 异常", e);
|
||||||
|
}
|
||||||
|
}, executor);
|
||||||
|
long endTime2 = System.currentTimeMillis();
|
||||||
|
log.info("第二个业务场景(dcc用户画像)执行时间: {} ms", (endTime2 - startTime2));
|
||||||
|
//第二个业务场景, 结束
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("dify 异常", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user