Просмотр исходного кода

优化批量调整费用比例业务逻辑(新增参数校验、调整计数、留点改出口比例)

lixiaolong 2 месяцев назад
Родитель
Сommit
4005ec120c

+ 17 - 4
commons/src/main/java/com/jzg/commons/entity/dto/PtlAgreementCostBatchAdjustParam.java

@@ -30,9 +30,22 @@ public class PtlAgreementCostBatchAdjustParam {
     @Schema(description = "操作类型:ADD-加,SUBTRACT-减", requiredMode = Schema.RequiredMode.REQUIRED, example = "ADD")
     private String operationType;
 
-    @Schema(description = "入口比例调整值(百分比)")
-    private BigDecimal inletRatio;
+    @Schema(description = "交强险入口比例调整值(百分比)")
+    private BigDecimal jqInletRatio;
+
+    @Schema(description = "交强险出口比例调整值(百分比)")
+    private BigDecimal jqExportRatio;
+
+    @Schema(description = "商业险入口比例调整值(百分比)")
+    private BigDecimal syInletRatio;
+
+    @Schema(description = "商业险出口比例调整值(百分比)")
+    private BigDecimal syExportRatio;
+
+    @Schema(description = "驾意险入口比例调整值(百分比)")
+    private BigDecimal jyInletRatio;
+
+    @Schema(description = "驾意险出口比例调整值(百分比)")
+    private BigDecimal jyExportRatio;
 
-    @Schema(description = "入口留点比例调整值(百分比)")
-    private BigDecimal inletKeepPointRatio;
 }

+ 33 - 11
tenant/organization/src/main/java/com/jzg/organization/service/impl/PtlAgreementCostServiceImpl.java

@@ -521,37 +521,59 @@ public class PtlAgreementCostServiceImpl extends ServiceImpl<PtlAgreementCostMap
 
         boolean isAdd = "ADD".equalsIgnoreCase(param.getOperationType());
 
+        // 校验:至少传递一种险种的比例
+        boolean hasJqRatio = param.getJqInletRatio() != null || param.getJqExportRatio() != null;
+        boolean hasSyRatio = param.getSyInletRatio() != null || param.getSyExportRatio() != null;
+        boolean hasJyRatio = param.getJyInletRatio() != null || param.getJyExportRatio() != null;
+
+        if (!hasJqRatio && !hasSyRatio && !hasJyRatio) {
+            return HttpResult.error("至少需要传递一种险种的比例(交强险/商业险/驾意险)");
+        }
+
+        int adjustedCount = 0;
         for (PtlAgreementCostType costType : costTypeList) {
             String costTypeStr = costType.getCostType();
+            boolean wasAdjusted = false;
 
             // 根据费用类型进行调整
-            if ("交强险".equals(costTypeStr)) {
-                adjustCostType(costType, param.getInletRatio(), param.getInletKeepPointRatio(), isAdd);
-            } else if ("商业险".equals(costTypeStr)) {
-                adjustCostType(costType, param.getInletRatio(), param.getInletKeepPointRatio(), isAdd);
-            } else if ("驾意险".equals(costTypeStr)) {
-                adjustCostType(costType, param.getInletRatio(), param.getInletKeepPointRatio(), isAdd);
+            if ("交强险".equals(costTypeStr) && hasJqRatio) {
+                adjustCostType(costType, param.getJqInletRatio(), param.getJqExportRatio(), isAdd);
+                wasAdjusted = true;
+            } else if ("商业险".equals(costTypeStr) && hasSyRatio) {
+                adjustCostType(costType, param.getSyInletRatio(), param.getSyExportRatio(), isAdd);
+                wasAdjusted = true;
+            } else if ("驾意险".equals(costTypeStr) && hasJyRatio) {
+                adjustCostType(costType, param.getJyInletRatio(), param.getJyExportRatio(), isAdd);
+                wasAdjusted = true;
             }
+
+            if (wasAdjusted) {
+                adjustedCount++;
+            }
+        }
+
+        if (adjustedCount == 0) {
+            return HttpResult.error("未找到匹配的费用类型记录进行调整");
         }
 
         // 批量更新
         ptlAgreementCostTypeService.updateBatchById(costTypeList);
 
-        return HttpResult.ok("批量调整成功");
+        return HttpResult.ok("批量调整成功,共调整 " + adjustedCount + " 条记录");
     }
 
     /**
      * 调整费用类型的各项比例
      */
     private void adjustCostType(PtlAgreementCostType costType, BigDecimal inlet,
-                                BigDecimal keepPointRatio, boolean isAdd) {
+                                BigDecimal export, boolean isAdd) {
         // 入口比例
         if (inlet != null) {
             costType.setInlet(calculateNewValue(costType.getInlet(), inlet, isAdd));
         }
-        // 入口留点比例
-        if (keepPointRatio != null) {
-            costType.setKeepPointRatio(calculateNewValue(costType.getKeepPointRatio(), keepPointRatio, isAdd));
+        // 出口比例
+        if (export != null) {
+            costType.setExport(calculateNewValue(costType.getExport(), export, isAdd));
         }
     }