|
|
@@ -66,7 +66,8 @@ public class InsFeeOrdersServiceImpl extends ServiceImpl<InsFeeOrdersMapper, Ins
|
|
|
// 常量定义 保留小数5位
|
|
|
final int SCALE = 5;
|
|
|
final RoundingMode ROUNDING_MODE = RoundingMode.HALF_EVEN;
|
|
|
- final BigDecimal TAX_FACTOR = new BigDecimal("1").divide(new BigDecimal("1.06"), 10, ROUNDING_MODE);
|
|
|
+ final BigDecimal ONE_HUNDRED = new BigDecimal("100");
|
|
|
+ final BigDecimal TAX_RATE = new BigDecimal("1.06");
|
|
|
|
|
|
// 获取订单信息
|
|
|
InsOrders insOrders = insOrdersService.getById(ptlAgreementCostRatioVo.getOrderNo());
|
|
|
@@ -78,83 +79,115 @@ public class InsFeeOrdersServiceImpl extends ServiceImpl<InsFeeOrdersMapper, Ins
|
|
|
PtlAgreement ptlAgreement = orgClient.getByAgreementId(insOrders.getAgreementId());
|
|
|
// 获取费用信息
|
|
|
InsFeeOrders insFeeOrders = insFeeOrdersMapper.selectById(insOrders.getId());
|
|
|
- // 保费
|
|
|
- BigDecimal jqPremium = insOrdersCosts.getJqPremium();
|
|
|
- BigDecimal syPremium = insOrdersCosts.getSyPremium();
|
|
|
- BigDecimal jyPremium = insOrdersCosts.getJyPremium();
|
|
|
- // 手续费比例
|
|
|
- BigDecimal jqCommissionRatio = covertPercent(ptlAgreementCostRatioVo.getJqCommissionRatio());
|
|
|
- BigDecimal syCommissionRatio = covertPercent(ptlAgreementCostRatioVo.getSyCommissionRatio());
|
|
|
- BigDecimal jyCommissionRatio = covertPercent(ptlAgreementCostRatioVo.getJyCommissionRatio());
|
|
|
- // 跟单费比例
|
|
|
- BigDecimal jqFollowRatio = covertPercent(ptlAgreementCostRatioVo.getJqFollowRatio());
|
|
|
- BigDecimal syFollowRatio = covertPercent(ptlAgreementCostRatioVo.getSyFollowRatio());
|
|
|
- BigDecimal jyFollowRatio = covertPercent(ptlAgreementCostRatioVo.getJyFollowRatio());
|
|
|
- // 加投费比例
|
|
|
- BigDecimal jqAddThrowRatio = covertPercent(ptlAgreementCostRatioVo.getJqAdditionalRatio());
|
|
|
- BigDecimal syAddThrowRatio = covertPercent(ptlAgreementCostRatioVo.getSyAdditionalRatio());
|
|
|
- BigDecimal jyAddThrowRatio = covertPercent(ptlAgreementCostRatioVo.getJyAdditionalRatio());
|
|
|
- // 留点比例
|
|
|
- BigDecimal jqKeepPointRatio = covertPercent(ptlAgreementCostRatioVo.getJqKeepPointRatio());
|
|
|
- BigDecimal syKeepPointRatio = covertPercent(ptlAgreementCostRatioVo.getSyKeepPointRatio());
|
|
|
- BigDecimal jyKeepPointRatio = covertPercent(ptlAgreementCostRatioVo.getJyKeepPointRatio());
|
|
|
- // 入口比例
|
|
|
- BigDecimal jqInletRatio = covertPercent(ptlAgreementCostRatioVo.getJqInletRatio());
|
|
|
- BigDecimal syInletRatio = covertPercent(ptlAgreementCostRatioVo.getSyInletRatio());
|
|
|
- BigDecimal jyInletRatio = covertPercent(ptlAgreementCostRatioVo.getJyInletRatio());
|
|
|
- // 出口比例
|
|
|
- BigDecimal jqExportRatio = covertPercent(ptlAgreementCostRatioVo.getJqExportRatio());
|
|
|
- BigDecimal syExportRatio = covertPercent(ptlAgreementCostRatioVo.getSyExportRatio());
|
|
|
- BigDecimal jyExportRatio = covertPercent(ptlAgreementCostRatioVo.getJyExportRatio());
|
|
|
|
|
|
- // 出口留点比例
|
|
|
- BigDecimal jqExportKeepPointRatio = covertPercent(ptlAgreementCostRatioVo.getJqExportKeepPointRatio());
|
|
|
- BigDecimal syExportKeepPointRatio = covertPercent(ptlAgreementCostRatioVo.getSyExportKeepPointRatio());
|
|
|
- BigDecimal jyExportKeepPointRatio = covertPercent(ptlAgreementCostRatioVo.getJyExportKeepPointRatio());
|
|
|
-
|
|
|
- List<CostTypeParam> typeParams = Arrays.asList(
|
|
|
- new CostTypeParam("jq", jqPremium, jqCommissionRatio, jqFollowRatio, jqAddThrowRatio,
|
|
|
- jqKeepPointRatio, jqInletRatio, jqExportRatio, jqExportKeepPointRatio),
|
|
|
- new CostTypeParam("sy", syPremium, syCommissionRatio, syFollowRatio, syAddThrowRatio,
|
|
|
- syKeepPointRatio, syInletRatio, syExportRatio, syExportKeepPointRatio),
|
|
|
- new CostTypeParam("jy", jyPremium, jyCommissionRatio, jyFollowRatio, jyAddThrowRatio,
|
|
|
- jyKeepPointRatio, jyInletRatio, jyExportRatio, jyExportKeepPointRatio)
|
|
|
- );
|
|
|
- // 5. 根据协议类型计算费用
|
|
|
- boolean isPlatformAgreement = ptlAgreement.getAgreementType() == 1;
|
|
|
- BigDecimal totalReceivable = BigDecimal.ZERO;
|
|
|
- BigDecimal totalPayable = BigDecimal.ZERO;
|
|
|
-
|
|
|
- for (CostTypeParam param : typeParams) {
|
|
|
- // 5.1 计算基础保费(平台协议直接用原始保费,私有协议扣税)
|
|
|
- BigDecimal basePremium = isPlatformAgreement ?
|
|
|
- param.premium : divideTaxFactor(param.premium, TAX_FACTOR, SCALE);
|
|
|
-
|
|
|
- // 5.2 计算各类费用
|
|
|
- BigDecimal commission = calculateFee(basePremium, param.commissionRatio, SCALE);
|
|
|
- BigDecimal follow = calculateFee(basePremium, param.followRatio, SCALE);
|
|
|
- BigDecimal addThrow = calculateFee(basePremium, param.addThrowRatio, SCALE);
|
|
|
- BigDecimal keepPoint = calculateFee(basePremium, param.keepPointRatio, SCALE);
|
|
|
- BigDecimal inlet = calculateFee(basePremium, param.inletRatio, SCALE);
|
|
|
- BigDecimal export = calculateFee(basePremium, param.exportRatio, SCALE);
|
|
|
- BigDecimal exportKeepPoint = calculateFee(basePremium, param.exportKeepPointRatio, SCALE);
|
|
|
-
|
|
|
- // 5.3 设置费用到对象(通过反射或方法引用简化setter调用)
|
|
|
- setFeeToOrder(insFeeOrders, param.typePrefix, commission, follow, addThrow, keepPoint, inlet, export, exportKeepPoint);
|
|
|
-
|
|
|
- // 5.4 累加总应收/应付款
|
|
|
- totalReceivable = totalReceivable.add(inlet);
|
|
|
- totalPayable = totalPayable.add(export);
|
|
|
- }
|
|
|
+ // 关键:获取是否含税标识
|
|
|
+ Integer withTax = ptlAgreement.getWithTax(); // 0-否 1-是
|
|
|
+
|
|
|
+ // 保费
|
|
|
+ BigDecimal jqPremium = insOrdersCosts.getJqPremium() == null ? BigDecimal.ZERO : insOrdersCosts.getJqPremium();
|
|
|
+ BigDecimal syPremium = insOrdersCosts.getSyPremium() == null ? BigDecimal.ZERO : insOrdersCosts.getSyPremium();
|
|
|
+ BigDecimal jyPremium = insOrdersCosts.getJyPremium() == null ? BigDecimal.ZERO : insOrdersCosts.getJyPremium();
|
|
|
+
|
|
|
+ // 更新对象中的比例字段
|
|
|
+ saveRatio(ptlAgreementCostRatioVo, insFeeOrders);
|
|
|
+
|
|
|
+ // 核心:规则重新计算所有费用
|
|
|
+ // 1. 交强险
|
|
|
+ calculatePremiumByRule(insFeeOrders, "jq", jqPremium,
|
|
|
+ insFeeOrders.getJqCommissionRatio(), insFeeOrders.getJqInletRatio(), insFeeOrders.getJqFollowRatio(),
|
|
|
+ insFeeOrders.getJqAdditionalRatio(), insFeeOrders.getJqKeepPointRatio(), insFeeOrders.getJqExportRatio(), insFeeOrders.getJqExportKeepPointRatio(),
|
|
|
+ withTax, TAX_RATE, SCALE);
|
|
|
+
|
|
|
+ // 2. 商业险
|
|
|
+ calculatePremiumByRule(insFeeOrders, "sy", syPremium,
|
|
|
+ insFeeOrders.getSyCommissionRatio(), insFeeOrders.getSyInletRatio(), insFeeOrders.getSyFollowRatio(),
|
|
|
+ insFeeOrders.getSyAdditionalRatio(), insFeeOrders.getSyKeepPointRatio(), insFeeOrders.getSyExportRatio(), insFeeOrders.getSyExportKeepPointRatio(),
|
|
|
+ withTax, TAX_RATE, SCALE);
|
|
|
+
|
|
|
+ // 3. 驾乘险
|
|
|
+ calculatePremiumByRule(insFeeOrders, "jy", jyPremium,
|
|
|
+ insFeeOrders.getJyCommissionRatio(), insFeeOrders.getJyInletRatio(), insFeeOrders.getJyFollowRatio(),
|
|
|
+ insFeeOrders.getJyAdditionalRatio(), insFeeOrders.getJyKeepPointRatio(), insFeeOrders.getJyExportRatio(), insFeeOrders.getJyExportKeepPointRatio(),
|
|
|
+ withTax, TAX_RATE, SCALE);
|
|
|
+
|
|
|
+ // 重新统计总应收、总应付
|
|
|
+ BigDecimal totalPayable = insFeeOrders.getJqPayablePremium().add(insFeeOrders.getSyPayablePremium()).add(insFeeOrders.getJyPayablePremium());
|
|
|
+ BigDecimal totalReceivable = insFeeOrders.getJqReceivablePremium().add(insFeeOrders.getSyReceivablePremium()).add(insFeeOrders.getJyReceivablePremium());
|
|
|
|
|
|
- // 6. 设置总费用、 比例并更新
|
|
|
- saveRatio(ptlAgreementCostRatioVo,insFeeOrders);
|
|
|
- insFeeOrders.setTotalReceivablePremium(scale(totalReceivable, SCALE));
|
|
|
insFeeOrders.setTotalPayablePremium(scale(totalPayable, SCALE));
|
|
|
+ insFeeOrders.setTotalReceivablePremium(scale(totalReceivable, SCALE));
|
|
|
+
|
|
|
+ // 保存比例
|
|
|
this.updateById(insFeeOrders);
|
|
|
return insFeeOrders;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 【按你的规则统一计算费用】
|
|
|
+ * withTax=0 → 保费 /1.06
|
|
|
+ * withTax=1 → 直接用保费
|
|
|
+ */
|
|
|
+ private void calculatePremiumByRule(
|
|
|
+ InsFeeOrders insFeeOrders, String type,
|
|
|
+ BigDecimal premium,
|
|
|
+ BigDecimal commissionRatio, BigDecimal inletRatio, BigDecimal followRatio,
|
|
|
+ BigDecimal addThrowRatio, BigDecimal keepPointRatio, BigDecimal exportRatio, BigDecimal exportKeepPointRatio,
|
|
|
+ Integer withTax, BigDecimal taxRate, int scale) {
|
|
|
+
|
|
|
+ // 计算基数
|
|
|
+ BigDecimal base = BigDecimal.ZERO;
|
|
|
+ if (withTax == 0) {
|
|
|
+ // 不含税:保费 / 1.06
|
|
|
+ base = premium.divide(taxRate, scale, RoundingMode.HALF_EVEN);
|
|
|
+ } else {
|
|
|
+ // 含税:直接用保费
|
|
|
+ base = premium;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ===================== 按比例计算各项费用 =====================
|
|
|
+ BigDecimal commission = base.multiply(commissionRatio).setScale(scale, RoundingMode.HALF_EVEN);
|
|
|
+ BigDecimal inlet = base.multiply(inletRatio).setScale(scale, RoundingMode.HALF_EVEN);
|
|
|
+ BigDecimal follow = base.multiply(followRatio).setScale(scale, RoundingMode.HALF_EVEN);
|
|
|
+
|
|
|
+ // 加投直接乘
|
|
|
+ BigDecimal addThrow = premium.multiply(addThrowRatio).setScale(scale, RoundingMode.HALF_EVEN);
|
|
|
+ // 出口直接乘
|
|
|
+ BigDecimal export = premium.multiply(exportRatio).setScale(scale, RoundingMode.HALF_EVEN);
|
|
|
+ BigDecimal exportKeepPoint = premium.multiply(exportKeepPointRatio).setScale(scale, RoundingMode.HALF_EVEN);
|
|
|
+ // 留点比例直接乘
|
|
|
+ BigDecimal keepPoint = premium.multiply(keepPointRatio).setScale(scale, RoundingMode.HALF_EVEN);
|
|
|
+
|
|
|
+ // 赋值到实体(自动匹配 jq / sy / jy)
|
|
|
+ if ("jq".equals(type)) {
|
|
|
+ insFeeOrders.setJqCommissionPremium(commission);
|
|
|
+ insFeeOrders.setJqReceivablePremium(inlet);
|
|
|
+ insFeeOrders.setJqFollowPremium(follow);
|
|
|
+ insFeeOrders.setJqAdditionalPremium(addThrow);
|
|
|
+ insFeeOrders.setJqKeepPointPremium(keepPoint);
|
|
|
+ insFeeOrders.setJqExportPremium(export);
|
|
|
+ insFeeOrders.setJqExportKeepPointPremium(exportKeepPoint);
|
|
|
+ insFeeOrders.setJqPayablePremium(commission);
|
|
|
+ } else if ("sy".equals(type)) {
|
|
|
+ insFeeOrders.setSyCommissionPremium(commission);
|
|
|
+ insFeeOrders.setSyReceivablePremium(inlet);
|
|
|
+ insFeeOrders.setSyFollowPremium(follow);
|
|
|
+ insFeeOrders.setSyAdditionalPremium(addThrow);
|
|
|
+ insFeeOrders.setSyKeepPointPremium(keepPoint);
|
|
|
+ insFeeOrders.setSyExportPremium(export);
|
|
|
+ insFeeOrders.setSyExportKeepPointPremium(exportKeepPoint);
|
|
|
+ insFeeOrders.setSyPayablePremium(commission);
|
|
|
+ } else if ("jy".equals(type)) {
|
|
|
+ insFeeOrders.setJyCommissionPremium(commission);
|
|
|
+ insFeeOrders.setJyReceivablePremium(inlet);
|
|
|
+ insFeeOrders.setJyFollowPremium(follow);
|
|
|
+ insFeeOrders.setJyAdditionalPremium(addThrow);
|
|
|
+ insFeeOrders.setJyKeepPointPremium(keepPoint);
|
|
|
+ insFeeOrders.setJyExportPremium(export);
|
|
|
+ insFeeOrders.setJyExportKeepPointPremium(exportKeepPoint);
|
|
|
+ insFeeOrders.setJyPayablePremium(commission);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 转换百分比
|
|
|
public BigDecimal covertPercent(BigDecimal ratio) {
|
|
|
if (ratio == null) {
|
|
|
@@ -249,8 +282,8 @@ public class InsFeeOrdersServiceImpl extends ServiceImpl<InsFeeOrdersMapper, Ins
|
|
|
insFeeOrders.setJyFollowRatio(insFeeOrders.getJyInletRatio().subtract(insFeeOrders.getJyCommissionRatio()));
|
|
|
// 加投比例
|
|
|
insFeeOrders.setJqAdditionalRatio(covertPercent(ptlAgreementCostRatioVo.getJqAdditionalRatio()));
|
|
|
- insFeeOrders.setSyAdditionalRatio(covertPercent(ptlAgreementCostRatioVo.getJqAdditionalRatio()));
|
|
|
- insFeeOrders.setJyAdditionalRatio(covertPercent(ptlAgreementCostRatioVo.getJqAdditionalRatio()));
|
|
|
+ insFeeOrders.setSyAdditionalRatio(covertPercent(ptlAgreementCostRatioVo.getSyAdditionalRatio()));
|
|
|
+ insFeeOrders.setJyAdditionalRatio(covertPercent(ptlAgreementCostRatioVo.getJyAdditionalRatio()));
|
|
|
// 留点比例
|
|
|
insFeeOrders.setJqKeepPointRatio(covertPercent(ptlAgreementCostRatioVo.getJqKeepPointRatio()));
|
|
|
insFeeOrders.setSyKeepPointRatio(covertPercent(ptlAgreementCostRatioVo.getSyKeepPointRatio()));
|