From 7b7000c2cfc2561c26f2a8162d41d47bd4fad216 Mon Sep 17 00:00:00 2001 From: ZLI263 Date: Thu, 4 Sep 2025 18:59:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=94=BB=E5=83=8Fmq=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A4=87=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../center/enums/BusinessTypeEnum.java | 1 - .../analytic/center/enums/CategoryEnum.java | 2 +- .../analytic/center/job/QiWeiCorpusJob.java | 25 ++++++++ .../impl/CorpusPortraitServiceImpl.java | 60 ++++++++++++++++--- .../impl/TmTelephoneCorpusServiceImpl.java | 3 +- 5 files changed, 81 insertions(+), 10 deletions(-) diff --git a/ai-analytic-center-api/src/main/java/com/volvo/ai/analytic/center/enums/BusinessTypeEnum.java b/ai-analytic-center-api/src/main/java/com/volvo/ai/analytic/center/enums/BusinessTypeEnum.java index 546e00f..8f1fade 100644 --- a/ai-analytic-center-api/src/main/java/com/volvo/ai/analytic/center/enums/BusinessTypeEnum.java +++ b/ai-analytic-center-api/src/main/java/com/volvo/ai/analytic/center/enums/BusinessTypeEnum.java @@ -40,7 +40,6 @@ public enum BusinessTypeEnum { SPOKESMAN_SENSITIVE_WORD("SPOKESMAN_SENSITIVE_WORD", "特邀发言官敏感词"), //特邀发言官审核规则 SPOKESMAN_AUDIT_RULE("SPOKESMAN_AUDIT_RULE", "特邀发言官审核规则"), - SMART_ASSISTANT_NAMEPLATE("SMART_ASSISTANT_NAMEPLATE", "智能助手-铭牌"), CORPUS_PORTRAIT_DCC("CORPUS_PORTRAIT_DCC", "智能助手-画像-DCC"), CORPUS_PORTRAIT_QIWEI("CORPUS_PORTRAIT_QIWEI", "智能助手-画像-企微"), diff --git a/ai-analytic-center-api/src/main/java/com/volvo/ai/analytic/center/enums/CategoryEnum.java b/ai-analytic-center-api/src/main/java/com/volvo/ai/analytic/center/enums/CategoryEnum.java index b280381..e83c5f9 100644 --- a/ai-analytic-center-api/src/main/java/com/volvo/ai/analytic/center/enums/CategoryEnum.java +++ b/ai-analytic-center-api/src/main/java/com/volvo/ai/analytic/center/enums/CategoryEnum.java @@ -4,7 +4,7 @@ public enum CategoryEnum { ENTERPRISE_WECHAT("enterprise_wechat", "企微记录"), PHONE_VOICE("phone_voice", "语音电话"), - + PHONE_VOICE_PORTRAIT("phone_voice_portrait", "语音电话,用户画像"), NAMEPLATE_VOICE("nameplate_voice", "铭牌"), OTHER("未知", "未知记录"), diff --git a/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/job/QiWeiCorpusJob.java b/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/job/QiWeiCorpusJob.java index be2a613..e23fc70 100644 --- a/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/job/QiWeiCorpusJob.java +++ b/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/job/QiWeiCorpusJob.java @@ -93,4 +93,29 @@ public class QiWeiCorpusJob { } + @XxlJob("dccCorpusFailRetryForPortrait") + @PostMapping("dccCorpusFailRetryForPortrait") + public ResultMsg dccCorpusFailRetryForPortrait(@RequestBody String paramJson) { + try { + // 获取任务参数 + String param = XxlJobHelper.getJobParam(); + if(StringUtils.isEmpty(param)){ + param = paramJson; + } + // 执行业务逻辑 + XxlJobHelper.log("dccCorpusFailRetry任务参数: {}", param); + List corpusDtoList = tmTelephoneCorpusMapper.queryTelephoneCorpusBySourceIds( Arrays.asList(param.split(","))); + corpusDtoList.stream().forEach(item-> + { + corpusPortraitService.portraitDcc(item); + } + ); + } catch (Exception e) { + log.error("processMessageByTask 定时任务补偿处理消息异常",e.getMessage()); + throw new RuntimeException(e); + } + return ResultMsg.ok(); + } + + } diff --git a/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/service/impl/CorpusPortraitServiceImpl.java b/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/service/impl/CorpusPortraitServiceImpl.java index e6bdcd9..3aa46d3 100644 --- a/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/service/impl/CorpusPortraitServiceImpl.java +++ b/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/service/impl/CorpusPortraitServiceImpl.java @@ -2,6 +2,7 @@ package com.volvo.ai.analytic.center.service.impl; import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.huaweicloud.sdk.eg.v1.model.CloudEvents; import com.volvo.ai.analytic.center.dto.corpus.AicorpusTelephoneDTO; @@ -14,6 +15,7 @@ import com.volvo.ai.analytic.center.dto.resp.ResultDTO; import com.volvo.ai.analytic.center.entity.*; import com.volvo.ai.analytic.center.enums.BizEnum; import com.volvo.ai.analytic.center.enums.BusinessTypeEnum; +import com.volvo.ai.analytic.center.enums.CategoryEnum; import com.volvo.ai.analytic.center.feign.CompetingBrandsClient; import com.volvo.ai.analytic.center.mapper.TmOdsVdqwMessagearchivingMapper; import com.volvo.ai.analytic.center.service.*; @@ -98,32 +100,71 @@ public class CorpusPortraitServiceImpl implements CorpusPortraitService { diFyImageReq.setUser(ConstantStr.corpus_user); diFyImageReq.setFlowId(dccToken); - - String chatContent = tmTelephoneCorpusService.processChatSegments(aicorpusTelephone.getDisplay(), maskingRuleItems); - if (chatContent == null) { + JSONObject jsonObject = JSONObject.parseObject( aicorpusTelephone.getDisplay()); + 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.parseObject(aicorpusTelephone.getDisplay()).getString("start_time")); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String formattedDateStartTime = zonedDateTime.format(formatter); - inputMap.put("chat", chatContent); + inputMap.put("chat", chatList); inputMap.put("recordId", aicorpusTelephone.getSourceId()); inputMap.put("communicateDate", formattedDateStartTime); inputMap.put("brand",getBrand()); inputMap.put("brandSeries",getSeriesByBrandId()); + inputMap.put("customerFlowId", aicorpusTelephone.getSourceId()); + diFyImageReq.setInputs(inputMap); + CorpusReportDTO corpusReportDTO = new CorpusReportDTO(); corpusReportDTO.setCorpusTime(formattedDateStartTime); corpusReportDTO.setRecordId(aicorpusTelephone.getSourceId()); + corpusReportDTO.setAnalysisScene(2l); + + // 获取配置 JSONObject execDifyFlow = diFyService.executeDifyFlow(diFyImageReq, BusinessTypeEnum.CORPUS_PORTRAIT_DCC.getCode(), JSONObject.toJSONString(corpusReportDTO), aicorpusTelephone.getAiAnalysisRequestId()); log.info("runDify execDifyFlow {}", execDifyFlow); String aiAnalysisRequestId = execDifyFlow.getString("aiAnalysisRequestId"); if (null != execDifyFlow && execDifyFlow.get("status").equals("succeeded")) { JSONObject text = execDifyFlow.getJSONObject("outputs"); +// huaWeiService.sendEvent(setCloudEvents(aiAnalysisRequestId, text.toJSONString(), "DCC"), ltoChannelId); + // 发送MQ + log.info("send mq ,DCC语料,画像场景 {}", text); + tmTelephoneCorpusService.sendMq( BusinessTypeEnum.CORPUS_PORTRAIT_DCC.getCode(), text.toJSONString()); - huaWeiService.sendEvent(setCloudEvents(aiAnalysisRequestId, text.toJSONString(), "DCC"), ltoChannelId); aiAnalysisRequestLogsService.saveAiAnalysisRequestLogs(AiAnalysisRequestLogs.builder().aiAnalysisRequestId(execDifyFlow.getString("aiAnalysisRequestId")).businessResponse(text.toJSONString()).build()); } @@ -223,7 +264,10 @@ public class CorpusPortraitServiceImpl implements CorpusPortraitService { if (null != execDifyFlow && execDifyFlow.get("status").equals("succeeded")) { JSONObject text = execDifyFlow.getJSONObject("outputs"); - huaWeiService.sendEvent(setCloudEvents(aiAnalysisRequestId, text.toJSONString(),"QIWEI"),ltoChannelId); +// huaWeiService.sendEvent(setCloudEvents(aiAnalysisRequestId, text.toJSONString(),"QIWEI"),ltoChannelId); + log.info("send mq ,企微语料,画像场景 {}", text); + tmTelephoneCorpusService.sendMq( BusinessTypeEnum.CORPUS_PORTRAIT_QIWEI.getCode(), text.toJSONString()); + aiAnalysisRequestLogsService.saveAiAnalysisRequestLogs(AiAnalysisRequestLogs.builder().aiAnalysisRequestId(execDifyFlow.getString("aiAnalysisRequestId")).businessResponse(text.toJSONString()).build()); } @@ -270,7 +314,9 @@ public class CorpusPortraitServiceImpl implements CorpusPortraitService { if (null != execDifyFlow && execDifyFlow.get("status").equals("succeeded")) { JSONObject text = execDifyFlow.getJSONObject("outputs"); - huaWeiService.sendEvent(setCloudEvents(aiAnalysisRequestId, text.toJSONString(),"NAMEPLATE"),ltoChannelId); +// huaWeiService.sendEvent(setCloudEvents(aiAnalysisRequestId, text.toJSONString(),"NAMEPLATE"),ltoChannelId); + log.info("send mq ,铭牌语料,画像场景 {}", text); + tmTelephoneCorpusService.sendMq( BusinessTypeEnum.CORPUS_PORTRAIT_NAMEPLATE.getCode(), text.toJSONString()); aiAnalysisRequestLogsService.saveAiAnalysisRequestLogs(AiAnalysisRequestLogs.builder().aiAnalysisRequestId(execDifyFlow.getString("aiAnalysisRequestId")).businessResponse(text.toJSONString()).build()); 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 6484d1d..382e9a7 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 @@ -63,7 +63,7 @@ public class TmTelephoneCorpusServiceImpl extends ServiceImpl