定位流程中断

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