|
|
@@ -2,7 +2,7 @@ package com.jzg.quotation.ansheng.crawler.build;
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.jzg.commons.constants.dict.InsOrderStatusEnum;
|
|
|
import com.jzg.commons.entity.quote.vo.KindInfoVo;
|
|
|
import com.jzg.commons.entity.quote.vo.QuoteVo;
|
|
|
@@ -15,7 +15,11 @@ import com.jzg.quotation.commons.component.ConversionOfQuoteInformation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.function.Function;
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
@@ -52,7 +56,7 @@ public final class AnShengCrawlerQuoteResultsVoBuild {
|
|
|
quoteResultsVo.setCiRiskInfoVo(buildCiRiskInfoVo(contract.getPolicyBase()));
|
|
|
buildRiskInfoVo(quoteVo.getCiRiskInfoVo(), contract.getPolicyBase());
|
|
|
quoteResultsVo.getCosts().setCiPremium(String.valueOf(contract.getPolicyBase().getTotalActualPremium()));
|
|
|
- quoteResultsVo.getCosts().setVvTax(String.valueOf(contract.getTargets().get(0).getVehicleTax().getVehicleTaxAmount()));
|
|
|
+ quoteResultsVo.getCosts().setVvTax(getVvTax(contract));
|
|
|
// 商业险
|
|
|
} else if (DepartmentPlanCode.PLAN_109.getCode()
|
|
|
.equals(contract.getPolicyBase().getPlanCode()) || DepartmentPlanCode.PLAN_113.getCode()
|
|
|
@@ -76,55 +80,77 @@ public final class AnShengCrawlerQuoteResultsVoBuild {
|
|
|
return quoteResultsVo;
|
|
|
}
|
|
|
|
|
|
+ public static String getVvTax(AnShengCrawlerCalculatePremiumApplyResponse.DataDTO.ContractsDTO contract) {
|
|
|
+ BigDecimal total = Optional.ofNullable(contract)
|
|
|
+ .map(c -> Optional.ofNullable(c.getTargets()).filter(list -> !list.isEmpty()).map(list -> list.get(0)))
|
|
|
+ .flatMap(targetOpt -> targetOpt)
|
|
|
+ .map(target -> Optional.ofNullable(target.getVehicleTax()))
|
|
|
+ .flatMap(taxOpt -> taxOpt)
|
|
|
+ .map(tax -> {
|
|
|
+ BigDecimal taxAmt = tax.getVehicleTaxAmount() == null ? BigDecimal.ZERO : BigDecimal.valueOf(tax.getVehicleTaxAmount());
|
|
|
+ BigDecimal lateAmt = tax.getLateFeeAmount() == null ? BigDecimal.ZERO : BigDecimal.valueOf(tax.getLateFeeAmount());
|
|
|
+ return taxAmt.add(lateAmt);
|
|
|
+ })
|
|
|
+ .orElse(BigDecimal.ZERO)
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ return total.toPlainString();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- private static QuoteResultsVo.ScoreVo buildScoreVo( AnShengCrawlerCalculatePremiumApplyResponse calculatePremiumApply) {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组装打分ScoreVo
|
|
|
+ */
|
|
|
+ private static QuoteResultsVo.ScoreVo buildScoreVo(AnShengCrawlerCalculatePremiumApplyResponse calculatePremiumApply) {
|
|
|
QuoteResultsVo.ScoreVo scoreVo = new QuoteResultsVo.ScoreVo();
|
|
|
JSONArray scoreArray = new JSONArray();
|
|
|
AnShengCrawlerCalculatePremiumApplyResponse.DataDTO data = calculatePremiumApply.getData();
|
|
|
- String basicstring = data.getBasicstring();
|
|
|
- if (StringUtils.isNotEmpty(basicstring)){
|
|
|
- String[] parts = basicstring.split(":");
|
|
|
- scoreArray.add(new JSONObject()
|
|
|
- .fluentPut("scoreName",parts.length > 0 ? parts[0].trim() : "")
|
|
|
- .fluentPut("scoreKey","basicstring")
|
|
|
- .fluentPut("score",parts.length > 1 ? parts[1].trim() : ""));
|
|
|
- }
|
|
|
- String blackDivisor = data.getBlackDivisor();
|
|
|
- if (StringUtils.isNotEmpty(blackDivisor)){
|
|
|
- String[] black = blackDivisor.split(":");
|
|
|
- scoreArray.add(new JSONObject()
|
|
|
- .fluentPut("scoreName",black.length > 0 ? black[0].trim() : "")
|
|
|
- .fluentPut("scoreKey","blackDivisor")
|
|
|
- .fluentPut("score",black.length > 0 ? black[1].trim() : ""));
|
|
|
- }
|
|
|
- String comprehensiveScoreStr = data.getComprehensiveScoreStr();
|
|
|
- if (StringUtils.isNotEmpty(comprehensiveScoreStr)){
|
|
|
- String[] comprehensiveScore = comprehensiveScoreStr.split(":");
|
|
|
- scoreArray.add(new JSONObject()
|
|
|
- .fluentPut("scoreName",comprehensiveScore.length > 0 ? comprehensiveScore[0].trim() : "")
|
|
|
- .fluentPut("scoreKey","comprehensiveScoreStr")
|
|
|
- .fluentPut("score",comprehensiveScore.length > 0 ? comprehensiveScore[1].trim() : ""));
|
|
|
- }
|
|
|
- String riskScore = data.getRiskScore();
|
|
|
- if (StringUtils.isNotEmpty(riskScore)){
|
|
|
- String[] riskScoreStr = riskScore.split(":");
|
|
|
- scoreArray.add(new JSONObject()
|
|
|
- .fluentPut("scoreName",riskScoreStr.length > 0 ? riskScoreStr[0].trim() : "")
|
|
|
- .fluentPut("scoreKey","riskScore")
|
|
|
- .fluentPut("score",riskScoreStr.length > 0 ? riskScoreStr[1].trim() : ""));
|
|
|
+ if (data == null) {
|
|
|
+ scoreVo.setScoreJson(scoreArray);
|
|
|
+ return scoreVo;
|
|
|
}
|
|
|
- String unifiedScore = data.getUnifiedScore();
|
|
|
- if (StringUtils.isNotEmpty(unifiedScore)){
|
|
|
- String[] unifiedScoreStr = unifiedScore.split(":");
|
|
|
- scoreArray.add(new JSONObject()
|
|
|
- .fluentPut("scoreName",unifiedScoreStr.length > 0 ? unifiedScoreStr[0].trim() : "")
|
|
|
- .fluentPut("scoreKey","unifiedScore")
|
|
|
- .fluentPut("score",unifiedScoreStr.length > 0 ? unifiedScoreStr[1].trim() : ""));
|
|
|
+ // 1. 统一配置:字段key + 取值函数
|
|
|
+ record ScoreItem(String scoreKey, Function<AnShengCrawlerCalculatePremiumApplyResponse.DataDTO, String> valueFunc) {}
|
|
|
+ List<ScoreItem> itemList = new ArrayList<>();
|
|
|
+ itemList.add(new ScoreItem("basicstring", AnShengCrawlerCalculatePremiumApplyResponse.DataDTO::getBasicstring));
|
|
|
+ itemList.add(new ScoreItem("blackDivisor", AnShengCrawlerCalculatePremiumApplyResponse.DataDTO::getBlackDivisor));
|
|
|
+ itemList.add(new ScoreItem("comprehensiveScoreStr", AnShengCrawlerCalculatePremiumApplyResponse.DataDTO::getComprehensiveScoreStr));
|
|
|
+ itemList.add(new ScoreItem("riskScore", AnShengCrawlerCalculatePremiumApplyResponse.DataDTO::getRiskScore));
|
|
|
+ itemList.add(new ScoreItem("unifiedScore", AnShengCrawlerCalculatePremiumApplyResponse.DataDTO::getUnifiedScore));
|
|
|
+
|
|
|
+ final String splitChar = ":";
|
|
|
+ for (ScoreItem item : itemList) {
|
|
|
+ String sourceStr = item.valueFunc().apply(data);
|
|
|
+ fillScoreItem(scoreArray, splitChar, item.scoreKey(), sourceStr);
|
|
|
}
|
|
|
+
|
|
|
scoreVo.setScoreJson(scoreArray);
|
|
|
return scoreVo;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 通用填充单个打分JSON对象,消除重复逻辑 + 规避下标越界
|
|
|
+ * @param scoreArray 外层JSON数组
|
|
|
+ * @param splitChar 分隔符
|
|
|
+ * @param scoreKey 唯一标识key
|
|
|
+ * @param sourceStr 原始待分割字符串
|
|
|
+ */
|
|
|
+ private static void fillScoreItem(JSONArray scoreArray, String splitChar, String scoreKey, String sourceStr) {
|
|
|
+ if (StringUtils.isEmpty(sourceStr)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String[] parts = sourceStr.split(splitChar, 2);
|
|
|
+ String scoreName = parts.length >= 1 ? parts[0].trim() : "";
|
|
|
+ String scoreVal = parts.length >= 2 ? parts[1].trim() : "";
|
|
|
+
|
|
|
+ JSONObject jsonObj = JSONObject.of(
|
|
|
+ "scoreName", scoreName,
|
|
|
+ "scoreKey", scoreKey,
|
|
|
+ "score", scoreVal
|
|
|
+ );
|
|
|
+ scoreArray.add(jsonObj);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
/**
|