|
|
|
|
@@ -1,20 +1,34 @@
|
|
|
|
|
package com.volvo.ai.analytic.center.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import com.obs.services.model.ObsObject;
|
|
|
|
|
import com.volvo.ai.analytic.center.dto.req.ClaimVerificationFileDTO;
|
|
|
|
|
import com.volvo.ai.analytic.center.dto.req.DiFyReq;
|
|
|
|
|
import com.volvo.ai.analytic.center.entity.AiAnalysisRequestLogs;
|
|
|
|
|
import com.volvo.ai.analytic.center.entity.AiAnalyticBusinessConfig;
|
|
|
|
|
import com.volvo.ai.analytic.center.enums.BusinessTypeEnum;
|
|
|
|
|
import com.volvo.ai.analytic.center.enums.ClaimVerificationFileTypeEnums;
|
|
|
|
|
import com.volvo.ai.analytic.center.feign.DiFyFeign;
|
|
|
|
|
import com.volvo.ai.analytic.center.mapper.AiAnalysisRequestLogsMapper;
|
|
|
|
|
import com.volvo.ai.analytic.center.mapper.AiAnalyticBusinessConfigMapper;
|
|
|
|
|
import com.volvo.ai.analytic.center.service.ClaimVerificationService;
|
|
|
|
|
import com.volvo.ai.analytic.center.service.DiFyService;
|
|
|
|
|
import com.volvo.ai.analytic.center.utils.AiAnalysisUtils;
|
|
|
|
|
import com.volvo.ai.analytic.center.utils.ObsUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
@@ -26,6 +40,12 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private AiAnalyticBusinessConfigMapper aiAnalyticBusinessConfigMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DiFyFeign diFyFeign;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DiFyService diFyService;
|
|
|
|
|
|
|
|
|
|
@Value("${dify.claimVerification.user}")
|
|
|
|
|
private String claimVerificationUser;
|
|
|
|
|
|
|
|
|
|
@@ -35,8 +55,11 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
|
|
|
|
|
@Value("${dify.claimVerification.verificationToken}")
|
|
|
|
|
private String verificationToken;
|
|
|
|
|
|
|
|
|
|
@Value("${rocketmq.producer.topic}")
|
|
|
|
|
@Value("${rocketmq.producer.claimVerification.topic}")
|
|
|
|
|
private String topic;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private RocketMQTemplate rocketMQTemplate;
|
|
|
|
|
@Override
|
|
|
|
|
public void consumerMessageByMQ(String message) {
|
|
|
|
|
log.info("售后索赔检核MQ message: {}", message);
|
|
|
|
|
@@ -46,30 +69,156 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
|
|
|
|
|
throw new RuntimeException(" 售后索赔检核文件分析入参为空");
|
|
|
|
|
}
|
|
|
|
|
// 生成ai分析请求id
|
|
|
|
|
String aiAnalysisRequestId = AiAnalysisUtils.getAiAnalysisRequestId(BusinessTypeEnum.COMMUNITYTARGET.getCode());
|
|
|
|
|
String aiAnalysisRequestId = AiAnalysisUtils.getAiAnalysisRequestId(BusinessTypeEnum.CLAIM_VERIFICATION.getCode());
|
|
|
|
|
// 异步保存请求日志
|
|
|
|
|
syncSaveRequestLogs(message, aiAnalysisRequestId);
|
|
|
|
|
|
|
|
|
|
if(claimVerificationFileAnalysisDTO.getBusinessType().equals(BusinessTypeEnum.CLAIM_VERIFICATION_FILE_ANALYSIS.getCode())){
|
|
|
|
|
//文件分析
|
|
|
|
|
List<String> fileObsPath = claimVerificationFileAnalysisDTO.getFileObsPath();
|
|
|
|
|
List<HashMap<String,String>> fileIds = Collections.EMPTY_LIST;
|
|
|
|
|
//上传所有文件到dify
|
|
|
|
|
if(fileObsPath != null && fileObsPath.size() > 0){
|
|
|
|
|
|
|
|
|
|
for (String filePath : fileObsPath) {
|
|
|
|
|
HashMap<String,String> fileToDifyDTO = new HashMap<>();
|
|
|
|
|
ObsObject obsObject = ObsUtil.downloadFile(filePath);
|
|
|
|
|
InputStream inputStream = obsObject.getObjectContent();
|
|
|
|
|
MultipartFile file = ObsUtil.getMultipartFile(inputStream, ObsUtil.getFilenameByUrl(filePath));
|
|
|
|
|
JSONObject fileUploadRes = diFyFeign.fileUpload(fileToken,file);
|
|
|
|
|
String uploadFileId = fileUploadRes.getString("id");
|
|
|
|
|
String extension = fileUploadRes.getString("extension");
|
|
|
|
|
fileToDifyDTO.put("id", uploadFileId);
|
|
|
|
|
fileToDifyDTO.put("type", extension);
|
|
|
|
|
fileIds.add(fileToDifyDTO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//根据业务线标识和文件配置分类查询配置
|
|
|
|
|
List<AiAnalyticBusinessConfig> aiAnalyticBusinessConfigs = aiAnalyticBusinessConfigMapper.selectList(
|
|
|
|
|
Wrappers.<AiAnalyticBusinessConfig>lambdaQuery()
|
|
|
|
|
.eq(AiAnalyticBusinessConfig::getBusinessLine, BusinessTypeEnum.CLAIM_VERIFICATION.getCode())
|
|
|
|
|
.eq(AiAnalyticBusinessConfig::getFileConfigCategory, claimVerificationFileAnalysisDTO.getFileType())
|
|
|
|
|
.eq(AiAnalyticBusinessConfig::getIsDeleted, 0)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//组装文件分析workflow入参
|
|
|
|
|
JSONArray files = new JSONArray();
|
|
|
|
|
for (HashMap<String, String> fileToDifyDTO : fileIds) {
|
|
|
|
|
JSONObject object = new JSONObject();
|
|
|
|
|
object.put("upload_file_id", fileToDifyDTO.get("id"));
|
|
|
|
|
object.put("type", fileToDifyDTO.get("type"));
|
|
|
|
|
object.put("transfer_method", "local_file");
|
|
|
|
|
files.add(object);
|
|
|
|
|
}
|
|
|
|
|
JSONObject fileToDifyDTO = new JSONObject();
|
|
|
|
|
fileToDifyDTO.put("files", files);
|
|
|
|
|
//根据类型获取配置内容
|
|
|
|
|
fileToDifyDTO.put("FileBusinessType",claimVerificationFileAnalysisDTO.getFileType());
|
|
|
|
|
fileToDifyDTO.put("FileDescription", aiAnalyticBusinessConfigs
|
|
|
|
|
.stream()
|
|
|
|
|
.filter(config -> config.getConfigType().equals("FileDescription"))
|
|
|
|
|
.map(AiAnalyticBusinessConfig::getConfigData)
|
|
|
|
|
.findFirst()
|
|
|
|
|
.orElse(null));
|
|
|
|
|
fileToDifyDTO.put("AnalysisRequirements", aiAnalyticBusinessConfigs
|
|
|
|
|
.stream()
|
|
|
|
|
.filter(config -> config.getConfigType().equals("AnalysisRequirements"))
|
|
|
|
|
.map(AiAnalyticBusinessConfig::getConfigData)
|
|
|
|
|
.findFirst()
|
|
|
|
|
.orElse(null));
|
|
|
|
|
fileToDifyDTO.put("ReportRequirements", aiAnalyticBusinessConfigs
|
|
|
|
|
.stream()
|
|
|
|
|
.filter(config -> config.getConfigType().equals("ReportRequirements"))
|
|
|
|
|
.map(AiAnalyticBusinessConfig::getConfigData)
|
|
|
|
|
.findFirst()
|
|
|
|
|
.orElse(null));
|
|
|
|
|
fileToDifyDTO.put("ReportTemplate", aiAnalyticBusinessConfigs
|
|
|
|
|
.stream()
|
|
|
|
|
.filter(config -> config.getConfigType().equals("ReportTemplate"))
|
|
|
|
|
.map(AiAnalyticBusinessConfig::getConfigData)
|
|
|
|
|
.findFirst()
|
|
|
|
|
.orElse(null));
|
|
|
|
|
|
|
|
|
|
DiFyReq diFyReq = new DiFyReq();
|
|
|
|
|
diFyReq.setUser(BusinessTypeEnum.CLAIM_VERIFICATION.getCode());
|
|
|
|
|
diFyReq.setFlowId(fileToken);
|
|
|
|
|
diFyReq.setInputs(fileToDifyDTO);
|
|
|
|
|
//调用dify 工作流
|
|
|
|
|
JSONObject diFyObject = (JSONObject) diFyService.getDiFyObject(diFyReq);
|
|
|
|
|
//处理结果并推送MQ
|
|
|
|
|
if (diFyObject == null) {
|
|
|
|
|
log.error(" 售后索赔检核文件分析dify返回结果为空");
|
|
|
|
|
throw new RuntimeException(" 售后索赔检核文件分析dify返回结果为空");
|
|
|
|
|
}else {
|
|
|
|
|
JSONObject data = new JSONObject();
|
|
|
|
|
data.put("newBieAfterSalesId", claimVerificationFileAnalysisDTO.getNewBieAfterSalesId());
|
|
|
|
|
data.put("businessType", claimVerificationFileAnalysisDTO.getBusinessType());
|
|
|
|
|
data.put("fileType", claimVerificationFileAnalysisDTO.getFileType());
|
|
|
|
|
data.put("fileData",diFyObject);
|
|
|
|
|
//返回结果推送到Newbie的MQ
|
|
|
|
|
rocketMQTemplate.syncSend(topic, data);
|
|
|
|
|
log.info("索赔检核文件分析发送回调MQ完成: {}", data);
|
|
|
|
|
}
|
|
|
|
|
//异步更新请求日志表的difyResponse字段
|
|
|
|
|
syncUpdateDiFyResponse(diFyObject, aiAnalysisRequestId);
|
|
|
|
|
} else if(claimVerificationFileAnalysisDTO.getBusinessType().equals(BusinessTypeEnum.CLAIM_VERIFICATION_AUDIT.getCode())){
|
|
|
|
|
//审计报告
|
|
|
|
|
|
|
|
|
|
//加载审计规则配置
|
|
|
|
|
List<AiAnalyticBusinessConfig> aiAnalyticBusinessConfigs = aiAnalyticBusinessConfigMapper.selectList(
|
|
|
|
|
Wrappers.<AiAnalyticBusinessConfig>lambdaQuery()
|
|
|
|
|
.eq(AiAnalyticBusinessConfig::getBusinessLine, BusinessTypeEnum.CLAIM_VERIFICATION.getCode())
|
|
|
|
|
.eq(AiAnalyticBusinessConfig::getConfigType, BusinessTypeEnum.AUDITRULES.getCode())
|
|
|
|
|
.eq(AiAnalyticBusinessConfig::getIsDeleted, 0));
|
|
|
|
|
|
|
|
|
|
//组装审计报告workflow入参
|
|
|
|
|
JSONObject auditRules = new JSONObject();
|
|
|
|
|
auditRules.put("AnalysisRules", aiAnalyticBusinessConfigs
|
|
|
|
|
.stream()
|
|
|
|
|
.filter(config -> config.getConfigType().equals("AuditRules"))
|
|
|
|
|
.map(AiAnalyticBusinessConfig::getConfigData)
|
|
|
|
|
.findFirst()
|
|
|
|
|
.orElse(null));
|
|
|
|
|
auditRules.put("DiagnosticReport", claimVerificationFileAnalysisDTO.getDiagnosticReport());
|
|
|
|
|
auditRules.put("PreCheckReport", claimVerificationFileAnalysisDTO.getPreCheckReport());
|
|
|
|
|
auditRules.put("DTCReport", claimVerificationFileAnalysisDTO.getDtcReport());
|
|
|
|
|
|
|
|
|
|
DiFyReq diFyReq = new DiFyReq();
|
|
|
|
|
diFyReq.setUser(BusinessTypeEnum.CLAIM_VERIFICATION.getCode());
|
|
|
|
|
diFyReq.setFlowId(verificationToken);
|
|
|
|
|
diFyReq.setInputs(auditRules);
|
|
|
|
|
//调用dify 工作流
|
|
|
|
|
JSONObject diFyObject = (JSONObject) diFyService.getDiFyObject(diFyReq);
|
|
|
|
|
//处理结果并推送MQ
|
|
|
|
|
if (diFyObject == null) {
|
|
|
|
|
log.error(" 售后索赔检核审计报告dify返回结果为空");
|
|
|
|
|
throw new RuntimeException(" 售后索赔检核审计报告dify返回结果为空");
|
|
|
|
|
}else {
|
|
|
|
|
JSONObject data = new JSONObject();
|
|
|
|
|
data.put("newBieAfterSalesId", claimVerificationFileAnalysisDTO.getNewBieAfterSalesId());
|
|
|
|
|
data.put("businessType", claimVerificationFileAnalysisDTO.getBusinessType());
|
|
|
|
|
data.put("warrantyAuditReport",diFyObject);
|
|
|
|
|
//返回结果推送到Newbie的MQ
|
|
|
|
|
rocketMQTemplate.syncSend(topic, data);
|
|
|
|
|
log.info("索赔检核审计报告发送回调MQ完成: {}", data);
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
throw new RuntimeException(" 售后索赔检核业务类型错误");
|
|
|
|
|
throw new RuntimeException("售后索赔检核业务类型错误");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Async
|
|
|
|
|
protected void syncUpdateDiFyResponse(JSONObject difResult, String aiAnalysisRequestId) {
|
|
|
|
|
aiAnalysisRequestLogsMapper.update(new AiAnalysisRequestLogs(),
|
|
|
|
|
new UpdateWrapper<AiAnalysisRequestLogs>().set("dify_response", difResult.toJSONString())
|
|
|
|
|
.eq("ai_analysis_request_id", aiAnalysisRequestId));
|
|
|
|
|
}
|
|
|
|
|
@Async
|
|
|
|
|
protected void syncSaveRequestLogs(String message, String aiAnalysisRequestId) {
|
|
|
|
|
aiAnalysisRequestLogsMapper.insert(AiAnalysisRequestLogs.builder()
|
|
|
|
|
.aiAnalysisRequestId(aiAnalysisRequestId)
|
|
|
|
|
.businessRequest(message)
|
|
|
|
|
.difyAgentKey("")
|
|
|
|
|
.aiAnalysisRequestType(BusinessTypeEnum.COMMUNITYTARGET.getCode())
|
|
|
|
|
.aiAnalysisRequestType(BusinessTypeEnum.CLAIM_VERIFICATION.getCode())
|
|
|
|
|
.build());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|