Merge remote-tracking branch 'origin/feature-20250520-release' into feature_20250521_nameplate_difyResult

This commit is contained in:
zren25
2025-05-23 10:27:07 +08:00
7 changed files with 69 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.RestTemplate;
@@ -16,6 +17,7 @@ import com.volvo.common.feign.annotation.EnableVolvoFeignClients;
@EnableScheduling
@MapperScan({"com.volvo.ai.analytic.center.mapper"})
@EnableDiscoveryClient
@EnableRetry
public class AiAnalyticCenterServiceApplication {
public static void main(String[] args) {

View File

@@ -10,6 +10,8 @@ public interface DiFyService {
public Object getDiFyObject(DiFyReq diFyReq);
public Object getDiFyObjectRetry(DiFyReq diFyReq);
public JSONObject executeDifyFlow(DiFyReq diFyReq, String businessType, String businessData, String aiAnalysisRequestId);
public JSONObject executeDifyFlow(DiFyReq diFyReq);

View File

@@ -79,6 +79,9 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
@Autowired
private AiAnalysisErrorsMapper aiAnalysisErrorsMapper;
@Autowired
private DiFyRetryImpl diFyRetry;
@Override
public void consumerMessageByMQ(String message) {
// 生成ai分析请求id
@@ -162,8 +165,8 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
diFyReq.setUser(BusinessTypeEnum.CLAIM_VERIFICATION.getCode());
diFyReq.setFlowId(verificationToken);
diFyReq.setInputs(parsedAudit);
//调用dify 工作流
diFyObject = (JSONObject) diFyService.getDiFyObject(diFyReq);
//调用dify 工作流 失败重试一次
diFyObject = diFyRetry.getDiFyRetry(diFyReq);
//处理结果并推送MQ
if (diFyObject == null) {
log.error("售后索赔检核审计报告dify返回结果为空");
@@ -196,7 +199,7 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
data.put("businessType", claimVerificationFileAnalysisDTO.getBusinessType());
data.put("aiAnalysisRequestId", aiAnalysisRequestId);
data.put("fileType", claimVerificationFileAnalysisDTO.getFileType());
log.info("索赔检核发送异常空MQMQ: {}", data.toString());
log.info("索赔检核发送异常空MQ: {}", data.toString());
rocketMQTemplate.syncSend(topic, data);
}

View File

@@ -0,0 +1,27 @@
package com.volvo.ai.analytic.center.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.volvo.ai.analytic.center.dto.req.DiFyReq;
import com.volvo.ai.analytic.center.service.DiFyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
/**
* dify调用retry
*/
@Slf4j
@Service
public class DiFyRetryImpl {
@Autowired
private DiFyService diFyService;
@Retryable(include = Exception.class,maxAttempts = 2, backoff = @Backoff(delay = 1000))
public JSONObject getDiFyRetry(DiFyReq diFyReq) {
log.info("AI索赔检核调用DIFYretry");
return (JSONObject) diFyService.getDiFyObjectRetry(diFyReq);
}
}

View File

@@ -13,6 +13,8 @@ import com.volvo.ai.analytic.center.utils.AiAnalysisUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import java.util.HashMap;
@@ -49,6 +51,24 @@ public class DiFyServiceImpl implements DiFyService{
return "";
}
@Override
@Retryable(include = Exception.class,maxAttempts = 2, backoff = @Backoff(delay = 1000))
public Object getDiFyObjectRetry(DiFyReq diFyReq) {
Map<String, Object> map = new HashMap<>();
map.put("inputs",diFyReq.getInputs());
map.put("response_mode","blocking");
map.put("user",diFyReq.getUser());
log.info("请求DiFy入参-Retry:{}",JSON.toJSONString(map));
JSONObject difyResult = diFyFeign.runWorkflowsRetry("Bearer "+diFyReq.getFlowId(),map);
log.info("请求DiFy响应结果:{}",difyResult.toJSONString());
JSONObject data = difyResult.getJSONObject("data");
if (data != null && "succeeded".equals(data.get("status"))){
JSONObject outputs = data.getJSONObject("outputs");
return outputs;
}
return "";
}
@Override
public JSONObject executeDifyFlow(DiFyReq diFyReq, String businessType, String businessData, String oldAiAnalysisRequestId) {
String aiAnalysisRequestId = StringUtils.isEmpty(oldAiAnalysisRequestId)? AiAnalysisUtils.getAiAnalysisRequestId(businessType):oldAiAnalysisRequestId;