|
@@ -0,0 +1,831 @@
|
|
|
|
|
+package com.jzg.quotation.summary.aop.aspect;
|
|
|
|
|
+
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.jzg.commons.constants.ProductsType;
|
|
|
|
|
+import com.jzg.commons.constants.quote.enums.quote.CarKindCode;
|
|
|
|
|
+import com.jzg.commons.constants.quote.enums.quote.CarNatureCode;
|
|
|
|
|
+import com.jzg.commons.constants.quote.enums.quote.EnergyTypeCode;
|
|
|
|
|
+import com.jzg.commons.core.base.BaseController;
|
|
|
|
|
+import com.jzg.commons.core.page.HttpResult;
|
|
|
|
|
+import com.jzg.commons.entity.dto.CostAgreementParam;
|
|
|
|
|
+import com.jzg.commons.entity.orders.po.*;
|
|
|
|
|
+import com.jzg.commons.entity.po.*;
|
|
|
|
|
+import com.jzg.commons.entity.quote.vo.aggregated.QuoteResultsVo;
|
|
|
|
|
+import com.jzg.commons.entity.vo.AgreementInfoVo;
|
|
|
|
|
+import com.jzg.commons.entity.vo.CostsListVo;
|
|
|
|
|
+import com.jzg.commons.entity.vo.PtlAgreementCostTypeVo;
|
|
|
|
|
+import com.jzg.commons.entity.vo.RuleAttrMappingVo;
|
|
|
|
|
+import com.jzg.quotation.commons.client.OrgClient;
|
|
|
|
|
+import com.jzg.quotation.summary.service.*;
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import org.aspectj.lang.annotation.AfterReturning;
|
|
|
|
|
+import org.aspectj.lang.annotation.Aspect;
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
+
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.math.RoundingMode;
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
+import java.util.function.BiConsumer;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @author quchen
|
|
|
|
|
+ * @date 2025/6/30 17:50
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+@Aspect
|
|
|
|
|
+@Component
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
|
+public class QuoteVerificationAspect {
|
|
|
|
|
+ private final InsOrdersService insOrdersService;
|
|
|
|
|
+
|
|
|
|
|
+ private final InsOrdersRiskService insOrdersRiskService;
|
|
|
|
|
+
|
|
|
|
|
+ private final InsOrdersCostsService insOrdersCostsService;
|
|
|
|
|
+
|
|
|
|
|
+ private final InsOrdersCarInfoService insOrdersCarInfoService;
|
|
|
|
|
+
|
|
|
|
|
+ private final InsOrdersCarUserInfoService insOrdersCarUserInfoService;
|
|
|
|
|
+
|
|
|
|
|
+ private final InsOrdersKindService insOrdersKindService;
|
|
|
|
|
+
|
|
|
|
|
+ private final InsOrdersAccidentalDrivingService insOrdersAccidentalDrivingService;
|
|
|
|
|
+
|
|
|
|
|
+ private final OrgClient orgClient;
|
|
|
|
|
+
|
|
|
|
|
+ private final InsOrdersOtherService insOrdersOtherService;
|
|
|
|
|
+
|
|
|
|
|
+ private final InsFeeOrdersService insFeeOrdersService;
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger("fee");
|
|
|
|
|
+
|
|
|
|
|
+ private final BaseController baseController;
|
|
|
|
|
+
|
|
|
|
|
+ @AfterReturning(pointcut = "@annotation(com.jzg.quotation.summary.aop.QuoteVerification)", returning = "result")
|
|
|
|
|
+ public void doAfter(HttpResult<QuoteResultsVo> result) {
|
|
|
|
|
+ if (result.getCode() == 200) {
|
|
|
|
|
+ StringBuilder logs = new StringBuilder();
|
|
|
|
|
+ InsOrders insOrders = insOrdersService.getById(result.getData().getOrdersNo());
|
|
|
|
|
+ // 获取订单车辆信息
|
|
|
|
|
+ InsOrdersCarInfo insOrdersCarInfo = insOrdersCarInfoService.getById(insOrders.getId());
|
|
|
|
|
+ // 获取订单险种信息
|
|
|
|
|
+ List<InsOrdersRisk> insOrdersRisks = insOrdersRiskService.list(new LambdaQueryWrapper<InsOrdersRisk>().eq(InsOrdersRisk::getOrderNo, insOrders.getId()));
|
|
|
|
|
+ // 获取订单车主、投被保人信息
|
|
|
|
|
+ List<InsOrdersCarUserInfo> insOrdersCarUserInfos = insOrdersCarUserInfoService.list(new LambdaQueryWrapper<InsOrdersCarUserInfo>().eq(InsOrdersCarUserInfo::getOrderNo, insOrders.getId()));
|
|
|
|
|
+ // 获取订单费用信息
|
|
|
|
|
+ InsOrdersCosts insOrdersCosts = insOrdersCostsService.getById(insOrders.getId());
|
|
|
|
|
+ // 获取订单险种信息
|
|
|
|
|
+ List<InsOrdersKind> kindList = insOrdersKindService.list(new LambdaQueryWrapper<InsOrdersKind>().eq(InsOrdersKind::getOrderNo, insOrders.getId()));
|
|
|
|
|
+ // 获取订单驾意险信息
|
|
|
|
|
+ InsOrdersAccidentalDriving insOrdersAccidentalDriving = insOrdersAccidentalDrivingService.getById(insOrders.getId());
|
|
|
|
|
+ // 获取订单其他信息
|
|
|
|
|
+ InsOrdersOther insOrdersOther = insOrdersOtherService.getById(insOrders.getId());
|
|
|
|
|
+ // 获取协议信息
|
|
|
|
|
+ HttpResult<AgreementInfoVo> ptlAgreement = orgClient.queryAgreementById(insOrders.getAgreementId(), baseController.getToken(),baseController.getAppSystemCode());
|
|
|
|
|
+ AgreementInfoVo agreementInfoVo = ptlAgreement.getData();
|
|
|
|
|
+ // 通过协议id和产品id查询费用列表
|
|
|
|
|
+ CostAgreementParam costAgreementParam = new CostAgreementParam();
|
|
|
|
|
+ costAgreementParam.setPtlAgreementId(insOrders.getAgreementId());
|
|
|
|
|
+ costAgreementParam.setProductId(insOrders.getProductId());
|
|
|
|
|
+ List<CostsListVo> costsList = orgClient.queryByAgreementIdAndProductId(costAgreementParam, baseController.getToken());
|
|
|
|
|
+ List<CostsListVo> agreementProductCosts = new ArrayList<>();
|
|
|
|
|
+ // 通过费用规则遍历 按优先级匹配 校验通过的费用
|
|
|
|
|
+ costsList.forEach(costsListVo -> {
|
|
|
|
|
+ AtomicBoolean matching = new AtomicBoolean(true);
|
|
|
|
|
+ costsListVo.getPtlAgreementCostRuleList().forEach(ptlAgreementCostRule -> {
|
|
|
|
|
+ //判断能源类型是 燃油/新能源
|
|
|
|
|
+ if (ptlAgreementCostRule.getAttrCode().equals("NewEnergyMark")) {
|
|
|
|
|
+ String energyType = EnergyTypeCode.isNewEnergy(insOrdersCarInfo.getEnergyTypeCode()) ? "1" : "0";
|
|
|
|
|
+ if(!ptlAgreementCostRule.getMin().equals(energyType)) {
|
|
|
|
|
+ matching.set(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //判断使用性质是 营业/非营业
|
|
|
|
|
+ if (ptlAgreementCostRule.getAttrCode().equals("CarNatureCode")) {
|
|
|
|
|
+ String[] split = ptlAgreementCostRule.getMin().split(",");
|
|
|
|
|
+ boolean isPipei = false;
|
|
|
|
|
+ for(int i = 0;i < split.length; i++){
|
|
|
|
|
+ if(split[i].equals(CarNatureCode.getByCode(insOrdersCarInfo.getCarNatureCode()))) {
|
|
|
|
|
+ isPipei = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!isPipei){
|
|
|
|
|
+ matching.set(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //车辆种类是 客车/货车
|
|
|
|
|
+ if(ptlAgreementCostRule.getAttrCode().equals("CarKindCode")) {
|
|
|
|
|
+ String[] split = ptlAgreementCostRule.getMin().split(",");
|
|
|
|
|
+ boolean isPipei = false;
|
|
|
|
|
+ for(int i = 0;i < split.length; i++){
|
|
|
|
|
+ if(split[i].equals(CarKindCode.getByCode(insOrdersCarInfo.getCarKindCode()))) {
|
|
|
|
|
+ isPipei = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!isPipei){
|
|
|
|
|
+ matching.set(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ if(matching.get()){
|
|
|
|
|
+ agreementProductCosts.add(costsListVo);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ // 若优先级为空 添加优先级
|
|
|
|
|
+ for (int i = 0; i < agreementProductCosts.size(); i++) {
|
|
|
|
|
+ if (agreementProductCosts.get(i).getPriorityLevel() == null) {
|
|
|
|
|
+ agreementProductCosts.get(i).setPriorityLevel(10);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!agreementProductCosts.isEmpty()) {
|
|
|
|
|
+ //按优先级进行排序
|
|
|
|
|
+ agreementProductCosts.sort(Comparator.comparingInt(CostsListVo::getPriorityLevel));
|
|
|
|
|
+ //遍历费用因子
|
|
|
|
|
+ String costId = verificationCosts(agreementProductCosts, logs, insOrdersOther, insOrdersCarInfo, insOrdersRisks, insOrdersCarUserInfos, kindList, insOrdersCosts, insOrdersAccidentalDriving);
|
|
|
|
|
+ if (costId != null) {
|
|
|
|
|
+ // 根据匹配到的协议、费用 开始计算入口费用
|
|
|
|
|
+ calcCosts(agreementInfoVo,costId, insOrders,insOrdersCosts);
|
|
|
|
|
+ log.debug("费用因子校验通过,子订单id:" + insOrders.getId() + ",费用id:" + costId);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ logs.append("没有找到该协议的费用信息" + "\n");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String verificationCosts(List<CostsListVo> agreementProductCosts,StringBuilder logs,
|
|
|
|
|
+ InsOrdersOther insOrdersOther, InsOrdersCarInfo insOrdersCarInfo,
|
|
|
|
|
+ List<InsOrdersRisk> riskList, List<InsOrdersCarUserInfo> insOrdersCarUserInfos,
|
|
|
|
|
+ List<InsOrdersKind> kindList, InsOrdersCosts insOrdersCosts,
|
|
|
|
|
+ InsOrdersAccidentalDriving insOrdersAccidentalDriving) {
|
|
|
|
|
+ //获取所有费用属性
|
|
|
|
|
+ List<PtlAgreementUndwrtRulesAttr> undwrtRulesAttrList = orgClient.list().getData();
|
|
|
|
|
+ //获取所有费用属性关联
|
|
|
|
|
+ List<RuleAttrMappingVo> ruleAttrMappingVoList = RuleAttrMappingVo.getRuleAttrMappingVoList(insOrdersOther,insOrdersCarInfo,
|
|
|
|
|
+ riskList, insOrdersCarUserInfos, kindList, insOrdersCosts, insOrdersAccidentalDriving);
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < agreementProductCosts.size(); i++) {
|
|
|
|
|
+ //判断是否匹配
|
|
|
|
|
+// log.debug("费用因子匹配开始:" + agreementProductCosts.get(i).getId());
|
|
|
|
|
+//
|
|
|
|
|
+// log.debug("车牌号:" + insOrdersCarInfo.getLicenseNo());
|
|
|
|
|
+// log.debug("费用因子备注:" + agreementProductCosts.get(i).getCostsDescription());
|
|
|
|
|
+// logs.append("费用id:" + agreementProductCosts.get(i).getId() + "\n");
|
|
|
|
|
+// logs.append("费用因子描述:" + agreementProductCosts.get(i).getCostsDescription() + "\n");
|
|
|
|
|
+ if (judgements(agreementProductCosts.get(i).getPtlAgreementCostRuleList(),ruleAttrMappingVoList,undwrtRulesAttrList,logs)) {
|
|
|
|
|
+ return agreementProductCosts.get(i).getId();
|
|
|
|
|
+ }
|
|
|
|
|
+ log.debug("当前费用因子匹配结束\n");
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 费用因子的对比
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean judgements(List<PtlAgreementCostRule> ptlAgreementCostRuleList,List<RuleAttrMappingVo> ruleAttrMappingVoList, List<PtlAgreementUndwrtRulesAttr> undwrtRulesAttrList,StringBuilder logs) {
|
|
|
|
|
+ boolean useFlag = true;
|
|
|
|
|
+ for (PtlAgreementCostRule ptlAgreementProductCostsAttrLink : ptlAgreementCostRuleList) {
|
|
|
|
|
+ //查找规则中的 传值属性
|
|
|
|
|
+ RuleAttrMappingVo ruleAttrMappingVo = ruleAttrMappingVoList.stream()
|
|
|
|
|
+ .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode()))
|
|
|
|
|
+ .findFirst()
|
|
|
|
|
+ .orElse(null);
|
|
|
|
|
+ //如果查找不到 传值属性 直接费用对比失败
|
|
|
|
|
+ if (ruleAttrMappingVo == null) {
|
|
|
|
|
+ log.debug("传入的值找不到该属性:" + ptlAgreementProductCostsAttrLink.getAttrCode());
|
|
|
|
|
+ log.debug("规则匹配失败:" + ptlAgreementProductCostsAttrLink.getAttrCode());
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ List<PtlAgreementUndwrtRulesAttr> collect = undwrtRulesAttrList.stream()
|
|
|
|
|
+ .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode()))
|
|
|
|
|
+ .toList();
|
|
|
|
|
+ if (!collect.isEmpty()) {
|
|
|
|
|
+ logs.append("规则匹配失败:" + collect.get(0).getAttrName() + "\n");
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //查找 费用因子规则
|
|
|
|
|
+ PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr = undwrtRulesAttrList.stream()
|
|
|
|
|
+ .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode()))
|
|
|
|
|
+ .findFirst()
|
|
|
|
|
+ .get();
|
|
|
|
|
+
|
|
|
|
|
+ if(!Objects.isNull(ruleAttrMappingVo.getValue())) {
|
|
|
|
|
+ useFlag = attrEqual(ptlAgreementProductCostsAttrLink, ptlAgreementUndwrtRulesAttr, ruleAttrMappingVo.getValue());
|
|
|
|
|
+ }else{
|
|
|
|
|
+ useFlag = false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!useFlag) {
|
|
|
|
|
+ log.debug("检验的值:" + ptlAgreementProductCostsAttrLink.getMin());
|
|
|
|
|
+ log.debug("传入的值:" + ruleAttrMappingVo.getValue());
|
|
|
|
|
+ log.debug("规则匹配失败:" + ptlAgreementProductCostsAttrLink.getAttrCode());
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ List<PtlAgreementUndwrtRulesAttr> collect = undwrtRulesAttrList.stream()
|
|
|
|
|
+ .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode()))
|
|
|
|
|
+ .toList();
|
|
|
|
|
+
|
|
|
|
|
+ if (ptlAgreementProductCostsAttrLink.getMin() != null) {
|
|
|
|
|
+ logs.append("检验的值:" + ptlAgreementProductCostsAttrLink.getMin() + "\n");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ logs.append("检验的值:" + ptlAgreementProductCostsAttrLink.getMax() + "\n");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ logs.append("传入的值:" + ruleAttrMappingVo.getValue() + "\n");
|
|
|
|
|
+
|
|
|
|
|
+ if (!collect.isEmpty()) {
|
|
|
|
|
+ logs.append("<span style=\"color:red;\">规则匹配失败:" + collect.get(0).getAttrName() + "</span>\n");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return useFlag;
|
|
|
|
|
+ }
|
|
|
|
|
+ private boolean attrEqual(PtlAgreementCostRule ptlAgreementCostRule,
|
|
|
|
|
+ PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, String value) {
|
|
|
|
|
+ if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("checkbox")) {
|
|
|
|
|
+ return checkBoxEqual(ptlAgreementCostRule, value);
|
|
|
|
|
+ } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("inputNumber")) {
|
|
|
|
|
+ return inputNumberEqual(ptlAgreementCostRule, value);
|
|
|
|
|
+ } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("input")) {
|
|
|
|
|
+ //截取身份证号码
|
|
|
|
|
+ if (ptlAgreementCostRule.getAttrCode().equals("CarOwnersIDNumber") || ptlAgreementCostRule.getAttrCode().equals("ApplicantIDNumber") ||
|
|
|
|
|
+ ptlAgreementCostRule.getAttrCode().equals("InsuredIDNumber")) {
|
|
|
|
|
+ value = value.substring(0, ptlAgreementCostRule.getMin().length());
|
|
|
|
|
+ }
|
|
|
|
|
+ return inputTextEqual(ptlAgreementCostRule, value);
|
|
|
|
|
+ } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("select")) {
|
|
|
|
|
+ //截取车牌
|
|
|
|
|
+ if (ptlAgreementUndwrtRulesAttr.getAttrCode().equals("LicenseNo")) {
|
|
|
|
|
+ value = value.substring(0, 2);
|
|
|
|
|
+ }
|
|
|
|
|
+ return selectEqual(ptlAgreementCostRule, value);
|
|
|
|
|
+ } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) {
|
|
|
|
|
+ return radioEqual(ptlAgreementCostRule, value);
|
|
|
|
|
+ } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("datetime")){ // 时间
|
|
|
|
|
+ return dateTimeEqual(ptlAgreementCostRule, value);
|
|
|
|
|
+ } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("date")){
|
|
|
|
|
+ return dateEqual(ptlAgreementCostRule, value);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 属性为多选判断
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean checkBoxEqual(PtlAgreementCostRule ptlAgreementCostRule, String value) {
|
|
|
|
|
+ String[] split = ptlAgreementCostRule.getMin().split(",");
|
|
|
|
|
+ for (String sp : split) {
|
|
|
|
|
+ if (sp.equals(value)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean checkBoxEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
|
|
|
|
|
+ if (!ptlAgreementUndwrtRulesAttrLink.getMin().equals(value)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 属性为数值型判断
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean inputNumberEqual(PtlAgreementCostRule ptlAgreementCostRule, String value) {
|
|
|
|
|
+ double v = Double.parseDouble(value);
|
|
|
|
|
+ //统一处理数值
|
|
|
|
|
+ if ("1".equals(ptlAgreementCostRule.getOperator())) {
|
|
|
|
|
+ if (Double.parseDouble(ptlAgreementCostRule.getMin()) <= v &&
|
|
|
|
|
+ Double.parseDouble(ptlAgreementCostRule.getMax()) >= v) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("2".equals(ptlAgreementCostRule.getOperator())) {
|
|
|
|
|
+ if (Double.parseDouble(ptlAgreementCostRule.getMin()) > v) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("3".equals(ptlAgreementCostRule.getOperator())) {
|
|
|
|
|
+ if (Double.parseDouble(ptlAgreementCostRule.getMin()) >= v) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("4".equals(ptlAgreementCostRule.getOperator())) {
|
|
|
|
|
+ if (Double.parseDouble(ptlAgreementCostRule.getMax()) < v) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("5".equals(ptlAgreementCostRule.getOperator())) {
|
|
|
|
|
+ if (Double.parseDouble(ptlAgreementCostRule.getMax()) <= v) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean inputNumberEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
|
|
|
|
|
+ double v = Double.parseDouble(value);
|
|
|
|
|
+ //统一处理数值
|
|
|
|
|
+ if ("1".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
|
|
|
|
|
+ if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMin()) <= v &&
|
|
|
|
|
+ Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMax()) >= v) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("2".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
|
|
|
|
|
+ if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMin()) > v) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("3".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
|
|
|
|
|
+ if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMin()) >= v) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("4".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
|
|
|
|
|
+ if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMax()) < v) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("5".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
|
|
|
|
|
+ if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMax()) <= v) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 属性为输入框判断
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean inputTextEqual(PtlAgreementCostRule ptlAgreementCostRule, String value) {
|
|
|
|
|
+ //将值进行分割
|
|
|
|
|
+ String[] split = ptlAgreementCostRule.getMin().split(",");
|
|
|
|
|
+ AtomicBoolean returnBool = new AtomicBoolean(false);
|
|
|
|
|
+
|
|
|
|
|
+ List<String> equalsMap = new ArrayList<>();
|
|
|
|
|
+ //字符型评分
|
|
|
|
|
+ equalsMap.add("CharacterBasedRating");
|
|
|
|
|
+ //交强字符型评分
|
|
|
|
|
+ equalsMap.add("JqCharacterBasedRating");
|
|
|
|
|
+ //商业字符型评分
|
|
|
|
|
+ equalsMap.add("SyCharacterBasedRating");
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //equest 等于判断
|
|
|
|
|
+ if(equalsMap.contains(ptlAgreementCostRule.getAttrCode())){
|
|
|
|
|
+ boolean b = Arrays.stream(split).anyMatch(value::equals);
|
|
|
|
|
+ returnBool.set(b);
|
|
|
|
|
+ }else if((ptlAgreementCostRule.getAttrCode().equals("BrandandModel") || ptlAgreementCostRule.getAttrCode().equals("CarOwnerName")
|
|
|
|
|
+ || ptlAgreementCostRule.getAttrCode().equals("CarOwnersAddress") || ptlAgreementCostRule.getAttrCode().equals("ApplicantAddress")
|
|
|
|
|
+ || ptlAgreementCostRule.getAttrCode().equals("InsuredAddress"))
|
|
|
|
|
+ && ptlAgreementCostRule.getOperator().equals("2")){
|
|
|
|
|
+ //处理品牌型号 不包含的情况
|
|
|
|
|
+ boolean anyMatch = Arrays.stream(split)
|
|
|
|
|
+ .anyMatch(value::contains);
|
|
|
|
|
+ returnBool.set(!anyMatch);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ boolean anyMatch = Arrays.stream(split)
|
|
|
|
|
+ .anyMatch(value::contains);
|
|
|
|
|
+ returnBool.set(anyMatch);
|
|
|
|
|
+ }
|
|
|
|
|
+ return returnBool.get();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean inputTextEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
|
|
|
|
|
+ //将值进行分割
|
|
|
|
|
+ String[] split = ptlAgreementUndwrtRulesAttrLink.getMin().split(",");
|
|
|
|
|
+ AtomicBoolean returnBool = new AtomicBoolean(false);
|
|
|
|
|
+
|
|
|
|
|
+ List<String> equalsMap = new ArrayList<>();
|
|
|
|
|
+ //字符型评分
|
|
|
|
|
+ equalsMap.add("CharacterBasedRating");
|
|
|
|
|
+ //交强字符型评分
|
|
|
|
|
+ equalsMap.add("JqCharacterBasedRating");
|
|
|
|
|
+ //商业字符型评分
|
|
|
|
|
+ equalsMap.add("SyCharacterBasedRating");
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //equest 等于判断
|
|
|
|
|
+ if(equalsMap.contains(ptlAgreementUndwrtRulesAttrLink.getAttrCode())){
|
|
|
|
|
+ boolean b = Arrays.stream(split).anyMatch(value::equals);
|
|
|
|
|
+ returnBool.set(b);
|
|
|
|
|
+ }else if((ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("BrandandModel") || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("CarOwnerName")
|
|
|
|
|
+ || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("CarOwnersAddress") || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("ApplicantAddress")
|
|
|
|
|
+ || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("InsuredAddress"))
|
|
|
|
|
+ && ptlAgreementUndwrtRulesAttrLink.getOperator().equals("2")){
|
|
|
|
|
+ //处理品牌型号 不包含的情况
|
|
|
|
|
+ boolean anyMatch = Arrays.stream(split)
|
|
|
|
|
+ .anyMatch(value::contains);
|
|
|
|
|
+ returnBool.set(!anyMatch);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ boolean anyMatch = Arrays.stream(split)
|
|
|
|
|
+ .anyMatch(value::contains);
|
|
|
|
|
+ returnBool.set(anyMatch);
|
|
|
|
|
+ }
|
|
|
|
|
+ return !returnBool.get();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 属性为下拉框判断
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean selectEqual(PtlAgreementCostRule ptlAgreementCostRule, String value) {
|
|
|
|
|
+ if (ptlAgreementCostRule.getMin() != null && ptlAgreementCostRule.getMin().contains(value)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 属性为选择框判断
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param ptlAgreementUndwrtRulesAttrLink
|
|
|
|
|
+ * @param value
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean selectEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
|
|
|
|
|
+ if (ptlAgreementUndwrtRulesAttrLink.getMin() == null) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!ptlAgreementUndwrtRulesAttrLink.getMin().contains(value)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 属性为单选框判断
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean radioEqual(PtlAgreementCostRule ptlAgreementCostRule, String value) {
|
|
|
|
|
+ //新能源判断
|
|
|
|
|
+ if ("NewEnergy".equals(ptlAgreementCostRule.getAttrCode())) {
|
|
|
|
|
+ // 是否是新能源车
|
|
|
|
|
+ boolean newEnergy = EnergyTypeCode.isNewEnergy(value);
|
|
|
|
|
+ if (newEnergy && ptlAgreementCostRule.getMin().equals("1")) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } else if (!newEnergy && ptlAgreementCostRule.getMin().equals("0")) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (ptlAgreementCostRule.getMin().contains(value)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean radioEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
|
|
|
|
|
+ //新能源判断
|
|
|
|
|
+ if ("NewEnergy".equals(ptlAgreementUndwrtRulesAttrLink.getAttrCode())) {
|
|
|
|
|
+ // 是否是新能源车
|
|
|
|
|
+ boolean newEnergy = EnergyTypeCode.isNewEnergy(value);
|
|
|
|
|
+ if (newEnergy && ptlAgreementUndwrtRulesAttrLink.getMin().equals("1")) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ } else if (!newEnergy && ptlAgreementUndwrtRulesAttrLink.getMin().equals("0")) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (ptlAgreementUndwrtRulesAttrLink.getMin().contains(value)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public boolean dateTimeEqual(PtlAgreementCostRule ptlAgreementCostRule, String value){
|
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ if(Objects.isNull(value) || value.equals("")){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ LocalDateTime v = LocalDateTime.parse(value,formatter);
|
|
|
|
|
+ LocalDateTime min = null,max = null;
|
|
|
|
|
+ if(!Objects.isNull(ptlAgreementCostRule.getMin())){
|
|
|
|
|
+ min = LocalDateTime.parse(ptlAgreementCostRule.getMin(),formatter);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!Objects.isNull(ptlAgreementCostRule.getMax())){
|
|
|
|
|
+ max = LocalDateTime.parse(ptlAgreementCostRule.getMax(),formatter);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //统一处理数值
|
|
|
|
|
+ if ("1".equals(ptlAgreementCostRule.getOperator())) {
|
|
|
|
|
+ if (v.isAfter(min) && v.isBefore(max)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("2".equals(ptlAgreementCostRule.getOperator())) {
|
|
|
|
|
+ if (v.isBefore(min)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("3".equals(ptlAgreementCostRule.getOperator())) {
|
|
|
|
|
+ if (v.isBefore(min) || v.isEqual(min)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("4".equals(ptlAgreementCostRule.getOperator())) {
|
|
|
|
|
+ if (v.isAfter(max)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("5".equals(ptlAgreementCostRule.getOperator())) {
|
|
|
|
|
+ if (v.isAfter(max) || v.isEqual(max)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public boolean dateEqual(PtlAgreementCostRule ptlAgreementCostRule, String value){
|
|
|
|
|
+// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
+ if(Objects.isNull(value) || value.equals("")){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ LocalDateTime v = LocalDate.parse(value).atStartOfDay();
|
|
|
|
|
+ LocalDateTime min = null,max = null;
|
|
|
|
|
+ if(!Objects.isNull(ptlAgreementCostRule.getMin())){
|
|
|
|
|
+ min = LocalDate.parse(ptlAgreementCostRule.getMin()).atStartOfDay();
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!Objects.isNull(ptlAgreementCostRule.getMax())){
|
|
|
|
|
+ max = LocalDate.parse(ptlAgreementCostRule.getMax()).atStartOfDay();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //统一处理数值
|
|
|
|
|
+ if ("1".equals(ptlAgreementCostRule.getOperator())) {
|
|
|
|
|
+ if (v.isAfter(min) && v.isBefore(max)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("2".equals(ptlAgreementCostRule.getOperator())) {
|
|
|
|
|
+ if (v.isBefore(min)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("3".equals(ptlAgreementCostRule.getOperator())) {
|
|
|
|
|
+ if (v.isBefore(min) || v.isEqual(min)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("4".equals(ptlAgreementCostRule.getOperator())) {
|
|
|
|
|
+ if (v.isAfter(max)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("5".equals(ptlAgreementCostRule.getOperator())) {
|
|
|
|
|
+ if (v.isAfter(max) || v.isEqual(max)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public boolean dateTimeEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value, InsOrders insOrders){
|
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ //判断险种 的起保时间
|
|
|
|
|
+ if(ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("SyStartTime") || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("JqStartTime"))
|
|
|
|
|
+ {
|
|
|
|
|
+ if(insOrders.getProductId().equals(ProductsType.PT_0330.getCode()) && ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("SyStartTime")){
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(insOrders.getProductId().equals(ProductsType.PT_034001.getCode()) && ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("JqStartTime")){
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!Objects.isNull(value) && !value.isEmpty()) {
|
|
|
|
|
+ LocalDateTime v = LocalDateTime.parse(value, formatter);
|
|
|
|
|
+ LocalDateTime min = null, max = null;
|
|
|
|
|
+ if (!Objects.isNull(ptlAgreementUndwrtRulesAttrLink.getMin())) {
|
|
|
|
|
+ min = LocalDateTime.parse(ptlAgreementUndwrtRulesAttrLink.getMin(), formatter);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Objects.isNull(ptlAgreementUndwrtRulesAttrLink.getMax())) {
|
|
|
|
|
+ max = LocalDateTime.parse(ptlAgreementUndwrtRulesAttrLink.getMax(), formatter);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //统一处理数值
|
|
|
|
|
+ if ("1".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
|
|
|
|
|
+ if (!v.isAfter(min) && v.isBefore(max)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("2".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
|
|
|
|
|
+ if (!v.isBefore(min)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("3".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
|
|
|
|
|
+ if (!v.isBefore(min)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("4".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
|
|
|
|
|
+ if (!v.isAfter(max)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("5".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
|
|
|
|
|
+ if (!v.isAfter(max)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public boolean dateEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value){
|
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
+
|
|
|
|
|
+ if(!Objects.isNull(value) && !value.isEmpty()) {
|
|
|
|
|
+ LocalDateTime v = LocalDate.parse(value).atStartOfDay();
|
|
|
|
|
+ LocalDateTime min = null, max = null;
|
|
|
|
|
+ if (!Objects.isNull(ptlAgreementUndwrtRulesAttrLink.getMin())) {
|
|
|
|
|
+ min = LocalDate.parse(ptlAgreementUndwrtRulesAttrLink.getMin()).atStartOfDay();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Objects.isNull(ptlAgreementUndwrtRulesAttrLink.getMax())) {
|
|
|
|
|
+ max = LocalDate.parse(ptlAgreementUndwrtRulesAttrLink.getMax()).atStartOfDay();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //统一处理数值
|
|
|
|
|
+ if ("1".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
|
|
|
|
|
+ if (!v.isAfter(min) && v.isBefore(max)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("2".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
|
|
|
|
|
+ if (!v.isBefore(min)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("3".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
|
|
|
|
|
+ if (!v.isBefore(min)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("4".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
|
|
|
|
|
+ if (!v.isAfter(max)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("5".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
|
|
|
|
|
+ if (!v.isAfter(max)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public void calcCosts(AgreementInfoVo agreementInfoVo, String costId, InsOrders insOrders, InsOrdersCosts insOrdersCosts) {
|
|
|
|
|
+ InsFeeOrders insFeeOrders = new InsFeeOrders();
|
|
|
|
|
+ insFeeOrders.setOrderNo(insOrders.getId());
|
|
|
|
|
+ insFeeOrders.setAgreementId(insOrders.getAgreementId());
|
|
|
|
|
+ insFeeOrders.setCostId(costId);
|
|
|
|
|
+ insFeeOrders.setJqPremium(insOrdersCosts.getJqPremium());
|
|
|
|
|
+ insFeeOrders.setSyPremium(insOrdersCosts.getSyPremium());
|
|
|
|
|
+ insFeeOrders.setJyPremium(insOrdersCosts.getJyPremium());
|
|
|
|
|
+ insFeeOrders.setTotalPremium(insOrdersCosts.getSumPremium());
|
|
|
|
|
+ // 获取协议是平台协议还是私有协议 1 平台协议 2 私有协议
|
|
|
|
|
+ String agreementType = agreementInfoVo.getAgreement().getAgreementType();
|
|
|
|
|
+ BigDecimal jqEntranceFeeRatio = convertPercent(agreementInfoVo.getAgreement().getJqEntranceFeeRatio());
|
|
|
|
|
+ BigDecimal syEntranceFeeRatio = convertPercent(agreementInfoVo.getAgreement().getSyEntranceFeeRatio());
|
|
|
|
|
+ BigDecimal jyEntranceFeeRatio = convertPercent(agreementInfoVo.getAgreement().getJyEntranceFeeRatio());
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 获取费用类型列表(处理空集合,避免NPE)
|
|
|
|
|
+ List<PtlAgreementCostTypeVo> costTypeList = orgClient.queryByCostId(costId);
|
|
|
|
|
+ costTypeList = costTypeList == null ? Collections.emptyList() : costTypeList;
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 获取各险种对应的费用类型配置
|
|
|
|
|
+ PtlAgreementCostTypeVo jqCostType = getCostTypeByTypeName(costTypeList, "交强险");
|
|
|
|
|
+ PtlAgreementCostTypeVo syCostType = getCostTypeByTypeName(costTypeList, "商业险");
|
|
|
|
|
+ PtlAgreementCostTypeVo jyCostType = getCostTypeByTypeName(costTypeList, "驾意险");
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 计算跟单费比例(入口比例 - 手续费比例)
|
|
|
|
|
+ BigDecimal jqFollowRatio = calculateFollowRatio(jqCostType, jqEntranceFeeRatio);
|
|
|
|
|
+ BigDecimal syFollowRatio = calculateFollowRatio(syCostType, syEntranceFeeRatio);
|
|
|
|
|
+ BigDecimal jyFollowRatio = calculateFollowRatio(jyCostType, jyEntranceFeeRatio);
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 根据协议类型确定税率因子(平台协议为1,私有协议为1/1.06)
|
|
|
|
|
+ BigDecimal taxFactor = "1".equals(agreementType)
|
|
|
|
|
+ ? BigDecimal.ONE
|
|
|
|
|
+ : new BigDecimal("1").divide(new BigDecimal("1.06"), 10, RoundingMode.HALF_EVEN);
|
|
|
|
|
+
|
|
|
|
|
+ // 6. 统一处理各险种的费用计算(应收、应付、各类费用)
|
|
|
|
|
+ processInsuranceType(
|
|
|
|
|
+ insOrdersCosts.getJqPremium(), jqCostType, jqEntranceFeeRatio, jqFollowRatio, taxFactor,
|
|
|
|
|
+ insFeeOrders,
|
|
|
|
|
+ InsFeeOrders::setJqReceivablePremium, InsFeeOrders::setJqPayablePremium,
|
|
|
|
|
+ InsFeeOrders::setJqCommissionPremium, InsFeeOrders::setJqFollowPremium, InsFeeOrders::setJqAdditionalPremium
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ processInsuranceType(
|
|
|
|
|
+ insOrdersCosts.getSyPremium(), syCostType, syEntranceFeeRatio, syFollowRatio, taxFactor,
|
|
|
|
|
+ insFeeOrders,
|
|
|
|
|
+ InsFeeOrders::setSyReceivablePremium, InsFeeOrders::setSyPayablePremium,
|
|
|
|
|
+ InsFeeOrders::setSyCommissionPremium, InsFeeOrders::setSyFollowPremium, InsFeeOrders::setSyAdditionalPremium
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ processInsuranceType(
|
|
|
|
|
+ insOrdersCosts.getJyPremium(), jyCostType, jyEntranceFeeRatio, jyFollowRatio, taxFactor,
|
|
|
|
|
+ insFeeOrders,
|
|
|
|
|
+ InsFeeOrders::setJyReceivablePremium, InsFeeOrders::setJyPayablePremium,
|
|
|
|
|
+ InsFeeOrders::setJyCommissionPremium, InsFeeOrders::setJyFollowPremium, InsFeeOrders::setJyAdditionalPremium
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // 7. 计算总应收、总应付并保存
|
|
|
|
|
+ calculateTotalPremium(insFeeOrders);
|
|
|
|
|
+ insFeeOrdersService.save(insFeeOrders);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 转换百分比为小数(如:50 -> 0.5)
|
|
|
|
|
+ */
|
|
|
|
|
+ private BigDecimal convertPercent(BigDecimal percent) {
|
|
|
|
|
+ return percent.divide(BigDecimal.valueOf(100), 10, RoundingMode.HALF_EVEN);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据险种名称从列表中获取对应的费用类型配置
|
|
|
|
|
+ */
|
|
|
|
|
+ private PtlAgreementCostTypeVo getCostTypeByTypeName(List<PtlAgreementCostTypeVo> costTypeList, String typeName) {
|
|
|
|
|
+ return costTypeList.stream()
|
|
|
|
|
+ .filter(costType -> typeName.equals(costType.getCostType()))
|
|
|
|
|
+ .findFirst()
|
|
|
|
|
+ .orElse(null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 计算跟单费比例(入口比例 - 手续费比例)
|
|
|
|
|
+ */
|
|
|
|
|
+ private BigDecimal calculateFollowRatio(PtlAgreementCostTypeVo costType, BigDecimal entranceFeeRatio) {
|
|
|
|
|
+ if (costType == null) {
|
|
|
|
|
+ return BigDecimal.ZERO;
|
|
|
|
|
+ }
|
|
|
|
|
+ BigDecimal inletPercent = convertPercent(costType.getInlet());
|
|
|
|
|
+ return inletPercent.subtract(entranceFeeRatio);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理单个险种的费用计算(核心复用方法)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param premium 险种保费
|
|
|
|
|
+ * @param costType 险种费用类型配置
|
|
|
|
|
+ * @param commissionRatio 手续费比例
|
|
|
|
|
+ * @param followRatio 跟单费比例
|
|
|
|
|
+ * @param taxFactor 税率因子(平台协议为1,私有协议为1/1.06)
|
|
|
|
|
+ * @param insFeeOrders 费用订单对象
|
|
|
|
|
+ * @param setReceivable 应收金额setter
|
|
|
|
|
+ * @param setPayable 应付金额setter
|
|
|
|
|
+ * @param setCommission 手续费setter
|
|
|
|
|
+ * @param setFollow 跟单费setter
|
|
|
|
|
+ * @param setAdditional 加投费setter
|
|
|
|
|
+ */
|
|
|
|
|
+ private void processInsuranceType(
|
|
|
|
|
+ BigDecimal premium,
|
|
|
|
|
+ PtlAgreementCostTypeVo costType,
|
|
|
|
|
+ BigDecimal commissionRatio,
|
|
|
|
|
+ BigDecimal followRatio,
|
|
|
|
|
+ BigDecimal taxFactor,
|
|
|
|
|
+ InsFeeOrders insFeeOrders,
|
|
|
|
|
+ BiConsumer<InsFeeOrders, BigDecimal> setReceivable,
|
|
|
|
|
+ BiConsumer<InsFeeOrders, BigDecimal> setPayable,
|
|
|
|
|
+ BiConsumer<InsFeeOrders, BigDecimal> setCommission,
|
|
|
|
|
+ BiConsumer<InsFeeOrders, BigDecimal> setFollow,
|
|
|
|
|
+ BiConsumer<InsFeeOrders, BigDecimal> setAdditional
|
|
|
|
|
+ ) {
|
|
|
|
|
+ // 若险种配置为空,默认应收应付为0
|
|
|
|
|
+ if (costType == null || premium == null) {
|
|
|
|
|
+ setReceivable.accept(insFeeOrders, BigDecimal.ZERO);
|
|
|
|
|
+ setPayable.accept(insFeeOrders, BigDecimal.ZERO);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 转换百分比(入口比例、加投比例、出口比例)
|
|
|
|
|
+ BigDecimal inletPercent = convertPercent(costType.getInlet());
|
|
|
|
|
+ BigDecimal addThrowPercent = convertPercent(costType.getAddThrow());
|
|
|
|
|
+ BigDecimal exportPercent = convertPercent(costType.getExport());
|
|
|
|
|
+
|
|
|
|
|
+ // 计算应收金额(保费 * 税率因子 * (入口比例 + 加投比例 + 跟单比例))
|
|
|
|
|
+ BigDecimal taxablePremium = premium.multiply(taxFactor);
|
|
|
|
|
+ BigDecimal receivable = taxablePremium.multiply(inletPercent)
|
|
|
|
|
+ .add(taxablePremium.multiply(addThrowPercent))
|
|
|
|
|
+ .add(taxablePremium.multiply(followRatio))
|
|
|
|
|
+ .setScale(5, RoundingMode.HALF_EVEN);
|
|
|
|
|
+
|
|
|
|
|
+ // 计算应付金额(保费 * 出口比例,保留2位小数)
|
|
|
|
|
+ BigDecimal payable = premium.multiply(exportPercent.setScale(2, RoundingMode.DOWN));
|
|
|
|
|
+
|
|
|
|
|
+ // 计算各类费用并设置到订单对象
|
|
|
|
|
+ setReceivable.accept(insFeeOrders, receivable);
|
|
|
|
|
+ setPayable.accept(insFeeOrders, payable);
|
|
|
|
|
+ setCommission.accept(insFeeOrders, premium.multiply(commissionRatio).setScale(5, RoundingMode.HALF_EVEN));
|
|
|
|
|
+ setFollow.accept(insFeeOrders, premium.multiply(followRatio).setScale(5, RoundingMode.HALF_EVEN));
|
|
|
|
|
+ setAdditional.accept(insFeeOrders, premium.multiply(addThrowPercent).setScale(5, RoundingMode.HALF_EVEN));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 计算总应收和总应付金额
|
|
|
|
|
+ */
|
|
|
|
|
+ private void calculateTotalPremium(InsFeeOrders insFeeOrders) {
|
|
|
|
|
+ // 总应收 = 交强险应收 + 商业险应收 + 驾意险应收
|
|
|
|
|
+ BigDecimal totalReceivable = insFeeOrders.getJqReceivablePremium()
|
|
|
|
|
+ .add(insFeeOrders.getSyReceivablePremium())
|
|
|
|
|
+ .add(insFeeOrders.getJyReceivablePremium())
|
|
|
|
|
+ .setScale(5, RoundingMode.HALF_EVEN);
|
|
|
|
|
+
|
|
|
|
|
+ // 总应付 = 交强险应付 + 商业险应付 + 驾意险应付
|
|
|
|
|
+ BigDecimal totalPayable = insFeeOrders.getJqPayablePremium()
|
|
|
|
|
+ .add(insFeeOrders.getSyPayablePremium())
|
|
|
|
|
+ .add(insFeeOrders.getJyPayablePremium())
|
|
|
|
|
+ .setScale(2, RoundingMode.DOWN);
|
|
|
|
|
+
|
|
|
|
|
+ insFeeOrders.setTotalReceivablePremium(totalReceivable);
|
|
|
|
|
+ insFeeOrders.setTotalPayablePremium(totalPayable);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|