|
|
|
|
@@ -9,6 +9,8 @@ import com.obs.services.model.ObsObject;
|
|
|
|
|
import com.volvo.ai.analytic.center.constant.ClaimVerificationConstant;
|
|
|
|
|
import com.volvo.ai.analytic.center.constant.Constant;
|
|
|
|
|
import com.volvo.ai.analytic.center.dto.req.ClaimVerificationFileDTO;
|
|
|
|
|
import com.volvo.ai.analytic.center.dto.req.ClaimVerificationFileDTO.ClaimVerificationFile;
|
|
|
|
|
import com.volvo.ai.analytic.center.dto.req.ClaimVerificationPartHoursDTO;
|
|
|
|
|
import com.volvo.ai.analytic.center.dto.req.DiFyReq;
|
|
|
|
|
import com.volvo.ai.analytic.center.dto.req.RunMaskingRuleInput;
|
|
|
|
|
import com.volvo.ai.analytic.center.entity.*;
|
|
|
|
|
@@ -16,6 +18,7 @@ import com.volvo.ai.analytic.center.enums.BusinessTypeEnum;
|
|
|
|
|
import com.volvo.ai.analytic.center.enums.ClaimVerificationFileTypeEnums;
|
|
|
|
|
import com.volvo.ai.analytic.center.mapper.AiAnalysisErrorsMapper;
|
|
|
|
|
import com.volvo.ai.analytic.center.mapper.AiAnalyticWarrantyAuditMapper;
|
|
|
|
|
import com.volvo.ai.analytic.center.mapper.TmClaimVerificationPartHoursMappingMapper;
|
|
|
|
|
import com.volvo.ai.analytic.center.service.DataMaskingRuleService;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.commons.text.StringEscapeUtils;
|
|
|
|
|
@@ -37,7 +40,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
@@ -49,6 +51,9 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private AiAnalyticBusinessConfigMapper aiAnalyticBusinessConfigMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private TmClaimVerificationPartHoursMappingMapper tmClaimVerificationPartHoursMappingMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DiFyFeign diFyFeign;
|
|
|
|
|
|
|
|
|
|
@@ -61,6 +66,9 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
|
|
|
|
|
@Value("${dify.claimVerification.verificationToken}")
|
|
|
|
|
private String verificationToken;
|
|
|
|
|
|
|
|
|
|
@Value("${dify.claimVerification.fileClassifyToken}")
|
|
|
|
|
private String fileClassifyToken;
|
|
|
|
|
|
|
|
|
|
@Value("${rocketmq.producer.claimVerification}")
|
|
|
|
|
private String topic;
|
|
|
|
|
|
|
|
|
|
@@ -89,12 +97,16 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
|
|
|
|
|
log.info("售后索赔检核MQ message: {}", message);
|
|
|
|
|
ClaimVerificationFileDTO claimVerificationFileAnalysisDTO = JSON.parseObject(message, ClaimVerificationFileDTO.class);
|
|
|
|
|
if (claimVerificationFileAnalysisDTO == null) {
|
|
|
|
|
log.error("售后索赔检核文件入参为空: {}", claimVerificationFileAnalysisDTO.toString());
|
|
|
|
|
log.error("售后索赔检核文件入参为空");
|
|
|
|
|
saveException("售后索赔检核文件分析入参为空", aiAnalysisRequestId, null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
JSONObject diFyObject = new JSONObject();
|
|
|
|
|
try {
|
|
|
|
|
// 异步保存请求日志
|
|
|
|
|
if (StringUtils.isNotEmpty(claimVerificationFileAnalysisDTO.getAiAnalysisRequestId())) {
|
|
|
|
|
aiAnalysisRequestId = claimVerificationFileAnalysisDTO.getAiAnalysisRequestId();
|
|
|
|
|
}
|
|
|
|
|
syncSaveRequestLogs(message, aiAnalysisRequestId);
|
|
|
|
|
if (claimVerificationFileAnalysisDTO.getBusinessType().equals(BusinessTypeEnum.CLAIM_VERIFICATION_FILE_ANALYSIS.getCode())) {
|
|
|
|
|
//文件分析
|
|
|
|
|
@@ -102,7 +114,7 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
|
|
|
|
|
List<HashMap<String, String>> fileIds = new ArrayList<>();
|
|
|
|
|
log.info("文件分析文件ID:{}", fileObsPath);
|
|
|
|
|
//上传所有文件到dify
|
|
|
|
|
uploadFileToObs(fileObsPath, fileIds);
|
|
|
|
|
uploadFileToObs(fileObsPath, fileIds, fileToken);
|
|
|
|
|
//根据业务线标识和文件配置分类查询配置
|
|
|
|
|
List<AiAnalyticBusinessConfig> aiAnalyticBusinessConfigs = aiAnalyticBusinessConfigMapper.selectList(
|
|
|
|
|
Wrappers.<AiAnalyticBusinessConfig>lambdaQuery()
|
|
|
|
|
@@ -146,19 +158,8 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
|
|
|
|
|
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)
|
|
|
|
|
.in(AiAnalyticBusinessConfig::getVerificationMethod, methodList)
|
|
|
|
|
);
|
|
|
|
|
String configDataString = aiAnalyticBusinessConfigs.stream()
|
|
|
|
|
.map(AiAnalyticBusinessConfig::getConfigData)
|
|
|
|
|
.collect(Collectors.joining(" "));
|
|
|
|
|
//组装审计报告workflow入参
|
|
|
|
|
JSONObject parsedAudit = buildAuditToDify(configDataString, claimVerificationFileAnalysisDTO);
|
|
|
|
|
JSONObject parsedAudit = buildAuditToDify(claimVerificationFileAnalysisDTO);
|
|
|
|
|
//根据aiAnalysisRequestId更新请求日志表的difyRequest字段
|
|
|
|
|
syncUpdateDiFyRequest(parsedAudit.toString(), aiAnalysisRequestId);
|
|
|
|
|
DiFyReq diFyReq = new DiFyReq();
|
|
|
|
|
@@ -181,6 +182,70 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
|
|
|
|
|
//审核次数记录
|
|
|
|
|
saveAuditCount(claimVerificationFileAnalysisDTO);
|
|
|
|
|
}
|
|
|
|
|
} else if (claimVerificationFileAnalysisDTO.getBusinessType().equals(BusinessTypeEnum.CLAIM_VERIFICATION_CLASSIFY_APP.getCode())) {
|
|
|
|
|
//文件分类
|
|
|
|
|
List<ClaimVerificationFile> claimVerificationFiles = claimVerificationFileAnalysisDTO.getClaimVerificationFiles();
|
|
|
|
|
List<ClaimVerificationFile> resultFiles = new ArrayList<>();
|
|
|
|
|
for (ClaimVerificationFile claimVerificationFile : claimVerificationFiles) {
|
|
|
|
|
try {
|
|
|
|
|
List<String> fileObsPath = new ArrayList<>();
|
|
|
|
|
fileObsPath.add(claimVerificationFile.getFileObsPath());
|
|
|
|
|
List<HashMap<String, String>> fileIds = new ArrayList<>();
|
|
|
|
|
log.info("文件分类文件ID:{}", fileObsPath);
|
|
|
|
|
//上传所有文件到dify
|
|
|
|
|
uploadFileToObs(fileObsPath, fileIds, fileClassifyToken);
|
|
|
|
|
|
|
|
|
|
//组装文件分析workflow入参
|
|
|
|
|
JSONArray files = new JSONArray();
|
|
|
|
|
for (HashMap<String, String> fileToDifyDTO : fileIds) {
|
|
|
|
|
JSONObject object = new JSONObject();
|
|
|
|
|
object.put(ClaimVerificationConstant.UPLOAD_FILE_ID, fileToDifyDTO.get(ClaimVerificationConstant.ID));
|
|
|
|
|
object.put(ClaimVerificationConstant.TYPE, fileToDifyDTO.get(ClaimVerificationConstant.TYPE));
|
|
|
|
|
object.put(ClaimVerificationConstant.TRANSFER_METHOD, ClaimVerificationConstant.LOCAL_FILE);
|
|
|
|
|
files.add(object);
|
|
|
|
|
}
|
|
|
|
|
//构建入参
|
|
|
|
|
JSONObject fileToDifyDTO = new JSONObject();
|
|
|
|
|
fileToDifyDTO.put("files", files);
|
|
|
|
|
//根据aiAnalysisRequestId更新请求日志表的difyRequest字段
|
|
|
|
|
syncUpdateDiFyRequest(fileToDifyDTO.toString(), aiAnalysisRequestId);
|
|
|
|
|
DiFyReq diFyReq = new DiFyReq();
|
|
|
|
|
diFyReq.setUser(BusinessTypeEnum.CLAIM_VERIFICATION.getCode());
|
|
|
|
|
diFyReq.setFlowId(fileClassifyToken);
|
|
|
|
|
diFyReq.setInputs(fileToDifyDTO);
|
|
|
|
|
//调用dify 工作流
|
|
|
|
|
JSONObject classifyDiFyObject = (JSONObject) diFyService.getDiFyObject(diFyReq);
|
|
|
|
|
|
|
|
|
|
//处理结果
|
|
|
|
|
if (classifyDiFyObject == null) {
|
|
|
|
|
log.error(" 售后索赔检核文件分类dify返回结果为空");
|
|
|
|
|
saveException("售后索赔检核文件分类dify返回结果为空", aiAnalysisRequestId, null);
|
|
|
|
|
} else {
|
|
|
|
|
//解析dify返回结果
|
|
|
|
|
String fileType = classifyDiFyObject.getString("fileBusinessType");
|
|
|
|
|
//判断字符串那个是不为空的然后进行处理
|
|
|
|
|
if (StringUtils.isNotBlank(fileType)) {
|
|
|
|
|
claimVerificationFile.setFileType(fileType);
|
|
|
|
|
} else {
|
|
|
|
|
claimVerificationFile.setFileType("3");
|
|
|
|
|
}
|
|
|
|
|
resultFiles.add(claimVerificationFile);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("文件分类异常:{}", e.getMessage());
|
|
|
|
|
claimVerificationFile.setFileType("3");
|
|
|
|
|
resultFiles.add(claimVerificationFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
JSONObject data = new JSONObject();
|
|
|
|
|
data.put("newBieAfterSalesId", claimVerificationFileAnalysisDTO.getNewBieAfterSalesId());
|
|
|
|
|
data.put("businessType", claimVerificationFileAnalysisDTO.getBusinessType());
|
|
|
|
|
data.put("claimVerificationFiles", resultFiles);
|
|
|
|
|
data.put("aiAnalysisRequestId", aiAnalysisRequestId);
|
|
|
|
|
rocketMQTemplate.syncSend(topic, data);
|
|
|
|
|
log.info("索赔检核文件分类发送回调MQ完成: {}", data);
|
|
|
|
|
//异步更新请求日志表的difyResponse字段
|
|
|
|
|
syncUpdateDiFyResponse(data, aiAnalysisRequestId);
|
|
|
|
|
} else {
|
|
|
|
|
saveException("售后索赔检核业务类型错误", aiAnalysisRequestId, null);
|
|
|
|
|
}
|
|
|
|
|
@@ -225,9 +290,8 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
|
|
|
|
|
.build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JSONObject buildAuditToDify(String configDataString, ClaimVerificationFileDTO claimVerificationFileAnalysisDTO) {
|
|
|
|
|
private JSONObject buildAuditToDify(ClaimVerificationFileDTO claimVerificationFileAnalysisDTO) {
|
|
|
|
|
JSONObject audit = new JSONObject();
|
|
|
|
|
audit.put("analysisRules", configDataString);
|
|
|
|
|
audit.put("diagnosticReport", claimVerificationFileAnalysisDTO.getDiagnosticReport() == null ? " " :claimVerificationFileAnalysisDTO.getDiagnosticReport().toString());
|
|
|
|
|
audit.put("preCheckReport", claimVerificationFileAnalysisDTO.getPreCheckReport() == null ? " " :claimVerificationFileAnalysisDTO.getPreCheckReport().toString());
|
|
|
|
|
audit.put("dtcReport", claimVerificationFileAnalysisDTO.getDtcReport() == null ? " " :claimVerificationFileAnalysisDTO.getDtcReport().toString());
|
|
|
|
|
@@ -240,9 +304,56 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
|
|
|
|
|
runMaskingRuleInput.setOldStr(audit.toString());
|
|
|
|
|
String corpusChat = dataMaskingRuleService.runMaskingRule(runMaskingRuleInput);
|
|
|
|
|
JSONObject parsedAudit = JSON.parseObject(corpusChat);
|
|
|
|
|
|
|
|
|
|
parsedAudit.put("diagnosticUndesensitized", claimVerificationFileAnalysisDTO.getDiagnosticReport() == null ? " " :claimVerificationFileAnalysisDTO.getDiagnosticReport().toString());
|
|
|
|
|
parsedAudit.put("preCheckUndesensitized", claimVerificationFileAnalysisDTO.getPreCheckReport() == null ? " " :claimVerificationFileAnalysisDTO.getPreCheckReport().toString());
|
|
|
|
|
parsedAudit.put("dtcUndesensitized", claimVerificationFileAnalysisDTO.getDtcReport() == null ? " " :claimVerificationFileAnalysisDTO.getDtcReport().toString());
|
|
|
|
|
parsedAudit.put("warrantyUndesensitized", claimVerificationFileAnalysisDTO.getWarrantyReport() == null ? " " :claimVerificationFileAnalysisDTO.getWarrantyReport().toString());
|
|
|
|
|
parsedAudit.put("partHoursConfig", claimVerificationFileAnalysisDTO.getWarrantyReport() == null ? " " :getPartHoursList(claimVerificationFileAnalysisDTO.getWarrantyReport()));
|
|
|
|
|
return parsedAudit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getPartHoursList(JSONObject warrantyJson) {
|
|
|
|
|
if (warrantyJson == null || !warrantyJson.containsKey("warrantyReport")) {
|
|
|
|
|
return " ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取warrantyReport对象
|
|
|
|
|
JSONObject warrantyReport = warrantyJson.getJSONObject("warrantyReport");
|
|
|
|
|
|
|
|
|
|
// 检查partItems是否存在且是数组
|
|
|
|
|
if (!warrantyReport.containsKey("partItems")) {
|
|
|
|
|
return " ";
|
|
|
|
|
} else {
|
|
|
|
|
Object value = warrantyReport.get("partItems");
|
|
|
|
|
if (!(value instanceof JSONArray)) {
|
|
|
|
|
return " ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取partItems数组
|
|
|
|
|
JSONArray partItems = warrantyReport.getJSONArray("partItems");
|
|
|
|
|
List<String> partNoList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// 遍历数组并提取partNo
|
|
|
|
|
for (int i = 0; i < partItems.size(); i++) {
|
|
|
|
|
JSONObject partItem = partItems.getJSONObject(i);
|
|
|
|
|
if (partItem.containsKey("partNo")) {
|
|
|
|
|
if (partItem.containsKey("isMain") && "10041001".equals(partItem.getString("isMain"))) {
|
|
|
|
|
partNoList.add(partItem.getString("partNo"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (partNoList.isEmpty()) {
|
|
|
|
|
return " ";
|
|
|
|
|
}
|
|
|
|
|
List<ClaimVerificationPartHoursDTO> result = tmClaimVerificationPartHoursMappingMapper.queryConfigByPartId(partNoList);
|
|
|
|
|
if (result.isEmpty()) {
|
|
|
|
|
return " ";
|
|
|
|
|
}
|
|
|
|
|
return JSONObject.toJSONString(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@NotNull
|
|
|
|
|
private static JSONObject getJsonObjectToNewBie(JSONObject diFyObject, ClaimVerificationFileDTO claimVerificationFileAnalysisDTO, String aiAnalysisRequestId) {
|
|
|
|
|
JSONObject warrantyAuditReport = diFyObject.getJSONObject("warrantyAuditReport");
|
|
|
|
|
@@ -340,15 +451,15 @@ public class ClaimVerificationServiceImpl implements ClaimVerificationService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void uploadFileToObs(List<String> fileObsPath, List<HashMap<String, String>> fileIds) {
|
|
|
|
|
private void uploadFileToObs(List<String> fileObsPath, List<HashMap<String, String>> fileIds, String uploadToken) {
|
|
|
|
|
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));
|
|
|
|
|
log.info("索赔检核文件上传dify请求参数:{},token:{}", file, fileToken);
|
|
|
|
|
JSONObject fileUploadRes = diFyFeign.fileUpload("Bearer " + fileToken, file);
|
|
|
|
|
log.info("索赔检核文件上传dify请求参数:{},token:{}", file, uploadToken);
|
|
|
|
|
JSONObject fileUploadRes = diFyFeign.fileUpload("Bearer " + uploadToken, file);
|
|
|
|
|
log.info("索赔检核文件上传dify响应结果:{}", fileUploadRes);
|
|
|
|
|
String uploadFileId = fileUploadRes.getString(ClaimVerificationConstant.ID);
|
|
|
|
|
String extension = fileUploadRes.getString(ClaimVerificationConstant.EXTENSION);
|
|
|
|
|
|