diff --git a/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/service/impl/TmNameplateCorpusServiceImpl.java b/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/service/impl/TmNameplateCorpusServiceImpl.java index 1427440..0bf0ed6 100644 --- a/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/service/impl/TmNameplateCorpusServiceImpl.java +++ b/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/service/impl/TmNameplateCorpusServiceImpl.java @@ -32,8 +32,8 @@ import java.util.concurrent.Executors; /** - * @description 铭牌语料表-同步表 * @author rz + * @description 铭牌语料表-同步表 * @date 2025-03-04 */ @RefreshScope @@ -42,282 +42,287 @@ import java.util.concurrent.Executors; public class TmNameplateCorpusServiceImpl extends ServiceImpl implements TmNameplateCorpusService { - @Autowired - private TmNameplateCorpusMapper tmNameplateCorpusMapper; + @Autowired + private TmNameplateCorpusMapper tmNameplateCorpusMapper; - @Autowired - private TtNameplateRecordMapper ttNameplateRecordMapper; - @Autowired - private TmTelephoneCorpusService tmTelephoneCorpusService; + @Autowired + private TtNameplateRecordMapper ttNameplateRecordMapper; + @Autowired + private TmTelephoneCorpusService tmTelephoneCorpusService; - @Autowired - private AiAnalysisRequestLogsService aiAnalysisRequestLogsService; + @Autowired + private AiAnalysisRequestLogsService aiAnalysisRequestLogsService; - @Autowired - private AiAnalysisErrorsMapper aiAnalysisErrorsMapper; - @Autowired - private DiFyService diFyService; - @Value("${dify.corpus.nameplate.appkey}") - private String nameplateAppKey; + @Autowired + private AiAnalysisErrorsMapper aiAnalysisErrorsMapper; + @Autowired + private DiFyService diFyService; + @Value("${dify.corpus.nameplate.appkey}") + private String nameplateAppKey; - @Value("${dify.corpus.portrait.oneToken}") - private String oneTokenPortrait; + @Value("${dify.corpus.portrait.oneToken}") + private String oneTokenPortrait; - @Value("${batch.size}") - public int pageSize = 100; + @Value("${batch.size}") + public int pageSize = 100; - @Autowired - private DataMaskingRuleService dataMaskingRuleService; - @Override - public void runNameplateCorpusDifyRetry(String paramJson) { - long startTime = System.currentTimeMillis(); - log.info("runNameplateCorpusDifyRetry paramJson {}", paramJson); - // 获取当前日期 - LocalDate today = LocalDate.now(); - // 获取前一天日期 - LocalDate yesterday = today.minusDays(1); - boolean retry = true; - List customerFlowIds = null; - // 格式化输出 - String formattedDate = yesterday.toString(); // 默认格式为 yyyy-MM-dd - String statTime = formattedDate.concat(" 00:00:00"); - String endTime = formattedDate.concat(" 23:59:59"); - if (StringUtils.isNotBlank(paramJson)) { - JSONObject paramJsonObj = JSONObject.parseObject(paramJson); - if (null != paramJsonObj && paramJsonObj.containsKey(ConstantStr.statTime) && paramJsonObj.containsKey(ConstantStr.endTime)) { - statTime = paramJsonObj.getString(ConstantStr.statTime); - endTime = paramJsonObj.getString(ConstantStr.endTime); - retry = paramJsonObj.getBoolean("retry"); - String customerFlowId = paramJsonObj.getString(ConstantStr.customerFlowIds); - customerFlowIds = Arrays.asList(customerFlowId.split(",")); - } - } + @Autowired + private DataMaskingRuleService dataMaskingRuleService; - Integer total = tmNameplateCorpusMapper.countQueryTmNameplateCorpusRetry(statTime, endTime, customerFlowIds ,retry); - int totalPages = PageDto.getTotalPages(total, pageSize); + @Override + public void runNameplateCorpusDifyRetry(String paramJson) { + long startTime = System.currentTimeMillis(); + log.info("runNameplateCorpusDifyRetry paramJson {}", paramJson); + // 获取当前日期 + LocalDate today = LocalDate.now(); + // 获取前一天日期 + LocalDate yesterday = today.minusDays(1); + boolean retry = true; + List customerFlowIds = null; + // 格式化输出 + String formattedDate = yesterday.toString(); // 默认格式为 yyyy-MM-dd + String statTime = formattedDate.concat(" 00:00:00"); + String endTime = formattedDate.concat(" 23:59:59"); + if (StringUtils.isNotBlank(paramJson)) { + JSONObject paramJsonObj = JSONObject.parseObject(paramJson); + if (null != paramJsonObj && paramJsonObj.containsKey(ConstantStr.statTime) && paramJsonObj.containsKey(ConstantStr.endTime)) { + statTime = paramJsonObj.getString(ConstantStr.statTime); + endTime = paramJsonObj.getString(ConstantStr.endTime); + retry = paramJsonObj.getBoolean("retry"); + String customerFlowId = paramJsonObj.getString(ConstantStr.customerFlowIds); + customerFlowIds = Arrays.asList(customerFlowId.split(",")); + } + } - // 获取消息列表 - int optimalThreadPoolSize = Runtime.getRuntime().availableProcessors() + 1; - log.info("获取的线程数:{}",optimalThreadPoolSize); - // 创建线程池 - ExecutorService executor = Executors.newFixedThreadPool(optimalThreadPoolSize); // 根据需求调整线程池大小 + Integer total = tmNameplateCorpusMapper.countQueryTmNameplateCorpusRetry(statTime, endTime, customerFlowIds, retry); + int totalPages = PageDto.getTotalPages(total, pageSize); - for (int i = 1; i <= totalPages; i++) { - int offset = (i - 1) * pageSize; - List messageList = tmNameplateCorpusMapper.queryTmNameplateCorpusRetry(statTime, endTime, offset, pageSize, customerFlowIds, retry); - // 处理查询到的数据 - // 使用 CompletableFuture 并行处理 - CompletableFuture[] futures = messageList.stream() - .map(item -> CompletableFuture.runAsync(() -> { - try { - processItem(item); - } catch (Exception e) { - log.error("重跑铭牌语料失败: customerFlowId={}, AcceptUserId={}, 异常: {}", - item.getCustomerFlowId(), e.getMessage(), e); - } - }, executor)) - .toArray(CompletableFuture[]::new); - // 等待所有任务完成 - CompletableFuture.allOf(futures).join(); - } - // 关闭线程池 - executor.shutdown(); - log.info("重跑铭牌语料铭牌数据跑批结束 耗时:{}",System.currentTimeMillis()-startTime); - } + // 获取消息列表 + int optimalThreadPoolSize = Runtime.getRuntime().availableProcessors() + 1; + log.info("获取的线程数:{}", optimalThreadPoolSize); + // 创建线程池 + ExecutorService executor = Executors.newFixedThreadPool(optimalThreadPoolSize); // 根据需求调整线程池大小 - public void processItem(TmNameplateCorpus item) { + for (int i = 1; i <= totalPages; i++) { + int offset = (i - 1) * pageSize; + List messageList = tmNameplateCorpusMapper.queryTmNameplateCorpusRetry(statTime, endTime, offset, pageSize, customerFlowIds, retry); + // 处理查询到的数据 + // 使用 CompletableFuture 并行处理 + CompletableFuture[] futures = messageList.stream() + .map(item -> CompletableFuture.runAsync(() -> { + try { + processItem(item); + } catch (Exception e) { + log.error("重跑铭牌语料失败: customerFlowId={}, AcceptUserId={}, 异常: {}", + item.getCustomerFlowId(), e.getMessage(), e); + } + }, executor)) + .toArray(CompletableFuture[]::new); + // 等待所有任务完成 + CompletableFuture.allOf(futures).join(); + } + // 关闭线程池 + executor.shutdown(); + log.info("重跑铭牌语料铭牌数据跑批结束 耗时:{}", System.currentTimeMillis() - startTime); + } - try { - Optional.ofNullable(item).filter(tmNameplateCorpus -> tmNameplateCorpus.getCustomerFlowId()!=null && tmNameplateCorpus.getNameplateContent()!=null).orElseThrow(()->new RuntimeException("铭牌语料为空")); + public void processItem(TmNameplateCorpus item) { - String customerFlowId = item.getCustomerFlowId(); - String nameplateContent = item.getNameplateContent(); - log.info("铭牌数据处理:customerFlowId:{}", customerFlowId); + try { + Optional.ofNullable(item).filter(tmNameplateCorpus -> tmNameplateCorpus.getCustomerFlowId() != null && tmNameplateCorpus.getNameplateContent() != null).orElseThrow(() -> new RuntimeException("铭牌语料为空")); - DiFyReq diFyImageReq = new DiFyReq(); - diFyImageReq.setUser(ConstantStr.corpus_user); - diFyImageReq.setFlowId(nameplateAppKey); - List maskingRuleItems = dataMaskingRuleService.getDataMaskingRuleListByApplicationChannel(BusinessTypeEnum.SMART_ASSISTANT_NAMEPLATE.getCode()); - RunMaskingRuleInput runMaskingRuleInput = new RunMaskingRuleInput(); - runMaskingRuleInput.setDataMaskingRules(maskingRuleItems); + String customerFlowId = item.getCustomerFlowId(); + String nameplateContent = item.getNameplateContent(); + log.info("铭牌数据处理:customerFlowId:{}", customerFlowId); - runMaskingRuleInput.setOldStr(nameplateContent); - String corpusChat = dataMaskingRuleService.runMaskingRule(runMaskingRuleInput); - Map inputMap = new HashMap<>(); - String carModel = tmTelephoneCorpusService.getCarModelList(); - inputMap.put("dialogue", corpusChat); - inputMap.put("model", carModel); - inputMap.put("customerFlowId", item.getCustomerFlowId()); - inputMap.put("analysisScene", "3"); - inputMap.put("version",2); - inputMap.put("businessType",BusinessTypeEnum.SMART_ASSISTANT_NAMEPLATE.getCode()); + DiFyReq diFyImageReq = new DiFyReq(); + diFyImageReq.setUser(ConstantStr.corpus_user); + diFyImageReq.setFlowId(nameplateAppKey); + List maskingRuleItems = dataMaskingRuleService.getDataMaskingRuleListByApplicationChannel(BusinessTypeEnum.SMART_ASSISTANT_NAMEPLATE.getCode()); + RunMaskingRuleInput runMaskingRuleInput = new RunMaskingRuleInput(); + runMaskingRuleInput.setDataMaskingRules(maskingRuleItems); - diFyImageReq.setInputs(inputMap); + runMaskingRuleInput.setOldStr(nameplateContent); + String corpusChat = dataMaskingRuleService.runMaskingRule(runMaskingRuleInput); + Map inputMap = new HashMap<>(); + String carModel = tmTelephoneCorpusService.getCarModelList(); + inputMap.put("dialogue", corpusChat); + inputMap.put("model", carModel); + inputMap.put("customerFlowId", item.getCustomerFlowId()); + inputMap.put("analysisScene", "3"); + inputMap.put("version", 2); + inputMap.put("businessType", BusinessTypeEnum.SMART_ASSISTANT_NAMEPLATE.getCode()); - CorpusReportDTO corpusReportDTO = new CorpusReportDTO(); - corpusReportDTO.setCustomerFlowId(customerFlowId); - corpusReportDTO.setAnalysisScene(3l); - corpusReportDTO.setCarModel(carModel); - // 获取配置 + diFyImageReq.setInputs(inputMap); + + CorpusReportDTO corpusReportDTO = new CorpusReportDTO(); + corpusReportDTO.setCustomerFlowId(customerFlowId); + corpusReportDTO.setAnalysisScene(3l); + corpusReportDTO.setCarModel(carModel); + // 获取配置 - // 使用多线程并行执行两个业务场景 - ExecutorService executorService = Executors.newFixedThreadPool(2); - log.info("第1个业务场景, 优先执行。 "); - long startTime = System.currentTimeMillis(); - CompletableFuture summaryFuture = CompletableFuture.runAsync(() -> { - //第一个业务场景 开始: 总结和分类业务场景 - JSONObject execDifyFlow = diFyService.executeDifyFlow(diFyImageReq, BusinessTypeEnum.SMART_ASSISTANT_NAMEPLATE.getCode(), - JSONObject.toJSONString(corpusReportDTO),null); - log.info("runDify execDifyFlow ,铭牌语料 ,总结和分类业务,返回: {}", execDifyFlow); - }, executorService); - long endTime = System.currentTimeMillis(); - log.info("第一个业务场景(总结和分类)执行时间: {} ms", (endTime - startTime)); - //第一个业务场景, 结束 + // 使用多线程并行执行两个业务场景 + ExecutorService executorService = Executors.newFixedThreadPool(2); + log.info("第1个业务场景, 优先执行。 "); + long startTime = System.currentTimeMillis(); + CompletableFuture summaryFuture = CompletableFuture.runAsync(() -> { + //第一个业务场景 开始: 总结和分类业务场景 + JSONObject execDifyFlow = diFyService.executeDifyFlow(diFyImageReq, BusinessTypeEnum.SMART_ASSISTANT_NAMEPLATE.getCode(), + JSONObject.toJSONString(corpusReportDTO), null); + log.info("runDify execDifyFlow ,铭牌语料 ,总结和分类业务,返回: {}", execDifyFlow); + }, executorService); + long endTime = System.currentTimeMillis(); + log.info("第一个业务场景(总结和分类)执行时间: {} ms", (endTime - startTime)); + //第一个业务场景, 结束 - long startTime2 = System.currentTimeMillis(); - CompletableFuture portraitFuture = CompletableFuture.runAsync(() -> { - //"analysisScene": "分析类型", // 1、企微会话 2、AI通话录音 3、AI铭牌(客流) 4、AI铭牌(试驾) - DiFyReq diFyImageReq2 = new DiFyReq(); - diFyImageReq2.setUser(ConstantStr.corpus_user); - Map inputMap2 = new HashMap<>(); - inputMap2.put("businessId",item.getCustomerFlowId()); - inputMap2.put("communicateDate",item.getNameplateEndTime().toString()); - inputMap2.put("analysisScene", "3"); - inputMap2.put("version",2); - inputMap2.put("chat",JSONObject.toJSONString(corpusReportDTO)); + long startTime2 = System.currentTimeMillis(); + CompletableFuture portraitFuture = CompletableFuture.runAsync(() -> { + //"analysisScene": "分析类型", // 1、企微会话 2、AI通话录音 3、AI铭牌(客流) 4、AI铭牌(试驾) + DiFyReq diFyImageReq2 = new DiFyReq(); + diFyImageReq2.setUser(ConstantStr.corpus_user); + Map inputMap2 = new HashMap<>(); + inputMap2.put("businessId", item.getCustomerFlowId()); + inputMap2.put("communicateDate", item.getNameplateEndTime().toString()); + inputMap2.put("analysisScene", "3"); + inputMap2.put("version", 2); + inputMap2.put("chat", JSONObject.toJSONString(corpusReportDTO)); - diFyImageReq2.setInputs(inputMap2); - // 创建新的DiFyReq对象以避免线程安全问题 - diFyImageReq2.setFlowId(oneTokenPortrait); - log.info("runDify execDifyFlow ,客户画像场景 ,token-{} , 对象: {}", oneTokenPortrait, diFyImageReq2); - JSONObject execDifyFlowForPortrait = diFyService.executeDifyFlow(diFyImageReq2, BusinessTypeEnum.CORPUS_PORTRAIT_NAMEPLATE.getCode(), - JSONObject.toJSONString(corpusReportDTO), null); - updateNameplate(execDifyFlowForPortrait.toJSONString()); - log.info("runDify execDifyFlow ,铭牌语料 ,客户画像场景,返回: {}", execDifyFlowForPortrait); + diFyImageReq2.setInputs(inputMap2); + // 创建新的DiFyReq对象以避免线程安全问题 + diFyImageReq2.setFlowId(oneTokenPortrait); + log.info("runDify execDifyFlow ,客户画像场景 ,token-{} , 对象: {}", oneTokenPortrait, diFyImageReq2); + JSONObject execDifyFlowForPortrait = diFyService.executeDifyFlow(diFyImageReq2, BusinessTypeEnum.CORPUS_PORTRAIT_NAMEPLATE.getCode(), + JSONObject.toJSONString(corpusReportDTO), null); + updateNameplate(execDifyFlowForPortrait.toJSONString()); + log.info("runDify execDifyFlow ,铭牌语料 ,客户画像场景,返回: {}", execDifyFlowForPortrait); - }, executorService); - long endTime2 = System.currentTimeMillis(); - log.info("第二个业务场景(用户画像)执行时间: {} ms", (endTime2 - startTime2)); + }, executorService); + long endTime2 = System.currentTimeMillis(); + log.info("第二个业务场景(用户画像)执行时间: {} ms", (endTime2 - startTime2)); - } catch (Exception e) { - log.error("nameplate processItem error {}", e); - } + } catch (Exception e) { + log.error("nameplate processItem error {}", e); + } - } + } + String outputsFinal = "outputs"; + String aiAnalysisRequestIdFinal = "aiAnalysisRequestId"; - String outputsFinal="outputs"; - String aiAnalysisRequestIdFinal = "aiAnalysisRequestId"; - @Override - public void sendNameplateLto(JSONObject execDifyFlow,String aiAnalysisRequestId, TmNameplateCorpus tmNameplateCorpus,String businessType) { - log.info("铭牌sendNameplateLto getCustomerFlowId:{}", tmNameplateCorpus.getCustomerFlowId()); - log.info("铭牌sendNameplateLto text contnt :{}", execDifyFlow.toString()); + @Override + public void sendNameplateLto(JSONObject execDifyFlow, String aiAnalysisRequestId, TmNameplateCorpus tmNameplateCorpus, String businessType) { - if (null != execDifyFlow && execDifyFlow.get("status").equals("succeeded")) { - String text = execDifyFlow.getString(outputsFinal); - // 发送MQ - log.info("铭牌send mq 业务类型是:{}, Json 是:{}", businessType, text); - if (BusinessTypeEnum.CORPUS_PORTRAIT_NAMEPLATE.getCode().equals(businessType)) {// 客户画像 - tmTelephoneCorpusService.sendMq( CategoryEnum.NAMEPLATE_VOICE_PORTRAIT.getCode(), text); - }else { //一句话总结+分类 - tmTelephoneCorpusService.sendMq( CategoryEnum.NAMEPLATE_VOICE.getCode(), text); - } + try { + log.info("铭牌sendNameplateLto getCustomerFlowId:{}", tmNameplateCorpus.getCustomerFlowId()); + log.info("铭牌sendNameplateLto text contnt :{}", execDifyFlow); + log.info("铭牌sendNameplateLto toJSONString :{}", execDifyFlow.toJSONString()); + + if (null != execDifyFlow && execDifyFlow.get("status").equals("succeeded")) { + String text = execDifyFlow.getString(outputsFinal); + // 发送MQ + log.info("铭牌send mq 业务类型是:{}, Json 是:{}", businessType, text); + if (BusinessTypeEnum.CORPUS_PORTRAIT_NAMEPLATE.getCode().equals(businessType)) {// 客户画像 + tmTelephoneCorpusService.sendMq(CategoryEnum.NAMEPLATE_VOICE_PORTRAIT.getCode(), text); + } else { //一句话总结+分类 + tmTelephoneCorpusService.sendMq(CategoryEnum.NAMEPLATE_VOICE.getCode(), text); + } + + ttNameplateRecordMapper.insert(TtNameplateRecord.builder().nameplateCorpusId(tmNameplateCorpus.getId()).customerFlowId(tmNameplateCorpus.getCustomerFlowId()).build()); + aiAnalysisRequestLogsService.saveOrUpdateAiAnalysisRequestLogs(AiAnalysisRequestLogs.builder().aiAnalysisRequestId(aiAnalysisRequestId).businessResponse(text).build()); + + } + } catch (Exception e) { + log.info(" 铭牌语料处理保存报告异常processItem:{} ", e); + } + } + + @Override + public ResultMsg updateNameplate(String message) { + try { + + if (StringUtils.isNotEmpty(message)) { + log.info("updateNameplate 回调 message: {}", message); + JSONObject analysisResp = JSONObject.parseObject(message); + String aiAnalysisRequestId = analysisResp.getString(aiAnalysisRequestIdFinal); + String difyResponse = analysisResp.getString("difyResponse"); + String customerFlowId = analysisResp.getString("customerFlowId"); + String businessType; + + AiAnalysisRequestLogs aiAnalysisRequestLogs = new AiAnalysisRequestLogs(); + JSONObject difyJson = null; + if (StringUtils.isEmpty(customerFlowId)) { // 客户画像场景 + log.info("customerFlowId 为空,客户画像场景"); + String text = analysisResp.getString(outputsFinal); + JSONObject outputs = JSONObject.parseObject(text); + customerFlowId = outputs.getString("businessId"); + aiAnalysisRequestId = analysisResp.getString(aiAnalysisRequestIdFinal); + businessType = BusinessTypeEnum.CORPUS_PORTRAIT_NAMEPLATE.getCode(); + aiAnalysisRequestLogs.setBusinessResponse(text); + } else { //总结+分类 + businessType = BusinessTypeEnum.SMART_ASSISTANT_NAMEPLATE.getCode(); + difyJson = JSONObject.parseObject(difyResponse); + aiAnalysisRequestLogs.setBusinessResponse(difyJson.getString(outputsFinal)); + } - try { - ttNameplateRecordMapper.insert(TtNameplateRecord.builder().nameplateCorpusId(tmNameplateCorpus.getId()).customerFlowId(tmNameplateCorpus.getCustomerFlowId()).build()); - aiAnalysisRequestLogsService.saveOrUpdateAiAnalysisRequestLogs(AiAnalysisRequestLogs.builder().aiAnalysisRequestId(aiAnalysisRequestId).businessResponse(text).build()); - } catch (Exception e) { - log.info(" 铭牌语料处理保存报告异常processItem:{} ", e); - } - } - } + Optional.ofNullable(aiAnalysisRequestLogsService.queryByAiAnalysisRequestId(aiAnalysisRequestId)) + .orElseThrow(() -> new IllegalArgumentException("AiAnalysisRequestId查询对象为空!")); + log.info("1111111111111,{}", customerFlowId); + aiAnalysisRequestLogs.setAiAnalysisRequestId(aiAnalysisRequestId); + aiAnalysisRequestLogs.setDifyResponse(difyResponse); + aiAnalysisRequestLogs.setAiAnalysisRequestType(businessType); + aiAnalysisRequestLogsService.saveOrUpdateAiAnalysisRequestLogs(aiAnalysisRequestLogs); + log.info("333333333333"); - @Override - public ResultMsg updateNameplate(String message) { - try { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(TmNameplateCorpus::getCustomerFlowId, customerFlowId); + List tmNameplateCorpusList = tmNameplateCorpusMapper.selectList(queryWrapper); + if (CollectionUtils.isNotEmpty(tmNameplateCorpusList)) { //这是补偿机制 + log.info("66666666666666"); + sendNameplateLto(difyJson, aiAnalysisRequestId, tmNameplateCorpusList.get(0), businessType); + LambdaQueryWrapper errorQueryWrapper = new LambdaQueryWrapper<>(); + errorQueryWrapper.eq(AiAnalysisErrors::getAiAnalysisRequestId, aiAnalysisRequestId); + errorQueryWrapper.eq(AiAnalysisErrors::getAiAnalysisErrorHandlingStatus, "0"); + errorQueryWrapper.eq(AiAnalysisErrors::getIsDeleted, "0"); + AiAnalysisErrors oldAiAnalysisErrors = aiAnalysisErrorsMapper.selectOne(errorQueryWrapper); + if (oldAiAnalysisErrors != null) { + aiAnalysisErrorsMapper.update(AiAnalysisErrors.builder().aiAnalysisRequestId(oldAiAnalysisErrors.getAiAnalysisRequestId()).aiAnalysisErrorHandlingStatus("1").build(), errorQueryWrapper); + } + } else { + log.info("没找到语料记录"); + } + return ResultMsg.ok(); + } + } catch (Exception e) { + log.error("updateNameplate error {}", e); - if(StringUtils.isNotEmpty(message)){ - log.info("updateNameplate 回调 message: {}", message); - JSONObject analysisResp = JSONObject.parseObject(message); - String aiAnalysisRequestId = analysisResp.getString(aiAnalysisRequestIdFinal); - String difyResponse = analysisResp.getString("difyResponse"); - String customerFlowId = analysisResp.getString("customerFlowId"); - String businessType; + } - AiAnalysisRequestLogs aiAnalysisRequestLogs = new AiAnalysisRequestLogs(); - JSONObject difyJson =null; - if (StringUtils.isEmpty(customerFlowId)){ // 客户画像场景 - log.info("customerFlowId 为空,客户画像场景"); - String text = analysisResp.getString(outputsFinal); - JSONObject outputs = JSONObject.parseObject(text); - customerFlowId = outputs.getString("businessId"); - aiAnalysisRequestId=analysisResp.getString(aiAnalysisRequestIdFinal); - businessType=BusinessTypeEnum.CORPUS_PORTRAIT_NAMEPLATE.getCode(); - aiAnalysisRequestLogs.setBusinessResponse(text); - }else { //总结+分类 - businessType = BusinessTypeEnum.SMART_ASSISTANT_NAMEPLATE.getCode(); - difyJson = JSONObject.parseObject(difyResponse); - aiAnalysisRequestLogs.setBusinessResponse(difyJson.getString(outputsFinal)); - } + return ResultMsg.failed(); + } + @Override + public ResultMsg mockInsert(String data) { + if (StringUtils.isNotEmpty(data)) { - Optional.ofNullable(aiAnalysisRequestLogsService.queryByAiAnalysisRequestId(aiAnalysisRequestId)) - .orElseThrow(() -> new IllegalArgumentException("AiAnalysisRequestId查询对象为空!")); - log.info("1111111111111,{}", customerFlowId); - aiAnalysisRequestLogs.setAiAnalysisRequestId(aiAnalysisRequestId); - aiAnalysisRequestLogs.setDifyResponse(difyResponse); - aiAnalysisRequestLogs.setAiAnalysisRequestType(businessType); - aiAnalysisRequestLogsService.saveOrUpdateAiAnalysisRequestLogs(aiAnalysisRequestLogs); - log.info("333333333333"); + List tmNameplateCorpusList = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + TmNameplateCorpus analysisResp = JSONObject.parseObject(data, TmNameplateCorpus.class); + analysisResp.setCustomerFlowId(analysisResp.getCustomerFlowId() + i); + tmNameplateCorpusList.add(analysisResp); + } + this.saveBatch(tmNameplateCorpusList); + return ResultMsg.ok(); + } + return ResultMsg.failed(); + } - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(TmNameplateCorpus::getCustomerFlowId, customerFlowId); - List tmNameplateCorpusList = tmNameplateCorpusMapper.selectList(queryWrapper); - if (CollectionUtils.isNotEmpty(tmNameplateCorpusList)){ //这是补偿机制 - log.info("66666666666666"); - sendNameplateLto(difyJson,aiAnalysisRequestId, tmNameplateCorpusList.get(0),businessType); - LambdaQueryWrapper errorQueryWrapper = new LambdaQueryWrapper<>(); - errorQueryWrapper.eq(AiAnalysisErrors::getAiAnalysisRequestId, aiAnalysisRequestId); - errorQueryWrapper.eq(AiAnalysisErrors::getAiAnalysisErrorHandlingStatus, "0"); - errorQueryWrapper.eq(AiAnalysisErrors::getIsDeleted, "0"); - AiAnalysisErrors oldAiAnalysisErrors = aiAnalysisErrorsMapper.selectOne(errorQueryWrapper); - if (oldAiAnalysisErrors != null) { - aiAnalysisErrorsMapper.update(AiAnalysisErrors.builder().aiAnalysisRequestId(oldAiAnalysisErrors.getAiAnalysisRequestId()).aiAnalysisErrorHandlingStatus("1").build(), errorQueryWrapper); - } - }else { - log.info("没找到语料记录"); - } - return ResultMsg.ok(); - } - } catch (Exception e) { - log.error("updateNameplate error {}", e); - - } - - return ResultMsg.failed(); - } - @Override - public ResultMsg mockInsert(String data) { - if(StringUtils.isNotEmpty(data)){ - - List tmNameplateCorpusList = new ArrayList<>(); - for(int i=0;i<100;i++){ - TmNameplateCorpus analysisResp = JSONObject.parseObject(data, TmNameplateCorpus.class); - analysisResp.setCustomerFlowId(analysisResp.getCustomerFlowId()+i); - tmNameplateCorpusList.add(analysisResp); - } - this.saveBatch(tmNameplateCorpusList); - return ResultMsg.ok(); - } - return ResultMsg.failed(); - } - @Override - public List queryTelephoneCorpusByCustomerFlowId(List customerFlowIds) { - return tmNameplateCorpusMapper.queryTmNameplateCorpusByCustomerFlowIds(customerFlowIds); - } + @Override + public List queryTelephoneCorpusByCustomerFlowId(List customerFlowIds) { + return tmNameplateCorpusMapper.queryTmNameplateCorpusByCustomerFlowIds(customerFlowIds); + } } \ No newline at end of file