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

@@ -19,7 +19,10 @@
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId> <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
<!--sentinel 依赖--> <!--sentinel 依赖-->
<dependency> <dependency>
<groupId>com.alibaba.cloud</groupId> <groupId>com.alibaba.cloud</groupId>

View File

@@ -3,6 +3,8 @@ package com.volvo.ai.analytic.center.feign;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@@ -16,6 +18,12 @@ public interface DiFyFeign {
, produces = MediaType.APPLICATION_JSON_VALUE) , produces = MediaType.APPLICATION_JSON_VALUE)
JSONObject runWorkflows(@RequestHeader(value = "Authorization") String authorization, @RequestBody Map<String, Object> map); JSONObject runWorkflows(@RequestHeader(value = "Authorization") String authorization, @RequestBody Map<String, Object> map);
@Retryable(include = Exception.class,maxAttempts = 2, backoff = @Backoff(delay = 1000))
@PostMapping(value = "v1/workflows/run"
, consumes = MediaType.APPLICATION_JSON_VALUE
, produces = MediaType.APPLICATION_JSON_VALUE)
JSONObject runWorkflowsRetry(@RequestHeader(value = "Authorization") String authorization, @RequestBody Map<String, Object> map);
@PostMapping(value = "/v1/files/upload" , consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @PostMapping(value = "/v1/files/upload" , consumes = MediaType.MULTIPART_FORM_DATA_VALUE)

View File

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

View File

@@ -10,6 +10,8 @@ public interface DiFyService {
public Object getDiFyObject(DiFyReq diFyReq); 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, String businessType, String businessData, String aiAnalysisRequestId);
public JSONObject executeDifyFlow(DiFyReq diFyReq); public JSONObject executeDifyFlow(DiFyReq diFyReq);

View File

@@ -79,6 +79,9 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
@Autowired @Autowired
private AiAnalysisErrorsMapper aiAnalysisErrorsMapper; private AiAnalysisErrorsMapper aiAnalysisErrorsMapper;
@Autowired
private DiFyRetryImpl diFyRetry;
@Override @Override
public void consumerMessageByMQ(String message) { public void consumerMessageByMQ(String message) {
// 生成ai分析请求id // 生成ai分析请求id
@@ -162,8 +165,8 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
diFyReq.setUser(BusinessTypeEnum.CLAIM_VERIFICATION.getCode()); diFyReq.setUser(BusinessTypeEnum.CLAIM_VERIFICATION.getCode());
diFyReq.setFlowId(verificationToken); diFyReq.setFlowId(verificationToken);
diFyReq.setInputs(parsedAudit); diFyReq.setInputs(parsedAudit);
//调用dify 工作流 //调用dify 工作流 失败重试一次
diFyObject = (JSONObject) diFyService.getDiFyObject(diFyReq); diFyObject = diFyRetry.getDiFyRetry(diFyReq);
//处理结果并推送MQ //处理结果并推送MQ
if (diFyObject == null) { if (diFyObject == null) {
log.error("售后索赔检核审计报告dify返回结果为空"); log.error("售后索赔检核审计报告dify返回结果为空");
@@ -196,7 +199,7 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
data.put("businessType", claimVerificationFileAnalysisDTO.getBusinessType()); data.put("businessType", claimVerificationFileAnalysisDTO.getBusinessType());
data.put("aiAnalysisRequestId", aiAnalysisRequestId); data.put("aiAnalysisRequestId", aiAnalysisRequestId);
data.put("fileType", claimVerificationFileAnalysisDTO.getFileType()); data.put("fileType", claimVerificationFileAnalysisDTO.getFileType());
log.info("索赔检核发送异常空MQMQ: {}", data.toString()); log.info("索赔检核发送异常空MQ: {}", data.toString());
rocketMQTemplate.syncSend(topic, data); 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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; 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 org.springframework.stereotype.Service;
import java.util.HashMap; import java.util.HashMap;
@@ -49,6 +51,24 @@ public class DiFyServiceImpl implements DiFyService{
return ""; 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 @Override
public JSONObject executeDifyFlow(DiFyReq diFyReq, String businessType, String businessData, String oldAiAnalysisRequestId) { public JSONObject executeDifyFlow(DiFyReq diFyReq, String businessType, String businessData, String oldAiAnalysisRequestId) {
String aiAnalysisRequestId = StringUtils.isEmpty(oldAiAnalysisRequestId)? AiAnalysisUtils.getAiAnalysisRequestId(businessType):oldAiAnalysisRequestId; String aiAnalysisRequestId = StringUtils.isEmpty(oldAiAnalysisRequestId)? AiAnalysisUtils.getAiAnalysisRequestId(businessType):oldAiAnalysisRequestId;