Kaynağa Gözat

新增接口批量修改协议费用入口比例、留点比例

lixiaolong 2 ay önce
ebeveyn
işleme
6c1a1e0de0

+ 38 - 0
commons/src/main/java/com/jzg/commons/entity/dto/PtlAgreementCostBatchAdjustParam.java

@@ -0,0 +1,38 @@
+package com.jzg.commons.entity.dto;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotEmpty;
+import jakarta.validation.constraints.NotNull;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * 批量加减费用请求参数
+ *
+ * @author lipf
+ * @date 2026/7/24
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Schema(description = "批量加减费用请求参数")
+public class PtlAgreementCostBatchAdjustParam {
+
+    @NotEmpty(message = "费用ID列表不能为空")
+    @Schema(description = "费用ID列表", requiredMode = Schema.RequiredMode.REQUIRED)
+    private List<String> costIds;
+
+    @NotNull(message = "操作类型不能为空")
+    @Schema(description = "操作类型:ADD-加,SUBTRACT-减", requiredMode = Schema.RequiredMode.REQUIRED, example = "ADD")
+    private String operationType;
+
+    @Schema(description = "入口比例调整值(百分比)")
+    private BigDecimal inletRatio;
+
+    @Schema(description = "入口留点比例调整值(百分比)")
+    private BigDecimal inletKeepPointRatio;
+}

+ 7 - 0
tenant/organization/src/main/java/com/jzg/organization/controller/AgreementController.java

@@ -19,6 +19,7 @@ import com.jzg.organization.service.PtlAgreementDeptService;
 import com.jzg.organization.service.PtlAgreementService;
 import com.jzg.organization.service.PtlAgreementService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.validation.Valid;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.validation.annotation.Validated;
@@ -227,6 +228,12 @@ public class AgreementController extends BaseController {
         return ptlAgreementCostService.batchUpdateValidDate(param);
         return ptlAgreementCostService.batchUpdateValidDate(param);
     }
     }
 
 
+    @Operation(summary = "批量加减费用比例")
+    @PostMapping("/batchAdjustCostRatio")
+    public HttpResult<String> batchAdjustCostRatio(@RequestBody @Valid PtlAgreementCostBatchAdjustParam param) {
+        return ptlAgreementCostService.batchAdjustCostRatio(param);
+    }
+
     /**
     /**
      * 外部协议添加
      * 外部协议添加
      * @param param
      * @param param

+ 9 - 0
tenant/organization/src/main/java/com/jzg/organization/service/PtlAgreementCostService.java

@@ -69,4 +69,13 @@ public interface PtlAgreementCostService extends IService<PtlAgreementCost> {
      */
      */
     HttpResult<String> batchUpdateValidDate(PtlAgreementCostBatchUpdateValidDateParam param);
     HttpResult<String> batchUpdateValidDate(PtlAgreementCostBatchUpdateValidDateParam param);
 
 
+    /**
+     * 批量加减费用比例
+     *
+     * @param param 批量调整参数
+     * @author lipf
+     * @date 2026/7/24
+     */
+    HttpResult<String> batchAdjustCostRatio(PtlAgreementCostBatchAdjustParam param);
+
 }
 }

+ 69 - 0
tenant/organization/src/main/java/com/jzg/organization/service/impl/PtlAgreementCostServiceImpl.java

@@ -42,6 +42,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.CollectionUtils;
 
 
+import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeFormatter;
 import java.util.Arrays;
 import java.util.Arrays;
@@ -499,6 +500,74 @@ public class PtlAgreementCostServiceImpl extends ServiceImpl<PtlAgreementCostMap
                 ? HttpResult.ok("批量修改成功,共修改 " + finalCostIds.size() + " 条记录")
                 ? HttpResult.ok("批量修改成功,共修改 " + finalCostIds.size() + " 条记录")
                 : HttpResult.error("批量修改失败");
                 : HttpResult.error("批量修改失败");
     }
     }
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public HttpResult<String> batchAdjustCostRatio(PtlAgreementCostBatchAdjustParam param) {
+        log.info("批量调整费用比例。param=[{}]", JSONUtil.toJsonStr(param));
+
+        if (CollectionUtils.isEmpty(param.getCostIds())) {
+            return HttpResult.error("费用ID列表不能为空");
+        }
+
+        // 查询所有需要调整的费用类型记录
+        LambdaQueryWrapper<PtlAgreementCostType> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.in(PtlAgreementCostType::getPtlAgreementCostId, param.getCostIds());
+        List<PtlAgreementCostType> costTypeList = ptlAgreementCostTypeService.list(queryWrapper);
+
+        if (CollectionUtils.isEmpty(costTypeList)) {
+            return HttpResult.error("未找到需要调整的费用类型记录");
+        }
 
 
+        boolean isAdd = "ADD".equalsIgnoreCase(param.getOperationType());
+
+        for (PtlAgreementCostType costType : costTypeList) {
+            String costTypeStr = costType.getCostType();
+
+            // 根据费用类型进行调整
+            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);
+            }
+        }
+
+        // 批量更新
+        ptlAgreementCostTypeService.updateBatchById(costTypeList);
+
+        return HttpResult.ok("批量调整成功");
+    }
+
+    /**
+     * 调整费用类型的各项比例
+     */
+    private void adjustCostType(PtlAgreementCostType costType, BigDecimal inlet,
+                                BigDecimal keepPointRatio, boolean isAdd) {
+        // 入口比例
+        if (inlet != null) {
+            costType.setInlet(calculateNewValue(costType.getInlet(), inlet, isAdd));
+        }
+        // 入口留点比例
+        if (keepPointRatio != null) {
+            costType.setKeepPointRatio(calculateNewValue(costType.getKeepPointRatio(), keepPointRatio, isAdd));
+        }
+    }
+
+    /**
+     * 计算新值
+     */
+    private BigDecimal calculateNewValue(BigDecimal currentValue, BigDecimal adjustValue, boolean isAdd) {
+        if (currentValue == null) {
+            currentValue = BigDecimal.ZERO;
+        }
+        if (isAdd) {
+            return currentValue.add(adjustValue);
+        } else {
+            BigDecimal result = currentValue.subtract(adjustValue);
+            // 确保结果不小于0
+            return result.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : result;
+        }
+    }
 
 
 }
 }