donglang 13 часов назад
Родитель
Сommit
0a9c746a2e

+ 60 - 0
sckw-modules-api/sckw-transport-api/src/main/java/com/sckw/transport/api/feign/ParkingWalletFeeFeignService.java

@@ -0,0 +1,60 @@
+package com.sckw.transport.api.feign;
+
+import com.sckw.core.web.response.BaseResult;
+import com.sckw.transport.api.model.param.ParkingWalletFeeFreezeParam;
+import com.sckw.transport.api.model.vo.ParkingWalletFeeFreezeResult;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.math.BigDecimal;
+
+/**
+ * 服务费钱包远程调用 Feign 客户端。
+ *
+ * @author system
+ */
+@FeignClient(name = "sckw-ng-transport", contextId = "parkingWalletFeeFeignService")
+public interface ParkingWalletFeeFeignService {
+
+    /**
+     * 交易订单下单时应用收费策略并冻结服务费余额。
+     *
+     * @param param 冻结参数
+     * @return 收费策略应用结果
+     */
+    @PostMapping("/parking/wallet/remote/apply-charge-strategy-freeze")
+    BaseResult<ParkingWalletFeeFreezeResult> applyChargeStrategyFreeze(@RequestBody @Validated ParkingWalletFeeFreezeParam param);
+
+    /**
+     * 交易订单审核拒绝时解冻服务费并返还余额。
+     *
+     * @param param 解冻参数
+     * @return 解冻结果
+     */
+    @PostMapping("/parking/wallet/remote/unfreeze-charge-strategy")
+    BaseResult<ParkingWalletFeeFreezeResult> unfreezeChargeStrategy(@RequestBody @Validated ParkingWalletFeeFreezeParam param);
+
+    /**
+     * 交易订单完结时结算服务费。
+     *
+     * @param param 结算参数
+     * @return 结算结果
+     */
+    @PostMapping("/parking/wallet/remote/settle-charge-strategy")
+    BaseResult<ParkingWalletFeeFreezeResult> settleChargeStrategy(@RequestBody @Validated ParkingWalletFeeFreezeParam param);
+
+    /**
+     * 查询采购方服务费余额。
+     *
+     * @param proEntId 采购方企业ID
+     * @param supEntId 供应商企业ID,可为空
+     * @return 服务费余额
+     */
+    @GetMapping("/parking/wallet/remote/service-fee-balance")
+    BaseResult<BigDecimal> queryServiceFeeBalance(@RequestParam("proEntId") Long proEntId,
+                                                  @RequestParam(value = "supEntId", required = false) Long supEntId);
+}

+ 39 - 5
sckw-modules/sckw-order/src/main/java/com/sckw/order/serivce/KwoTradeOrderService.java

@@ -87,6 +87,7 @@ import com.sckw.system.api.model.dto.res.*;
 import com.sckw.transport.api.dubbo.ParkingWalletFeeRemoteService;
 import com.sckw.transport.api.dubbo.TransportRemoteStatisticsService;
 import com.sckw.transport.api.dubbo.TransportRemoteService;
+import com.sckw.transport.api.feign.ParkingWalletFeeFeignService;
 import com.sckw.transport.api.model.dto.RawOreOrderExecutionDto;
 import com.sckw.transport.api.model.dto.TradeOrderWaybillAggDto;
 import com.sckw.transport.api.model.param.AddLogisticOrderParam;
@@ -176,6 +177,10 @@ public class KwoTradeOrderService {
     @DubboReference(version = "1.0.0", group = "design", check = false, timeout = 6000)
     private ParkingWalletFeeRemoteService parkingWalletFeeRemoteService;
 
+    @Autowired
+    private ParkingWalletFeeFeignService parkingWalletFeeFeignService;
+
+
     @Autowired
     private PaymentFeignService paymentFeignService;
 
@@ -2252,7 +2257,8 @@ public class KwoTradeOrderService {
         feeFreezeParam.setPurchaseQuantity(tradeOrderParam.getAmount());
         feeFreezeParam.setOperatorId(LoginUserHolder.getUserId());
         log.info("贸易订单下单应用收费策略,orderNo:{}, feeFreezeParam:{}", order.getTOrderNo(), JSON.toJSONString(feeFreezeParam));
-        ParkingWalletFeeFreezeResult feeFreezeResult = parkingWalletFeeRemoteService.applyChargeStrategyFreeze(feeFreezeParam);
+        ParkingWalletFeeFreezeResult feeFreezeResult = resolveParkingWalletFeeFeignResult(
+                parkingWalletFeeFeignService.applyChargeStrategyFreeze(feeFreezeParam), "服务费冻结");
         fillChargeStrategyInfo(order, feeFreezeResult);
         log.info("贸易订单收费策略处理完成,orderNo:{}, feeFreezeResult:{}", order.getTOrderNo(), JSON.toJSONString(feeFreezeResult));
 
@@ -2651,8 +2657,8 @@ public class KwoTradeOrderService {
                 serviceFeeUnfreezeParam.setOperatorId(LoginUserHolder.getUserId());
                 log.info("贸易订单审核拒绝解冻服务费,orderNo:{}, param:{}",
                         kwoTradeOrder.getTOrderNo(), JSON.toJSONString(serviceFeeUnfreezeParam));
-                ParkingWalletFeeFreezeResult unfreezeResult =
-                        parkingWalletFeeRemoteService.unfreezeChargeStrategy(serviceFeeUnfreezeParam);
+                ParkingWalletFeeFreezeResult unfreezeResult = resolveParkingWalletFeeFeignResult(
+                        parkingWalletFeeFeignService.unfreezeChargeStrategy(serviceFeeUnfreezeParam), "服务费解冻");
                 serviceFeeBalance = unfreezeResult.getServiceFeeBalance();
             }
 
@@ -2961,10 +2967,37 @@ public class KwoTradeOrderService {
         }
         Long proEntId = unitMap.get(String.valueOf(1)).getEntId();
         Long supEntId = unitMap.get(String.valueOf(2)).getEntId();
-        resp.setServiceFeeBalance(parkingWalletFeeRemoteService.queryServiceFeeBalance(proEntId, supEntId));
+        resp.setServiceFeeBalance(resolveParkingWalletFeeFeignResult(
+                parkingWalletFeeFeignService.queryServiceFeeBalance(proEntId, supEntId), "服务费余额查询"));
         return resp;
     }
 
+    /**
+     * 统一解析服务费 Feign 调用结果,避免调用点遗漏空响应、失败码和空数据判断。
+     *
+     * @param result        Feign 返回结果
+     * @param operationName 业务操作名称
+     * @param <T>           返回数据类型
+     * @return Feign 响应数据
+     */
+    static <T> T resolveParkingWalletFeeFeignResult(BaseResult<T> result, String operationName) {
+        if (result == null) {
+            log.error("{}失败,服务费Feign响应为空", operationName);
+            throw new BusinessException(operationName + "失败,服务费响应为空");
+        }
+        if (result.getCode() != HttpStatus.SUCCESS_CODE) {
+            log.error("{}失败,服务费Feign返回失败,code:{},message:{}",
+                    operationName, result.getCode(), result.getMessage());
+            throw new BusinessException(operationName + "失败:" + result.getMessage());
+        }
+        if (result.getData() == null) {
+            log.error("{}失败,服务费Feign返回数据为空,code:{},message:{}",
+                    operationName, result.getCode(), result.getMessage());
+            throw new BusinessException(operationName + "失败,服务费返回数据为空");
+        }
+        return result.getData();
+    }
+
     @NotNull
     private List<LogisticsEntDtoVO> checkAutoContractLogOrder(Map<String, KwoTradeOrderUnit> unitMap, KwoTradeOrderGoods byOrderId, TradeContractResDto tradeContractResDto) {
         KwoTradeOrderUnit tradeOrderUnit = unitMap.get(String.valueOf(Global.NUMERICAL_TWO));
@@ -3121,7 +3154,8 @@ public class KwoTradeOrderService {
                 order.getTOrderNo(), proEntId, supEntId, transportNetWeight, order.getChargeStrategyId(),
                 order.getChargeStrategyAmount(), settleParam.getOperatorId());
 
-        ParkingWalletFeeFreezeResult settleResult = parkingWalletFeeRemoteService.settleChargeStrategy(settleParam);
+        ParkingWalletFeeFreezeResult settleResult = resolveParkingWalletFeeFeignResult(
+                parkingWalletFeeFeignService.settleChargeStrategy(settleParam), "服务费完结结算");
         log.info("服务费完结结算完成,订单号:{}, 扣减金额:{}, 收费策略ID:{}, 收费策略描述:{}, 扣减后服务费余额:{}",
                 order.getTOrderNo(), settleResult.getFreezeAmount(), settleResult.getChargeStrategyId(),
                 settleResult.getChargeStrategyDesc(), settleResult.getServiceFeeBalance());

+ 89 - 4
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/controller/ParkingWalletFeeController.java

@@ -3,6 +3,8 @@ package com.sckw.transport.controller;
 
 import com.sckw.core.web.response.BaseResult;
 import com.sckw.core.web.response.result.PageDataResult;
+import com.sckw.transport.api.model.param.ParkingWalletFeeFreezeParam;
+import com.sckw.transport.api.model.vo.ParkingWalletFeeFreezeResult;
 import com.sckw.transport.model.ParkingWalletFeeSaveParam;
 import com.sckw.transport.model.ParkingWalletFeeTotalQueryParam;
 import com.sckw.transport.model.param.ParkingWalletFeeBalanceQueryParam;
@@ -14,10 +16,10 @@ import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import jakarta.validation.Valid;
 import lombok.RequiredArgsConstructor;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+
+import java.math.BigDecimal;
 
 /**s
  * Author: donglang
@@ -30,6 +32,7 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/parking/wallet")
 @RequiredArgsConstructor
 @Tag(name = "服务费接口", description = "服务费接口")
+@Slf4j
 public class ParkingWalletFeeController {
 
     private final ParkingWalletFeeService parkingWalletFeeService;
@@ -87,5 +90,87 @@ public class ParkingWalletFeeController {
         return BaseResult.success(gatekeeperOrderList);
     }
 
+    /**
+     * 交易订单下单时应用收费策略并冻结服务费余额。
+     *
+     * @param param 冻结参数
+     * @return 收费策略应用结果
+     */
+    @PostMapping("/remote/apply-charge-strategy-freeze")
+    public BaseResult<ParkingWalletFeeFreezeResult> applyChargeStrategyFreeze(@RequestBody @Valid ParkingWalletFeeFreezeParam param) {
+        try {
+            return BaseResult.success(parkingWalletFeeService.applyChargeStrategyFreeze(param));
+        } catch (Exception e) {
+            log.error("Feign调用服务费冻结失败,orderNo:{},proEntId:{},supEntId:{}",
+                    param == null ? null : param.getOrderNo(),
+                    param == null ? null : param.getProEntId(),
+                    param == null ? null : param.getSupEntId(), e);
+            return BaseResult.failed(e.getMessage());
+        }
+    }
+
+    /**
+     * 交易订单审核拒绝时解冻服务费并返还余额。
+     *
+     * @param param 解冻参数
+     * @return 解冻结果
+     */
+    @PostMapping("/remote/unfreeze-charge-strategy")
+    public BaseResult<ParkingWalletFeeFreezeResult> unfreezeChargeStrategy(@RequestBody @Valid ParkingWalletFeeFreezeParam param) {
+        try {
+            return BaseResult.success(parkingWalletFeeService.unfreezeChargeStrategy(param));
+        } catch (Exception e) {
+            log.error("Feign调用服务费解冻失败,orderNo:{},proEntId:{},supEntId:{}",
+                    param == null ? null : param.getOrderNo(),
+                    param == null ? null : param.getProEntId(),
+                    param == null ? null : param.getSupEntId(), e);
+            return BaseResult.failed(e.getMessage());
+        }
+    }
+
+    /**
+     * 交易订单完结时结算服务费。
+     *
+     * @param param 结算参数
+     * @return 结算结果
+     */
+    @PostMapping("/remote/settle-charge-strategy")
+    public BaseResult<ParkingWalletFeeFreezeResult> settleChargeStrategy(@RequestBody @Valid ParkingWalletFeeFreezeParam param) {
+        try {
+            log.info("Feign调用服务费完结结算,orderNo:{},proEntId:{},supEntId:{}",
+                    param == null ? null : param.getOrderNo(),
+                    param == null ? null : param.getProEntId(),
+                    param == null ? null : param.getSupEntId());
+            return BaseResult.success(parkingWalletFeeService.settleChargeStrategy(param));
+        } catch (Exception e) {
+            log.error("Feign调用服务费完结结算失败,orderNo:{},proEntId:{},supEntId:{}",
+                    param == null ? null : param.getOrderNo(),
+                    param == null ? null : param.getProEntId(),
+                    param == null ? null : param.getSupEntId(), e);
+            return BaseResult.failed(e.getMessage());
+        }
+    }
+
+    /**
+     * 查询采购方服务费余额。
+     *
+     * @param proEntId 采购方企业ID
+     * @param supEntId 供应商企业ID,可为空
+     * @return 服务费余额
+     */
+    @GetMapping("/remote/service-fee-balance")
+    public BaseResult<BigDecimal> queryServiceFeeBalance(@RequestParam("proEntId") Long proEntId,
+                                                         @RequestParam(value = "supEntId", required = false) Long supEntId) {
+        try {
+            if (proEntId == null) {
+                return BaseResult.failed("采购方企业ID不能为空");
+            }
+            return BaseResult.success(parkingWalletFeeService.queryPurchaserServiceFeeBalance(proEntId, supEntId));
+        } catch (Exception e) {
+            log.error("Feign调用查询服务费余额失败,proEntId:{},supEntId:{}", proEntId, supEntId, e);
+            return BaseResult.failed(e.getMessage());
+        }
+    }
+
 
 }