|
@@ -12,6 +12,7 @@ import com.jzg.commons.core.page.HttpResult;
|
|
|
import com.jzg.commons.entity.finance.dto.*;
|
|
import com.jzg.commons.entity.finance.dto.*;
|
|
|
import com.jzg.commons.entity.finance.po.*;
|
|
import com.jzg.commons.entity.finance.po.*;
|
|
|
import com.jzg.commons.entity.finance.vo.*;
|
|
import com.jzg.commons.entity.finance.vo.*;
|
|
|
|
|
+import com.jzg.commons.entity.orders.po.InsOrderAdjust;
|
|
|
import com.jzg.commons.entity.po.EsmInsCompany;
|
|
import com.jzg.commons.entity.po.EsmInsCompany;
|
|
|
import com.jzg.commons.entity.po.PtlAgreement;
|
|
import com.jzg.commons.entity.po.PtlAgreement;
|
|
|
import com.jzg.commons.entity.po.SysUploadFiles;
|
|
import com.jzg.commons.entity.po.SysUploadFiles;
|
|
@@ -50,6 +51,8 @@ import java.time.format.DateTimeFormatter;
|
|
|
import java.time.format.DateTimeParseException;
|
|
import java.time.format.DateTimeParseException;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
+import java.util.function.BiConsumer;
|
|
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
/**
|
|
/**
|
|
|
* @author tz
|
|
* @author tz
|
|
@@ -1218,16 +1221,138 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void restockInsPlyIncome(String orderNo, String companyId) {
|
|
|
|
|
|
|
+ public void restockInsPlyIncome(InsOrderAdjust insOrderAdjust) {
|
|
|
|
|
+ final String AGREEMENT_TYPE_PLATFORM = "1";
|
|
|
|
|
+ final BigDecimal RATIO_1_06 = new BigDecimal("1.06");
|
|
|
List<InsPlyIncome> insPlyIncomeList = baseMapper
|
|
List<InsPlyIncome> insPlyIncomeList = baseMapper
|
|
|
- .selectList(new LambdaQueryWrapper<InsPlyIncome>().eq(InsPlyIncome::getOrderNo, orderNo).eq(InsPlyIncome::getCompanyId, companyId));
|
|
|
|
|
|
|
+ .selectList(new LambdaQueryWrapper<InsPlyIncome>().eq(InsPlyIncome::getOrderNo, insOrderAdjust.getOrderNo()).eq(InsPlyIncome::getCompanyId, insOrderAdjust.getCompanyId()));
|
|
|
if (insPlyIncomeList.isEmpty()) {
|
|
if (insPlyIncomeList.isEmpty()) {
|
|
|
throw new SystemException("未找到该应收订单");
|
|
throw new SystemException("未找到该应收订单");
|
|
|
}
|
|
}
|
|
|
InsPlyIncome insPlyIncome = insPlyIncomeList.get(0);
|
|
InsPlyIncome insPlyIncome = insPlyIncomeList.get(0);
|
|
|
- InsPlyIncome restockInsPlyIncome = new InsPlyIncome();
|
|
|
|
|
- BeanUtils.copyProperties(insPlyIncome, restockInsPlyIncome);
|
|
|
|
|
- this.save(restockInsPlyIncome);
|
|
|
|
|
|
|
+ InsPlyIncome restockIncome = new InsPlyIncome();
|
|
|
|
|
+ BeanUtils.copyProperties(insPlyIncome, restockIncome);
|
|
|
|
|
+ // 获取批改后的保费
|
|
|
|
|
+ BigDecimal adjustJqPremium = insOrderAdjust.getAfterJqPremium();
|
|
|
|
|
+ BigDecimal adjustSyPremium = insOrderAdjust.getAfterSyPremium();
|
|
|
|
|
+ BigDecimal adjustJyPremium = insOrderAdjust.getAfterJyPremium();
|
|
|
|
|
+ restockIncome.setJqPremium(adjustJqPremium.toPlainString());
|
|
|
|
|
+ restockIncome.setSyPremium(adjustSyPremium.toPlainString());
|
|
|
|
|
+ restockIncome.setJyPremium(adjustJyPremium.toPlainString());
|
|
|
|
|
+ // 计算手续费
|
|
|
|
|
+ calculateAndSetCosts(restockIncome, adjustJqPremium,
|
|
|
|
|
+ InsPlyIncome::getJqSuperviseCostsProportion,
|
|
|
|
|
+ InsPlyIncome::setJqSuperviseCostsPremiums);
|
|
|
|
|
+
|
|
|
|
|
+ calculateAndSetCosts(restockIncome, adjustSyPremium,
|
|
|
|
|
+ InsPlyIncome::getSySuperviseCostsProportion,
|
|
|
|
|
+ InsPlyIncome::setSySuperviseCostsPremiums);
|
|
|
|
|
+
|
|
|
|
|
+ calculateAndSetCosts(restockIncome, adjustJyPremium,
|
|
|
|
|
+ InsPlyIncome::getJySuperviseCostsProportion,
|
|
|
|
|
+ InsPlyIncome::setJySuperviseCostsPremiums);
|
|
|
|
|
+
|
|
|
|
|
+ // 计算并设置跟单费
|
|
|
|
|
+ calculateAndSetCosts(restockIncome, adjustJqPremium,
|
|
|
|
|
+ InsPlyIncome::getJqOtherCostsProportion,
|
|
|
|
|
+ InsPlyIncome::setJqOtherCostsPremiums);
|
|
|
|
|
+
|
|
|
|
|
+ calculateAndSetCosts(restockIncome, adjustSyPremium,
|
|
|
|
|
+ InsPlyIncome::getSyOtherCostsProportion,
|
|
|
|
|
+ InsPlyIncome::setSyOtherCostsPremiums);
|
|
|
|
|
+
|
|
|
|
|
+ calculateAndSetCosts(restockIncome, adjustJyPremium,
|
|
|
|
|
+ InsPlyIncome::getJyOtherCostsProportion,
|
|
|
|
|
+ InsPlyIncome::setJyOtherCostsPremiums);
|
|
|
|
|
+
|
|
|
|
|
+ // 计算并设置应收保费(按协议类型处理)
|
|
|
|
|
+ calculateAndSetReceivable(restockIncome, adjustJqPremium, adjustSyPremium, adjustJyPremium,
|
|
|
|
|
+ AGREEMENT_TYPE_PLATFORM, RATIO_1_06);
|
|
|
|
|
+ this.save(restockIncome);
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 通用计算费用(手续费/跟单费)并设置到对象
|
|
|
|
|
+ * @param income 目标对象
|
|
|
|
|
+ * @param premium 保费
|
|
|
|
|
+ * @param proportionGetter 比例获取器
|
|
|
|
|
+ * @param costSetter 费用设置器
|
|
|
|
|
+ */
|
|
|
|
|
+ private void calculateAndSetCosts(InsPlyIncome income, BigDecimal premium,
|
|
|
|
|
+ Function<InsPlyIncome, String> proportionGetter,
|
|
|
|
|
+ BiConsumer<InsPlyIncome, String> costSetter) {
|
|
|
|
|
+ // 转换比例字符串为BigDecimal(处理可能的空值或异常)
|
|
|
|
|
+ BigDecimal proportion = new BigDecimal(proportionGetter.apply(income));
|
|
|
|
|
+ // 计算费用并设置(使用toPlainString避免科学计数法)
|
|
|
|
|
+ BigDecimal cost = premium.multiply(proportion);
|
|
|
|
|
+ costSetter.accept(income, cost.toPlainString());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 计算并设置应收保费
|
|
|
|
|
+ */
|
|
|
|
|
+ private void calculateAndSetReceivable(InsPlyIncome income, BigDecimal jqPremium, BigDecimal syPremium, BigDecimal jyPremium,
|
|
|
|
|
+ String platformAgreementType, BigDecimal ratio106) {
|
|
|
|
|
+ // 平台协议逻辑
|
|
|
|
|
+ if (platformAgreementType.equals(income.getAgreementType())) {
|
|
|
|
|
+ setReceivableForPlatform(income, jqPremium, syPremium, jyPremium);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 私有协议逻辑
|
|
|
|
|
+ setReceivableForPrivate(income, jqPremium, syPremium, jyPremium, ratio106);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 平台协议应收保费计算
|
|
|
|
|
+ */
|
|
|
|
|
+ private void setReceivableForPlatform(InsPlyIncome income, BigDecimal jqPremium, BigDecimal syPremium, BigDecimal jyPremium) {
|
|
|
|
|
+ // 从已计算的手续费和跟单费中获取值(避免重复计算)
|
|
|
|
|
+ BigDecimal jqTotal = new BigDecimal(income.getJqSuperviseCostsPremiums())
|
|
|
|
|
+ .add(new BigDecimal(income.getJqOtherCostsPremiums()));
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal syTotal = new BigDecimal(income.getSySuperviseCostsPremiums())
|
|
|
|
|
+ .add(new BigDecimal(income.getSyOtherCostsPremiums()));
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal jyTotal = new BigDecimal(income.getJySuperviseCostsPremiums())
|
|
|
|
|
+ .add(new BigDecimal(income.getJyOtherCostsPremiums()));
|
|
|
|
|
+
|
|
|
|
|
+ income.setJqReceivablePremium(jqTotal.toPlainString());
|
|
|
|
|
+ income.setSyReceivablePremium(syTotal.toPlainString());
|
|
|
|
|
+ income.setJyReceivablePremium(jyTotal.toPlainString());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 私有协议应收保费计算
|
|
|
|
|
+ */
|
|
|
|
|
+ private void setReceivableForPrivate(InsPlyIncome income, BigDecimal jqPremium, BigDecimal syPremium, BigDecimal jyPremium,
|
|
|
|
|
+ BigDecimal ratio106) {
|
|
|
|
|
+ // 计算私有协议下的应收保费
|
|
|
|
|
+ calculatePrivateReceivable(income, jqPremium, ratio106,
|
|
|
|
|
+ InsPlyIncome::getJqSuperviseCostsProportion,
|
|
|
|
|
+ InsPlyIncome::getJqOtherCostsProportion,
|
|
|
|
|
+ InsPlyIncome::setJqReceivablePremium);
|
|
|
|
|
+
|
|
|
|
|
+ calculatePrivateReceivable(income, syPremium, ratio106,
|
|
|
|
|
+ InsPlyIncome::getSySuperviseCostsProportion,
|
|
|
|
|
+ InsPlyIncome::getSyOtherCostsProportion,
|
|
|
|
|
+ InsPlyIncome::setSyReceivablePremium);
|
|
|
|
|
+
|
|
|
|
|
+ calculatePrivateReceivable(income, jyPremium, ratio106,
|
|
|
|
|
+ InsPlyIncome::getJySuperviseCostsProportion,
|
|
|
|
|
+ InsPlyIncome::getJyOtherCostsProportion,
|
|
|
|
|
+ InsPlyIncome::setJyReceivablePremium);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 私有协议下单个类型的应收保费计算
|
|
|
|
|
+ */
|
|
|
|
|
+ private void calculatePrivateReceivable(InsPlyIncome income, BigDecimal premium, BigDecimal ratio106,
|
|
|
|
|
+ Function<InsPlyIncome, String> superviseProportionGetter,
|
|
|
|
|
+ Function<InsPlyIncome, String> otherProportionGetter,
|
|
|
|
|
+ BiConsumer<InsPlyIncome, String> receivableSetter) {
|
|
|
|
|
+ BigDecimal base = premium.multiply(ratio106);
|
|
|
|
|
+ BigDecimal superviseCost = base.multiply(new BigDecimal(superviseProportionGetter.apply(income)));
|
|
|
|
|
+ BigDecimal otherCost = base.multiply(new BigDecimal(otherProportionGetter.apply(income)));
|
|
|
|
|
+ receivableSetter.accept(income, superviseCost.add(otherCost).toPlainString());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|