Преглед на файлове

提交收费系统展示优化

chenxiaofei преди 1 ден
родител
ревизия
b1d689bcb8

+ 9 - 3
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/model/param/ParkingWalletFeeEstimateResp.java

@@ -17,19 +17,25 @@ public class ParkingWalletFeeEstimateResp implements Serializable {
     private static final long serialVersionUID = -5146116069901904418L;
 
     /**
-     * 服务费余额
+     * 是否展示服务费余额和本次预计服务费(收费策略开关开启且采购方收费策略为按吨计费时为 true)
+     */
+    @Schema(description = "是否展示服务费余额和本次预计服务费")
+    private Boolean showServiceFee;
+
+    /**
+     * 服务费余额(showServiceFee 为 true 时返回)
      */
     @Schema(description = "服务费余额")
     private BigDecimal serviceFeeBalance;
 
     /**
-     * 本次预计服务费
+     * 本次预计服务费(showServiceFee 为 true 时返回)
      */
     @Schema(description = "本次预计服务费")
     private BigDecimal estimatedServiceFee;
 
     /**
-     * 最大可购买数量(收费策略开启时,按服务费余额/策略单价计算)
+     * 最大可购买数量(收费策略开启且按吨计费时,按服务费余额/策略单价计算)
      */
     @Schema(description = "最大可购买数量")
     private BigDecimal maxPurchaseQuantity;

+ 39 - 18
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/ParkingWalletFeeService.java

@@ -366,11 +366,12 @@ public class ParkingWalletFeeService {
      * 查询服务费余额、本次预计服务费与最大可购买数量。
      * <p>
      * 业务规则:
-     * 1. 服务费余额取当前登录采购企业的可用服务费余额;
-     * 2. 收费策略总开关关闭时,不计算预计服务费,最大可购买数量返回 null,表示不做余额约束;
-     * 3. 收费策略总开关开启时,按企业绑定的当前收费策略计算预计服务费;无企业策略时使用开关表 default_fee;
-     * 4. 策略 method 为 0.00 时,实际单价使用 kwt_parking_strategy_switch.default_fee;
-     * 5. 最大可购买数量 = 服务费余额 / 实际策略单价,向下取整,避免超出余额。
+     * 1. 服务费余额、本次预计服务费仅当收费策略总开关开启且采购方收费策略为按吨计费时展示,并通过 showServiceFee 标识告知前端;
+     * 2. 服务费余额取当前登录采购企业的可用服务费余额;
+     * 3. 收费策略总开关关闭时,不计算预计服务费,最大可购买数量返回 null,表示不做余额约束;
+     * 4. 收费策略总开关开启时,按企业绑定的当前收费策略计算预计服务费;无企业策略时使用开关表 default_fee;
+     * 5. 策略 method 为 0.00 时,实际单价使用 kwt_parking_strategy_switch.default_fee;
+     * 6. 最大可购买数量 = 服务费余额 / 实际策略单价,向下取整,避免超出余额(仅按吨计费时计算)。
      *
      * @param param 服务费预估查询参数,purchaseQuantity 为本次采购数量
      * @return 服务费余额、本次预计服务费与最大可购买数量
@@ -388,40 +389,49 @@ public class ParkingWalletFeeService {
             throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "采购数量不能为空且不能小于0");
         }
 
-        // 查询采购企业当前可用服务费余额;supEntId 为空时按采购企业汇总口径取最新钱包记录。
-        BigDecimal serviceFeeBalance = queryServiceFeeBalance(entId, null);
-        log.info("服务费预估余额查询完成,企业id:{}, 服务费余额:{}", entId, serviceFeeBalance);
-
         // 收费策略总开关统一以 kwt_parking_strategy_switch.status 为准,策略表 status 不再作为计费开关。
         boolean chargeStrategySwitchOpen = isChargeStrategySwitchOpen();
 
         // 查询当前企业绑定的最新收费策略;无企业策略或 method 为 0.00 时,resolveStrategyUnitFee 会使用开关表 default_fee。
         KwtParkingChargeStrategy currentStrategy = queryCurrentEnableStrategy(entId);
-        BigDecimal currentStrategyUnitFee = resolveStrategyUnitFee(currentStrategy);
-        log.info("服务费预估策略匹配完成,企业id:{}, 开关状态:{}, 策略id:{}, 策略原始单价:{}, 实际计费单价:{}",
+        boolean chargeByTon = isChargeByTonStrategy(currentStrategy);
+        boolean showServiceFeeInfo = chargeStrategySwitchOpen && chargeByTon;
+        log.info("服务费预估展示判断完成,企业id:{}, 开关状态:{}, 策略id:{}, 策略类型:{}, 是否展示服务费信息:{}",
                 entId,
                 chargeStrategySwitchOpen ? "开启" : "关闭",
                 currentStrategy == null ? null : currentStrategy.getId(),
+                currentStrategy == null ? null : currentStrategy.getType(),
+                showServiceFeeInfo);
+
+        // 查询采购企业当前可用服务费余额;supEntId 为空时按采购企业汇总口径取最新钱包记录。
+        BigDecimal serviceFeeBalance = queryServiceFeeBalance(entId, null);
+        log.info("服务费预估余额查询完成,企业id:{}, 服务费余额:{}", entId, serviceFeeBalance);
+
+        BigDecimal currentStrategyUnitFee = resolveStrategyUnitFee(currentStrategy);
+        log.info("服务费预估策略匹配完成,企业id:{}, 策略原始单价:{}, 实际计费单价:{}",
+                entId,
                 currentStrategy == null ? null : currentStrategy.getMethod(),
                 currentStrategyUnitFee);
 
-        // 本次预计服务费 = 采购数量 * 实际计费单价,金额保留2位小数;开关关闭时固定返回0。
-        BigDecimal estimatedServiceFee = chargeStrategySwitchOpen
+        // 本次预计服务费 = 采购数量 * 实际计费单价,金额保留2位小数;不满足展示条件时固定返回0。
+        BigDecimal estimatedServiceFee = showServiceFeeInfo
                 ? formatMoney(param.getPurchaseQuantity().multiply(currentStrategyUnitFee))
                 : formatMoney(ZERO_AMOUNT);
         log.info("服务费预估金额计算完成,企业id:{}, 采购数量:{}, 实际计费单价:{}, 预计服务费:{}",
                 entId, param.getPurchaseQuantity(), currentStrategyUnitFee, estimatedServiceFee);
 
-        // 开关开启且存在有效单价时,按服务费余额计算最大可购买数量;否则返回 null。
-        BigDecimal maxPurchaseQuantity = calculateMaxPurchaseQuantity(currentStrategyUnitFee, serviceFeeBalance);
+        // 按吨计费且存在有效单价时,按服务费余额计算最大可购买数量;否则返回 null。
+        BigDecimal maxPurchaseQuantity = showServiceFeeInfo
+                ? calculateMaxPurchaseQuantity(currentStrategyUnitFee, serviceFeeBalance)
+                : null;
         log.info("服务费预估计算完成,企业id:{}, 采购数量:{}, 服务费余额:{}, 预计服务费:{}, 最大可购买数量:{}",
                 entId, param.getPurchaseQuantity(), serviceFeeBalance, estimatedServiceFee, maxPurchaseQuantity);
 
         ParkingWalletFeeEstimateResp resp = new ParkingWalletFeeEstimateResp();
-        resp.setServiceFeeBalance(formatMoney(serviceFeeBalance));
-        resp.setEstimatedServiceFee(estimatedServiceFee);
+        resp.setShowServiceFee(showServiceFeeInfo);
+        resp.setServiceFeeBalance(showServiceFeeInfo ? formatMoney(serviceFeeBalance) : null);
+        resp.setEstimatedServiceFee(showServiceFeeInfo ? estimatedServiceFee : null);
         resp.setMaxPurchaseQuantity(maxPurchaseQuantity);
-        log.info("服务费预估结束,企业id:{}, 响应结果:{}", entId, resp);
         return resp;
     }
 
@@ -1008,6 +1018,17 @@ public class ParkingWalletFeeService {
     }
 
 
+    /**
+     * 判断采购方收费策略是否为按吨计费。
+     *
+     * @param strategy 采购方当前收费策略
+     * @return true-按吨计费
+     */
+    private boolean isChargeByTonStrategy(KwtParkingChargeStrategy strategy) {
+        return strategy != null
+                && Objects.equals(ParkingChangeStrategyEnum.BY_TON.getCode(), strategy.getType());
+    }
+
     /**
      * 判断收费策略总开关是否开启(以 kwt_parking_strategy_switch 表为准)
      */