定位流程中断

This commit is contained in:
ZLI263
2025-09-20 15:52:08 +08:00
parent 887709db51
commit 5326a6f431

View File

@@ -111,121 +111,123 @@ public class TmTelephoneCorpusServiceImpl extends ServiceImpl<TmTelephoneCorpusM
private String aiAnalysisRequestIdStr = "aiAnalysisRequestId";
@Override
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();
runMaskingRuleInput.setDataMaskingRules(maskingRuleItems);
Map<String, Object> inputMap = new HashMap();
DiFyReq diFyImageReq = new DiFyReq();
diFyImageReq.setUser(ConstantStr.corpus_user);
Map<String, Object> inputMap = new HashMap();
DiFyReq diFyImageReq = new DiFyReq();
diFyImageReq.setUser(ConstantStr.corpus_user);
JSONObject jsonObject = JSONObject.parseObject(aicorpusTelephone.getDisplay());
log.info("电话语料内容:{}", jsonObject.toString());
inputMap.put("chat", aicorpusTelephone.getDisplay());
JSONArray segments = jsonObject.getJSONArray("segments");
log.info("电话语料内容segments{}", segments.toString());
// 遍历 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");
JSONObject jsonObject = JSONObject.parseObject( aicorpusTelephone.getDisplay());
});
inputMap.put("chat",aicorpusTelephone.getDisplay());
JSONArray segments = jsonObject.getJSONArray("segments");
ZonedDateTime zonedDateTime = ZonedDateTime.parse(jsonObject.getString("start_time"));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateStartTime = zonedDateTime.format(formatter);
// 遍历 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");
inputMap.put("chat", chatList.toString());
inputMap.put("model", getCarModelList());
inputMap.put("recordId", aicorpusTelephone.getSourceId());
inputMap.put("version", 2);
});
diFyImageReq.setInputs(inputMap);
CorpusReportDTO corpusReportDTO = new CorpusReportDTO();
corpusReportDTO.setCorpusTime(formattedDateStartTime);
corpusReportDTO.setRecordId(aicorpusTelephone.getSourceId());
corpusReportDTO.setAnalysisScene(2l);
ZonedDateTime zonedDateTime = ZonedDateTime.parse(jsonObject.getString("start_time"));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateStartTime = zonedDateTime.format(formatter);
long startTime = System.currentTimeMillis();
CompletableFuture.runAsync(() -> {
try {
log.info("铭牌语料可用许可授权数,总结和分类场景={}", semaphore.availablePermits());
// 获取许可 - 如果没有可用许可会阻塞等待
semaphore.acquire();
diFyImageReq.setFlowId(telephoneToken);
log.info("铭牌语料telephoneToken{}", telephoneToken);
JSONObject execDifyFlow = diFyService.executeDifyFlow(diFyImageReq, BusinessTypeEnum.SMART_ASSISTANT.getCode(),
JSONObject.toJSONString(corpusReportDTO), aicorpusTelephone.getAiAnalysisRequestId());
inputMap.put("chat",chatList.toString());
inputMap.put("model",getCarModelList());
inputMap.put("recordId",aicorpusTelephone.getSourceId());
inputMap.put("version",2);
log.info("dcc总结场景,总结和分类 runDify execDifyFlow 返回 {}", execDifyFlow);
parseDfiyResult(execDifyFlow, aicorpusTelephone.getSourceId(), formattedDateStartTime, aicorpusTelephone.getAiAnalysisRequestId(),
BusinessTypeEnum.SMART_ASSISTANT.getCode());
} catch (Exception e) {
log.error("runDify 异常", e);
} finally {
// 释放许可
semaphore.release();
}
}, executor);
long endTime = System.currentTimeMillis();
log.info("第一个业务场景dcc总结和分类执行时间: {} ms", (endTime - startTime));
//第一个业务场景, 结束
diFyImageReq.setInputs(inputMap);
CorpusReportDTO corpusReportDTO = new CorpusReportDTO();
corpusReportDTO.setCorpusTime(formattedDateStartTime);
corpusReportDTO.setRecordId(aicorpusTelephone.getSourceId());
corpusReportDTO.setAnalysisScene(2l);
long startTime2 = System.currentTimeMillis();
CompletableFuture.runAsync(() -> {
try {
log.info("铭牌语料可用许可授权数,客户画像场景={}", semaphore.availablePermits());
Thread.sleep(2000);
// 获取许可 - 如果没有可用许可会阻塞等待
semaphore.acquire();
// 创建新的DiFyReq对象以避免线程安全问题
inputMap.put("businessId", aicorpusTelephone.getSourceId());
inputMap.put(communicateDateStr, aicorpusTelephone.getTranscribeTime());
inputMap.put("analysisScene", "2");
diFyImageReq.setInputs(inputMap);
long startTime = System.currentTimeMillis();
CompletableFuture.runAsync(() -> {
try {
log.info("铭牌语料可用许可授权数,总结和分类场景={}", semaphore.availablePermits());
// 获取许可 - 如果没有可用许可会阻塞等待
semaphore.acquire();
diFyImageReq.setFlowId(telephoneToken);
log.info("铭牌语料telephoneToken{}", telephoneToken);
JSONObject execDifyFlow = diFyService.executeDifyFlow(diFyImageReq, BusinessTypeEnum.SMART_ASSISTANT.getCode(),
JSONObject.toJSONString(corpusReportDTO), aicorpusTelephone.getAiAnalysisRequestId());
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 返回 {}", execDifyFlow);
parseDfiyResult(execDifyFlow, aicorpusTelephone.getSourceId(), formattedDateStartTime, aicorpusTelephone.getAiAnalysisRequestId(),
BusinessTypeEnum.SMART_ASSISTANT.getCode());
} catch (Exception e) {
log.error("runDify 异常", e);
}finally {
// 释放许可
semaphore.release();
}
}, executor);
long endTime = System.currentTimeMillis();
log.info("第一个业务场景dcc总结和分类执行时间: {} ms", (endTime - startTime));
//第一个业务场景, 结束
log.info("dcc客户画像场景 runDify execDifyFlow 返回 , dcc {}", execDifyFlowForPortrait);
long startTime2 = System.currentTimeMillis();
CompletableFuture.runAsync(() -> {
try {
log.info("铭牌语料可用许可授权数,客户画像场景={}", semaphore.availablePermits());
Thread.sleep(2000);
// 获取许可 - 如果没有可用许可会阻塞等待
semaphore.acquire();
// 创建新的DiFyReq对象以避免线程安全问题
inputMap.put("businessId",aicorpusTelephone.getSourceId());
inputMap.put(communicateDateStr,aicorpusTelephone.getTranscribeTime());
inputMap.put("analysisScene", "2");
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);
}finally {
// 释放许可
semaphore.release();
}
}, executor);
long endTime2 = System.currentTimeMillis();
log.info("第二个业务场景dcc用户画像执行时间: {} ms", (endTime2 - startTime2));
//第二个业务场景, 结束
parseDfiyResult(execDifyFlowForPortrait, aicorpusTelephone.getSourceId(), formattedDateStartTime,
aicorpusTelephone.getAiAnalysisRequestId(), BusinessTypeEnum.CORPUS_PORTRAIT_DCC.getCode());
} catch (Exception e) {
log.error("runDify 异常", e);
} finally {
// 释放许可
semaphore.release();
}
}, executor);
long endTime2 = System.currentTimeMillis();
log.info("第二个业务场景dcc用户画像执行时间: {} ms", (endTime2 - startTime2));
//第二个业务场景, 结束
}
} catch (Exception e) {
log.error("runTelephoneCorpusDify error:{}", e);
}
}