加日志,发送mq之前
This commit is contained in:
@@ -32,8 +32,8 @@ import java.util.concurrent.Executors;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 铭牌语料表-同步表
|
|
||||||
* @author rz
|
* @author rz
|
||||||
|
* @description 铭牌语料表-同步表
|
||||||
* @date 2025-03-04
|
* @date 2025-03-04
|
||||||
*/
|
*/
|
||||||
@RefreshScope
|
@RefreshScope
|
||||||
@@ -42,282 +42,287 @@ import java.util.concurrent.Executors;
|
|||||||
public class TmNameplateCorpusServiceImpl extends ServiceImpl<TmNameplateCorpusMapper, TmNameplateCorpus> implements TmNameplateCorpusService {
|
public class TmNameplateCorpusServiceImpl extends ServiceImpl<TmNameplateCorpusMapper, TmNameplateCorpus> implements TmNameplateCorpusService {
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TmNameplateCorpusMapper tmNameplateCorpusMapper;
|
private TmNameplateCorpusMapper tmNameplateCorpusMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TtNameplateRecordMapper ttNameplateRecordMapper;
|
private TtNameplateRecordMapper ttNameplateRecordMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private TmTelephoneCorpusService tmTelephoneCorpusService;
|
private TmTelephoneCorpusService tmTelephoneCorpusService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AiAnalysisRequestLogsService aiAnalysisRequestLogsService;
|
private AiAnalysisRequestLogsService aiAnalysisRequestLogsService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AiAnalysisErrorsMapper aiAnalysisErrorsMapper;
|
private AiAnalysisErrorsMapper aiAnalysisErrorsMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private DiFyService diFyService;
|
private DiFyService diFyService;
|
||||||
@Value("${dify.corpus.nameplate.appkey}")
|
@Value("${dify.corpus.nameplate.appkey}")
|
||||||
private String nameplateAppKey;
|
private String nameplateAppKey;
|
||||||
|
|
||||||
@Value("${dify.corpus.portrait.oneToken}")
|
@Value("${dify.corpus.portrait.oneToken}")
|
||||||
private String oneTokenPortrait;
|
private String oneTokenPortrait;
|
||||||
|
|
||||||
@Value("${batch.size}")
|
@Value("${batch.size}")
|
||||||
public int pageSize = 100;
|
public int pageSize = 100;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DataMaskingRuleService dataMaskingRuleService;
|
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<String> 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(","));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer total = tmNameplateCorpusMapper.countQueryTmNameplateCorpusRetry(statTime, endTime, customerFlowIds ,retry);
|
@Override
|
||||||
int totalPages = PageDto.getTotalPages(total, pageSize);
|
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<String> 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(","));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 获取消息列表
|
Integer total = tmNameplateCorpusMapper.countQueryTmNameplateCorpusRetry(statTime, endTime, customerFlowIds, retry);
|
||||||
int optimalThreadPoolSize = Runtime.getRuntime().availableProcessors() + 1;
|
int totalPages = PageDto.getTotalPages(total, pageSize);
|
||||||
log.info("获取的线程数:{}",optimalThreadPoolSize);
|
|
||||||
// 创建线程池
|
|
||||||
ExecutorService executor = Executors.newFixedThreadPool(optimalThreadPoolSize); // 根据需求调整线程池大小
|
|
||||||
|
|
||||||
for (int i = 1; i <= totalPages; i++) {
|
// 获取消息列表
|
||||||
int offset = (i - 1) * pageSize;
|
int optimalThreadPoolSize = Runtime.getRuntime().availableProcessors() + 1;
|
||||||
List<TmNameplateCorpus> messageList = tmNameplateCorpusMapper.queryTmNameplateCorpusRetry(statTime, endTime, offset, pageSize, customerFlowIds, retry);
|
log.info("获取的线程数:{}", optimalThreadPoolSize);
|
||||||
// 处理查询到的数据
|
// 创建线程池
|
||||||
// 使用 CompletableFuture 并行处理
|
ExecutorService executor = Executors.newFixedThreadPool(optimalThreadPoolSize); // 根据需求调整线程池大小
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void processItem(TmNameplateCorpus item) {
|
for (int i = 1; i <= totalPages; i++) {
|
||||||
|
int offset = (i - 1) * pageSize;
|
||||||
|
List<TmNameplateCorpus> 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 {
|
public void processItem(TmNameplateCorpus item) {
|
||||||
Optional.ofNullable(item).filter(tmNameplateCorpus -> tmNameplateCorpus.getCustomerFlowId()!=null && tmNameplateCorpus.getNameplateContent()!=null).orElseThrow(()->new RuntimeException("铭牌语料为空"));
|
|
||||||
|
|
||||||
String customerFlowId = item.getCustomerFlowId();
|
try {
|
||||||
String nameplateContent = item.getNameplateContent();
|
Optional.ofNullable(item).filter(tmNameplateCorpus -> tmNameplateCorpus.getCustomerFlowId() != null && tmNameplateCorpus.getNameplateContent() != null).orElseThrow(() -> new RuntimeException("铭牌语料为空"));
|
||||||
log.info("铭牌数据处理:customerFlowId:{}", customerFlowId);
|
|
||||||
|
|
||||||
DiFyReq diFyImageReq = new DiFyReq();
|
String customerFlowId = item.getCustomerFlowId();
|
||||||
diFyImageReq.setUser(ConstantStr.corpus_user);
|
String nameplateContent = item.getNameplateContent();
|
||||||
diFyImageReq.setFlowId(nameplateAppKey);
|
log.info("铭牌数据处理:customerFlowId:{}", customerFlowId);
|
||||||
List<DataMaskingRule> maskingRuleItems = dataMaskingRuleService.getDataMaskingRuleListByApplicationChannel(BusinessTypeEnum.SMART_ASSISTANT_NAMEPLATE.getCode());
|
|
||||||
RunMaskingRuleInput runMaskingRuleInput = new RunMaskingRuleInput();
|
|
||||||
runMaskingRuleInput.setDataMaskingRules(maskingRuleItems);
|
|
||||||
|
|
||||||
runMaskingRuleInput.setOldStr(nameplateContent);
|
DiFyReq diFyImageReq = new DiFyReq();
|
||||||
String corpusChat = dataMaskingRuleService.runMaskingRule(runMaskingRuleInput);
|
diFyImageReq.setUser(ConstantStr.corpus_user);
|
||||||
Map<String, Object> inputMap = new HashMap<>();
|
diFyImageReq.setFlowId(nameplateAppKey);
|
||||||
String carModel = tmTelephoneCorpusService.getCarModelList();
|
List<DataMaskingRule> maskingRuleItems = dataMaskingRuleService.getDataMaskingRuleListByApplicationChannel(BusinessTypeEnum.SMART_ASSISTANT_NAMEPLATE.getCode());
|
||||||
inputMap.put("dialogue", corpusChat);
|
RunMaskingRuleInput runMaskingRuleInput = new RunMaskingRuleInput();
|
||||||
inputMap.put("model", carModel);
|
runMaskingRuleInput.setDataMaskingRules(maskingRuleItems);
|
||||||
inputMap.put("customerFlowId", item.getCustomerFlowId());
|
|
||||||
inputMap.put("analysisScene", "3");
|
|
||||||
inputMap.put("version",2);
|
|
||||||
inputMap.put("businessType",BusinessTypeEnum.SMART_ASSISTANT_NAMEPLATE.getCode());
|
|
||||||
|
|
||||||
diFyImageReq.setInputs(inputMap);
|
runMaskingRuleInput.setOldStr(nameplateContent);
|
||||||
|
String corpusChat = dataMaskingRuleService.runMaskingRule(runMaskingRuleInput);
|
||||||
|
Map<String, Object> 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();
|
diFyImageReq.setInputs(inputMap);
|
||||||
corpusReportDTO.setCustomerFlowId(customerFlowId);
|
|
||||||
corpusReportDTO.setAnalysisScene(3l);
|
CorpusReportDTO corpusReportDTO = new CorpusReportDTO();
|
||||||
corpusReportDTO.setCarModel(carModel);
|
corpusReportDTO.setCustomerFlowId(customerFlowId);
|
||||||
// 获取配置
|
corpusReportDTO.setAnalysisScene(3l);
|
||||||
|
corpusReportDTO.setCarModel(carModel);
|
||||||
|
// 获取配置
|
||||||
|
|
||||||
|
|
||||||
// 使用多线程并行执行两个业务场景
|
// 使用多线程并行执行两个业务场景
|
||||||
ExecutorService executorService = Executors.newFixedThreadPool(2);
|
ExecutorService executorService = Executors.newFixedThreadPool(2);
|
||||||
log.info("第1个业务场景, 优先执行。 ");
|
log.info("第1个业务场景, 优先执行。 ");
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
CompletableFuture<Void> summaryFuture = CompletableFuture.runAsync(() -> {
|
CompletableFuture<Void> summaryFuture = CompletableFuture.runAsync(() -> {
|
||||||
//第一个业务场景 开始: 总结和分类业务场景
|
//第一个业务场景 开始: 总结和分类业务场景
|
||||||
JSONObject execDifyFlow = diFyService.executeDifyFlow(diFyImageReq, BusinessTypeEnum.SMART_ASSISTANT_NAMEPLATE.getCode(),
|
JSONObject execDifyFlow = diFyService.executeDifyFlow(diFyImageReq, BusinessTypeEnum.SMART_ASSISTANT_NAMEPLATE.getCode(),
|
||||||
JSONObject.toJSONString(corpusReportDTO),null);
|
JSONObject.toJSONString(corpusReportDTO), null);
|
||||||
log.info("runDify execDifyFlow ,铭牌语料 ,总结和分类业务,返回: {}", execDifyFlow);
|
log.info("runDify execDifyFlow ,铭牌语料 ,总结和分类业务,返回: {}", execDifyFlow);
|
||||||
}, executorService);
|
}, executorService);
|
||||||
long endTime = System.currentTimeMillis();
|
long endTime = System.currentTimeMillis();
|
||||||
log.info("第一个业务场景(总结和分类)执行时间: {} ms", (endTime - startTime));
|
log.info("第一个业务场景(总结和分类)执行时间: {} ms", (endTime - startTime));
|
||||||
//第一个业务场景, 结束
|
//第一个业务场景, 结束
|
||||||
|
|
||||||
long startTime2 = System.currentTimeMillis();
|
long startTime2 = System.currentTimeMillis();
|
||||||
CompletableFuture<Void> portraitFuture = CompletableFuture.runAsync(() -> {
|
CompletableFuture<Void> portraitFuture = CompletableFuture.runAsync(() -> {
|
||||||
//"analysisScene": "分析类型", // 1、企微会话 2、AI通话录音 3、AI铭牌(客流) 4、AI铭牌(试驾)
|
//"analysisScene": "分析类型", // 1、企微会话 2、AI通话录音 3、AI铭牌(客流) 4、AI铭牌(试驾)
|
||||||
DiFyReq diFyImageReq2 = new DiFyReq();
|
DiFyReq diFyImageReq2 = new DiFyReq();
|
||||||
diFyImageReq2.setUser(ConstantStr.corpus_user);
|
diFyImageReq2.setUser(ConstantStr.corpus_user);
|
||||||
Map<String, Object> inputMap2 = new HashMap<>();
|
Map<String, Object> inputMap2 = new HashMap<>();
|
||||||
inputMap2.put("businessId",item.getCustomerFlowId());
|
inputMap2.put("businessId", item.getCustomerFlowId());
|
||||||
inputMap2.put("communicateDate",item.getNameplateEndTime().toString());
|
inputMap2.put("communicateDate", item.getNameplateEndTime().toString());
|
||||||
inputMap2.put("analysisScene", "3");
|
inputMap2.put("analysisScene", "3");
|
||||||
inputMap2.put("version",2);
|
inputMap2.put("version", 2);
|
||||||
inputMap2.put("chat",JSONObject.toJSONString(corpusReportDTO));
|
inputMap2.put("chat", JSONObject.toJSONString(corpusReportDTO));
|
||||||
|
|
||||||
diFyImageReq2.setInputs(inputMap2);
|
diFyImageReq2.setInputs(inputMap2);
|
||||||
// 创建新的DiFyReq对象以避免线程安全问题
|
// 创建新的DiFyReq对象以避免线程安全问题
|
||||||
diFyImageReq2.setFlowId(oneTokenPortrait);
|
diFyImageReq2.setFlowId(oneTokenPortrait);
|
||||||
log.info("runDify execDifyFlow ,客户画像场景 ,token-{} , 对象: {}", oneTokenPortrait, diFyImageReq2);
|
log.info("runDify execDifyFlow ,客户画像场景 ,token-{} , 对象: {}", oneTokenPortrait, diFyImageReq2);
|
||||||
JSONObject execDifyFlowForPortrait = diFyService.executeDifyFlow(diFyImageReq2, BusinessTypeEnum.CORPUS_PORTRAIT_NAMEPLATE.getCode(),
|
JSONObject execDifyFlowForPortrait = diFyService.executeDifyFlow(diFyImageReq2, BusinessTypeEnum.CORPUS_PORTRAIT_NAMEPLATE.getCode(),
|
||||||
JSONObject.toJSONString(corpusReportDTO), null);
|
JSONObject.toJSONString(corpusReportDTO), null);
|
||||||
updateNameplate(execDifyFlowForPortrait.toJSONString());
|
updateNameplate(execDifyFlowForPortrait.toJSONString());
|
||||||
log.info("runDify execDifyFlow ,铭牌语料 ,客户画像场景,返回: {}", execDifyFlowForPortrait);
|
log.info("runDify execDifyFlow ,铭牌语料 ,客户画像场景,返回: {}", execDifyFlowForPortrait);
|
||||||
|
|
||||||
}, executorService);
|
}, executorService);
|
||||||
long endTime2 = System.currentTimeMillis();
|
long endTime2 = System.currentTimeMillis();
|
||||||
log.info("第二个业务场景(用户画像)执行时间: {} ms", (endTime2 - startTime2));
|
log.info("第二个业务场景(用户画像)执行时间: {} ms", (endTime2 - startTime2));
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("nameplate processItem error {}", e);
|
log.error("nameplate processItem error {}", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String outputsFinal = "outputs";
|
||||||
|
String aiAnalysisRequestIdFinal = "aiAnalysisRequestId";
|
||||||
|
|
||||||
String outputsFinal="outputs";
|
@Override
|
||||||
String aiAnalysisRequestIdFinal = "aiAnalysisRequestId";
|
public void sendNameplateLto(JSONObject execDifyFlow, String aiAnalysisRequestId, TmNameplateCorpus tmNameplateCorpus, String businessType) {
|
||||||
@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());
|
|
||||||
|
|
||||||
if (null != execDifyFlow && execDifyFlow.get("status").equals("succeeded")) {
|
try {
|
||||||
String text = execDifyFlow.getString(outputsFinal);
|
log.info("铭牌sendNameplateLto getCustomerFlowId:{}", tmNameplateCorpus.getCustomerFlowId());
|
||||||
// 发送MQ
|
log.info("铭牌sendNameplateLto text contnt :{}", execDifyFlow);
|
||||||
log.info("铭牌send mq 业务类型是:{}, Json 是:{}", businessType, text);
|
log.info("铭牌sendNameplateLto toJSONString :{}", execDifyFlow.toJSONString());
|
||||||
if (BusinessTypeEnum.CORPUS_PORTRAIT_NAMEPLATE.getCode().equals(businessType)) {// 客户画像
|
|
||||||
tmTelephoneCorpusService.sendMq( CategoryEnum.NAMEPLATE_VOICE_PORTRAIT.getCode(), text);
|
if (null != execDifyFlow && execDifyFlow.get("status").equals("succeeded")) {
|
||||||
}else { //一句话总结+分类
|
String text = execDifyFlow.getString(outputsFinal);
|
||||||
tmTelephoneCorpusService.sendMq( CategoryEnum.NAMEPLATE_VOICE.getCode(), text);
|
// 发送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<Object> 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 {
|
Optional.ofNullable(aiAnalysisRequestLogsService.queryByAiAnalysisRequestId(aiAnalysisRequestId))
|
||||||
ttNameplateRecordMapper.insert(TtNameplateRecord.builder().nameplateCorpusId(tmNameplateCorpus.getId()).customerFlowId(tmNameplateCorpus.getCustomerFlowId()).build());
|
.orElseThrow(() -> new IllegalArgumentException("AiAnalysisRequestId查询对象为空!"));
|
||||||
aiAnalysisRequestLogsService.saveOrUpdateAiAnalysisRequestLogs(AiAnalysisRequestLogs.builder().aiAnalysisRequestId(aiAnalysisRequestId).businessResponse(text).build());
|
log.info("1111111111111,{}", customerFlowId);
|
||||||
} catch (Exception e) {
|
aiAnalysisRequestLogs.setAiAnalysisRequestId(aiAnalysisRequestId);
|
||||||
log.info(" 铭牌语料处理保存报告异常processItem:{} ", e);
|
aiAnalysisRequestLogs.setDifyResponse(difyResponse);
|
||||||
}
|
aiAnalysisRequestLogs.setAiAnalysisRequestType(businessType);
|
||||||
}
|
aiAnalysisRequestLogsService.saveOrUpdateAiAnalysisRequestLogs(aiAnalysisRequestLogs);
|
||||||
}
|
log.info("333333333333");
|
||||||
|
|
||||||
@Override
|
LambdaQueryWrapper<TmNameplateCorpus> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
public ResultMsg<Object> updateNameplate(String message) {
|
queryWrapper.eq(TmNameplateCorpus::getCustomerFlowId, customerFlowId);
|
||||||
try {
|
List<TmNameplateCorpus> tmNameplateCorpusList = tmNameplateCorpusMapper.selectList(queryWrapper);
|
||||||
|
if (CollectionUtils.isNotEmpty(tmNameplateCorpusList)) { //这是补偿机制
|
||||||
|
log.info("66666666666666");
|
||||||
|
sendNameplateLto(difyJson, aiAnalysisRequestId, tmNameplateCorpusList.get(0), businessType);
|
||||||
|
LambdaQueryWrapper<AiAnalysisErrors> 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();
|
return ResultMsg.failed();
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResultMsg<Object> mockInsert(String data) {
|
||||||
|
if (StringUtils.isNotEmpty(data)) {
|
||||||
|
|
||||||
Optional.ofNullable(aiAnalysisRequestLogsService.queryByAiAnalysisRequestId(aiAnalysisRequestId))
|
List<TmNameplateCorpus> tmNameplateCorpusList = new ArrayList<>();
|
||||||
.orElseThrow(() -> new IllegalArgumentException("AiAnalysisRequestId查询对象为空!"));
|
for (int i = 0; i < 100; i++) {
|
||||||
log.info("1111111111111,{}", customerFlowId);
|
TmNameplateCorpus analysisResp = JSONObject.parseObject(data, TmNameplateCorpus.class);
|
||||||
aiAnalysisRequestLogs.setAiAnalysisRequestId(aiAnalysisRequestId);
|
analysisResp.setCustomerFlowId(analysisResp.getCustomerFlowId() + i);
|
||||||
aiAnalysisRequestLogs.setDifyResponse(difyResponse);
|
tmNameplateCorpusList.add(analysisResp);
|
||||||
aiAnalysisRequestLogs.setAiAnalysisRequestType(businessType);
|
}
|
||||||
aiAnalysisRequestLogsService.saveOrUpdateAiAnalysisRequestLogs(aiAnalysisRequestLogs);
|
this.saveBatch(tmNameplateCorpusList);
|
||||||
log.info("333333333333");
|
return ResultMsg.ok();
|
||||||
|
}
|
||||||
|
return ResultMsg.failed();
|
||||||
|
}
|
||||||
|
|
||||||
LambdaQueryWrapper<TmNameplateCorpus> queryWrapper = new LambdaQueryWrapper<>();
|
@Override
|
||||||
queryWrapper.eq(TmNameplateCorpus::getCustomerFlowId, customerFlowId);
|
public List<TmNameplateCorpus> queryTelephoneCorpusByCustomerFlowId(List<String> customerFlowIds) {
|
||||||
List<TmNameplateCorpus> tmNameplateCorpusList = tmNameplateCorpusMapper.selectList(queryWrapper);
|
return tmNameplateCorpusMapper.queryTmNameplateCorpusByCustomerFlowIds(customerFlowIds);
|
||||||
if (CollectionUtils.isNotEmpty(tmNameplateCorpusList)){ //这是补偿机制
|
}
|
||||||
log.info("66666666666666");
|
|
||||||
sendNameplateLto(difyJson,aiAnalysisRequestId, tmNameplateCorpusList.get(0),businessType);
|
|
||||||
LambdaQueryWrapper<AiAnalysisErrors> 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<Object> mockInsert(String data) {
|
|
||||||
if(StringUtils.isNotEmpty(data)){
|
|
||||||
|
|
||||||
List<TmNameplateCorpus> 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<TmNameplateCorpus> queryTelephoneCorpusByCustomerFlowId(List<String> customerFlowIds) {
|
|
||||||
return tmNameplateCorpusMapper.queryTmNameplateCorpusByCustomerFlowIds(customerFlowIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user