From 5326a6f43183a027006de52df98185bf5a3f4771 Mon Sep 17 00:00:00 2001 From: ZLI263 Date: Sat, 20 Sep 2025 15:52:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E4=BD=8D=E6=B5=81=E7=A8=8B=E4=B8=AD?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/TmTelephoneCorpusServiceImpl.java | 200 +++++++++--------- 1 file changed, 101 insertions(+), 99 deletions(-) diff --git a/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/service/impl/TmTelephoneCorpusServiceImpl.java b/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/service/impl/TmTelephoneCorpusServiceImpl.java index 79c68c2..cc44438 100644 --- a/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/service/impl/TmTelephoneCorpusServiceImpl.java +++ b/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/service/impl/TmTelephoneCorpusServiceImpl.java @@ -111,121 +111,123 @@ public class TmTelephoneCorpusServiceImpl extends ServiceImpl maskingRuleItems = dataMaskingRuleService.getDataMaskingRuleListByApplicationChannel(BusinessTypeEnum.SMART_ASSISTANT.getCode()); - List maskingRuleItems = dataMaskingRuleService.getDataMaskingRuleListByApplicationChannel(BusinessTypeEnum.SMART_ASSISTANT.getCode()); + RunMaskingRuleInput runMaskingRuleInput = new RunMaskingRuleInput(); + runMaskingRuleInput.setDataMaskingRules(maskingRuleItems); - RunMaskingRuleInput runMaskingRuleInput = new RunMaskingRuleInput(); - runMaskingRuleInput.setDataMaskingRules(maskingRuleItems); - - Map inputMap = new HashMap(); - DiFyReq diFyImageReq = new DiFyReq(); - diFyImageReq.setUser(ConstantStr.corpus_user); + Map 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); } }