소스 검색

现询费用bug修改 现询费用出口费用显示 起保日期规则添加

785834757 1 년 전
부모
커밋
954ecaca4b

+ 6 - 0
src/main/java/com/ydtech/modules/fee/dto/vo/RuleAttrMappingVo.java

@@ -74,6 +74,12 @@ public class RuleAttrMappingVo {
         LocalDate registrationDate = LocalDate.parse(carInfo.getRegisterDate());
         LocalDate currentDate = LocalDate.now();
 
+        //交强起保日期
+        ruleAttrMappingVoList.add(new RuleAttrMappingVo("JqStartTime",insOrders.getJqstartdate()));
+
+        //商业起保日期
+        ruleAttrMappingVoList.add(new RuleAttrMappingVo("SyStartTime",insOrders.getSystartdate()));
+
         boolean isNoLicenseFlag = false;
         if (carJudgeRule != null) {
             if (carJudgeRule.getUnitTypeCode().equals("天")) {

+ 3 - 0
src/main/java/com/ydtech/modules/fee/service/FeeRuleSchemeNewService.java

@@ -5,8 +5,10 @@ import com.ydtech.modules.fee.dto.vo.ReCalcuLateProportion;
 import com.ydtech.modules.fee.dto.vo.RetailProportion;
 import com.ydtech.modules.order.entity.InsAreaCompany;
 import com.ydtech.modules.order.entity.InsOrders;
+import com.ydtech.modules.order.entity.vo.ExternalOrderFeeVo;
 import com.ydtech.modules.order.entity.vo.QueryOrderFeeResultVo;
 import com.ydtech.modules.order.entity.vo.QueryOrderFeeVo;
+import com.ydtech.modules.protocol.entity.po.PtlAgreement;
 import com.ydtech.modules.protocols.entity.po.PtlAgreementProductCostsExport;
 import com.ydtech.modules.protocols.entity.po.PtlAgreementProductCostsNew;
 
@@ -106,6 +108,7 @@ public interface FeeRuleSchemeNewService {
      */
     void calcCostsExternal(PtlAgreementProductCostsNew costsNew, InsAreaCompany insAreaCompany);
 
+    ExternalOrderFeeVo calcCostsExternalExportData(PtlAgreement ptlAgreement, PtlAgreementProductCostsNew ptlAgreementProductCostsNew, ExternalOrderFeeVo externalOrderFeeVo);
 
     void calcCostsExternalTest(PtlAgreementProductCostsNew costsNew, InsAreaCompany insAreaCompany);
 

+ 361 - 0
src/main/java/com/ydtech/modules/fee/service/impl/FeeRuleSchemeServiceNewImpl.java

@@ -26,6 +26,7 @@ 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;
@@ -46,6 +47,9 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
@@ -1572,6 +1576,283 @@ public class FeeRuleSchemeServiceNewImpl implements FeeRuleSchemeNewService {
     }
 
 
+
+    @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<PtlAgreementProductCostsExport>().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<EsmRetail> 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.setSyExportPremium(syExportFee.getTotalAmount());
+        externalOrderFeeVo.setNoExportPremium(noExportFee.getTotalAmount());
+        //endregion
+
+        return externalOrderFeeVo;
+
+    }
+
     @Override
     public void calcCostsExternalTest(PtlAgreementProductCostsNew ptlAgreementProductCostsNew, InsAreaCompany insAreaCompany) {
         //获取协议信息
@@ -2769,6 +3050,8 @@ public class FeeRuleSchemeServiceNewImpl implements FeeRuleSchemeNewService {
             return selectEqual(ptlAgreementProductCostsAttrLink, value);
         } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) {
             return radioEqual(ptlAgreementProductCostsAttrLink, value);
+        } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("datetime")){ // 时间
+            return dateTimeEqual(ptlAgreementProductCostsAttrLink, value);
         }
 
         return false;
@@ -2790,6 +3073,8 @@ public class FeeRuleSchemeServiceNewImpl implements FeeRuleSchemeNewService {
             return selectEqual(ptlAgreementUndwrtRulesAttrLink, value);
         } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) {
             return radioEqual(ptlAgreementUndwrtRulesAttrLink, value);
+        } else if(ptlAgreementUndwrtRulesAttr.getAttrType().equals("datetime")){
+            return dateTimeEqual(ptlAgreementUndwrtRulesAttrLink, value);
         }
         return false;
     }
@@ -3011,6 +3296,82 @@ public class FeeRuleSchemeServiceNewImpl implements FeeRuleSchemeNewService {
         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)) {
+                return true;
+            }
+        } else if ("4".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
+            if (v.isAfter(max)) {
+                return true;
+            }
+        } else if ("5".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
+            if (v.isAfter(max)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+
+    public boolean dateTimeEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value){
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        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;
+    }
+
     /**
      * 获取车辆新旧车信息
      *

+ 38 - 0
src/main/java/com/ydtech/modules/order/controller/ExternalOrderController.java

@@ -1,10 +1,13 @@
 package com.ydtech.modules.order.controller;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ydtech.constants.enums.InsuranceRisk;
 import com.ydtech.constants.enums.dict.FeeAuditAuditstatus;
+import com.ydtech.constants.enums.dict.agreement.ProductsType;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.exception.SystemException;
 import com.ydtech.modules.base.controller.BaseController;
+import com.ydtech.modules.fee.service.FeeRuleSchemeNewService;
 import com.ydtech.modules.fnc.entity.InsFeeAudit;
 import com.ydtech.modules.fnc.service.InsFeeAuditService;
 import com.ydtech.modules.ins.model.vo.QuoteRespVo;
@@ -13,6 +16,10 @@ import com.ydtech.modules.order.entity.vo.*;
 import com.ydtech.modules.order.service.InsAreaCompanyExternalPolicyService;
 import com.ydtech.modules.order.service.InsAreaCompanyService;
 import com.ydtech.modules.order.service.InsTaskImagesService;
+import com.ydtech.modules.protocol.entity.po.PtlAgreement;
+import com.ydtech.modules.protocol.service.PtlAgreementService;
+import com.ydtech.modules.protocols.entity.po.PtlAgreementProductCostsNew;
+import com.ydtech.modules.protocols.service.PtlAgreementProductCostsNewService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
@@ -20,6 +27,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.Objects;
+
 import static com.ydtech.modules.base.model.vo.PageVo.buildPageRequest;
 
 @Api(tags = "外部订单 api")
@@ -43,6 +52,15 @@ public class ExternalOrderController {
     @Autowired
     private InsFeeAuditService insFeeAuditService;
 
+    @Autowired
+    private PtlAgreementService ptlAgreementService;
+
+    @Autowired
+    private PtlAgreementProductCostsNewService ptlAgreementProductCostsNewService;
+
+    @Autowired
+    private FeeRuleSchemeNewService feeRuleSchemeNewService;
+
     @PostMapping("/saveSubOrder")
     @ApiOperation("保存子订单")
     public HttpResult<QuoteRespVo> saveSubOrder(@RequestBody BaseQuoteVo<AccidentalDrivingVo> quoteVo) {
@@ -165,4 +183,24 @@ public class ExternalOrderController {
         Page page = buildPageRequest(rejectPageQueryVo.getPageDto());
         return HttpResult.ok(insAreaCompanyService.getAllRejectOrders(page, rejectPageQueryVo));
     }
+
+    /**
+     * 查询外部订单费用
+     */
+    @PostMapping("/externalOrderFee")
+    @ApiOperation("外部订单费用")
+    public HttpResult<Object> externalOrderFee(@RequestBody ExternalOrderFeeVo externalOrderFeeVo){
+        //校验是否是外部订单的非现询协议
+        PtlAgreement ptlAgreement = ptlAgreementService.getById(externalOrderFeeVo.getAgreementId());
+        ProductsType productsType = InsuranceRisk.determineInsuranceInformation(externalOrderFeeVo.getKinds(), externalOrderFeeVo.getRisks());
+        externalOrderFeeVo.setProductCode(productsType.getCode());
+        PtlAgreementProductCostsNew noInquiryNowFee = ptlAgreementProductCostsNewService.getNoInquiryNowFee(externalOrderFeeVo.getAgreementId(), externalOrderFeeVo.getProductCode());
+        if(Objects.isNull(noInquiryNowFee)){
+            throw new SystemException("不存在该协议");
+        }
+        externalOrderFeeVo.blank();
+        ExternalOrderFeeVo resultExternalOrderFeeVo = feeRuleSchemeNewService.calcCostsExternalExportData(ptlAgreement, noInquiryNowFee, externalOrderFeeVo);
+
+        return HttpResult.ok(resultExternalOrderFeeVo);
+    }
 }

+ 112 - 0
src/main/java/com/ydtech/modules/order/entity/vo/ExternalOrderFeeVo.java

@@ -0,0 +1,112 @@
+package com.ydtech.modules.order.entity.vo;
+
+import com.ydtech.modules.ins.model.vo.KindInfoVo;
+import com.ydtech.modules.ins.model.vo.RiskInfoVo;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * 外部订单费用vo
+ */
+@Data
+public class ExternalOrderFeeVo {
+
+    @ApiModelProperty(value = "协议id")
+    private String agreementId;
+
+    @ApiModelProperty(value = "产品code")
+    private String productCode;
+
+    @ApiModelProperty(value = "待客录单的用户id")
+    private String userId;
+
+    @ApiModelProperty(value = "险种大类")
+    private List<RiskInfoVo> risks;
+
+    @ApiModelProperty(value = "商业险种")
+    private List<KindInfoVo> kinds;
+
+    @ApiModelProperty(value = "交强保费")
+    private BigDecimal jqPremium;
+
+    @ApiModelProperty(value = "不含税交强保费")
+    private BigDecimal jqNoTaxPremium;
+
+    @ApiModelProperty(value = "交强总比例")
+    private BigDecimal jqRadio;
+
+    @ApiModelProperty(value = "商业保费")
+    private BigDecimal syPremium;
+
+    @ApiModelProperty(value = "不含税商业保费")
+    private BigDecimal syNoTaxPremium;
+
+    @ApiModelProperty(value = "商业总比例")
+    private BigDecimal syRadio;
+
+    @ApiModelProperty(value = "驾意保费")
+    private BigDecimal noPremium;
+
+    @ApiModelProperty(value = "不含税驾意保费")
+    private BigDecimal noNoTaxPremium;
+
+    @ApiModelProperty(value = "驾意总比例")
+    private BigDecimal noRadio;
+
+    @ApiModelProperty(value = "交强出口费用")
+    private BigDecimal jqExportPremium;
+
+    @ApiModelProperty(value = "交强出口比例")
+    private BigDecimal jqExportRadio;
+
+    @ApiModelProperty(value = "商业出口费用")
+    private BigDecimal syExportPremium;
+
+    @ApiModelProperty(value = "商业出口比例")
+    private BigDecimal syExportRadio;
+
+    @ApiModelProperty(value = "非车出口费用")
+    private BigDecimal noExportPremium;
+
+    @ApiModelProperty(value = "非车出口比例")
+    private BigDecimal noExportRadio;
+
+    @ApiModelProperty(value = "计算的交强入口比例")
+    private BigDecimal JqCostsProportion;
+
+    @ApiModelProperty(value = "计算的商业入口比例")
+    private BigDecimal syCostsProportion;
+
+    @ApiModelProperty(value = "计算的非车入口比例")
+    private BigDecimal NoCostsProportion;
+
+
+    public void blank(){
+        if(Objects.isNull(this.jqPremium)){
+            this.jqPremium = new BigDecimal(BigInteger.ZERO);
+        }
+        if(Objects.isNull(this.syPremium)){
+            this.syPremium = new BigDecimal(BigInteger.ZERO);
+        }
+        if(Objects.isNull(this.noPremium)){
+            this.noPremium = new BigDecimal(BigInteger.ZERO);
+        }
+
+        if(Objects.isNull(this.jqRadio)){
+            this.jqRadio = new BigDecimal(BigInteger.ZERO);
+        }
+        if(Objects.isNull(this.syRadio)){
+            this.syRadio = new BigDecimal(BigInteger.ZERO);
+        }
+        if(Objects.isNull(this.noRadio)){
+            this.noRadio = new BigDecimal(BigInteger.ZERO);
+        }
+
+    }
+
+}

+ 5 - 0
src/main/java/com/ydtech/modules/order/entity/vo/InsOrdersEditingVo.java

@@ -90,6 +90,9 @@ public class InsOrdersEditingVo extends InsOrders implements Serializable {
     @ApiModelProperty("规则过滤完后的保险公司")
     private List<PtlAgreementInsCompanyDto> companyDtos;
 
+    @ApiModelProperty("现询费用id")
+    private String nowCostsId;
+
     @Data
     @AllArgsConstructor
     @NoArgsConstructor
@@ -266,6 +269,8 @@ public class InsOrdersEditingVo extends InsOrders implements Serializable {
         @ApiModelProperty("接口类型")
         private String apiType;
 
+
+
         public void feeVacant() {
             this.jqExportFee = null;
             this.syExportFee = null;

+ 1 - 0
src/main/java/com/ydtech/modules/order/service/impl/InsAreaCompanyServiceImpl.java

@@ -846,6 +846,7 @@ public class InsAreaCompanyServiceImpl extends ServiceImpl<InsAreaCompanyMapper,
         agreementProductQueryVo.setProductCode(productId);
         agreementProductQueryVo.setIsAudit("1");
         agreementProductQueryVo.setAgreementId(ptlAgreement.getId());
+        agreementProductQueryVo.setNowCostsId(insOrdersEditingVo.getNowCostsId());
 
         List<PtlAgreementProductCostsNew> costsNews = ptlAgreementProductCostsNewService.getByAgreementId(agreementProductQueryVo);
 

+ 2 - 0
src/main/java/com/ydtech/modules/protocols/service/PtlAgreementProductCostsNewService.java

@@ -130,4 +130,6 @@ public interface PtlAgreementProductCostsNewService extends IService<PtlAgreemen
      * @return
      */
     List<PtlAgreementProductCostsNew> getInquiryNowFee(InquiryNowFeeQueryVo inquiryNowFeeQueryVo);
+
+    PtlAgreementProductCostsNew getNoInquiryNowFee(String agreementId,String productCode);
 }

+ 18 - 0
src/main/java/com/ydtech/modules/protocols/service/impl/PtlAgreementProductCostsNewServiceImpl.java

@@ -2387,4 +2387,22 @@ public class PtlAgreementProductCostsNewServiceImpl extends ServiceImpl<PtlAgree
 
         return ptlAgreementProductCostsNews;
     }
+
+    @Override
+    public PtlAgreementProductCostsNew getNoInquiryNowFee(String agreementId, String productCode) {
+
+        LambdaQueryWrapper<PtlAgreementProductCostsNew> queryWrapper = new LambdaQueryWrapper<>();
+
+        queryWrapper.lt(PtlAgreementProductCostsNew::getCostsStartDate, LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+        queryWrapper.gt(PtlAgreementProductCostsNew::getCostsEndDate, LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+
+        queryWrapper.eq(PtlAgreementProductCostsNew::getIsAudit, "1");
+        queryWrapper.eq(PtlAgreementProductCostsNew::getIsInquiryNow, "0");
+
+        queryWrapper.eq(PtlAgreementProductCostsNew::getAgreementId, agreementId);
+        queryWrapper.eq(PtlAgreementProductCostsNew::getProductId, productCode);
+
+        PtlAgreementProductCostsNew ptlAgreementProductCostsNews = baseMapper.selectOne(queryWrapper);
+        return ptlAgreementProductCostsNews;
+    }
 }