Przeglądaj źródła

原矿运输货损率从物流合同里取

donglang 2 tygodni temu
rodzic
commit
10161be7e3

+ 3 - 2
sckw-common/sckw-common-core/src/main/java/com/sckw/core/common/enums/enums/ErrorCodeEnum.java

@@ -59,8 +59,9 @@ public enum ErrorCodeEnum {
     LOGISTICS_ORDER_NOT_GOODS("700002", "物流订单无商品信息"),
     LOGISTICS_ORDER_NOT_ENT("700003", "物流订单无关联企业信息"),
     LOGISTICS_ORDER_NOT_ADDRESS("700004", "物流订单无装卸货信息"),
-    LOGISTICS_ORDER_AMOUNT_ERROR("70005", "物流运单的总运单量异常"),
-    LOGISTICS_ORDER_NOT_DISPATCH_TRUCK("70005", "物流运单无当前派车数据"),
+    LOGISTICS_ORDER_AMOUNT_ERROR("70005", "物流订单的总运单量异常"),
+    LOGISTICS_ORDER_NOT_DISPATCH_TRUCK("70006", "物流订单无当前派车数据"),
+    LOGISTICS_CONTRACT_NOT_FOUND("70007", "物流订单无合同数据"),
 
     // ====================== 运单订单(80000~89999)======================
     WAYBILL_ORDER_NOT_FOUND("80000", "当前物流运单不存在"),

+ 5 - 0
sckw-modules-api/sckw-contract-api/src/main/java/com/sckw/contract/api/model/vo/KwcContractLogisticsDto.java

@@ -149,4 +149,9 @@ public class KwcContractLogisticsDto implements Serializable {
      */
     private Long supEntId;
 
+    /**
+     * 允许误差(千分比数值,如 5 表示 5‰)
+     */
+    private BigDecimal allowedError;
+
 }

+ 1 - 0
sckw-modules/sckw-contract/src/main/java/com/sckw/contract/dubbo/RemoteContractServiceImpl.java

@@ -333,6 +333,7 @@ public class RemoteContractServiceImpl implements RemoteContractService {
             tradeContractResDto.setId(kwcContractTrade.getId());
             tradeContractResDto.setName(kwcContractTrade.getName());
             tradeContractResDto.setContractNo(kwcContractTrade.getContractNo());
+            tradeContractResDto.setAllowedError(kwcContractTrade.getAllowedError());
             return tradeContractResDto;
         }
         return new KwcContractLogisticsDto();

+ 21 - 4
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/app/GatekeeperOrderService.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.google.common.collect.Lists;
 import com.sckw.contract.api.RemoteContractService;
+import com.sckw.contract.api.model.vo.KwcContractLogisticsDto;
 import com.sckw.core.common.enums.enums.DictTypeEnum;
 import com.sckw.core.common.enums.enums.ErrorCodeEnum;
 import com.sckw.core.exception.BusinessPlatfromException;
@@ -69,6 +70,7 @@ public class GatekeeperOrderService {
     private final KwtWaybillOrderTicketRepository waybillOrderTicketRepository;
     private final KwtLogisticsOrderRepository logisticsOrderRepository;
     private final KwtLogisticsOrderGoodsRepository logisticsOrderGoodsRepository;
+    private final KwtLogisticsOrderContractRepository logisticsOrderContractRepository;
     private final KwtWaybillOrderNodeRepository waybillOrderNodeRepository;
     private final KwtWaybillOrderWeighbridgeRepository waybillOrderWeighbridgeRepository;
     @Autowired
@@ -441,7 +443,7 @@ public class GatekeeperOrderService {
             //计算货损率
             BigDecimal lossRate = calculateLossRate(loadAmount, unloadAmount);
             gatekeeper.setLossRate(lossRate);
-            gatekeeper.setIsPassReason(isLossRateExceeded(lossRate));
+            gatekeeper.setIsPassReason(isLossRateExceeded(logOrder, lossRate));
         }
 
         gatekeeper.setOrderType(logOrder.getOrderType());
@@ -471,9 +473,24 @@ public class GatekeeperOrderService {
     /**
      * 校验货损率是否超过千分之三
      */
-    private static boolean isLossRateExceeded(BigDecimal lossRate) {
-        BigDecimal threshold = new BigDecimal("0.003");
-        return lossRate.compareTo(threshold) > 0;
+    private boolean isLossRateExceeded(KwtLogisticsOrder logOrder, BigDecimal lossRate) {
+        log.info("[门卫]开始计算货损率是否超过配置值,物流订单:{},货损率:{}", JSON.toJSONString(logOrder), JSON.toJSONString(lossRate));
+        KwtLogisticsOrderContract orderContract = logisticsOrderContractRepository.queryByLogOrderId(logOrder.getId());
+        if (orderContract == null) {
+            throw new BusinessPlatfromException(ErrorCodeEnum.LOGISTICS_CONTRACT_NOT_FOUND, "物流订单无合同数据!");
+        }
+        KwcContractLogisticsDto contractLogisticsDto = remoteContractService.queryContractByContractId(orderContract.getContractId());
+        if (contractLogisticsDto == null) {
+            throw new BusinessPlatfromException(ErrorCodeEnum.DATA_NOT_EXIST, "物流合同不存在!");
+        }
+        if (contractLogisticsDto.getAllowedError() == null || contractLogisticsDto.getAllowedError().compareTo(BigDecimal.ZERO) <= 0) {
+            return false;
+        }
+        // 查询出来的货损率为5,表示千分之5,需除以1000
+        BigDecimal allowedError = contractLogisticsDto.getAllowedError().divide(new BigDecimal("1000"), 6, RoundingMode.HALF_UP);
+
+        log.info("[门卫]计算货损率是否超过配置值完成,配置的货损率:{}", JSON.toJSONString(allowedError));
+        return lossRate.compareTo(allowedError) > 0;
     }
 
     /**