package com.ydtech.modules.fee.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.ydtech.constants.enums.dict.agreement.ProductsType; import com.ydtech.constants.enums.dict.insurance.EnergyType; import com.ydtech.constants.enums.dict.insurance.NatureOfVehicleUse; import com.ydtech.constants.enums.dict.insurance.VehicleType; import com.ydtech.exception.SystemException; import com.ydtech.modules.admin.model.SysUser; import com.ydtech.modules.admin.service.SysChannelGroupService; import com.ydtech.modules.admin.service.SysSwitchConfigService; import com.ydtech.modules.admin.service.SysUserAccountService; import com.ydtech.modules.admin.service.SysUserService; import com.ydtech.modules.esm.model.EsmRetail; import com.ydtech.modules.esm.model.EsmUserReferrer; import com.ydtech.modules.esm.service.EsmRetailService; import com.ydtech.modules.esm.service.EsmUserReferrerService; import com.ydtech.modules.fee.constants.CostAllocation; import com.ydtech.modules.fee.dto.po.InsFeeOrderConfig; import com.ydtech.modules.fee.dto.vo.ReCalcuLateProportion; import com.ydtech.modules.fee.dto.vo.RetailProportion; import com.ydtech.modules.fee.dto.vo.RuleAttrMappingVo; import com.ydtech.modules.fee.service.FeeRuleSchemeNewService; import com.ydtech.modules.fee.service.FeeRuleSchemeService; import com.ydtech.modules.fee.service.InsFeeOrderConfigService; import com.ydtech.modules.fee.service.InsFeeOrderNewHistoryService; import com.ydtech.modules.order.entity.InsAreaCompany; import com.ydtech.modules.order.entity.InsOrders; import com.ydtech.modules.order.entity.api.dajia.constants.TypeVehicleMapping; import com.ydtech.modules.order.entity.vo.ExternalOrderFeeVo; import com.ydtech.modules.order.entity.vo.FeeOrderNewVo; import com.ydtech.modules.order.entity.vo.QueryOrderFeeResultVo; import com.ydtech.modules.order.entity.vo.QueryOrderFeeVo; import com.ydtech.modules.order.service.InsOrdersService; import com.ydtech.modules.protocol.entity.po.PtlAgreement; import com.ydtech.modules.protocol.entity.po.PtlNewCarJudgeRules; import com.ydtech.modules.protocol.service.PtlAgreementService; import com.ydtech.modules.protocol.service.PtlNewCarJudgeRulesService; import com.ydtech.modules.protocols.entity.po.*; import com.ydtech.modules.protocols.entity.vo.AgreementProductCosts; import com.ydtech.modules.protocols.service.*; import com.ydtech.utils.idgen.IdGenerate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; import java.math.RoundingMode; import java.text.DateFormat; 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.stream.Collectors; /** * @author: tz * @description: 费用接口中相关功能的实现类 * @create: 2024-3-1 11:45:33 */ @Service public class FeeRuleSchemeServiceNewImpl implements FeeRuleSchemeNewService { private static final Logger log = LoggerFactory.getLogger("fee"); @Resource private InsOrdersService insOrdersService; @Resource private PtlAgreementProductCostsNewService ptlAgreementProductCostsNewService; @Resource private PtlAgreementUndwrtRulesAttrService ptlAgreementUndwrtRulesAttrService; @Resource private PtlAgreementProductCostsExportService ptlAgreementProductCostsExportService; @Resource private PtlAgreementProductCostsAttrLinkService ptlAgreementProductCostsAttrLinkService; @Resource private PtlAgreementUndwrtRulesNewService ptlAgreementUndwrtRulesNewService; @Resource private SysUserService sysUserService; @Resource private EsmRetailService esmRetailService; @Resource private InsFeeOrderNewService insFeeOrderNewService; @Autowired private EsmUserReferrerService esmUserReferrerService; @Autowired private SysUserAccountService sysUserAccountService; @Autowired private PtlNewCarJudgeRulesService ptlNewCarJudgeRulesService; @Autowired private PtlAgreementService ptlAgreementService; @Autowired private FeeRuleSchemeService feeRuleSchemeService; @Autowired private InsFeeOrderConfigService insFeeOrderConfigService; @Autowired private SysSwitchConfigService sysSwitchConfigService; @Autowired private InsFeeOrderNewHistoryService insFeeOrderNewHistoryService; @Autowired private SysChannelGroupService sysChannelGroupService; @Override public QueryOrderFeeVo queryFeeOrderInfo(String companyId) { return null; } @Override public List convertOrderFeeVoData(QueryOrderFeeVo orderFeeVo) { return null; } @Override public void compareAndUpdateFeeOrderInfo(String insOrderNo, String jqCostsProportionStr, String syCostsProportionStr, String dealUser) { } /** * 校验费用因子 */ @Override public void verificationCostFactor(InsAreaCompany insAreaCompany, InsOrders insOrders, StringBuilder logs) { List agreementProductCostsNoMatched = ptlAgreementProductCostsNewService.costsGetList(insAreaCompany.getAgreementId(), insAreaCompany.getProductid()); List agreementProductCosts = new ArrayList<>(); //过滤费用因子 根据使用性质,能源种类,车辆种类过滤 agreementProductCostsNoMatched.forEach(item->{ AtomicBoolean matching = new AtomicBoolean(true); item.getCostsAttrLinks().forEach(attr->{ //判断能源类型 燃油 新能源 if(attr.getAttrCode().equals("NewEnergy")){ //传入的能源类型 String energyType = EnergyType.isNewEnergy(insOrders.getCarinfo().getString("energyType")) ? "1" : "0"; if(!attr.getMin().equals(energyType)) { matching.set(false); } } //使用性质 营业 非营业 if(attr.getAttrCode().equals("NatureOfUse")){ String[] split = attr.getMin().split(","); boolean isPipei = false; for(int i=0;i ptlAgreementUndwrtRules = ptlAgreementUndwrtRulesNewService.rulesList(insAreaCompany.getAgreementId()); verificationRules(ptlAgreementUndwrtRules, insAreaCompany, insOrders); } //BigDecimal取两位 private BigDecimal twoPeople(BigDecimal number) { return number.setScale(2, BigDecimal.ROUND_DOWN); } /** * 重新计算分销和机构比例 * * @param sumCostsProportion 总入口费用比例 * @param deptProportion 机构管理总比例 * @param retailProportion 默认分销总比例 * @param retailLevel 分销级别 * @return 如果不够减则 返回新的分销比例 */ public ReCalcuLateProportion recalculateProportion(BigDecimal sumCostsProportion, BigDecimal deptProportion, BigDecimal retailProportion, BigDecimal taxRadio, Integer retailLevel, PtlAgreementProductCostsExport ptlAgreementProductCostsExport, RetailProportion originalRetailProportion, String type, BigDecimal enterProportion) { ReCalcuLateProportion reCalcuLateProportion = new ReCalcuLateProportion(); BigDecimal costsProportion = sumCostsProportion.divide(taxRadio, 2, BigDecimal.ROUND_DOWN); List list = insFeeOrderConfigService.list(); //总比例 / 比例 / 分销等级 // 不够减扣除比例 Map notEnoughReduce = list.stream().collect(Collectors.toMap(InsFeeOrderConfig::getKeyword, InsFeeOrderConfig::getVal)); //分销配置的比例 BigDecimal retailProportionConfig = notEnoughReduce.get(CostAllocation.CA_01.getCode()); BigDecimal retailSettingProportion = new BigDecimal(retailProportionConfig.toString()); // 机构配置的比例 BigDecimal deptProportionConfig = notEnoughReduce.get(CostAllocation.CA_02.getCode()); // 代课录单比例 BigDecimal proxyProportionConfig = notEnoughReduce.get(CostAllocation.CA_03.getCode()); BigDecimal deptSettingProportion = new BigDecimal(deptProportionConfig.toString()); //机构比例均分 BigDecimal jqAverageDept = twoPeople(twoPeople(costsProportion.multiply(deptSettingProportion)).divide(new BigDecimal(5))); //如果不够减的话 if (deptProportion.add(retailProportion).add(enterProportion).compareTo(costsProportion) > 0) { //分销比例均分 BigDecimal jqAverageRetail = new BigDecimal(0); if (retailLevel != 0) { jqAverageRetail = twoPeople(twoPeople(costsProportion.multiply(retailSettingProportion)).divide(new BigDecimal(retailLevel), 2, RoundingMode.DOWN)); } if (enterProportion.compareTo(BigDecimal.ZERO) == 0) { reCalcuLateProportion.setProxyProportion(BigDecimal.ZERO); } else { // 代客比例 BigDecimal proxyProportion = costsProportion.multiply(proxyProportionConfig); reCalcuLateProportion.setProxyProportion(twoPeople(proxyProportion)); } if (retailLevel >= 3) { reCalcuLateProportion.setRetail_level_3_proportion(jqAverageRetail); } if (retailLevel >= 2) { reCalcuLateProportion.setRetail_level_2_proportion(jqAverageRetail); } if (retailLevel >= 1) { reCalcuLateProportion.setRetail_level_1_proportion(jqAverageRetail); } reCalcuLateProportion.setDept_level_1_proportion(jqAverageDept); reCalcuLateProportion.setDept_level_2_proportion(jqAverageDept); reCalcuLateProportion.setDept_level_3_proportion(jqAverageDept); reCalcuLateProportion.setDept_level_4_proportion(jqAverageDept); reCalcuLateProportion.setDept_level_5_proportion(jqAverageDept); } else { if (type.equals("jq")) { reCalcuLateProportion.setDept_level_1_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel1()); reCalcuLateProportion.setDept_level_2_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel2()); reCalcuLateProportion.setDept_level_3_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel3()); reCalcuLateProportion.setDept_level_4_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel4()); reCalcuLateProportion.setDept_level_5_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel5()); reCalcuLateProportion.setRetail_level_1_proportion(originalRetailProportion.getJqRetailLevel1Proportion()); reCalcuLateProportion.setRetail_level_2_proportion(originalRetailProportion.getJqRetailLevel2Proportion()); reCalcuLateProportion.setRetail_level_3_proportion(originalRetailProportion.getJqRetailLevel3Proportion()); } else if (type.equals("sy")) { reCalcuLateProportion.setDept_level_1_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel1()); reCalcuLateProportion.setDept_level_2_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel2()); reCalcuLateProportion.setDept_level_3_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel3()); reCalcuLateProportion.setDept_level_4_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel4()); reCalcuLateProportion.setDept_level_5_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel5()); reCalcuLateProportion.setRetail_level_1_proportion(originalRetailProportion.getSyRetailLevel1Proportion()); reCalcuLateProportion.setRetail_level_2_proportion(originalRetailProportion.getSyRetailLevel2Proportion()); reCalcuLateProportion.setRetail_level_3_proportion(originalRetailProportion.getSyRetailLevel3Proportion()); } else if (type.equals("no")) { reCalcuLateProportion.setDept_level_1_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel1()); reCalcuLateProportion.setDept_level_2_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()); reCalcuLateProportion.setDept_level_3_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()); reCalcuLateProportion.setDept_level_4_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()); reCalcuLateProportion.setDept_level_5_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5()); reCalcuLateProportion.setRetail_level_1_proportion(originalRetailProportion.getNoRetailLevel1Proportion()); reCalcuLateProportion.setRetail_level_2_proportion(originalRetailProportion.getNoRetailLevel2Proportion()); reCalcuLateProportion.setRetail_level_3_proportion(originalRetailProportion.getNoRetailLevel3Proportion()); } // 代课比例 reCalcuLateProportion.setProxyProportion(enterProportion); } return reCalcuLateProportion; } /** * 计算费用 * * @param costsId * @param insAreaCompany */ @Override public void calcCosts(String costsId, InsAreaCompany insAreaCompany) { //获取协议信息 PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId()); InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno()); SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid()); BigDecimal taxRadio = new BigDecimal("1.00"); //如果是外部订单则 不含税 if (ptlAgreement.getWithTax().equals("否") && ptlAgreement.getIsExternal() == 0) { taxRadio = new BigDecimal("1.06"); } //税比例 固定1.06 //查找入口与出口费用比例 //入口配置 PtlAgreementProductCostsNew ptlAgreementProductCostsNew = ptlAgreementProductCostsNewService.getById(costsId); ptlAgreementProductCostsNew.blank(); //出口配置 PtlAgreementProductCostsExport ptlAgreementProductCostsExport = ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper().eq(PtlAgreementProductCostsExport::getCostsId, costsId)); InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew(); insFeeOrderNew.setId(IdGenerate.nextId()); insFeeOrderNew.setCostsId(costsId); insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId()); //存储部门id与用户id InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno()); InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId()); if (insFeeOrderNewByCompanyId != null) { insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId()); } insFeeOrderNew.setDeptId(order.getDeptid()); insFeeOrderNew.setUserId(order.getUserid()); insFeeOrderNew.setInsOrderNo(insAreaCompany.getId()); insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium()); insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium()); insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium()); //不含税 BigDecimal bigDecimal = new BigDecimal("1.06"); insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2)); insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2)); insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2)); //region 计算入口费用 //交强入口信息 FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee( insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()), new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()), taxRadio); insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion()); insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts()); insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums()); insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion()); insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums()); insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums())); //商业入口信息 FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()) , new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio); insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion()); insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts()); insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums()); insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion()); insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums()); insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums())); //非车入口信息 FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()), new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio); insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion()); insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts()); insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums()); insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion()); insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums()); insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums())); //endregion //region 重新计算管理费比例和分销比例 List esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ", new Object[]{sysUser.getDeptId()}); Integer retailLevel = 0; //默认分销比例设置 RetailProportion retailProportion = new RetailProportion(); if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) { retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype()); //赋值默认的分销比例 retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3()); } //获取交强机构管理费总比例 BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1() .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()) .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()) .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()) .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5()); //获取商业机构管理费总比例 BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1() .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()) .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()) .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()) .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5()); //获取非车机构管理费总比例 BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1() .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()) .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()) .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()) .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5()); //获取交强分销总比例 BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion() .add(retailProportion.getJqRetailLevel2Proportion()) .add(retailProportion.getJqRetailLevel3Proportion()); //获取商业分销总比例 BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion() .add(retailProportion.getSyRetailLevel2Proportion()) .add(retailProportion.getSyRetailLevel3Proportion()); //获取非车分销总比例 BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion() .add(retailProportion.getNoRetailLevel2Proportion()) .add(retailProportion.getNoRetailLevel3Proportion()); // 外部订单比例 BigDecimal enterProportion = sysSwitchConfigService.getEnterProportion(insOrders.getDeptid(), insOrders.getEntryStatus()); //重新计算比例 入口是否超出支付的比例 ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion( new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()), jqDeptProportion, jqRetailProportion, taxRadio, retailLevel, ptlAgreementProductCostsExport, retailProportion, "jq", enterProportion ); ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion( new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()), syDeptProportion, syRetailProportion, taxRadio, retailLevel, ptlAgreementProductCostsExport, retailProportion, "sy", enterProportion ); ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion( new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()), noDeptProportion, noRetailProportion, taxRadio, retailLevel, ptlAgreementProductCostsExport, retailProportion, "no", enterProportion ); retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion); // ptlAgreementProductCostsExportService.updateById(ptlAgreementProductCostsExport); //endregion //region 计算分销费用 //获取分销比例 //分销总比例 BigDecimal jqRetailRadio = new BigDecimal("0"); BigDecimal syRetailRadio = new BigDecimal("0"); BigDecimal noRetailRadio = new BigDecimal("0"); FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee(); FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee(); FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee(); if (esmRetailList != null && !esmRetailList.isEmpty()) { EsmRetail esmRetail = esmRetailList.get(0); //分销等级 insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype()); //用户分销人员id List parents = esmUserReferrerService.findParents(sysUser.getId()); if (esmRetail != null) { if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) { insFeeOrderNew.setThirdDetailProportion(retailProportion.getJqRetailLevel3Proportion()); retailFeeLevel3 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getJqCostsProportion(), insFeeOrderNew.getSyPremium(), insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()), insFeeOrderNew.getNoPremium(), insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()), retailProportion.getJqRetailLevel3Proportion(), retailProportion.getSyRetailLevel3Proportion(), retailProportion.getNoRetailLevel3Proportion()); insFeeOrderNew.setThirdDetailPremiums(retailFeeLevel3.getTotalRetailPremiums()); if (parents != null && parents.size() > 2) { insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId()); } } else { insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0)); } if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) { insFeeOrderNew.setSecondDetailProportion(retailProportion.getJqRetailLevel2Proportion()); retailFeeLevel2 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getJqCostsProportion(), insFeeOrderNew.getSyPremium(), insFeeOrderNew.getSyCostsProportion(), insFeeOrderNew.getNoPremium(), insFeeOrderNew.getNoCostsProportion(), retailProportion.getJqRetailLevel2Proportion(), retailProportion.getSyRetailLevel2Proportion(), retailProportion.getNoRetailLevel2Proportion()); insFeeOrderNew.setSecondDetailPremiums(retailFeeLevel2.getTotalRetailPremiums()); if (parents != null && parents.size() > 1) { insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId()); } } else { insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0)); } if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) { insFeeOrderNew.setFirstDetailProportion(retailProportion.getJqRetailLevel1Proportion()); retailFeeLevel1 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getJqCostsProportion(), insFeeOrderNew.getSyPremium(), insFeeOrderNew.getSyCostsProportion(), insFeeOrderNew.getNoPremium(), insFeeOrderNew.getNoCostsProportion(), retailProportion.getJqRetailLevel1Proportion(), retailProportion.getSyRetailLevel1Proportion(), retailProportion.getNoRetailLevel1Proportion()); insFeeOrderNew.setFirstDetailPremiums(retailFeeLevel1.getTotalRetailPremiums()); if (parents != null && !parents.isEmpty()) { insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId()); } } else { insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0)); } } else { insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0)); insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0)); insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0)); } } else { insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0)); insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0)); insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0)); } jqRetailRadio = jqRetailRadio.add(retailFeeLevel1.getJqRetailProportion()) .add(retailFeeLevel2.getJqRetailProportion()) .add(retailFeeLevel3.getJqRetailProportion()); syRetailRadio = syRetailRadio.add(retailFeeLevel1.getSyRetailProportion()) .add(retailFeeLevel2.getSyRetailProportion()) .add(retailFeeLevel3.getSyRetailProportion()); noRetailRadio = noRetailRadio.add(retailFeeLevel1.getNoRetailProportion()) .add(retailFeeLevel2.getNoRetailProportion()) .add(retailFeeLevel3.getNoRetailProportion()); insFeeOrderNew.assignRetail(retailFeeLevel1, retailFeeLevel2, retailFeeLevel3); //endregion //region 设置机构管理费 //交强机构管理费 BigDecimal jqDeptRadio = jqReCalcuLateProportion.getDept_level_1_proportion() .add(jqReCalcuLateProportion.getDept_level_2_proportion()) .add(jqReCalcuLateProportion.getDept_level_3_proportion()) .add(jqReCalcuLateProportion.getDept_level_4_proportion()) .add(jqReCalcuLateProportion.getDept_level_5_proportion()); FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee( insFeeOrderNew.getJqPremium(), jqReCalcuLateProportion.getDept_level_1_proportion(), jqReCalcuLateProportion.getDept_level_2_proportion(), jqReCalcuLateProportion.getDept_level_3_proportion(), jqReCalcuLateProportion.getDept_level_4_proportion(), jqReCalcuLateProportion.getDept_level_5_proportion()); BigDecimal syDeptRadio = syReCalcuLateProportion.getDept_level_1_proportion() .add(syReCalcuLateProportion.getDept_level_2_proportion()) .add(syReCalcuLateProportion.getDept_level_3_proportion()) .add(syReCalcuLateProportion.getDept_level_4_proportion()) .add(syReCalcuLateProportion.getDept_level_5_proportion()); FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee( insFeeOrderNew.getSyPremium(), syReCalcuLateProportion.getDept_level_1_proportion(), syReCalcuLateProportion.getDept_level_2_proportion(), syReCalcuLateProportion.getDept_level_3_proportion(), syReCalcuLateProportion.getDept_level_4_proportion(), syReCalcuLateProportion.getDept_level_5_proportion()); BigDecimal noDeptRadio = noReCalcuLateProportion.getDept_level_1_proportion() .add(noReCalcuLateProportion.getDept_level_2_proportion()) .add(noReCalcuLateProportion.getDept_level_3_proportion()) .add(noReCalcuLateProportion.getDept_level_4_proportion()) .add(noReCalcuLateProportion.getDept_level_5_proportion()); FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee( insFeeOrderNew.getNoPremium(), noReCalcuLateProportion.getDept_level_1_proportion(), noReCalcuLateProportion.getDept_level_2_proportion(), noReCalcuLateProportion.getDept_level_3_proportion(), noReCalcuLateProportion.getDept_level_4_proportion(), noReCalcuLateProportion.getDept_level_5_proportion()); insFeeOrderNew.assignDept(jqDeptManagerFee, syDeptManagerFee, noDeptManagerFee); //endregion //region 出口费用 //交强出口手续费比例 FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee( insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()), insFeeOrderNew.getJqCostsProportion(), jqDeptRadio, jqRetailRadio, taxRadio, jqReCalcuLateProportion.getProxyProportion() ); //商业出口手续费比例 FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee( insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()), insFeeOrderNew.getSyCostsProportion(), syDeptRadio, syRetailRadio, taxRadio, syReCalcuLateProportion.getProxyProportion() ); //非车出口手续费比例 FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee( insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()), insFeeOrderNew.getNoCostsProportion(), noDeptRadio, noRetailRadio, taxRadio, noReCalcuLateProportion.getProxyProportion() ); //出口手续费用 insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums())); insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums())); insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums())); //出口其他费用比例 insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion())); insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion())); insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion())); //出口其他费用 insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums())); insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums())); insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums())); //设置出口手续费比例 insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts())); insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts())); insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts())); // 外部费用 insFeeOrderNew.setJqExternalProportion(jqExportFee.getExternalProportion()); insFeeOrderNew.setJqExternalPremiums(jqExportFee.getExternalPremiums()); insFeeOrderNew.setSyExternalProportion(syExportFee.getExternalProportion()); insFeeOrderNew.setSyExternalPremiums(syExportFee.getExternalPremiums()); insFeeOrderNew.setNoExternalProportion(noExportFee.getExternalProportion()); insFeeOrderNew.setNoExternalPremiums(noExportFee.getExternalPremiums()); //endregion //region 计算利润差值 //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值 //分销交强费用 //分开算 1 2 3 级 BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird); //分销商业费用 BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird); //分销非车费用 BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird); BigDecimal jqDifference = jqEntranceFee.getTotalAmount() .subtract(jqExportFee.getExternalPremiums()) .subtract( (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums()))) .subtract( (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive()))) ) .subtract(jqFenXiao) .setScale(5, BigDecimal.ROUND_HALF_DOWN); insFeeOrderNew.setJqProfitMarginPremiums(jqDifference); BigDecimal syDifference = syEntranceFee.getTotalAmount() .subtract(syExportFee.getExternalPremiums()) .subtract( (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums()))) .subtract( (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive()))) ) .subtract(syFenXiao) .setScale(5, BigDecimal.ROUND_HALF_DOWN); insFeeOrderNew.setSyProfitMarginPremiums(syDifference); BigDecimal noDifference = noEntranceFee.getTotalAmount() .subtract(noExportFee.getExternalPremiums()) .subtract( (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums()))) .subtract( (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive()))) ) .subtract(noFenXiao) .setScale(5, BigDecimal.ROUND_HALF_DOWN); insFeeOrderNew.setNoProfitMarginPremiums(noDifference); //endregion //region 比例逆推是否等于0 if (!feeRuleSchemeService.calculateProportion(jqEntranceFee, jqDeptManagerFee, jqExportFee, jqRetailRadio, taxRadio, insFeeOrderNew.getJqPremium())) throw new SystemException("交强比例异常"); if (!feeRuleSchemeService.calculateProportion(syEntranceFee, syDeptManagerFee, syExportFee, syRetailRadio, taxRadio, insFeeOrderNew.getSyPremium())) throw new SystemException("商业比例异常"); if (!feeRuleSchemeService.calculateProportion(noEntranceFee, noDeptManagerFee, noExportFee, noRetailRadio, taxRadio, insFeeOrderNew.getNoPremium())) throw new SystemException("非车比例异常"); //endregion sysChannelGroupService.costCompute(insFeeOrderNew,ptlAgreement,ptlAgreementProductCostsNew,sysUser,insAreaCompany,insOrders); insFeeOrderNewService.saveOrUpdate(insFeeOrderNew); } /** * 计算费用测试方法 没有数据库保存操作 只带入值进行计算核对 * * @param costsId * @param insAreaCompany */ @Override public void calcCostsTest(String costsId, InsAreaCompany insAreaCompany) { // //获取协议信息 // PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId()); // BigDecimal taxRadio = new BigDecimal("1.00"); // //如果是外部订单则 不含税 // if (ptlAgreement.getWithTax().equals("否") && ptlAgreement.getIsExternal() == 0) { // taxRadio = new BigDecimal("1.06"); // } // //税比例 固定1.06 // //查找入口与出口费用比例 // //入口配置 // PtlAgreementProductCostsNew ptlAgreementProductCostsNew = ptlAgreementProductCostsNewService.getById(costsId); // // //出口配置 // PtlAgreementProductCostsExport ptlAgreementProductCostsExport = // ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper().eq(PtlAgreementProductCostsExport::getCostsId, costsId)); // InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew(); // insFeeOrderNew.setId(IdGenerate.nextId()); // insFeeOrderNew.setCostsId(costsId); // insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId()); // // //存储部门id与用户id // InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno()); // InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId()); // if (insFeeOrderNewByCompanyId != null) { // insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId()); // } // insFeeOrderNew.setDeptId(order.getDeptid()); // insFeeOrderNew.setUserId(order.getUserid()); // insFeeOrderNew.setInsOrderNo(insAreaCompany.getId()); // insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium()); // insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium()); // insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium()); // //不含税 // BigDecimal bigDecimal = new BigDecimal("1.06"); // insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2)); // insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2)); // insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2)); // // //region 计算入口费用 // // //交强入口信息 // FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getJqPremium(), // new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()), // new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()), taxRadio); // insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion()); // insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts()); // insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums()); // insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion()); // insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums()); // insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums())); // // //商业入口信息 // FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(), // new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()), // new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio); // insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion()); // insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts()); // insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums()); // insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion()); // insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums()); // insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums())); // // //非车入口信息 // FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(), // new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()), // new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio); // insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion()); // insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts()); // insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums()); // insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion()); // insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums()); // insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums())); // //endregion // // //region 计算分销费用 // InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno()); // SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid()); // // //获取分销比例 // List esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ", // new Object[]{sysUser.getDeptId()}); // // //分销总比例 // BigDecimal retailRadio = new BigDecimal("0"); // if (esmRetailList != null && !esmRetailList.isEmpty()) { // EsmRetail esmRetail = esmRetailList.get(0); // //分销等级 // insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype()); // //用户分销人员id // List parents = esmUserReferrerService.findParents(sysUser.getId()); // // if (esmRetail != null) { // BigDecimal sumPremium = insFeeOrderNew.getJqPremium().add(insFeeOrderNew.getSyPremium()).add(insFeeOrderNew.getNoPremium()); // if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) { // insFeeOrderNew.setThirdDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate3()))); // retailRadio = retailRadio.add(insFeeOrderNew.getThirdDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN); // BigDecimal thirdDetailPremiums = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(), // insFeeOrderNew.getJqCostsProportion().add(insFeeOrderNew.getJqOtherCostsProportion()), // insFeeOrderNew.getSyPremium(), // insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()), // insFeeOrderNew.getNoPremium(), // insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()), // insFeeOrderNew.getThirdDetailProportion()); // insFeeOrderNew.setThirdDetailPremiums(thirdDetailPremiums); // if (parents != null && parents.size() > 2) { // insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId()); // } // }else{ // insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0)); // } // if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) { // insFeeOrderNew.setSecondDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate2()))); // retailRadio = retailRadio.add(insFeeOrderNew.getSecondDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN); // BigDecimal secondDetailPremiums = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(), // insFeeOrderNew.getJqCostsProportion().add(insFeeOrderNew.getJqOtherCostsProportion()), // insFeeOrderNew.getSyPremium(), // insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()), // insFeeOrderNew.getNoPremium(), // insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()), // insFeeOrderNew.getSecondDetailProportion()); // insFeeOrderNew.setSecondDetailPremiums(secondDetailPremiums); // if (parents != null && parents.size() > 1) { // insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId()); // } // }else{ // insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0)); // } // if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) { // insFeeOrderNew.setFirstDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate1()))); // retailRadio = retailRadio.add(insFeeOrderNew.getFirstDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN); // BigDecimal firstDetailPremiums = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(), // insFeeOrderNew.getJqCostsProportion().add(insFeeOrderNew.getJqOtherCostsProportion()), // insFeeOrderNew.getSyPremium(), // insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()), // insFeeOrderNew.getNoPremium(), // insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()), // insFeeOrderNew.getFirstDetailProportion()); // insFeeOrderNew.setFirstDetailPremiums(firstDetailPremiums); // if (parents != null && parents.size() > 0) { // insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId()); // } // }else{ // insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0)); // } // }else{ // insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0)); // insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0)); // insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0)); // } // }else{ // insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0)); // insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0)); // insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0)); // } // // // //endregion // // //region 设置机构管理费 // // //交强机构管理费 // BigDecimal jqDeptRadio = // ptlAgreementProductCostsExport.getJqExportRadioLevel1().add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel5()); // FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getJqPremium(), // ptlAgreementProductCostsExport.getJqExportRadioLevel1(), ptlAgreementProductCostsExport.getJqExportRadioLevel2(), // ptlAgreementProductCostsExport.getJqExportRadioLevel3(), ptlAgreementProductCostsExport.getJqExportRadioLevel4(), // ptlAgreementProductCostsExport.getJqExportRadioLevel5()); // insFeeOrderNew.setJqDeptProportionLevel1(jqDeptManagerFee.getDeptProportionLevelOne()); // insFeeOrderNew.setJqDeptPremiumsLevel1(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelOne())); // insFeeOrderNew.setJqDeptProportionLevel2(jqDeptManagerFee.getDeptProportionLevelTwo()); // insFeeOrderNew.setJqDeptPremiumsLevel2(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelTwo())); // insFeeOrderNew.setJqDeptProportionLevel3(jqDeptManagerFee.getDeptProportionLevelThree()); // insFeeOrderNew.setJqDeptPremiumsLevel3(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelThree())); // insFeeOrderNew.setJqDeptProportionLevel4(jqDeptManagerFee.getDeptProportionLevelFoure()); // insFeeOrderNew.setJqDeptPremiumsLevel4(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFoure())); // insFeeOrderNew.setJqDeptProportionLevel5(jqDeptManagerFee.getDeptProportionLevelFive()); // insFeeOrderNew.setJqDeptPremiumsLevel5(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFive())); // // BigDecimal syDeptRadio = // ptlAgreementProductCostsExport.getSyExportRadioLevel1().add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel5()); // FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getSyPremium(), // ptlAgreementProductCostsExport.getSyExportRadioLevel1(), ptlAgreementProductCostsExport.getSyExportRadioLevel2(), // ptlAgreementProductCostsExport.getSyExportRadioLevel3(), ptlAgreementProductCostsExport.getSyExportRadioLevel4(), // ptlAgreementProductCostsExport.getSyExportRadioLevel5()); // insFeeOrderNew.setSyDeptProportionLevel1(syDeptManagerFee.getDeptProportionLevelOne()); // insFeeOrderNew.setSyDeptPremiumsLevel1(twoPeople(syDeptManagerFee.getDeptPremiumsLevelOne())); // insFeeOrderNew.setSyDeptProportionLevel2(syDeptManagerFee.getDeptProportionLevelTwo()); // insFeeOrderNew.setSyDeptPremiumsLevel2(twoPeople(syDeptManagerFee.getDeptPremiumsLevelTwo())); // insFeeOrderNew.setSyDeptProportionLevel3(syDeptManagerFee.getDeptProportionLevelThree()); // insFeeOrderNew.setSyDeptPremiumsLevel3(twoPeople(syDeptManagerFee.getDeptPremiumsLevelThree())); // insFeeOrderNew.setSyDeptProportionLevel4(syDeptManagerFee.getDeptProportionLevelFoure()); // insFeeOrderNew.setSyDeptPremiumsLevel4(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFoure())); // insFeeOrderNew.setSyDeptProportionLevel5(syDeptManagerFee.getDeptProportionLevelFive()); // insFeeOrderNew.setSyDeptPremiumsLevel5(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFive())); // // BigDecimal noDeptRadio = // ptlAgreementProductCostsExport.getNoCarExportRadioLevel1().add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5()); // FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getNoPremium(), // ptlAgreementProductCostsExport.getNoCarExportRadioLevel1(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel2(), // ptlAgreementProductCostsExport.getNoCarExportRadioLevel3(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel4(), // ptlAgreementProductCostsExport.getNoCarExportRadioLevel5()); // insFeeOrderNew.setNoDeptProportionLevel1(noDeptManagerFee.getDeptProportionLevelOne()); // insFeeOrderNew.setNoDeptPremiumsLevel1(twoPeople(noDeptManagerFee.getDeptPremiumsLevelOne())); // insFeeOrderNew.setNoDeptProportionLevel2(noDeptManagerFee.getDeptProportionLevelTwo()); // insFeeOrderNew.setNoDeptPremiumsLevel2(twoPeople(noDeptManagerFee.getDeptPremiumsLevelTwo())); // insFeeOrderNew.setNoDeptProportionLevel3(noDeptManagerFee.getDeptProportionLevelThree()); // insFeeOrderNew.setNoDeptPremiumsLevel3(twoPeople(noDeptManagerFee.getDeptPremiumsLevelThree())); // insFeeOrderNew.setNoDeptProportionLevel4(noDeptManagerFee.getDeptProportionLevelFoure()); // insFeeOrderNew.setNoDeptPremiumsLevel4(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFoure())); // insFeeOrderNew.setNoDeptProportionLevel5(noDeptManagerFee.getDeptProportionLevelFive()); // insFeeOrderNew.setNoDeptPremiumsLevel5(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFive())); // // //endregion // // //region 出口费用 // // //交强出口手续费比例 // FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()), // insFeeOrderNew.getJqCostsProportion(), jqDeptRadio, retailRadio, taxRadio); // // //商业出口手续费比例 // FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()), // insFeeOrderNew.getSyCostsProportion(), syDeptRadio, retailRadio, taxRadio); // // //非车出口手续费比例 // FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()), // insFeeOrderNew.getNoCostsProportion(), noDeptRadio, retailRadio, taxRadio); // // //出口手续费用 // insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums())); // insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums())); // insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums())); // // //出口其他费用比例 // insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion())); // insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion())); // insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion())); // // //出口其他费用 // insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums())); // insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums())); // insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums())); // // //设置出口手续费比例 // insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts())); // insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts())); // insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts())); // // //endregion // // //region 计算利润差值 // //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值 // // //分销交强费用 // //分开算 1 2 3 级 // BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN); // BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN); // BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN); // BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird); // //分销商业费用 // BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN); // BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN); // BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN); // BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird); // //分销非车费用 // BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN); // BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN); // BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN); // BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird); // // // BigDecimal jqDifference = jqEntranceFee.getTotalAmount().subtract( // (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums()))) // .subtract( // (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive()))) // ) // .subtract(jqFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN); // insFeeOrderNew.setJqProfitMarginPremiums(jqDifference); // // BigDecimal syDifference = syEntranceFee.getTotalAmount().subtract( // (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums()))) // .subtract( // (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive()))) // ) // .subtract(syFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN); // insFeeOrderNew.setSyProfitMarginPremiums(syDifference); // // // BigDecimal noDifference = noEntranceFee.getTotalAmount().subtract( // (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums()))) // .subtract( // (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive()))) // ) // .subtract(noFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN); // // insFeeOrderNew.setNoProfitMarginPremiums(noDifference); // // //endregion // // //region 比例逆推是否等于0 // // if(!feeRuleSchemeService.calculateProportion(jqEntranceFee,jqDeptManagerFee,jqExportFee,retailRadio,taxRadio,insFeeOrderNew.getJqPremium())) // throw new SystemException("交强比例异常"); // // if(!feeRuleSchemeService.calculateProportion(syEntranceFee,syDeptManagerFee,syExportFee,retailRadio,taxRadio,insFeeOrderNew.getSyPremium())) // throw new SystemException("商业比例异常"); // // if(!feeRuleSchemeService.calculateProportion(noEntranceFee,noDeptManagerFee,noExportFee,retailRadio,taxRadio,insFeeOrderNew.getNoPremium())) // throw new SystemException("非车比例异常"); //endregion // insFeeOrderNewService.saveOrUpdate(insFeeOrderNew); } @Override public void calcCostsExternal(PtlAgreementProductCostsNew ptlAgreementProductCostsNew, InsAreaCompany insAreaCompany) { //获取协议信息 // 外部订单比例 ptlAgreementProductCostsNew.blank(); PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId()); InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno()); SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid()); BigDecimal enterProportion = sysSwitchConfigService.getEnterProportion(insOrders.getDeptid(), insOrders.getEntryStatus()); BigDecimal taxRadio = new BigDecimal("1.00"); //如果是外部订单则 不含税 if (ptlAgreement.getWithTax().equals("否")) { taxRadio = new BigDecimal("1.06"); } //税比例 固定1.06 //查找入口与出口费用比例 //出口配置 PtlAgreementProductCostsExport ptlAgreementProductCostsExport = ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper().eq(PtlAgreementProductCostsExport::getCostsId, ptlAgreementProductCostsNew.getId())); InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew(); insFeeOrderNew.setId(IdGenerate.nextId()); insFeeOrderNew.setCostsId(ptlAgreementProductCostsNew.getId()); insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId()); //存储部门id与用户id InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno()); InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId()); if (insFeeOrderNewByCompanyId != null) { insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId()); } insFeeOrderNew.setDeptId(order.getDeptid()); insFeeOrderNew.setUserId(order.getUserid()); insFeeOrderNew.setInsOrderNo(insAreaCompany.getId()); insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium()); insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium()); insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium()); //不含税 BigDecimal bigDecimal = new BigDecimal("1.06"); insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2)); insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2)); insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2)); //region 计算入口费用 //交强入口信息 FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()), new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()), taxRadio); insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion()); insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts()); insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums()); insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion()); insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums()); insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums())); //商业入口信息 FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()), new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio); insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion()); insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts()); insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums()); insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion()); insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums()); insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums())); //非车入口信息 FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()), new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio); insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion()); insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts()); insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums()); insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion()); insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums()); insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums())); //endregion //region 重新计算管理费比例和分销比例 List esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ", new Object[]{sysUser.getDeptId()}); Integer retailLevel = 0; //默认分销比例设置 RetailProportion retailProportion = new RetailProportion(); if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) { retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype()); //赋值默认的分销比例 retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3()); } //获取交强机构管理费总比例 BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1() .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()) .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()) .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()) .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5()); //获取商业机构管理费总比例 BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1() .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()) .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()) .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()) .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5()); //获取非车机构管理费总比例 BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1() .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()) .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()) .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()) .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5()); //获取交强分销总比例 BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion() .add(retailProportion.getJqRetailLevel2Proportion()) .add(retailProportion.getJqRetailLevel3Proportion()); //获取商业分销总比例 BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion() .add(retailProportion.getSyRetailLevel2Proportion()) .add(retailProportion.getSyRetailLevel3Proportion()); //获取非车分销总比例 BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion() .add(retailProportion.getNoRetailLevel2Proportion()) .add(retailProportion.getNoRetailLevel3Proportion()); //重新计算比例 入口是否超出支付的比例 ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion( new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()), jqDeptProportion, jqRetailProportion, taxRadio, retailLevel, ptlAgreementProductCostsExport, retailProportion, "jq", enterProportion ); ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion( new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()), syDeptProportion, syRetailProportion, taxRadio, retailLevel, ptlAgreementProductCostsExport, retailProportion, "sy", enterProportion ); ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion( new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()), noDeptProportion, noRetailProportion, taxRadio, retailLevel, ptlAgreementProductCostsExport, retailProportion, "no", enterProportion ); retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion); // ptlAgreementProductCostsExportService.updateById(ptlAgreementProductCostsExport); //endregion //region 计算分销费用 //分销总比例 // BigDecimal jqRetailRadio = new BigDecimal("0"); // BigDecimal syRetailRadio = new BigDecimal("0"); // BigDecimal noRetailRadio = new BigDecimal("0"); FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee(); FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee(); FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee(); //分销总比例 BigDecimal retailRadio = new BigDecimal("0"); if (esmRetailList != null && !esmRetailList.isEmpty()) { EsmRetail esmRetail = esmRetailList.get(0); //分销等级 insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype()); //用户分销人员id List parents = esmUserReferrerService.findParents(sysUser.getId()); if (esmRetail != null) { BigDecimal sumPremium = insFeeOrderNew.getJqPremium().add(insFeeOrderNew.getSyPremium()).add(insFeeOrderNew.getNoPremium()); if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) { insFeeOrderNew.setThirdDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate3()))); retailRadio = retailRadio.add(insFeeOrderNew.getThirdDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN); retailFeeLevel3 = feeRuleSchemeService.calcRetail( insFeeOrderNew.getJqPremium(), insFeeOrderNew.getJqCostsProportion(), insFeeOrderNew.getSyPremium(), insFeeOrderNew.getSyCostsProportion(), insFeeOrderNew.getNoPremium(), insFeeOrderNew.getNoCostsProportion(), retailProportion.getJqRetailLevel3Proportion(), retailProportion.getSyRetailLevel3Proportion(), retailProportion.getNoRetailLevel3Proportion()); insFeeOrderNew.setThirdDetailPremiums(retailFeeLevel3.getTotalRetailPremiums()); if (parents != null && parents.size() > 2) { insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId()); } } else { insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0)); } if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) { insFeeOrderNew.setSecondDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate2()))); retailRadio = retailRadio.add(insFeeOrderNew.getSecondDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN); retailFeeLevel2 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getJqCostsProportion(), insFeeOrderNew.getSyPremium(), insFeeOrderNew.getSyCostsProportion(), insFeeOrderNew.getNoPremium(), insFeeOrderNew.getNoCostsProportion(), retailProportion.getJqRetailLevel2Proportion(), retailProportion.getSyRetailLevel2Proportion(), retailProportion.getNoRetailLevel2Proportion()); insFeeOrderNew.setSecondDetailPremiums(retailFeeLevel2.getTotalRetailPremiums()); if (parents != null && parents.size() > 1) { insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId()); } } else { insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0)); } if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) { insFeeOrderNew.setFirstDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate1()))); retailRadio = retailRadio.add(insFeeOrderNew.getFirstDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN); retailFeeLevel1 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getJqCostsProportion(), insFeeOrderNew.getSyPremium(), insFeeOrderNew.getSyCostsProportion(), insFeeOrderNew.getNoPremium(), insFeeOrderNew.getNoCostsProportion(), retailProportion.getJqRetailLevel1Proportion(), retailProportion.getSyRetailLevel1Proportion(), retailProportion.getNoRetailLevel1Proportion()); insFeeOrderNew.setFirstDetailPremiums(retailFeeLevel1.getTotalRetailPremiums()); if (parents != null && !parents.isEmpty()) { insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId()); } } else { insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0)); } } else { insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0)); insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0)); insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0)); } } else { insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0)); insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0)); insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0)); } insFeeOrderNew.assignRetail(retailFeeLevel1, retailFeeLevel2, retailFeeLevel3); //endregion //region 设置机构管理费 //交强机构管理费 BigDecimal jqDeptRadio = ptlAgreementProductCostsExport.getJqExportRadioLevel1().add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel5()); FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getJqPremium(), ptlAgreementProductCostsExport.getJqExportRadioLevel1(), ptlAgreementProductCostsExport.getJqExportRadioLevel2(), ptlAgreementProductCostsExport.getJqExportRadioLevel3(), ptlAgreementProductCostsExport.getJqExportRadioLevel4(), ptlAgreementProductCostsExport.getJqExportRadioLevel5()); insFeeOrderNew.setJqDeptProportionLevel1(jqDeptManagerFee.getDeptProportionLevelOne()); insFeeOrderNew.setJqDeptPremiumsLevel1(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelOne())); insFeeOrderNew.setJqDeptProportionLevel2(jqDeptManagerFee.getDeptProportionLevelTwo()); insFeeOrderNew.setJqDeptPremiumsLevel2(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelTwo())); insFeeOrderNew.setJqDeptProportionLevel3(jqDeptManagerFee.getDeptProportionLevelThree()); insFeeOrderNew.setJqDeptPremiumsLevel3(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelThree())); insFeeOrderNew.setJqDeptProportionLevel4(jqDeptManagerFee.getDeptProportionLevelFoure()); insFeeOrderNew.setJqDeptPremiumsLevel4(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFoure())); insFeeOrderNew.setJqDeptProportionLevel5(jqDeptManagerFee.getDeptProportionLevelFive()); insFeeOrderNew.setJqDeptPremiumsLevel5(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFive())); BigDecimal syDeptRadio = ptlAgreementProductCostsExport.getSyExportRadioLevel1().add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel5()); FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getSyPremium(), ptlAgreementProductCostsExport.getSyExportRadioLevel1(), ptlAgreementProductCostsExport.getSyExportRadioLevel2(), ptlAgreementProductCostsExport.getSyExportRadioLevel3(), ptlAgreementProductCostsExport.getSyExportRadioLevel4(), ptlAgreementProductCostsExport.getSyExportRadioLevel5()); insFeeOrderNew.setSyDeptProportionLevel1(syDeptManagerFee.getDeptProportionLevelOne()); insFeeOrderNew.setSyDeptPremiumsLevel1(twoPeople(syDeptManagerFee.getDeptPremiumsLevelOne())); insFeeOrderNew.setSyDeptProportionLevel2(syDeptManagerFee.getDeptProportionLevelTwo()); insFeeOrderNew.setSyDeptPremiumsLevel2(twoPeople(syDeptManagerFee.getDeptPremiumsLevelTwo())); insFeeOrderNew.setSyDeptProportionLevel3(syDeptManagerFee.getDeptProportionLevelThree()); insFeeOrderNew.setSyDeptPremiumsLevel3(twoPeople(syDeptManagerFee.getDeptPremiumsLevelThree())); insFeeOrderNew.setSyDeptProportionLevel4(syDeptManagerFee.getDeptProportionLevelFoure()); insFeeOrderNew.setSyDeptPremiumsLevel4(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFoure())); insFeeOrderNew.setSyDeptProportionLevel5(syDeptManagerFee.getDeptProportionLevelFive()); insFeeOrderNew.setSyDeptPremiumsLevel5(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFive())); BigDecimal noDeptRadio = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1().add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5()); FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getNoPremium(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel1(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel2(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel3(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel4(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel5()); insFeeOrderNew.setNoDeptProportionLevel1(noDeptManagerFee.getDeptProportionLevelOne()); insFeeOrderNew.setNoDeptPremiumsLevel1(twoPeople(noDeptManagerFee.getDeptPremiumsLevelOne())); insFeeOrderNew.setNoDeptProportionLevel2(noDeptManagerFee.getDeptProportionLevelTwo()); insFeeOrderNew.setNoDeptPremiumsLevel2(twoPeople(noDeptManagerFee.getDeptPremiumsLevelTwo())); insFeeOrderNew.setNoDeptProportionLevel3(noDeptManagerFee.getDeptProportionLevelThree()); insFeeOrderNew.setNoDeptPremiumsLevel3(twoPeople(noDeptManagerFee.getDeptPremiumsLevelThree())); insFeeOrderNew.setNoDeptProportionLevel4(noDeptManagerFee.getDeptProportionLevelFoure()); insFeeOrderNew.setNoDeptPremiumsLevel4(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFoure())); insFeeOrderNew.setNoDeptProportionLevel5(noDeptManagerFee.getDeptProportionLevelFive()); insFeeOrderNew.setNoDeptPremiumsLevel5(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFive())); //endregion //region 出口费用 //交强出口手续费比例 FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()), insFeeOrderNew.getJqCostsProportion(), jqDeptRadio, retailRadio, taxRadio, jqReCalcuLateProportion.getProxyProportion()); //商业出口手续费比例 FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()), insFeeOrderNew.getSyCostsProportion(), syDeptRadio, retailRadio, taxRadio, syReCalcuLateProportion.getProxyProportion()); //非车出口手续费比例 FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()), insFeeOrderNew.getNoCostsProportion(), noDeptRadio, retailRadio, taxRadio, noReCalcuLateProportion.getProxyProportion()); //出口手续费用 insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums())); insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums())); insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums())); //出口其他费用比例 insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion())); insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion())); insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion())); //出口其他费用 insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums())); insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums())); insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums())); //设置出口手续费比例 insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts())); insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts())); insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts())); // 外部订单费用 insFeeOrderNew.setJqExternalProportion(jqExportFee.getExternalProportion()); insFeeOrderNew.setJqExternalPremiums(jqExportFee.getExternalPremiums()); insFeeOrderNew.setSyExternalProportion(syExportFee.getExternalProportion()); insFeeOrderNew.setSyExternalPremiums(syExportFee.getExternalPremiums()); insFeeOrderNew.setNoExternalProportion(noExportFee.getExternalProportion()); insFeeOrderNew.setNoExternalPremiums(noExportFee.getExternalPremiums()); //endregion //region 计算利润差值 //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值 //分销交强费用 //分开算 1 2 3 级 BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird); //分销商业费用 BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird); //分销非车费用 BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird); BigDecimal jqDifference = jqEntranceFee.getTotalAmount() .subtract(jqExportFee.getExternalPremiums()) .subtract( (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums()))) .subtract( (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive()))) ) .subtract(jqFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN); insFeeOrderNew.setJqProfitMarginPremiums(jqDifference); BigDecimal syDifference = syEntranceFee.getTotalAmount() .subtract(syExportFee.getExternalPremiums()) .subtract( (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums()))) .subtract( (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive()))) ) .subtract(syFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN); insFeeOrderNew.setSyProfitMarginPremiums(syDifference); BigDecimal noDifference = noEntranceFee.getTotalAmount() .subtract(noExportFee.getExternalPremiums()) .subtract( (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums()))) .subtract( (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive()))) ) .subtract(noFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN); insFeeOrderNew.setNoProfitMarginPremiums(noDifference); //endregion //region 比例逆推是否等于0 if (!feeRuleSchemeService.calculateProportion(jqEntranceFee, jqDeptManagerFee, jqExportFee, retailRadio, taxRadio, insFeeOrderNew.getJqPremium())) throw new SystemException("交强比例异常"); if (!feeRuleSchemeService.calculateProportion(syEntranceFee, syDeptManagerFee, syExportFee, retailRadio, taxRadio, insFeeOrderNew.getSyPremium())) throw new SystemException("商业比例异常"); if (!feeRuleSchemeService.calculateProportion(noEntranceFee, noDeptManagerFee, noExportFee, retailRadio, taxRadio, insFeeOrderNew.getNoPremium())) throw new SystemException("非车比例异常"); //endregion insFeeOrderNewService.saveOrUpdate(insFeeOrderNew); } @Override public ExternalOrderFeeVo calcCostsExternalExportData(PtlAgreement ptlAgreement, PtlAgreementProductCostsNew ptlAgreementProductCostsNew, ExternalOrderFeeVo externalOrderFeeVo) { //获取协议信息 // 外部订单比例 ptlAgreementProductCostsNew.blank(); SysUser sysUser = sysUserService.findByUserId(externalOrderFeeVo.getUserId()); BigDecimal enterProportion = sysSwitchConfigService.getEnterProportion(sysUser.getDeptId(), 3); BigDecimal taxRadio = new BigDecimal("1.00"); //如果是外部订单则 不含税 if (ptlAgreement.getWithTax().equals("否")) { taxRadio = new BigDecimal("1.06"); } //税比例 固定1.06 //查找入口与出口费用比例 //出口配置 PtlAgreementProductCostsExport ptlAgreementProductCostsExport = ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper() .eq(PtlAgreementProductCostsExport::getCostsId, ptlAgreementProductCostsNew.getId())); //不含税 BigDecimal bigDecimal = new BigDecimal("1.06"); externalOrderFeeVo.setJqNoTaxPremium(externalOrderFeeVo.getJqPremium().divide(bigDecimal, 2)); externalOrderFeeVo.setSyNoTaxPremium(externalOrderFeeVo.getSyPremium().divide(bigDecimal, 2)); externalOrderFeeVo.setNoNoTaxPremium(externalOrderFeeVo.getNoPremium().divide(bigDecimal, 2)); //region 计算入口费用 //交强入口信息 FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(externalOrderFeeVo.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()), externalOrderFeeVo.getJqRadio(), taxRadio); //endregion //region 重新计算管理费比例和分销比例 List esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ", new Object[]{sysUser.getDeptId()}); Integer retailLevel = 0; //默认分销比例设置 RetailProportion retailProportion = new RetailProportion(); if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) { retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype()); //赋值默认的分销比例 retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3()); } //获取交强机构管理费总比例 BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1() .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()) .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()) .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()) .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5()); //获取商业机构管理费总比例 BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1() .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()) .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()) .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()) .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5()); //获取非车机构管理费总比例 BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1() .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()) .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()) .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()) .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5()); //获取交强分销总比例 BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion() .add(retailProportion.getJqRetailLevel2Proportion()) .add(retailProportion.getJqRetailLevel3Proportion()); //获取商业分销总比例 BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion() .add(retailProportion.getSyRetailLevel2Proportion()) .add(retailProportion.getSyRetailLevel3Proportion()); //获取非车分销总比例 BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion() .add(retailProportion.getNoRetailLevel2Proportion()) .add(retailProportion.getNoRetailLevel3Proportion()); //重新计算比例 入口是否超出支付的比例 ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion( new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()), jqDeptProportion, jqRetailProportion, taxRadio, retailLevel, ptlAgreementProductCostsExport, retailProportion, "jq", enterProportion ); ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion( new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()), syDeptProportion, syRetailProportion, taxRadio, retailLevel, ptlAgreementProductCostsExport, retailProportion, "sy", enterProportion ); ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion( new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()), noDeptProportion, noRetailProportion, taxRadio, retailLevel, ptlAgreementProductCostsExport, retailProportion, "no", enterProportion ); retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion); // ptlAgreementProductCostsExportService.updateById(ptlAgreementProductCostsExport); //endregion //region 计算分销费用 //分销总比例 BigDecimal jqRetailRadio = new BigDecimal("0"); BigDecimal syRetailRadio = new BigDecimal("0"); BigDecimal noRetailRadio = new BigDecimal("0"); FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee(); FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee(); FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee(); //分销总比例 BigDecimal retailRadio = new BigDecimal("0"); if (esmRetailList != null && !esmRetailList.isEmpty()) { EsmRetail esmRetail = esmRetailList.get(0); if (esmRetail != null) { BigDecimal sumPremium = externalOrderFeeVo.getJqPremium().add(externalOrderFeeVo.getSyPremium()).add(externalOrderFeeVo.getNoPremium()); if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) { retailRadio = retailRadio.add(new BigDecimal(String.valueOf(esmRetail.getDisrate3()))).setScale(2, BigDecimal.ROUND_DOWN); retailFeeLevel3 = feeRuleSchemeService.calcRetail( externalOrderFeeVo.getJqPremium(), externalOrderFeeVo.getJqRadio(), externalOrderFeeVo.getSyPremium(), externalOrderFeeVo.getSyRadio(), externalOrderFeeVo.getNoPremium(), externalOrderFeeVo.getNoRadio(), retailProportion.getJqRetailLevel3Proportion(), retailProportion.getSyRetailLevel3Proportion(), retailProportion.getNoRetailLevel3Proportion()); //三级分销费用 retailFeeLevel3.getTotalRetailPremiums() } else { //三级分销费用为 空值0 } if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) { retailRadio = retailRadio.add(new BigDecimal(String.valueOf(esmRetail.getDisrate2()))).setScale(2, BigDecimal.ROUND_DOWN); retailFeeLevel2 = feeRuleSchemeService.calcRetail( externalOrderFeeVo.getJqPremium(), externalOrderFeeVo.getJqRadio(), externalOrderFeeVo.getSyPremium(), externalOrderFeeVo.getSyRadio(), externalOrderFeeVo.getNoPremium(), externalOrderFeeVo.getNoRadio(), retailProportion.getJqRetailLevel2Proportion(), retailProportion.getSyRetailLevel2Proportion(), retailProportion.getNoRetailLevel2Proportion()); //二级分销费用 retailFeeLevel2.getTotalRetailPremiums() } else { // 空的 } if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) { retailRadio = retailRadio.add(new BigDecimal(String.valueOf(esmRetail.getDisrate1()))).setScale(2, BigDecimal.ROUND_DOWN); retailFeeLevel1 = feeRuleSchemeService.calcRetail( externalOrderFeeVo.getJqPremium(), externalOrderFeeVo.getJqRadio(), externalOrderFeeVo.getSyPremium(), externalOrderFeeVo.getSyRadio(), externalOrderFeeVo.getNoPremium(), externalOrderFeeVo.getNoRadio(), retailProportion.getJqRetailLevel1Proportion(), retailProportion.getSyRetailLevel1Proportion(), retailProportion.getNoRetailLevel1Proportion()); //一级 retailFeeLevel1.getTotalRetailPremiums() } else { // 空的 } } else { //null } } else { // null } //endregion //region 设置机构管理费 //交强机构管理费 BigDecimal jqDeptRadio = ptlAgreementProductCostsExport.getJqExportRadioLevel1().add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel5()); FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(externalOrderFeeVo.getJqPremium(), ptlAgreementProductCostsExport.getJqExportRadioLevel1(), ptlAgreementProductCostsExport.getJqExportRadioLevel2(), ptlAgreementProductCostsExport.getJqExportRadioLevel3(), ptlAgreementProductCostsExport.getJqExportRadioLevel4(), ptlAgreementProductCostsExport.getJqExportRadioLevel5()); BigDecimal syDeptRadio = ptlAgreementProductCostsExport.getSyExportRadioLevel1().add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel5()); FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(externalOrderFeeVo.getSyPremium(), ptlAgreementProductCostsExport.getSyExportRadioLevel1(), ptlAgreementProductCostsExport.getSyExportRadioLevel2(), ptlAgreementProductCostsExport.getSyExportRadioLevel3(), ptlAgreementProductCostsExport.getSyExportRadioLevel4(), ptlAgreementProductCostsExport.getSyExportRadioLevel5()); BigDecimal noDeptRadio = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1().add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5()); FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(externalOrderFeeVo.getNoPremium(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel1(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel2(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel3(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel4(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel5()); //endregion //region 出口费用 //交强出口手续费比例 FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee( externalOrderFeeVo.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()), externalOrderFeeVo.getJqRadio(), jqDeptRadio, retailRadio, taxRadio, jqReCalcuLateProportion.getProxyProportion()); //商业出口手续费比例 FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee( externalOrderFeeVo.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()), externalOrderFeeVo.getSyRadio(), syDeptRadio, retailRadio, taxRadio, syReCalcuLateProportion.getProxyProportion()); //非车出口手续费比例 FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee( externalOrderFeeVo.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()), externalOrderFeeVo.getNoRadio(), noDeptRadio, retailRadio, taxRadio, noReCalcuLateProportion.getProxyProportion()); externalOrderFeeVo.setJqExportPremium(jqExportFee.getTotalAmount()); externalOrderFeeVo.setJqExportRadio(jqExportFee.getTotalProportion()); externalOrderFeeVo.setSyExportPremium(syExportFee.getTotalAmount()); externalOrderFeeVo.setSyExportRadio(syExportFee.getTotalProportion()); externalOrderFeeVo.setNoExportPremium(noExportFee.getTotalAmount()); externalOrderFeeVo.setNoExportRadio(noExportFee.getTotalProportion()); //endregion return externalOrderFeeVo; } @Override public void calcCostsExternalTest(PtlAgreementProductCostsNew ptlAgreementProductCostsNew, InsAreaCompany insAreaCompany) { //获取协议信息 // 外部订单比例 PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId()); InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno()); SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid()); BigDecimal enterProportion = sysSwitchConfigService.getEnterProportion(insOrders.getDeptid(), insOrders.getEntryStatus()); BigDecimal taxRadio = new BigDecimal("1.00"); //如果是外部订单则 不含税 if (ptlAgreement.getWithTax().equals("否")) { taxRadio = new BigDecimal("1.06"); } //税比例 固定1.06 //查找入口与出口费用比例 //出口配置 PtlAgreementProductCostsExport ptlAgreementProductCostsExport = ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper().eq(PtlAgreementProductCostsExport::getCostsId, ptlAgreementProductCostsNew.getId())); InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew(); insFeeOrderNew.setId(IdGenerate.nextId()); insFeeOrderNew.setCostsId(ptlAgreementProductCostsNew.getId()); insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId()); //存储部门id与用户id InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno()); InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId()); if (insFeeOrderNewByCompanyId != null) { insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId()); } insFeeOrderNew.setDeptId(order.getDeptid()); insFeeOrderNew.setUserId(order.getUserid()); insFeeOrderNew.setInsOrderNo(insAreaCompany.getId()); insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium()); insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium()); insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium()); //不含税 BigDecimal bigDecimal = new BigDecimal("1.06"); insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2)); insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2)); insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2)); //region 计算入口费用 //交强入口信息 FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()), new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()), taxRadio); insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion()); insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts()); insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums()); insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion()); insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums()); insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums())); //商业入口信息 FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()), new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio); insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion()); insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts()); insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums()); insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion()); insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums()); insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums())); //非车入口信息 FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()), new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio); insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion()); insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts()); insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums()); insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion()); insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums()); insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums())); //endregion //region 重新计算管理费比例和分销比例 List esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ", new Object[]{sysUser.getDeptId()}); Integer retailLevel = 0; //默认分销比例设置 RetailProportion retailProportion = new RetailProportion(); if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) { retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype()); //赋值默认的分销比例 retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3()); } //获取交强机构管理费总比例 BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1() .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()) .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()) .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()) .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5()); //获取商业机构管理费总比例 BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1() .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()) .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()) .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()) .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5()); //获取非车机构管理费总比例 BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1() .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()) .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()) .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()) .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5()); //获取交强分销总比例 BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion() .add(retailProportion.getJqRetailLevel2Proportion()) .add(retailProportion.getJqRetailLevel3Proportion()); //获取商业分销总比例 BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion() .add(retailProportion.getSyRetailLevel2Proportion()) .add(retailProportion.getSyRetailLevel3Proportion()); //获取非车分销总比例 BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion() .add(retailProportion.getNoRetailLevel2Proportion()) .add(retailProportion.getNoRetailLevel3Proportion()); //重新计算比例 入口是否超出支付的比例 ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion( new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()), jqDeptProportion, jqRetailProportion, taxRadio, retailLevel, ptlAgreementProductCostsExport, retailProportion, "jq", enterProportion ); ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion( new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()), syDeptProportion, syRetailProportion, taxRadio, retailLevel, ptlAgreementProductCostsExport, retailProportion, "sy", enterProportion ); ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion( new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()), noDeptProportion, noRetailProportion, taxRadio, retailLevel, ptlAgreementProductCostsExport, retailProportion, "no", enterProportion ); retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion); // ptlAgreementProductCostsExportService.updateById(ptlAgreementProductCostsExport); //endregion //region 计算分销费用 //分销总比例 BigDecimal jqRetailRadio = new BigDecimal("0"); BigDecimal syRetailRadio = new BigDecimal("0"); BigDecimal noRetailRadio = new BigDecimal("0"); FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee(); FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee(); FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee(); //分销总比例 BigDecimal retailRadio = new BigDecimal("0"); if (esmRetailList != null && !esmRetailList.isEmpty()) { EsmRetail esmRetail = esmRetailList.get(0); //分销等级 insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype()); //用户分销人员id List parents = esmUserReferrerService.findParents(sysUser.getId()); if (esmRetail != null) { BigDecimal sumPremium = insFeeOrderNew.getJqPremium().add(insFeeOrderNew.getSyPremium()).add(insFeeOrderNew.getNoPremium()); if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) { insFeeOrderNew.setThirdDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate3()))); retailRadio = retailRadio.add(insFeeOrderNew.getThirdDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN); retailFeeLevel3 = feeRuleSchemeService.calcRetail( insFeeOrderNew.getJqPremium(), insFeeOrderNew.getJqCostsProportion(), insFeeOrderNew.getSyPremium(), insFeeOrderNew.getSyCostsProportion(), insFeeOrderNew.getNoPremium(), insFeeOrderNew.getNoCostsProportion(), retailProportion.getJqRetailLevel3Proportion(), retailProportion.getSyRetailLevel3Proportion(), retailProportion.getNoRetailLevel3Proportion()); insFeeOrderNew.setThirdDetailPremiums(retailFeeLevel3.getTotalRetailPremiums()); if (parents != null && parents.size() > 2) { insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId()); } } else { insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0)); } if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) { insFeeOrderNew.setSecondDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate2()))); retailRadio = retailRadio.add(insFeeOrderNew.getSecondDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN); retailFeeLevel2 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getJqCostsProportion(), insFeeOrderNew.getSyPremium(), insFeeOrderNew.getSyCostsProportion(), insFeeOrderNew.getNoPremium(), insFeeOrderNew.getNoCostsProportion(), retailProportion.getJqRetailLevel2Proportion(), retailProportion.getSyRetailLevel2Proportion(), retailProportion.getNoRetailLevel2Proportion()); insFeeOrderNew.setSecondDetailPremiums(retailFeeLevel2.getTotalRetailPremiums()); if (parents != null && parents.size() > 1) { insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId()); } } else { insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0)); } if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) { insFeeOrderNew.setFirstDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate1()))); retailRadio = retailRadio.add(insFeeOrderNew.getFirstDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN); retailFeeLevel1 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getJqCostsProportion(), insFeeOrderNew.getSyPremium(), insFeeOrderNew.getSyCostsProportion(), insFeeOrderNew.getNoPremium(), insFeeOrderNew.getNoCostsProportion(), retailProportion.getJqRetailLevel1Proportion(), retailProportion.getSyRetailLevel1Proportion(), retailProportion.getNoRetailLevel1Proportion()); insFeeOrderNew.setFirstDetailPremiums(retailFeeLevel1.getTotalRetailPremiums()); if (parents != null && !parents.isEmpty()) { insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId()); } } else { insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0)); } } else { insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0)); insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0)); insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0)); } } else { insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0)); insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0)); insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0)); } insFeeOrderNew.assignRetail(retailFeeLevel1, retailFeeLevel2, retailFeeLevel3); //endregion //region 设置机构管理费 //交强机构管理费 BigDecimal jqDeptRadio = ptlAgreementProductCostsExport.getJqExportRadioLevel1().add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel5()); FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getJqPremium(), ptlAgreementProductCostsExport.getJqExportRadioLevel1(), ptlAgreementProductCostsExport.getJqExportRadioLevel2(), ptlAgreementProductCostsExport.getJqExportRadioLevel3(), ptlAgreementProductCostsExport.getJqExportRadioLevel4(), ptlAgreementProductCostsExport.getJqExportRadioLevel5()); insFeeOrderNew.setJqDeptProportionLevel1(jqDeptManagerFee.getDeptProportionLevelOne()); insFeeOrderNew.setJqDeptPremiumsLevel1(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelOne())); insFeeOrderNew.setJqDeptProportionLevel2(jqDeptManagerFee.getDeptProportionLevelTwo()); insFeeOrderNew.setJqDeptPremiumsLevel2(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelTwo())); insFeeOrderNew.setJqDeptProportionLevel3(jqDeptManagerFee.getDeptProportionLevelThree()); insFeeOrderNew.setJqDeptPremiumsLevel3(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelThree())); insFeeOrderNew.setJqDeptProportionLevel4(jqDeptManagerFee.getDeptProportionLevelFoure()); insFeeOrderNew.setJqDeptPremiumsLevel4(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFoure())); insFeeOrderNew.setJqDeptProportionLevel5(jqDeptManagerFee.getDeptProportionLevelFive()); insFeeOrderNew.setJqDeptPremiumsLevel5(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFive())); BigDecimal syDeptRadio = ptlAgreementProductCostsExport.getSyExportRadioLevel1().add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel5()); FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getSyPremium(), ptlAgreementProductCostsExport.getSyExportRadioLevel1(), ptlAgreementProductCostsExport.getSyExportRadioLevel2(), ptlAgreementProductCostsExport.getSyExportRadioLevel3(), ptlAgreementProductCostsExport.getSyExportRadioLevel4(), ptlAgreementProductCostsExport.getSyExportRadioLevel5()); insFeeOrderNew.setSyDeptProportionLevel1(syDeptManagerFee.getDeptProportionLevelOne()); insFeeOrderNew.setSyDeptPremiumsLevel1(twoPeople(syDeptManagerFee.getDeptPremiumsLevelOne())); insFeeOrderNew.setSyDeptProportionLevel2(syDeptManagerFee.getDeptProportionLevelTwo()); insFeeOrderNew.setSyDeptPremiumsLevel2(twoPeople(syDeptManagerFee.getDeptPremiumsLevelTwo())); insFeeOrderNew.setSyDeptProportionLevel3(syDeptManagerFee.getDeptProportionLevelThree()); insFeeOrderNew.setSyDeptPremiumsLevel3(twoPeople(syDeptManagerFee.getDeptPremiumsLevelThree())); insFeeOrderNew.setSyDeptProportionLevel4(syDeptManagerFee.getDeptProportionLevelFoure()); insFeeOrderNew.setSyDeptPremiumsLevel4(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFoure())); insFeeOrderNew.setSyDeptProportionLevel5(syDeptManagerFee.getDeptProportionLevelFive()); insFeeOrderNew.setSyDeptPremiumsLevel5(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFive())); BigDecimal noDeptRadio = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1().add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5()); FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getNoPremium(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel1(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel2(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel3(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel4(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel5()); insFeeOrderNew.setNoDeptProportionLevel1(noDeptManagerFee.getDeptProportionLevelOne()); insFeeOrderNew.setNoDeptPremiumsLevel1(twoPeople(noDeptManagerFee.getDeptPremiumsLevelOne())); insFeeOrderNew.setNoDeptProportionLevel2(noDeptManagerFee.getDeptProportionLevelTwo()); insFeeOrderNew.setNoDeptPremiumsLevel2(twoPeople(noDeptManagerFee.getDeptPremiumsLevelTwo())); insFeeOrderNew.setNoDeptProportionLevel3(noDeptManagerFee.getDeptProportionLevelThree()); insFeeOrderNew.setNoDeptPremiumsLevel3(twoPeople(noDeptManagerFee.getDeptPremiumsLevelThree())); insFeeOrderNew.setNoDeptProportionLevel4(noDeptManagerFee.getDeptProportionLevelFoure()); insFeeOrderNew.setNoDeptPremiumsLevel4(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFoure())); insFeeOrderNew.setNoDeptProportionLevel5(noDeptManagerFee.getDeptProportionLevelFive()); insFeeOrderNew.setNoDeptPremiumsLevel5(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFive())); //endregion //region 出口费用 //交强出口手续费比例 FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()), insFeeOrderNew.getJqCostsProportion(), jqDeptRadio, retailRadio, taxRadio, jqReCalcuLateProportion.getProxyProportion()); //商业出口手续费比例 FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()), insFeeOrderNew.getSyCostsProportion(), syDeptRadio, retailRadio, taxRadio, syReCalcuLateProportion.getProxyProportion()); //非车出口手续费比例 FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()), insFeeOrderNew.getNoCostsProportion(), noDeptRadio, retailRadio, taxRadio, noReCalcuLateProportion.getProxyProportion()); //出口手续费用 insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums())); insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums())); insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums())); //出口其他费用比例 insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion())); insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion())); insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion())); //出口其他费用 insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums())); insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums())); insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums())); //设置出口手续费比例 insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts())); insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts())); insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts())); // 外部订单费用 insFeeOrderNew.setJqExternalProportion(jqExportFee.getExternalProportion()); insFeeOrderNew.setJqExternalPremiums(jqExportFee.getExternalPremiums()); insFeeOrderNew.setSyExternalProportion(syExportFee.getExternalProportion()); insFeeOrderNew.setSyExternalPremiums(syExportFee.getExternalPremiums()); insFeeOrderNew.setNoExternalProportion(noExportFee.getExternalProportion()); insFeeOrderNew.setNoExternalPremiums(noExportFee.getExternalPremiums()); //endregion //region 计算利润差值 //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值 //分销交强费用 //分开算 1 2 3 级 BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird); //分销商业费用 BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird); //分销非车费用 BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird); BigDecimal jqDifference = jqEntranceFee.getTotalAmount() .subtract(jqExportFee.getExternalPremiums()) .subtract( (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums()))) .subtract( (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive()))) ) .subtract(jqFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN); insFeeOrderNew.setJqProfitMarginPremiums(jqDifference); BigDecimal syDifference = syEntranceFee.getTotalAmount() .subtract(syExportFee.getExternalPremiums()) .subtract( (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums()))) .subtract( (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive()))) ) .subtract(syFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN); insFeeOrderNew.setSyProfitMarginPremiums(syDifference); BigDecimal noDifference = noEntranceFee.getTotalAmount() .subtract(noExportFee.getExternalPremiums()) .subtract( (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums()))) .subtract( (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive()))) ) .subtract(noFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN); insFeeOrderNew.setNoProfitMarginPremiums(noDifference); //endregion //region 比例逆推是否等于0 if (!feeRuleSchemeService.calculateProportion(jqEntranceFee, jqDeptManagerFee, jqExportFee, retailRadio, taxRadio, insFeeOrderNew.getJqPremium())) throw new SystemException("交强比例异常"); if (!feeRuleSchemeService.calculateProportion(syEntranceFee, syDeptManagerFee, syExportFee, retailRadio, taxRadio, insFeeOrderNew.getSyPremium())) throw new SystemException("商业比例异常"); if (!feeRuleSchemeService.calculateProportion(noEntranceFee, noDeptManagerFee, noExportFee, retailRadio, taxRadio, insFeeOrderNew.getNoPremium())) throw new SystemException("非车比例异常"); //endregion insFeeOrderNewService.saveOrUpdate(insFeeOrderNew); } @Override public void calcCostsExternalTelemarketing(PtlAgreementProductCostsExport ptlAgreementProductCostsExport, InsAreaCompany insAreaCompany) { //获取协议信息 PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId()); InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno()); SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid()); //入口配置 PtlAgreementProductCostsNew ptlAgreementProductCostsNew = ptlAgreementProductCostsNewService.getById(ptlAgreementProductCostsExport.getCostsId()); ptlAgreementProductCostsNew.blank(); BigDecimal taxRadio = new BigDecimal("1.00"); //如果是外部订单则 不含税 if (ptlAgreement.getWithTax().equals("否") && ptlAgreement.getIsExternal() == 0) { taxRadio = new BigDecimal("1.06"); } InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew(); insFeeOrderNew.setId(IdGenerate.nextId()); insFeeOrderNew.setCostsId(ptlAgreementProductCostsNew.getId()); insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId()); //存储部门id与用户id InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno()); InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId()); if (insFeeOrderNewByCompanyId != null) { insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId()); } insFeeOrderNew.setDeptId(order.getDeptid()); insFeeOrderNew.setUserId(order.getUserid()); insFeeOrderNew.setInsOrderNo(insAreaCompany.getId()); insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium()); insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium()); insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium()); //不含税 BigDecimal bigDecimal = new BigDecimal("1.06"); insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2)); insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2)); insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2)); //region 计算入口费用 //交强入口信息 FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee( insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()), new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()), taxRadio); insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion()); insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts()); insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums()); insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion()); insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums()); insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums())); //商业入口信息 FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()), new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio); insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion()); insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts()); insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums()); insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion()); insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums()); insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums())); //非车入口信息 FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()), new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio); insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion()); insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts()); insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums()); insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion()); insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums()); insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums())); //endregion //region 重新计算管理费比例和分销比例 List esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ", new Object[]{sysUser.getDeptId()}); Integer retailLevel = 0; //默认分销比例设置 RetailProportion retailProportion = new RetailProportion(); if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) { retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype()); //赋值默认的分销比例 retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3()); } //获取交强机构管理费总比例 BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1() .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()) .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()) .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()) .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5()); //获取商业机构管理费总比例 BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1() .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()) .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()) .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()) .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5()); //获取非车机构管理费总比例 BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1() .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()) .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()) .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()) .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5()); //获取交强分销总比例 BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion() .add(retailProportion.getJqRetailLevel2Proportion()) .add(retailProportion.getJqRetailLevel3Proportion()); //获取商业分销总比例 BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion() .add(retailProportion.getSyRetailLevel2Proportion()) .add(retailProportion.getSyRetailLevel3Proportion()); //获取非车分销总比例 BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion() .add(retailProportion.getNoRetailLevel2Proportion()) .add(retailProportion.getNoRetailLevel3Proportion()); // 外部订单比例 BigDecimal enterProportion = sysSwitchConfigService.getEnterProportion(insOrders.getDeptid(), insOrders.getEntryStatus()); //重新计算比例 入口是否超出支付的比例 ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion( new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()), jqDeptProportion, jqRetailProportion, taxRadio, retailLevel, ptlAgreementProductCostsExport, retailProportion, "jq", enterProportion ); ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion( new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()), syDeptProportion, syRetailProportion, taxRadio, retailLevel, ptlAgreementProductCostsExport, retailProportion, "sy", enterProportion ); ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion( new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()), noDeptProportion, noRetailProportion, taxRadio, retailLevel, ptlAgreementProductCostsExport, retailProportion, "no", enterProportion ); retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion); //endregion //region 计算分销费用 //获取分销比例 //分销总比例 BigDecimal jqRetailRadio = new BigDecimal("0"); BigDecimal syRetailRadio = new BigDecimal("0"); BigDecimal noRetailRadio = new BigDecimal("0"); FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee(); FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee(); FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee(); if (esmRetailList != null && !esmRetailList.isEmpty()) { EsmRetail esmRetail = esmRetailList.get(0); //分销等级 insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype()); //用户分销人员id List parents = esmUserReferrerService.findParents(sysUser.getId()); if (esmRetail != null) { if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) { insFeeOrderNew.setThirdDetailProportion(retailProportion.getJqRetailLevel3Proportion()); retailFeeLevel3 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getJqCostsProportion(), insFeeOrderNew.getSyPremium(), insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()), insFeeOrderNew.getNoPremium(), insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()), retailProportion.getJqRetailLevel3Proportion(), retailProportion.getSyRetailLevel3Proportion(), retailProportion.getNoRetailLevel3Proportion()); insFeeOrderNew.setThirdDetailPremiums(retailFeeLevel3.getTotalRetailPremiums()); if (parents != null && parents.size() > 2) { insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId()); } } else { insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0)); } if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) { insFeeOrderNew.setSecondDetailProportion(retailProportion.getJqRetailLevel2Proportion()); retailFeeLevel2 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getJqCostsProportion(), insFeeOrderNew.getSyPremium(), insFeeOrderNew.getSyCostsProportion(), insFeeOrderNew.getNoPremium(), insFeeOrderNew.getNoCostsProportion(), retailProportion.getJqRetailLevel2Proportion(), retailProportion.getSyRetailLevel2Proportion(), retailProportion.getNoRetailLevel2Proportion()); insFeeOrderNew.setSecondDetailPremiums(retailFeeLevel2.getTotalRetailPremiums()); if (parents != null && parents.size() > 1) { insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId()); } } else { insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0)); } if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) { insFeeOrderNew.setFirstDetailProportion(retailProportion.getJqRetailLevel1Proportion()); retailFeeLevel1 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getJqCostsProportion(), insFeeOrderNew.getSyPremium(), insFeeOrderNew.getSyCostsProportion(), insFeeOrderNew.getNoPremium(), insFeeOrderNew.getNoCostsProportion(), retailProportion.getJqRetailLevel1Proportion(), retailProportion.getSyRetailLevel1Proportion(), retailProportion.getNoRetailLevel1Proportion()); insFeeOrderNew.setFirstDetailPremiums(retailFeeLevel1.getTotalRetailPremiums()); if (parents != null && !parents.isEmpty()) { insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId()); } } else { insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0)); } } else { insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0)); insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0)); insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0)); } } else { insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0)); insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0)); insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0)); } jqRetailRadio = jqRetailRadio.add(retailFeeLevel1.getJqRetailProportion()) .add(retailFeeLevel2.getJqRetailProportion()) .add(retailFeeLevel3.getJqRetailProportion()); syRetailRadio = syRetailRadio.add(retailFeeLevel1.getSyRetailProportion()) .add(retailFeeLevel2.getSyRetailProportion()) .add(retailFeeLevel3.getSyRetailProportion()); noRetailRadio = noRetailRadio.add(retailFeeLevel1.getNoRetailProportion()) .add(retailFeeLevel2.getNoRetailProportion()) .add(retailFeeLevel3.getNoRetailProportion()); insFeeOrderNew.assignRetail(retailFeeLevel1, retailFeeLevel2, retailFeeLevel3); //endregion //region 设置机构管理费 //交强机构管理费 BigDecimal jqDeptRadio = jqReCalcuLateProportion.getDept_level_1_proportion() .add(jqReCalcuLateProportion.getDept_level_2_proportion()) .add(jqReCalcuLateProportion.getDept_level_3_proportion()) .add(jqReCalcuLateProportion.getDept_level_4_proportion()) .add(jqReCalcuLateProportion.getDept_level_5_proportion()); FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee( insFeeOrderNew.getJqPremium(), jqReCalcuLateProportion.getDept_level_1_proportion(), jqReCalcuLateProportion.getDept_level_2_proportion(), jqReCalcuLateProportion.getDept_level_3_proportion(), jqReCalcuLateProportion.getDept_level_4_proportion(), jqReCalcuLateProportion.getDept_level_5_proportion()); BigDecimal syDeptRadio = syReCalcuLateProportion.getDept_level_1_proportion() .add(syReCalcuLateProportion.getDept_level_2_proportion()) .add(syReCalcuLateProportion.getDept_level_3_proportion()) .add(syReCalcuLateProportion.getDept_level_4_proportion()) .add(syReCalcuLateProportion.getDept_level_5_proportion()); FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee( insFeeOrderNew.getSyPremium(), syReCalcuLateProportion.getDept_level_1_proportion(), syReCalcuLateProportion.getDept_level_2_proportion(), syReCalcuLateProportion.getDept_level_3_proportion(), syReCalcuLateProportion.getDept_level_4_proportion(), syReCalcuLateProportion.getDept_level_5_proportion()); BigDecimal noDeptRadio = noReCalcuLateProportion.getDept_level_1_proportion() .add(noReCalcuLateProportion.getDept_level_2_proportion()) .add(noReCalcuLateProportion.getDept_level_3_proportion()) .add(noReCalcuLateProportion.getDept_level_4_proportion()) .add(noReCalcuLateProportion.getDept_level_5_proportion()); FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee( insFeeOrderNew.getNoPremium(), noReCalcuLateProportion.getDept_level_1_proportion(), noReCalcuLateProportion.getDept_level_2_proportion(), noReCalcuLateProportion.getDept_level_3_proportion(), noReCalcuLateProportion.getDept_level_4_proportion(), noReCalcuLateProportion.getDept_level_5_proportion()); insFeeOrderNew.assignDept(jqDeptManagerFee, syDeptManagerFee, noDeptManagerFee); //endregion //region 出口费用 //交强出口手续费比例 FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee( insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()), insFeeOrderNew.getJqCostsProportion(), jqDeptRadio, jqRetailRadio, taxRadio, jqReCalcuLateProportion.getProxyProportion() ); //商业出口手续费比例 FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee( insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()), insFeeOrderNew.getSyCostsProportion(), syDeptRadio, syRetailRadio, taxRadio, syReCalcuLateProportion.getProxyProportion() ); //非车出口手续费比例 FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee( insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()), insFeeOrderNew.getNoCostsProportion(), noDeptRadio, noRetailRadio, taxRadio, noReCalcuLateProportion.getProxyProportion() ); //出口手续费用 insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums())); insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums())); insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums())); //出口其他费用比例 insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion())); insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion())); insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion())); //出口其他费用 insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums())); insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums())); insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums())); //设置出口手续费比例 insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts())); insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts())); insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts())); // 外部费用 insFeeOrderNew.setJqExternalProportion(jqExportFee.getExternalProportion()); insFeeOrderNew.setJqExternalPremiums(jqExportFee.getExternalPremiums()); insFeeOrderNew.setSyExternalProportion(syExportFee.getExternalProportion()); insFeeOrderNew.setSyExternalPremiums(syExportFee.getExternalPremiums()); insFeeOrderNew.setNoExternalProportion(noExportFee.getExternalProportion()); insFeeOrderNew.setNoExternalPremiums(noExportFee.getExternalPremiums()); //endregion //region 计算利润差值 //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值 //分销交强费用 //分开算 1 2 3 级 BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird); //分销商业费用 BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird); //分销非车费用 BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird); BigDecimal jqDifference = jqEntranceFee.getTotalAmount() .subtract(jqExportFee.getExternalPremiums()) .subtract( (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums()))) .subtract( (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive()))) ) .subtract(jqFenXiao) .setScale(5, BigDecimal.ROUND_HALF_DOWN); insFeeOrderNew.setJqProfitMarginPremiums(jqDifference); BigDecimal syDifference = syEntranceFee.getTotalAmount() .subtract(syExportFee.getExternalPremiums()) .subtract( (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums()))) .subtract( (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive()))) ) .subtract(syFenXiao) .setScale(5, BigDecimal.ROUND_HALF_DOWN); insFeeOrderNew.setSyProfitMarginPremiums(syDifference); BigDecimal noDifference = noEntranceFee.getTotalAmount() .subtract(noExportFee.getExternalPremiums()) .subtract( (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums()))) .subtract( (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive()))) ) .subtract(noFenXiao) .setScale(5, BigDecimal.ROUND_HALF_DOWN); insFeeOrderNew.setNoProfitMarginPremiums(noDifference); //endregion //region 比例逆推是否等于0 if (!feeRuleSchemeService.calculateProportion(jqEntranceFee, jqDeptManagerFee, jqExportFee, jqRetailRadio, taxRadio, insFeeOrderNew.getJqPremium())) throw new SystemException("交强比例异常"); if (!feeRuleSchemeService.calculateProportion(syEntranceFee, syDeptManagerFee, syExportFee, syRetailRadio, taxRadio, insFeeOrderNew.getSyPremium())) throw new SystemException("商业比例异常"); if (!feeRuleSchemeService.calculateProportion(noEntranceFee, noDeptManagerFee, noExportFee, noRetailRadio, taxRadio, insFeeOrderNew.getNoPremium())) throw new SystemException("非车比例异常"); //endregion insFeeOrderNewHistoryService.saveInsFeeOrderNewHistory(insFeeOrderNew); insFeeOrderNewService.saveOrUpdate(insFeeOrderNew); } /** * 判断是否包含非车险 * * @param insAreaCompany * @return */ private boolean isContainNonCar(InsAreaCompany insAreaCompany) { if (insAreaCompany.getCrossInsurance() != null && insAreaCompany.getJypremium().equals(BigDecimal.ZERO)) { return false; } return true; } /** * 匹配费用因子 * * @param agreementProductCosts * @param insAreaCompany * @param insOrders * @return */ private String verificationCosts(List agreementProductCosts, InsAreaCompany insAreaCompany, InsOrders insOrders, StringBuilder logs) { //匹配费用因子 //获取所有费用属性 List undwrtRulesAttrList = ptlAgreementUndwrtRulesAttrService.getUndwrtRulesAttrList(); //获取新旧车信息 PtlNewCarJudgeRules carJudgeRule = getCarJudgeRule(insAreaCompany.getCompanyId()); //获取所有费用属性关联 List ruleAttrMappingVoList = RuleAttrMappingVo.getRuleAttrMappingVoList(insAreaCompany, insOrders, undwrtRulesAttrList, carJudgeRule); for (int i = 0; i < agreementProductCosts.size(); i++) { //判断是否匹配 log.debug("费用因子匹配开始:" + agreementProductCosts.get(i).getId()); log.debug("车牌号:" + insOrders.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).getCostsAttrLinks(), undwrtRulesAttrList, ruleAttrMappingVoList, logs)) { //返回 费用id 如果需要匹配非车的情况 将返回值返回list 后赛选 return agreementProductCosts.get(i).getId(); } log.debug("当前费用因子匹配结束\n"); } return null; // throw new SystemException("费用因子匹配失败"); } private boolean verificationRules(List ptlAgreementUndwrtRulesNews, InsAreaCompany insAreaCompany, InsOrders insOrders) { StringBuilder logs = new StringBuilder(); //匹配承保规则 //获取所有承保规则属性 List undwrtRulesAttrList = ptlAgreementUndwrtRulesAttrService.getUndwrtRulesAttrList(); //获取所有费用属性关联 List ruleAttrMappingVoList = RuleAttrMappingVo.getRuleAttrMappingVoList(insAreaCompany, insOrders, undwrtRulesAttrList, getCarJudgeRule(insAreaCompany.getCompanyId())); for (int i = 0; i < ptlAgreementUndwrtRulesNews.size(); i++) { logs.append("触发承保规则:" + ptlAgreementUndwrtRulesNews.get(i).getRuleDescription() + "\n"); //判断是否匹配 if (!judgementsRules(ptlAgreementUndwrtRulesNews.get(i).getRulesAttrList(), undwrtRulesAttrList, ruleAttrMappingVoList, logs,insOrders)) { throw new SystemException(logs.toString()); }else{ //如果没有出现异常则清空匹配消息 logs.delete(0,logs.length()); } } return true; } /** * 费用因子的对比 * * @param ptlAgreementProductCostsAttrLinks 费用因子范围规则 * @param rulesAttrs 费用因子属性 * @param ruleAttrMappingVoList 表单提交的值 * @return */ private boolean judgements(List ptlAgreementProductCostsAttrLinks, List rulesAttrs, List ruleAttrMappingVoList, StringBuilder logs) { boolean useFlag = true; for (PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink : ptlAgreementProductCostsAttrLinks) { //查找规则中的 传值属性 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 collect = rulesAttrs.stream() .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode())) .collect(Collectors.toList()); if (!collect.isEmpty()) { logs.append("规则匹配失败:" + collect.get(0).getAttrName() + "\n"); } return false; } //查找 费用因子规则 PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr = rulesAttrs.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 collect = rulesAttrs.stream() .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode())) .collect(Collectors.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("规则匹配失败:" + collect.get(0).getAttrName() + "\n"); } return false; } } return useFlag; } /** * 承保规则因子的对比 * * @param ptlAgreementUndwrtRulesAttrLinks * @param rulesAttrs * @param ruleAttrMappingVoList * @return */ private boolean judgementsRules(List ptlAgreementUndwrtRulesAttrLinks, List rulesAttrs, List ruleAttrMappingVoList, StringBuilder logs,InsOrders insOrders) { boolean useFlag = true; for (int i = 0; i < ptlAgreementUndwrtRulesAttrLinks.size(); i++) { int finalI = i; //查找规则中的 传值属性 RuleAttrMappingVo ruleAttrMappingVo = ruleAttrMappingVoList.stream().filter(x -> x.getAttrCode().equals(ptlAgreementUndwrtRulesAttrLinks.get(finalI).getAttrCode())).findFirst().orElse(null); //如果查找不到 传值属性 直接费用对比失败 if (ruleAttrMappingVo == null) { return true; } //查找 费用因子规则 PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr = rulesAttrs.stream().filter(x -> x.getAttrCode().equals(ptlAgreementUndwrtRulesAttrLinks.get(finalI).getAttrCode())).findFirst().get(); //如果是多选 对value进行转换 if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("checkbox")) { PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal = ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x -> x.getName().equals(ruleAttrMappingVo.getValue())).findFirst().orElse(null); ruleAttrMappingVo.setValue(ptlAgreementUndwrtRulesDictLabal.getName()); } //如果是单选 并且是 性别的话 转换为code if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) { if ("CarOwnersSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode()) || "ApplicantSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode()) || "InsuredSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode())) { PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal = ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x -> x.getCode().equals(ruleAttrMappingVo.getValue())).findFirst().orElse(null); ruleAttrMappingVo.setValue(ptlAgreementUndwrtRulesDictLabal.getCode()); } } if(!Objects.isNull(ruleAttrMappingVo.getValue())) { useFlag = attrEqual(ptlAgreementUndwrtRulesAttrLinks.get(i), ptlAgreementUndwrtRulesAttr, ruleAttrMappingVo.getValue(),insOrders); }else{ useFlag = false; } if (useFlag) { return true; } else { logs.append("规则匹配失败:" + ptlAgreementUndwrtRulesAttrLinks.get(i).getAttrCode() + "\n"); if (ptlAgreementUndwrtRulesAttrLinks.get(i).getMin() != null) { logs.append("校验的值:" + ptlAgreementUndwrtRulesAttrLinks.get(i).getMin() + "\n"); } else { logs.append("校验的值:" + ptlAgreementUndwrtRulesAttrLinks.get(i).getMax() + "\n"); } logs.append("传入的值:" + ruleAttrMappingVo.getValue() + "\n"); } } return useFlag; } /** * 费用因子的对比 强制非车险 * * @param ptlAgreementProductCostsAttrLinks 费用因子范围规则 * @param rulesAttrs 费用因子属性 * @param ruleAttrMappingVoList 表单提交的值 * @return */ private boolean judgementsIsNoCar(List ptlAgreementProductCostsAttrLinks, List rulesAttrs, List ruleAttrMappingVoList) { boolean useFlag = true; for (int i = 0; i < ptlAgreementProductCostsAttrLinks.size(); i++) { int finalI = i; //查找规则中的 传值属性 RuleAttrMappingVo ruleAttrMappingVo = ruleAttrMappingVoList.stream().filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLinks.get(finalI).getAttrCode())).findFirst().orElse(null); //如果是强制非车险 if (ptlAgreementProductCostsAttrLinks.get(i).getAttrCode().equals("IsNonMotorInsurance")) continue; //如果查找不到 传值属性 直接费用对比失败 if (ruleAttrMappingVo == null) return false; //查找 费用因子规则 PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr = rulesAttrs.stream().filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLinks.get(finalI).getAttrCode())).findFirst().get(); //如果是多选 对value进行转换 if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("checkbox")) { PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal = ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x -> x.getCode().equals(ruleAttrMappingVo.getValue())).findFirst().orElse(null); ruleAttrMappingVo.setValue(ptlAgreementUndwrtRulesDictLabal.getName()); } //如果是单选 并且是 性别的话 转换为code if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) { if ("CarOwnersSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode()) || "ApplicantSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode()) || "InsuredSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode())) { PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal = ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x -> x.getName().equals(ruleAttrMappingVo.getValue())).findFirst().orElse(null); ruleAttrMappingVo.setValue(ptlAgreementUndwrtRulesDictLabal.getCode()); } } useFlag = attrEqual(ptlAgreementProductCostsAttrLinks.get(i), ptlAgreementUndwrtRulesAttr, ruleAttrMappingVo.getValue()); if (!useFlag) { System.out.printf("规则匹配失败:" + ptlAgreementProductCostsAttrLinks.get(i).getAttrCode()); return false; } } return useFlag; } /** * 属性比较 返回 是否匹配 * * @param ptlAgreementProductCostsAttrLink * @param ptlAgreementUndwrtRulesAttr * @param value * @return */ private boolean attrEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, String value) { if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("checkbox")) { return checkBoxEqual(ptlAgreementProductCostsAttrLink, value); } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("inputNumber")) { return inputNumberEqual(ptlAgreementProductCostsAttrLink, value); } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("input")) { //截取身份证号码 if (ptlAgreementProductCostsAttrLink.getAttrCode().equals("CarOwnersIDNumber") || ptlAgreementProductCostsAttrLink.getAttrCode().equals("ApplicantIDNumber") || ptlAgreementProductCostsAttrLink.getAttrCode().equals("InsuredIDNumber")) { value = value.substring(0, ptlAgreementProductCostsAttrLink.getMin().length()); } return inputTextEqual(ptlAgreementProductCostsAttrLink, value); } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("select")) { //截取车牌 if (ptlAgreementUndwrtRulesAttr.getAttrCode().equals("LicenseNo")) { value = value.substring(0, 2); } return selectEqual(ptlAgreementProductCostsAttrLink, value); } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) { return radioEqual(ptlAgreementProductCostsAttrLink, value); } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("datetime")){ // 时间 return dateTimeEqual(ptlAgreementProductCostsAttrLink, value); } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("date")){ return dateEqual(ptlAgreementProductCostsAttrLink, value); } return false; } private boolean attrEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, String value,InsOrders insOrders) { if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("checkbox")) { return checkBoxEqual(ptlAgreementUndwrtRulesAttrLink, value); } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("inputNumber")) { //如果是空字符串 则返回false // if(value.equals("")){ // return false; // } return inputNumberEqual(ptlAgreementUndwrtRulesAttrLink, value); } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("input")) { //截取身份证号码 if (ptlAgreementUndwrtRulesAttr.getAttrCode().equals("CarOwnersIDNumber") || ptlAgreementUndwrtRulesAttr.getAttrCode().equals("ApplicantIDNumber") || ptlAgreementUndwrtRulesAttr.getAttrCode().equals("InsuredIDNumber")) { value = value.substring(0, ptlAgreementUndwrtRulesAttrLink.getMin().length()); } return inputTextEqual(ptlAgreementUndwrtRulesAttrLink, value); } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("select")) { //截取车牌 if (ptlAgreementUndwrtRulesAttr.getAttrCode().equals("LicenseNo")) { value = value.substring(0, 2); } return selectEqual(ptlAgreementUndwrtRulesAttrLink, value); } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) { return radioEqual(ptlAgreementUndwrtRulesAttrLink, value); } else if(ptlAgreementUndwrtRulesAttr.getAttrType().equals("datetime")){ return dateTimeEqual(ptlAgreementUndwrtRulesAttrLink, value, insOrders); } else if(ptlAgreementUndwrtRulesAttr.getAttrType().equals("date")){ return dateEqual(ptlAgreementUndwrtRulesAttrLink,value); } return false; } /** * 属性为多选判断 * * @param ptlAgreementProductCostsAttrLink * @param value * @return */ private boolean checkBoxEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) { String[] split = ptlAgreementProductCostsAttrLink.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; } /** * 属性为数值型判断 * * @param ptlAgreementProductCostsAttrLink * @param value * @return */ private boolean inputNumberEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) { double v = Double.parseDouble(value); //统一处理数值 if ("1".equals(ptlAgreementProductCostsAttrLink.getOperator())) { if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMin()) <= v && Double.parseDouble(ptlAgreementProductCostsAttrLink.getMax()) >= v) { return true; } } else if ("2".equals(ptlAgreementProductCostsAttrLink.getOperator())) { if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMin()) > v) { return true; } } else if ("3".equals(ptlAgreementProductCostsAttrLink.getOperator())) { if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMin()) >= v) { return true; } } else if ("4".equals(ptlAgreementProductCostsAttrLink.getOperator())) { if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMax()) < v) { return true; } } else if ("5".equals(ptlAgreementProductCostsAttrLink.getOperator())) { if (Double.parseDouble(ptlAgreementProductCostsAttrLink.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; } /** * 属性为输入框判断 * * @param ptlAgreementProductCostsAttrLink * @param value * @return */ private boolean inputTextEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) { //将值进行分割 String[] split = ptlAgreementProductCostsAttrLink.getMin().split(","); AtomicBoolean returnBool = new AtomicBoolean(false); List equalsMap = new ArrayList<>(); //字符型评分 equalsMap.add("CharacterBasedRating"); //交强字符型评分 equalsMap.add("JqCharacterBasedRating"); //商业字符型评分 equalsMap.add("SyCharacterBasedRating"); //equest 等于判断 if(equalsMap.contains(ptlAgreementProductCostsAttrLink.getAttrCode())){ boolean b = Arrays.stream(split).anyMatch(value::equals); returnBool.set(b); }else if((ptlAgreementProductCostsAttrLink.getAttrCode().equals("BrandandModel") || ptlAgreementProductCostsAttrLink.getAttrCode().equals("CarOwnerName") || ptlAgreementProductCostsAttrLink.getAttrCode().equals("CarOwnersAddress") || ptlAgreementProductCostsAttrLink.getAttrCode().equals("ApplicantAddress") || ptlAgreementProductCostsAttrLink.getAttrCode().equals("InsuredAddress")) && ptlAgreementProductCostsAttrLink.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 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(); } /** * 属性为下拉框判断 * * @param ptlAgreementProductCostsAttrLink * @param value * @return */ private boolean selectEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) { if (ptlAgreementProductCostsAttrLink.getMin() != null && ptlAgreementProductCostsAttrLink.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; } /** * 属性为单选框判断 * * @param ptlAgreementProductCostsAttrLink * @param value * @return */ private boolean radioEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) { //新能源判断 if ("NewEnergy".equals(ptlAgreementProductCostsAttrLink.getAttrCode())) { // 是否是新能源车 boolean newEnergy = EnergyType.isNewEnergy(value); if (newEnergy && ptlAgreementProductCostsAttrLink.getMin().equals("1")) { return true; } else if (!newEnergy && ptlAgreementProductCostsAttrLink.getMin().equals("0")) { return true; } } else if (ptlAgreementProductCostsAttrLink.getMin().contains(value)) { return true; } return false; } private boolean radioEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) { //新能源判断 if ("NewEnergy".equals(ptlAgreementUndwrtRulesAttrLink.getAttrCode())) { // 是否是新能源车 boolean newEnergy = EnergyType.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(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, 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(ptlAgreementProductCostsAttrLink.getMin())){ min = LocalDateTime.parse(ptlAgreementProductCostsAttrLink.getMin(),formatter); } if(!Objects.isNull(ptlAgreementProductCostsAttrLink.getMax())){ max = LocalDateTime.parse(ptlAgreementProductCostsAttrLink.getMax(),formatter); } //统一处理数值 if ("1".equals(ptlAgreementProductCostsAttrLink.getOperator())) { if (v.isAfter(min) && v.isBefore(max)) { return true; } } else if ("2".equals(ptlAgreementProductCostsAttrLink.getOperator())) { if (v.isBefore(min)) { return true; } } else if ("3".equals(ptlAgreementProductCostsAttrLink.getOperator())) { if (v.isBefore(min) || v.isEqual(min)) { return true; } } else if ("4".equals(ptlAgreementProductCostsAttrLink.getOperator())) { if (v.isAfter(max)) { return true; } } else if ("5".equals(ptlAgreementProductCostsAttrLink.getOperator())) { if (v.isAfter(max) || v.isEqual(max)) { return true; } } return false; } public boolean dateEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, 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(ptlAgreementProductCostsAttrLink.getMin())){ min = LocalDate.parse(ptlAgreementProductCostsAttrLink.getMin()).atStartOfDay(); } if(!Objects.isNull(ptlAgreementProductCostsAttrLink.getMax())){ max = LocalDate.parse(ptlAgreementProductCostsAttrLink.getMax()).atStartOfDay(); } //统一处理数值 if ("1".equals(ptlAgreementProductCostsAttrLink.getOperator())) { if (v.isAfter(min) && v.isBefore(max)) { return true; } } else if ("2".equals(ptlAgreementProductCostsAttrLink.getOperator())) { if (v.isBefore(min)) { return true; } } else if ("3".equals(ptlAgreementProductCostsAttrLink.getOperator())) { if (v.isBefore(min) || v.isEqual(min)) { return true; } } else if ("4".equals(ptlAgreementProductCostsAttrLink.getOperator())) { if (v.isAfter(max)) { return true; } } else if ("5".equals(ptlAgreementProductCostsAttrLink.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; } /** * 获取车辆新旧车信息 * * @param companyId * @return */ private PtlNewCarJudgeRules getCarJudgeRule(String companyId) { //获取车辆新旧车信息 List list = ptlNewCarJudgeRulesService.list(new LambdaQueryWrapper().eq(PtlNewCarJudgeRules::getCompanyId, companyId)); if (list.size() > 0) { return list.get(0); } return null; } }