Преглед изворни кода

新增费用因子匹配逻辑

li.pengfei пре 3 година
родитељ
комит
b777ec28cb

+ 31 - 0
src/main/java/com/ydtech/modules/fee/dto/FeeFactorInfoDto.java

@@ -0,0 +1,31 @@
+package com.ydtech.modules.fee.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 费用因子对象
+ */
+@Data
+@ApiModel("费用方案因子对象")
+public class FeeFactorInfoDto {
+    @ApiModelProperty("因子名称")
+    private String factorName;
+    @ApiModelProperty("是否需要匹配该因子   true  需要进行匹配校验  false 不校验该因子")
+    private boolean isNeedMatch;
+    @ApiModelProperty("匹配类型  1.单字符串匹配(相等)  2.多字符串匹配(包含)  3.区间范围比较(左闭右闭)   ")
+    private String matchType;
+    @ApiModelProperty("匹配顺序")
+    private Integer matchSequence;
+    @ApiModelProperty("区间最小值")
+    private Integer minRangeVal;
+    @ApiModelProperty("区间最大值")
+    private Integer maxRangeVal;
+    @ApiModelProperty("多选字符串列表")
+    private String multipleSelectVal;
+    @ApiModelProperty("单选字符串")
+    private String singleSelectVal;
+}

+ 57 - 0
src/main/java/com/ydtech/modules/fee/dto/FeeSchemeReqDto.java

@@ -0,0 +1,57 @@
+package com.ydtech.modules.fee.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 费用方案获取请求数据实体
+ */
+@Data
+@ApiModel("费用接口入参DTO")
+public class FeeSchemeReqDto {
+
+    @ApiModelProperty("业务类型:单交0330、单商034001、单三034002、交三0330034002、交商0330034001")
+    private String busType;
+    @ApiModelProperty("协议ID")
+    private String agreementId;
+    @ApiModelProperty("是否过户    1是  0否")
+    private String isTransfer;
+    @ApiModelProperty("是否新车    1是  0否")
+    private String isNewCar;
+    @ApiModelProperty("是否新能源    1是  0否")
+    private String isNewEnergy;
+    @ApiModelProperty("是否续保    1是  0否")
+    private String isRenewal;
+    @ApiModelProperty("车辆大类: 客车、货车、特种车、挂车、摩托车、拖拉机")
+    private String vehicleCategory;
+    @ApiModelProperty("使用性质: 营业出租、营业租赁、营业公交、营业客运、营业货运、营业旅游、家庭自用、非营业机关事业、非营业企业、非营业个人")
+    private String useNature;
+    @ApiModelProperty("座位数")
+    private String seatNum;
+    @ApiModelProperty("新车购置价")
+    private String purchasePrice;
+    @ApiModelProperty("核定载质量")
+    private String approvedLoadCapacity;
+    @ApiModelProperty("交强保费")
+    private String jqPremium;
+    @ApiModelProperty("商业保费")
+    private String syPremium;
+    @ApiModelProperty("车船税金额")
+    private String sumPayTax;
+    @ApiModelProperty("三者险保额")
+    private String thirdPartyInsurance;
+    @ApiModelProperty("随车产品保费")
+    private String noCarPremium;
+    @ApiModelProperty("商业险折扣")
+    private String syDiscount;
+    @ApiModelProperty("交强险折扣")
+    private String jqDiscount;
+    @ApiModelProperty("保司评分")
+    private String insuranceScore;
+    @ApiModelProperty("预期赔付率")
+    private String expectedLossRate;
+    @ApiModelProperty("车牌号")
+    private String licenseNo;
+
+}

+ 45 - 0
src/main/java/com/ydtech/modules/fee/dto/FeeSchemeResDto.java

@@ -0,0 +1,45 @@
+package com.ydtech.modules.fee.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 获取费用后返回的对应信息实体
+ */
+@Data
+@ApiModel("费用接口反参DTO")
+public class FeeSchemeResDto {
+    @ApiModelProperty("协议ID")
+    private String agreementId;
+    @ApiModelProperty("方案ID")
+    private String schemeId;
+    @ApiModelProperty("溢出保费(交强)")
+    private String jqSpilloverPremiums;
+    @ApiModelProperty("溢出比例(交强)")
+    private String jqSpilloverProportion;
+    @ApiModelProperty("新车费用比例(交强)")
+    private String jqNewCarCostsProportion;
+    @ApiModelProperty("旧车费用比例(交强)")
+    private String jqOldCarCostsProportion;
+    @ApiModelProperty("总费用比例(交强)")
+    private String jqCostsProportion;
+    @ApiModelProperty("新车其他费用比例(交强)")
+    private String jqNewCarOtherCostsProportion;
+    @ApiModelProperty("旧车其他费用比例(交强)")
+    private String jqOldCarOtherCostsProportion;
+    @ApiModelProperty("溢出保费(商业)")
+    private String sySpilloverPremiums;
+    @ApiModelProperty("溢出比例(商业)")
+    private String sySpilloverProportion;
+    @ApiModelProperty("新车费用比例(商业)")
+    private String syNewCarCostsProportion;
+    @ApiModelProperty("旧车费用比例(商业)")
+    private String syOldCarCostsProportion;
+    @ApiModelProperty("总费用比例(商业)")
+    private String syCostsProportion;
+    @ApiModelProperty("新车其他费用比例(商业)")
+    private String syNewCarOtherCostsProportion;
+    @ApiModelProperty("旧车其他费用比例(商业)")
+    private String syOldCarOtherCostsProportion;
+}

+ 18 - 0
src/main/java/com/ydtech/modules/fee/service/FeeRuleSchemeService.java

@@ -0,0 +1,18 @@
+package com.ydtech.modules.fee.service;
+
+
+import com.ydtech.modules.fee.dto.FeeSchemeReqDto;
+import com.ydtech.modules.fee.dto.FeeSchemeResDto;
+
+/**
+ * 该类中只要包含费用的一些相关接口
+ * 跟单费用的获取、跟单费用的拆分等
+ */
+public interface FeeRuleSchemeService {
+    /**
+     * 根据跟单信息,以及配置的费用因子,获取合适的跟单费用
+     * @param feeSchemeReqDto
+     * @return
+     */
+    public FeeSchemeResDto matchTheAppropriateFees(FeeSchemeReqDto feeSchemeReqDto);
+}

+ 540 - 0
src/main/java/com/ydtech/modules/fee/service/impl/FeeRuleSchemeServiceImpl.java

@@ -0,0 +1,540 @@
+package com.ydtech.modules.fee.service.impl;
+
+import com.ydtech.exception.SystemException;
+import com.ydtech.modules.fee.dto.FeeFactorInfoDto;
+import com.ydtech.modules.fee.dto.FeeSchemeReqDto;
+import com.ydtech.modules.fee.dto.FeeSchemeResDto;
+import com.ydtech.modules.fee.service.FeeRuleSchemeService;
+import com.ydtech.modules.protocol.entity.po.PtlAgreementProductCosts;
+import com.ydtech.modules.protocol.service.PtlAgreementProductCostsService;
+import org.apache.commons.lang3.math.NumberUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 费用接口中相关功能的实现类
+ */
+@Service
+public class FeeRuleSchemeServiceImpl implements FeeRuleSchemeService {
+    @Autowired
+    private   PtlAgreementProductCostsService ptlAgreementProductCostsService;
+
+    /**
+     * 根据跟单信息,以及配置的费用因子,获取合适的跟单费用
+     * @param feeSchemeReqDto
+     * @return
+     */
+    @Override
+    public FeeSchemeResDto matchTheAppropriateFees(FeeSchemeReqDto feeSchemeReqDto) {
+        FeeSchemeResDto feeSchemeResDto=new FeeSchemeResDto();
+
+        //先根据业务类别、有效期、协议编码、历史标志代码字段 获取对应费用方案列表
+        List<PtlAgreementProductCosts> ptlAgreementProductCosts =ptlAgreementProductCostsService.selectVliadFeeFactor(feeSchemeReqDto.getBusType(),feeSchemeReqDto.getAgreementId());
+        if (ptlAgreementProductCosts.isEmpty()) {
+           //如果查询不到费用方案信息,则阻断算费流程,进行提示
+            throw new SystemException("未查询到费用配置,请先配置该协议的费用方案!");
+        }else{
+            //符合跟单信息的方案列表
+            List validSchemeList=new ArrayList();
+            //循环符合的方案列表,再进行细化的因子匹配,获取最终可以匹配到的方案
+            for(int i=0;i<ptlAgreementProductCosts.size();i++){
+                PtlAgreementProductCosts factorCost=ptlAgreementProductCosts.get(i);
+                //获取处理后的待校验因子
+                Map<Integer, FeeFactorInfoDto> factorToBeVerified=getFactorToBeVerified(factorCost);
+                //按规则拼接跟单信息
+                String matchKeyStr=getMatchKeyWithInsuranceInfo(feeSchemeReqDto);
+                //循环进行各项因子校验
+                boolean checkFlag=checkFactorValidWithInsuranceInfo(matchKeyStr,factorToBeVerified);
+                //如果该方案所有因子都校验通过,则放入符合校验方案列表
+                if(checkFlag){
+                    validSchemeList.add(factorCost);
+                }
+            }
+
+            if(validSchemeList.size()>0){
+                //匹配到唯一一条费用方案,直接用这条
+                if(validSchemeList.size()==1){
+                    //进行费用比例赋值,给返回对象
+                    feeSchemeResDto=generateSchemeResDto((PtlAgreementProductCosts)validSchemeList.get(0));
+                }else{
+                    //如果最终符合的有多条,则按特殊规则选择其中一条
+                    PtlAgreementProductCosts finalSchemeCost=changeSchemeWithSpecialRule(validSchemeList,feeSchemeReqDto);
+                    //进行费用比例赋值,给返回对象
+                    feeSchemeResDto=generateSchemeResDto(finalSchemeCost);
+                }
+            }else{
+                throw new SystemException("未匹配到合适的费用方案,请先配置该协议的费用方案!");
+            }
+        }
+        return feeSchemeResDto;
+    }
+
+    /**
+     * 特殊处理选择费用方案
+     * 如果最终符合的有多条,则先看交强、商业谁的保费多,然后根据保费多得在匹配到的方案中找费用比例大的那一条
+     * @param validSchemeList
+     * @param feeSchemeReqDto
+     * @return
+     */
+    private PtlAgreementProductCosts changeSchemeWithSpecialRule(List<PtlAgreementProductCosts> validSchemeList, FeeSchemeReqDto feeSchemeReqDto) {
+        PtlAgreementProductCosts finalScheme=null;
+        //险种标志,最终取哪个险种费用比例   1取交强   2取商业
+        String riskFlag="";
+        //判断险种标志
+        if("0330".equals(feeSchemeReqDto.getBusType())){//单交
+            riskFlag="1";
+        }else if("034001".equals(feeSchemeReqDto.getBusType())){//单商
+            riskFlag="2";
+        }else if("034002".equals(feeSchemeReqDto.getBusType())){//单三
+            riskFlag="2";
+        }else if("0330034002".equals(feeSchemeReqDto.getBusType())){//交三
+            if(Double.parseDouble(feeSchemeReqDto.getJqPremium())<=Double.parseDouble(feeSchemeReqDto.getSyPremium())){
+                riskFlag="2";
+            }else{
+                riskFlag="1";
+            }
+        }else if("0330034001".equals(feeSchemeReqDto.getBusType())){//交商
+            if(Double.parseDouble(feeSchemeReqDto.getJqPremium())<=Double.parseDouble(feeSchemeReqDto.getSyPremium())){
+                riskFlag="2";
+            }else{
+                riskFlag="1";
+            }
+        }
+        //循环找出对应比例最大的
+        for(int i=0;i<validSchemeList.size();i++){
+            PtlAgreementProductCosts tempCostDto=validSchemeList.get(i);
+            if(finalScheme!=null){
+                if("1".equals(riskFlag)){//按交强比例排序,找比例最大的
+                    if(Double.parseDouble(finalScheme.getJqCostsProportion())<Double.parseDouble(tempCostDto.getJqCostsProportion())){
+                        finalScheme=tempCostDto;
+                    }
+                }else if("2".equals(riskFlag)){//按商业比例排序,找比例最大的
+                    if(Double.parseDouble(finalScheme.getSyCostsProportion())<Double.parseDouble(tempCostDto.getSyCostsProportion())){
+                        finalScheme=tempCostDto;
+                    }
+                }
+            }else{
+                finalScheme=tempCostDto;
+            }
+        }
+        return  finalScheme;
+    }
+
+    /**
+     * 组装费用接口反参对象
+     * @param agreementProductCost
+     * @return
+     */
+    private FeeSchemeResDto generateSchemeResDto(PtlAgreementProductCosts agreementProductCost) {
+        FeeSchemeResDto resDto=new FeeSchemeResDto();
+        resDto.setAgreementId(agreementProductCost.getAgreementId());
+        resDto.setSchemeId(agreementProductCost.getId());
+        resDto.setJqSpilloverPremiums(agreementProductCost.getJqSpilloverPremiums());
+        resDto.setJqSpilloverProportion(agreementProductCost.getJqSpilloverProportion());
+        resDto.setJqNewCarCostsProportion(agreementProductCost.getJqNewCarCostsProportion());
+        resDto.setJqOldCarCostsProportion(agreementProductCost.getJqOldCarCostsProportion());
+        resDto.setJqCostsProportion(agreementProductCost.getJqCostsProportion());
+        resDto.setJqNewCarOtherCostsProportion(agreementProductCost.getJqNewCarOtherCostsProportion());
+        resDto.setJqOldCarOtherCostsProportion(agreementProductCost.getJqOldCarOtherCostsProportion());
+        resDto.setSySpilloverPremiums(agreementProductCost.getSySpilloverPremiums());
+        resDto.setSySpilloverProportion(agreementProductCost.getSySpilloverProportion());
+        resDto.setSyNewCarCostsProportion(agreementProductCost.getSyNewCarCostsProportion());
+        resDto.setSyOldCarCostsProportion(agreementProductCost.getSyOldCarCostsProportion());
+        resDto.setSyCostsProportion(agreementProductCost.getSyCostsProportion());
+        resDto.setSyNewCarOtherCostsProportion(agreementProductCost.getSyNewCarOtherCostsProportion());
+        resDto.setSyOldCarOtherCostsProportion(agreementProductCost.getSyOldCarOtherCostsProportion());
+        return resDto;
+    }
+
+    /**
+     * 根据跟单信息,循环各项因子 校验该方案的匹配情况
+     * @param matchKeyStr
+     * @param factorToBeVerified
+     * @return
+     */
+    private boolean checkFactorValidWithInsuranceInfo(String matchKeyStr, Map<Integer, FeeFactorInfoDto> factorToBeVerified) {
+        boolean result=false; //默认没有匹配到
+        String[] matchKeys= matchKeyStr.split(",");
+        //循环待校验因子列表
+        for(Map.Entry<Integer,FeeFactorInfoDto> entry : factorToBeVerified.entrySet()){
+            Integer key=entry.getKey();
+            FeeFactorInfoDto checkFactorInfo=entry.getValue();
+            //先看该方案是否需要匹配该因子,不需要则跳过本条因子
+            if(!checkFactorInfo.isNeedMatch()){
+                continue;
+            }
+            //下面处理需要进行匹配的因子
+            if("1".equals(checkFactorInfo.getMatchType())){//1.单字符串匹配(相等)
+                if(matchKeys[key]!=null&&!"".equals(matchKeys[key])){
+                    if(checkFactorInfo.getSingleSelectVal().equals(matchKeys[key])){
+                        result=true;
+                        continue;
+                    }else{
+                        //如果需要匹配且没有匹配到,则直接跳出本次循环,该方案不符合
+                        result=false;
+                        break;
+                    }
+                }else{
+                    //判断跟单信息是否为空,如果为空,则直接没有匹配到,该方案不符合
+                    result=false;
+                    break;
+                }
+            }else if("2".equals(checkFactorInfo.getMatchType())){//2.多字符串匹配(包含)
+                if(matchKeys[key]!=null&&!"".equals(matchKeys[key])){
+                    //如果需要匹配,且匹配成功,则跳过本次循环,继续校验下一因子
+                    if(checkFactorInfo.getMultipleSelectVal().indexOf(matchKeys[key])>-1){
+                        result=true;
+                        continue;
+                    }else{
+                        //如果需要匹配且没有匹配到,则直接跳出循环,该方案不符合
+                        result=false;
+                        break;
+                    }
+                }else{
+                    //判断跟单信息是否为空,如果为空,则直接没有匹配到,该方案不符合
+                    result=false;
+                    break;
+                }
+            }else if("3".equals(checkFactorInfo.getMatchType())){//3.区间范围比较(左闭右闭)
+                if(matchKeys[key]!=null&&NumberUtils.isDigits(matchKeys[key])){
+                    //如果需要匹配,且匹配成功,则跳过本次循环,继续校验下一因子
+                    if(Integer.parseInt(matchKeys[key])>=checkFactorInfo.getMinRangeVal()&&Integer.parseInt(matchKeys[key])<=checkFactorInfo.getMaxRangeVal()){
+                        result=true;
+                        continue;
+                    }else{
+                        //如果需要匹配且没有匹配到,则直接跳出循环,该方案不符合
+                        result=false;
+                        break;
+                    }
+                }else{
+                    //判断跟单信息是否为空和可转整型,如果不符,则直接没有匹配到,该方案不符合
+                    result=false;
+                    break;
+                }
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * 根据跟单信息,按照约定顺序进行拼接匹配串
+     * 新增因子时,顺序需要与getFactorToBeVerified()方法放入待校验因子一致
+     * @param feeSchemeReqDto
+     * @return
+     */
+    private String getMatchKeyWithInsuranceInfo(FeeSchemeReqDto feeSchemeReqDto) {
+        StringBuffer result=new StringBuffer();
+        result.append(feeSchemeReqDto.getIsTransfer()).append(",");
+        result.append(feeSchemeReqDto.getIsNewCar()).append(",");
+        result.append(feeSchemeReqDto.getIsNewEnergy()).append(",");
+        result.append(feeSchemeReqDto.getIsRenewal()).append(",");
+        result.append(feeSchemeReqDto.getVehicleCategory()).append(",");
+        result.append(feeSchemeReqDto.getUseNature()).append(",");
+        result.append(feeSchemeReqDto.getSeatNum()).append(",");
+        result.append(feeSchemeReqDto.getPurchasePrice()).append(",");
+        result.append(feeSchemeReqDto.getApprovedLoadCapacity()).append(",");
+        result.append(feeSchemeReqDto.getJqPremium()).append(",");
+        result.append(feeSchemeReqDto.getSumPayTax()).append(",");
+        result.append(feeSchemeReqDto.getThirdPartyInsurance()).append(",");
+        result.append(feeSchemeReqDto.getNoCarPremium()).append(",");
+        result.append(feeSchemeReqDto.getSyDiscount()).append(",");
+        result.append(feeSchemeReqDto.getJqDiscount()).append(",");
+        result.append(feeSchemeReqDto.getInsuranceScore()).append(",");
+        result.append(feeSchemeReqDto.getExpectedLossRate()).append(",");
+        result.append(feeSchemeReqDto.getLicenseNo());
+        return result.toString();
+    }
+
+    /**
+     * 根据配置的因子表数据,组装标准的待校验因子列表
+     * 新增因子时,顺序需要与getMatchKeyWithInsuranceInfo()方法放入跟单信息一致
+     * @param factorCost
+     * @return
+     */
+    private Map<Integer, FeeFactorInfoDto> getFactorToBeVerified(PtlAgreementProductCosts factorCost) {
+        Map<Integer, FeeFactorInfoDto> resultMqp=new HashMap<>();
+        //以下各项因子必须按顺序放入MAP,以便校验时关联
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor0=new FeeFactorInfoDto();
+        factor0.setFactorName("是否过户");
+        factor0.setMatchType("1");
+        factor0.setMatchSequence(0);
+        if(factorCost.getTransfer()!=null){
+            factor0.setNeedMatch(true);
+            factor0.setSingleSelectVal(String.valueOf(factorCost.getTransfer()));
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor0.setNeedMatch(false);
+        }
+        resultMqp.put(0,factor0);
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor1=new FeeFactorInfoDto();
+        factor1.setFactorName("新旧车");
+        factor1.setMatchType("1");
+        factor1.setMatchSequence(1);
+        if(factorCost.getOldAndNew()!=null){
+            factor1.setNeedMatch(true);
+            factor1.setSingleSelectVal(String.valueOf(factorCost.getOldAndNew()));
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor1.setNeedMatch(false);
+        }
+        resultMqp.put(1,factor1);
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor2=new FeeFactorInfoDto();
+        factor2.setFactorName("是否新能源");
+        factor2.setMatchType("1");
+        factor2.setMatchSequence(2);
+        if(factorCost.getNewEnergy()!=null){
+            factor2.setNeedMatch(true);
+            factor2.setSingleSelectVal(String.valueOf(factorCost.getNewEnergy()));
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor2.setNeedMatch(false);
+        }
+        resultMqp.put(2,factor2);
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor3=new FeeFactorInfoDto();
+        factor3.setFactorName("是否续保");
+        factor3.setMatchType("1");
+        factor3.setMatchSequence(3);
+        if(factorCost.getRenewal()!=null){
+            factor3.setNeedMatch(true);
+            factor3.setSingleSelectVal(String.valueOf(factorCost.getRenewal()));
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor3.setNeedMatch(false);
+        }
+        resultMqp.put(3,factor3);
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor4=new FeeFactorInfoDto();
+        factor4.setFactorName("车辆大类");
+        factor4.setMatchType("2");
+        factor4.setMatchSequence(4);
+        if(factorCost.getVehicleCategory()!=null&&!"".equals(factorCost.getVehicleCategory())){
+            factor4.setNeedMatch(true);
+            factor4.setMultipleSelectVal(String.valueOf(factorCost.getVehicleCategory()));
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor4.setNeedMatch(false);
+        }
+        resultMqp.put(4,factor4);
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor5=new FeeFactorInfoDto();
+        factor5.setFactorName("使用性质");
+        factor5.setMatchType("2");
+        factor5.setMatchSequence(5);
+        if(factorCost.getNatureOfUse()!=null&&!"".equals(factorCost.getNatureOfUse())){
+            factor5.setNeedMatch(true);
+            factor5.setMultipleSelectVal(String.valueOf(factorCost.getNatureOfUse()));
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor5.setNeedMatch(false);
+        }
+        resultMqp.put(5,factor5);
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor6=new FeeFactorInfoDto();
+        factor6.setFactorName("客车座位数区间");
+        factor6.setMatchType("3");
+        factor6.setMatchSequence(6);
+        if(checkFactorConfigWithArea(factorCost.getMinSeats(),factorCost.getMaxSeats(),factor6,factorCost)){
+            factor6.setNeedMatch(true);
+            factor6.setMinRangeVal(factorCost.getMinSeats());
+            factor6.setMaxRangeVal(factorCost.getMaxSeats());
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor6.setNeedMatch(false);
+        }
+        resultMqp.put(6,factor6);
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor7=new FeeFactorInfoDto();
+        factor7.setFactorName("新车购置价区间");
+        factor7.setMatchType("3");
+        factor7.setMatchSequence(7);
+        if(checkFactorConfigWithArea(factorCost.getMinPurchasePrice(),factorCost.getMaxPurchasePrice(),factor7,factorCost)){
+            factor7.setNeedMatch(true);
+            factor7.setMinRangeVal(factorCost.getMinPurchasePrice());
+            factor7.setMaxRangeVal(factorCost.getMaxPurchasePrice());
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor7.setNeedMatch(false);
+        }
+        resultMqp.put(7,factor7);
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor8=new FeeFactorInfoDto();
+        factor8.setFactorName("核定载质量区间");
+        factor8.setMatchType("3");
+        factor8.setMatchSequence(8);
+        if(checkFactorConfigWithArea(factorCost.getMinApprovedLoadCapacity(),factorCost.getMaxApprovedLoadCapacity(),factor8,factorCost)){
+            factor8.setNeedMatch(true);
+            factor8.setMinRangeVal(factorCost.getMinApprovedLoadCapacity());
+            factor8.setMaxRangeVal(factorCost.getMaxApprovedLoadCapacity());
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor8.setNeedMatch(false);
+        }
+        resultMqp.put(8,factor8);
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor9=new FeeFactorInfoDto();
+        factor9.setFactorName("交强险保费区间");
+        factor9.setMatchType("3");
+        factor9.setMatchSequence(9);
+        if(checkFactorConfigWithArea(factorCost.getMinCompulsoryInsurancePremium(),factorCost.getMaxCompulsoryInsurancePremium(),factor9,factorCost)){
+            factor9.setNeedMatch(true);
+            factor9.setMinRangeVal(factorCost.getMinCompulsoryInsurancePremium());
+            factor9.setMaxRangeVal(factorCost.getMaxCompulsoryInsurancePremium());
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor9.setNeedMatch(false);
+        }
+        resultMqp.put(9,factor9);
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor10=new FeeFactorInfoDto();
+        factor10.setFactorName("车船税金额区间");
+        factor10.setMatchType("3");
+        factor10.setMatchSequence(10);
+        if(checkFactorConfigWithArea(factorCost.getMinTaxAmount(),factorCost.getMaxTaxAmount(),factor10,factorCost)){
+            factor10.setNeedMatch(true);
+            factor10.setMinRangeVal(factorCost.getMinTaxAmount());
+            factor10.setMaxRangeVal(factorCost.getMaxTaxAmount());
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor10.setNeedMatch(false);
+        }
+        resultMqp.put(10,factor10);
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor11=new FeeFactorInfoDto();
+        factor11.setFactorName("三者保额区间");
+        factor11.setMatchType("3");
+        factor11.setMatchSequence(11);
+        if(checkFactorConfigWithArea(factorCost.getMinTheThreePremium(),factorCost.getMaxTheThreePremium(),factor11,factorCost)){
+            factor11.setNeedMatch(true);
+            factor11.setMinRangeVal(factorCost.getMinTheThreePremium());
+            factor11.setMaxRangeVal(factorCost.getMaxTheThreePremium());
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor11.setNeedMatch(false);
+        }
+        resultMqp.put(11,factor11);
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor12=new FeeFactorInfoDto();
+        factor12.setFactorName("随车产品保费区间");
+        factor12.setMatchType("3");
+        factor12.setMatchSequence(12);
+        if(checkFactorConfigWithArea(factorCost.getMinOnboardProductsPremium(),factorCost.getMaxOnboardProductsPremium(),factor12,factorCost)){
+            factor12.setNeedMatch(true);
+            factor12.setMinRangeVal(factorCost.getMinOnboardProductsPremium());
+            factor12.setMaxRangeVal(factorCost.getMaxOnboardProductsPremium());
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor12.setNeedMatch(false);
+        }
+        resultMqp.put(12,factor12);
+
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor13=new FeeFactorInfoDto();
+        factor13.setFactorName("商业险折扣区间");
+        factor13.setMatchType("3");
+        factor13.setMatchSequence(13);
+        if(checkFactorConfigWithArea(factorCost.getMinCommercialInsuranceDiscount(),factorCost.getMaxCommercialInsuranceDiscount(),factor13,factorCost)){
+            factor13.setNeedMatch(true);
+            factor13.setMinRangeVal(factorCost.getMinCommercialInsuranceDiscount());
+            factor13.setMaxRangeVal(factorCost.getMaxCommercialInsuranceDiscount());
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor13.setNeedMatch(false);
+        }
+        resultMqp.put(13,factor13);
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor14=new FeeFactorInfoDto();
+        factor14.setFactorName("交强险折扣区间");
+        factor14.setMatchType("3");
+        factor14.setMatchSequence(14);
+        if(checkFactorConfigWithArea(factorCost.getMinCompulsoryInsuranceDiscount(),factorCost.getMaxCompulsoryInsuranceDiscount(),factor14,factorCost)){
+            factor14.setNeedMatch(true);
+            factor14.setMinRangeVal(factorCost.getMinCompulsoryInsuranceDiscount());
+            factor14.setMaxRangeVal(factorCost.getMaxCompulsoryInsuranceDiscount());
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor14.setNeedMatch(false);
+        }
+        resultMqp.put(14,factor14);
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor15=new FeeFactorInfoDto();
+        factor15.setFactorName("保司评分区间");
+        factor15.setMatchType("3");
+        factor15.setMatchSequence(15);
+        if(checkFactorConfigWithArea(factorCost.getMinScore(),factorCost.getMaxScore(),factor15,factorCost)){
+            factor15.setNeedMatch(true);
+            factor15.setMinRangeVal(factorCost.getMinScore());
+            factor15.setMaxRangeVal(factorCost.getMaxScore());
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor15.setNeedMatch(false);
+        }
+        resultMqp.put(15,factor15);
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor16=new FeeFactorInfoDto();
+        factor16.setFactorName("预期赔付率区间");
+        factor16.setMatchType("3");
+        factor16.setMatchSequence(16);
+        if(checkFactorConfigWithArea(factorCost.getMinLossRation(),factorCost.getMaxLossRation(),factor16,factorCost)){
+            factor16.setNeedMatch(true);
+            factor16.setMinRangeVal(factorCost.getMinLossRation());
+            factor16.setMaxRangeVal(factorCost.getMaxLossRation());
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor16.setNeedMatch(false);
+        }
+        resultMqp.put(16,factor16);
+        //--------------------因子处理分割线----------------------------------
+        FeeFactorInfoDto factor17=new FeeFactorInfoDto();
+        factor17.setFactorName("车牌号地区");
+        factor17.setMatchType("2");
+        factor17.setMatchSequence(17);
+        if(factorCost.getLicenseNumber()!=null&&!"".equals(factorCost.getLicenseNumber())){
+            factor17.setNeedMatch(true);
+            String matchStr=factorCost.getLicenseNumber();
+//            //考虑是否含暂未上牌标志--待加字段后完善
+//            if(factorCost.暂未上牌标志){
+//                matchStr=matchStr+",暂未上牌";
+//            }
+            factor17.setMultipleSelectVal(matchStr);
+        }else{
+            //如果方案中未录入,则不校验该项因子
+            factor17.setNeedMatch(false);
+        }
+        resultMqp.put(17,factor17);
+        return resultMqp;
+    }
+
+    /**
+     * 判断区间类因子是否需要匹配
+     * @param minVal
+     * @param maxVal
+     * @param factorInfoDto
+     * @param productCosts
+     * @return
+     */
+    private boolean checkFactorConfigWithArea(Integer minVal, Integer maxVal,FeeFactorInfoDto factorInfoDto,PtlAgreementProductCosts productCosts) {
+        boolean result=false; //默认不需要匹配
+        if(minVal!=null&&maxVal!=null){
+            if(minVal<=maxVal){
+                result=true;
+            }else{
+                throw new SystemException("协议ID:"+productCosts.getAgreementId()+" 方案序号:"+productCosts.getId()+" 费用因子:"+factorInfoDto.getFactorName()+"配置有问题,请检查!");
+            }
+        }else if(minVal!=null && maxVal==null){
+            throw new SystemException("协议ID:"+productCosts.getAgreementId()+" 方案序号:"+productCosts.getId()+" 费用因子:"+factorInfoDto.getFactorName()+"配置有问题,请检查!");
+        }else if(minVal==null&&maxVal!=null){
+            throw new SystemException("协议ID:"+productCosts.getAgreementId()+" 方案序号:"+productCosts.getId()+" 费用因子:"+factorInfoDto.getFactorName()+"配置有问题,请检查!");
+        }
+        return result;
+    }
+}

+ 9 - 0
src/main/java/com/ydtech/modules/protocol/service/PtlAgreementProductCostsService.java

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.ydtech.modules.protocol.entity.dto.PltAgreementSchemeSaveDto;
 import com.ydtech.modules.protocol.entity.po.PtlAgreementProductCosts;
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -57,4 +59,11 @@ public interface PtlAgreementProductCostsService extends IService<PtlAgreementPr
         return wrapper;
     }
 
+    /**
+     * 通过协议ID、业务类型 获取需要进行匹配的费用因子
+     * @param busType
+     * @param agreementId
+     * @return
+     */
+    public List<PtlAgreementProductCosts> selectVliadFeeFactor(String busType,String agreementId);
 }

+ 25 - 5
src/main/java/com/ydtech/modules/protocol/service/impl/PtlAgreementProductCostsServiceImpl.java

@@ -1,5 +1,6 @@
 package com.ydtech.modules.protocol.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ydtech.exception.SystemException;
 import com.ydtech.modules.protocol.dao.PtlAgreementProductCostsMapper;
@@ -13,11 +14,9 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.ObjectUtils;
 
+import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -102,6 +101,27 @@ public class PtlAgreementProductCostsServiceImpl extends ServiceImpl<PtlAgreemen
         return ptlAgreementProductCosts;
     }
 
-
+    /**
+     * 通过协议ID 获取需要进行匹配的费用因子
+     * @param busType
+     * @param agreementId
+     * @return
+     */
+    @Override
+    public List<PtlAgreementProductCosts> selectVliadFeeFactor(String busType,String agreementId){
+        //获取当前时间,用来卡费用方案中有效期区间
+        Date date=new Date();
+        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
+        String nowDate=sdf.format(date);
+        //组织查询条件
+        LambdaQueryWrapper<PtlAgreementProductCosts> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(PtlAgreementProductCosts::getAgreementId, agreementId);
+        wrapper.eq(PtlAgreementProductCosts::getProductId,busType);
+        wrapper.le(PtlAgreementProductCosts::getJqCostsStartDate,nowDate);//有效起期小于等于当前时间
+        wrapper.ge(PtlAgreementProductCosts::getJqCostsEndDate,nowDate);//有效止期大于等于当前时间
+        wrapper.eq(PtlAgreementProductCosts::getHistory, 0);//查询所有非历史记录的
+        List<PtlAgreementProductCosts> ptlAgreementProductCosts = baseMapper.selectList(wrapper);
+        return ptlAgreementProductCosts;
+    }
 
 }