2 Commits fd6fc2d35c ... cf45b29d2f

Autor SHA1 Mensaje Fecha
  donglang cf45b29d2f Merge remote-tracking branch 'origin/dev_20251130' into dev_20251130 hace 2 semanas
  donglang d483e9b8f7 优化两地距离计算 hace 2 semanas

+ 13 - 5
sckw-modules/sckw-system/src/main/java/com/sckw/system/dubbo/RemoteSystemServiceImpl.java

@@ -1007,11 +1007,19 @@ public class RemoteSystemServiceImpl implements RemoteSystemService {
         }
 
         //应卸货地与实际卸货地之间距离
-        double twoPlaceDistanceKm = DistanceUtils.calculateDistance(
-                Optional.ofNullable(dto.getLon1()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(dto.getLat1()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(dto.getLon2()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(dto.getLat2()).map(Double::valueOf).orElse(null));
+        double twoPlaceDistanceKm = com.sckw.core.utils.LocUtils.calculateDistanceByAmap(
+                Optional.ofNullable(dto.getLon1()).map(String::valueOf).orElse(null),
+                Optional.ofNullable(dto.getLat1()).map(String::valueOf).orElse(null),
+                Optional.ofNullable(dto.getLon2()).map(String::valueOf).orElse(null),
+                Optional.ofNullable(dto.getLat2()).map(String::valueOf).orElse(null));
+        // 如果高德API调用失败,使用原始方法作为备选
+        if (twoPlaceDistanceKm == -1) {
+            twoPlaceDistanceKm = DistanceUtils.calculateDistance(
+                    Optional.ofNullable(dto.getLon1()).map(Double::valueOf).orElse(null),
+                    Optional.ofNullable(dto.getLat1()).map(Double::valueOf).orElse(null),
+                    Optional.ofNullable(dto.getLon2()).map(Double::valueOf).orElse(null),
+                    Optional.ofNullable(dto.getLat2()).map(Double::valueOf).orElse(null));
+        }
         //运输时间/返回时间(小时) = 两地距离除以平均行驶速度
         if (twoPlaceDistanceKm == 0.0 || Double.isNaN(twoPlaceDistanceKm)) {
             throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "物流运单装货地址有误!");

+ 26 - 10
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/handler/UnloadingHandler.java

@@ -299,11 +299,19 @@ public class UnloadingHandler extends AbstractWaybillOrderHandler<WaybillOrderUn
         KwtWaybillOrderNode unloadingNodes = getNodesByOrderId(waybillOrder.getId(), CarWaybillV1Enum.COMPLETION_LOADING.getCode());
 
         //应卸货地与实际卸货地之间距离
-        double distanceKm = DistanceUtils.calculateDistance(
-                Optional.ofNullable(takeAddress.getLng()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(takeAddress.getLat()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(unloadingNodes.getLng()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(unloadingNodes.getLat()).map(Double::valueOf).orElse(null));
+        double distanceKm = com.sckw.core.utils.LocUtils.calculateDistanceByAmap(
+                Optional.ofNullable(takeAddress.getLng()).map(String::valueOf).orElse(null),
+                Optional.ofNullable(takeAddress.getLat()).map(String::valueOf).orElse(null),
+                Optional.ofNullable(unloadingNodes.getLng()).map(String::valueOf).orElse(null),
+                Optional.ofNullable(unloadingNodes.getLat()).map(String::valueOf).orElse(null));
+        // 如果高德API调用失败,使用原始方法作为备选
+        if (distanceKm == -1) {
+            distanceKm = DistanceUtils.calculateDistance(
+                    Optional.ofNullable(takeAddress.getLng()).map(Double::valueOf).orElse(null),
+                    Optional.ofNullable(takeAddress.getLat()).map(Double::valueOf).orElse(null),
+                    Optional.ofNullable(unloadingNodes.getLng()).map(Double::valueOf).orElse(null),
+                    Optional.ofNullable(unloadingNodes.getLat()).map(Double::valueOf).orElse(null));
+        }
         if (distanceKm > distance) {
             log.info("【虚假卸货】运单ID={},卸货地址偏差={}KM",waybillOrder.getId(), distanceKm);
             //1、更新司机分数(减分)
@@ -411,11 +419,19 @@ public class UnloadingHandler extends AbstractWaybillOrderHandler<WaybillOrderUn
         KwtWaybillOrderAddress takeAddress = addressMap.getOrDefault(AddressTypeEnum.TAKE.getCode(), new KwtWaybillOrderAddress());
 
         //应卸货地与实际卸货地之间距离
-        double twoPlaceDistanceKm = DistanceUtils.calculateDistance(
-                Optional.ofNullable(takeAddress.getLng()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(takeAddress.getLat()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(shipmentAddress.getLng()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(shipmentAddress.getLat()).map(Double::valueOf).orElse(null));
+        double twoPlaceDistanceKm = com.sckw.core.utils.LocUtils.calculateDistanceByAmap(
+                Optional.ofNullable(takeAddress.getLng()).map(String::valueOf).orElse(null),
+                Optional.ofNullable(takeAddress.getLat()).map(String::valueOf).orElse(null),
+                Optional.ofNullable(shipmentAddress.getLng()).map(String::valueOf).orElse(null),
+                Optional.ofNullable(shipmentAddress.getLat()).map(String::valueOf).orElse(null));
+        // 如果高德API调用失败,使用原始方法作为备选
+        if (twoPlaceDistanceKm == -1) {
+            twoPlaceDistanceKm = DistanceUtils.calculateDistance(
+                    Optional.ofNullable(takeAddress.getLng()).map(Double::valueOf).orElse(null),
+                    Optional.ofNullable(takeAddress.getLat()).map(Double::valueOf).orElse(null),
+                    Optional.ofNullable(shipmentAddress.getLng()).map(Double::valueOf).orElse(null),
+                    Optional.ofNullable(shipmentAddress.getLat()).map(Double::valueOf).orElse(null));
+        }
         //运输时间/返回时间(小时) = 两地距离除以平均行驶速度
         if (twoPlaceDistanceKm == 0.0 || Double.isNaN(twoPlaceDistanceKm)) {
             throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "物流运单装货地址有误!");

+ 1 - 1
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/model/param/WaybillOrderStatusResp.java

@@ -174,7 +174,7 @@ public class WaybillOrderStatusResp implements Serializable {
      * 装卸货之间距离
      */
     @Schema(description = "装卸货之间距离")
-    private double distanceKm;
+    private String distanceKm;
 
     /**
      * 派单时间

+ 1 - 1
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/model/vo/WaybillOrderDetailResp.java

@@ -170,7 +170,7 @@ public class WaybillOrderDetailResp implements Serializable {
      * 装卸货之间距离
      */
     @Schema(description = "装卸货之间距离")
-    private double distanceKm;
+    private String distanceKm;
 
     /**
      * 装货地址经度

+ 19 - 45
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/KwtWaybillOrderV1Service.java

@@ -3559,20 +3559,7 @@ public class KwtWaybillOrderV1Service {
         waybillOrderDetailResp.setUnloadAddress(unLoadAdd.getCityName()+unLoadAdd.getDetailAddress());
 
         //预计里程
-        double distanceKm = com.sckw.core.utils.LocUtils.calculateDistanceByAmap(
-                Optional.ofNullable(loadAdd.getLat()).map(String::valueOf).orElse(null),
-                Optional.ofNullable(loadAdd.getLng()).map(String::valueOf).orElse(null),
-                Optional.ofNullable(unLoadAdd.getLat()).map(String::valueOf).orElse(null),
-                Optional.ofNullable(unLoadAdd.getLng()).map(String::valueOf).orElse(null));
-        // 如果高德API调用失败,使用原始方法作为备选
-        if (distanceKm == -1) {
-            distanceKm = DistanceUtils.calculateDistance(
-                Optional.ofNullable(loadAdd.getLat()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(loadAdd.getLng()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(unLoadAdd.getLat()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(unLoadAdd.getLng()).map(Double::valueOf).orElse(null));
-        }
-        waybillOrderDetailResp.setDistanceKm(distanceKm);
+        waybillOrderDetailResp.setDistanceKm(logOrder.getDistance());
         waybillOrderDetailResp.setLoadLatitude(loadAdd.getLat());
         waybillOrderDetailResp.setLoadLongitude(loadAdd.getLng());
         waybillOrderDetailResp.setUnloadLatitude(unLoadAdd.getLat());
@@ -3787,6 +3774,9 @@ public class KwtWaybillOrderV1Service {
             //先不执行自动派单逻辑
             return;
         }
+        //查询物流订单
+        KwtLogisticsOrder logisticsOrder = kwtLogisticsOrderRepository.queryByLogisticsOrderId(billOrder.getLOrderId());
+
         //查询运单装卸货地址
         List<KwtWaybillOrderAddress> addressList = waybillOrderAddressRepository.queryByWOrderId(billOrder.getId());
         if (CollectionUtils.isEmpty(addressList)) {
@@ -3814,10 +3804,10 @@ public class KwtWaybillOrderV1Service {
         }
 
         //2. 校验司机运单完成是否超时
-        checkCompletionTimeout(billOrder, addressMap, driverRulesVO);
+        checkCompletionTimeout(billOrder, logisticsOrder, driverRulesVO);
 
         //3. 校验司机连续准时卸货(审核通过)
-        checkContinuousUnload(billOrder, addressMap);
+        checkContinuousUnload(billOrder, logisticsOrder);
 
         //4. 校验司机连续准确填写卸货信息(审核通过)
         checkContinuousPass(billOrder, addressMap);
@@ -3854,7 +3844,7 @@ public class KwtWaybillOrderV1Service {
      * 校验司机运单完成是否超时
      * @param waybillOrder
      */
-    private void checkCompletionTimeout(KwtWaybillOrder waybillOrder, Map<Integer, KwtWaybillOrderAddress> addressMap,
+    private void checkCompletionTimeout(KwtWaybillOrder waybillOrder, KwtLogisticsOrder logisticsOrder,
                                         DriverConductRulesVO driverRulesVO) {
         //单趟严重超时倍数
         BigDecimal timeoutMultiple = driverRulesVO.getUnloadSeriousTimeoutMultiple();
@@ -3866,7 +3856,7 @@ public class KwtWaybillOrderV1Service {
         }
 
         //校验司机运单完成是否超时
-        Boolean isTimeOut = isTimeOut(waybillOrder, addressMap, timeoutMultiple);
+        Boolean isTimeOut = isTimeOut(waybillOrder, logisticsOrder, timeoutMultiple);
         if (isTimeOut) {
             //1、更新司机分数(减分)
             timeoutScore = -Math.abs(timeoutScore);
@@ -3881,14 +3871,14 @@ public class KwtWaybillOrderV1Service {
     /**
      * 校验司机运单完成是否超时
      * @param waybillOrder 运单
-     * @param addressMap  运单地址
+     * @param logisticsOrder  运单地址
      */
-    protected Boolean isTimeOut(KwtWaybillOrder waybillOrder, Map<Integer, KwtWaybillOrderAddress> addressMap, BigDecimal timeoutMultiple) {
+    protected Boolean isTimeOut(KwtWaybillOrder waybillOrder, KwtLogisticsOrder logisticsOrder, BigDecimal timeoutMultiple) {
         log.info("校验司机运单完成是否超时:运单ID:{}", waybillOrder.getId());
         //运单总耗时
         Long orderTotalTimes = calOrderTotalTimes(waybillOrder);
         //平台配置的单趟总耗时
-        Integer singleTripTotalTimes = calSingleTripTotalTimes(waybillOrder, addressMap);
+        Integer singleTripTotalTimes = calSingleTripTotalTimes(waybillOrder, logisticsOrder);
         //计算超时阈值
         BigDecimal threshold = timeoutMultiple.compareTo(BigDecimal.ZERO) == 0 ?
                 new BigDecimal(singleTripTotalTimes) : timeoutMultiple.multiply(new BigDecimal(singleTripTotalTimes));
@@ -3927,10 +3917,10 @@ public class KwtWaybillOrderV1Service {
     /**
      * 计算平台配置的运单单趟总耗时
      * @param waybillOrder
-     * @param addressMap
+     * @param logisticsOrder
      * @return
      */
-    private Integer calSingleTripTotalTimes(KwtWaybillOrder waybillOrder, Map<Integer, KwtWaybillOrderAddress> addressMap) {
+    private Integer calSingleTripTotalTimes(KwtWaybillOrder waybillOrder, KwtLogisticsOrder logisticsOrder) {
         // 获取自动派单系数配置(单趟耗时 = 装货时间 + 卸货时间 + 运输时间 + 返回时间)
         TruckDispatchCoefficientVO truckDispatchVO = remoteFleetService.findAutoTruckDispatchByEntId(waybillOrder.getEntId());
         if (truckDispatchVO == null) {
@@ -3947,29 +3937,13 @@ public class KwtWaybillOrderV1Service {
                     waybillOrder.getEntId(), vehicleLoadingHours, vehicleUnloadingHours, vehicleAvgSpeed, waybillOrder.getId());
             throw new BusinessPlatfromException(ErrorCodeEnum.DATA_NOT_EXIST, "司机配置的装货时长/卸货时长/平均行驶速度需要≥0!");
         }
-        //查询运单装卸货地址
-        KwtWaybillOrderAddress shipmentAddress = addressMap.getOrDefault(AddressTypeEnum.SHIPMENT.getCode(), new KwtWaybillOrderAddress());
-        KwtWaybillOrderAddress takeAddress = addressMap.getOrDefault(AddressTypeEnum.TAKE.getCode(), new KwtWaybillOrderAddress());
-
         //应卸货地与实际卸货地之间距离
-        double twoPlaceDistanceKm = com.sckw.core.utils.LocUtils.calculateDistanceByAmap(
-                Optional.ofNullable(takeAddress.getLng()).map(String::valueOf).orElse(null),
-                Optional.ofNullable(takeAddress.getLat()).map(String::valueOf).orElse(null),
-                Optional.ofNullable(shipmentAddress.getLng()).map(String::valueOf).orElse(null),
-                Optional.ofNullable(shipmentAddress.getLat()).map(String::valueOf).orElse(null));
-        // 如果高德API调用失败,使用原始方法作为备选
-        if (twoPlaceDistanceKm == -1) {
-            twoPlaceDistanceKm = DistanceUtils.calculateDistance(
-                Optional.ofNullable(takeAddress.getLng()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(takeAddress.getLat()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(shipmentAddress.getLng()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(shipmentAddress.getLat()).map(Double::valueOf).orElse(null));
-        }
-        //运输时间/返回时间(小时) = 两地距离除以平均行驶速度
-        if (twoPlaceDistanceKm == 0.0 || Double.isNaN(twoPlaceDistanceKm)) {
+        String distance = logisticsOrder.getDistance();
+        if (StringUtils.isBlank(distance)) {
             throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "物流运单装货地址有误!");
         }
-        BigDecimal bdDividend = BigDecimal.valueOf(twoPlaceDistanceKm);
+        //运输时间/返回时间(小时) = 两地距离除以平均行驶速度
+        BigDecimal bdDividend = new BigDecimal(distance);
         BigDecimal bdDivisor = BigDecimal.valueOf(vehicleAvgSpeed);
         //运输时间小时
         BigDecimal transportTimeHours = bdDividend.divide(bdDivisor, 4, RoundingMode.HALF_UP);
@@ -3988,7 +3962,7 @@ public class KwtWaybillOrderV1Service {
      * 校验司机连续准时卸货
      * @param waybillOrder
      */
-    private void checkContinuousUnload(KwtWaybillOrder waybillOrder, Map<Integer, KwtWaybillOrderAddress> addressMap) {
+    private void checkContinuousUnload(KwtWaybillOrder waybillOrder, KwtLogisticsOrder logisticsOrder) {
         // 获取司机行为规则配置(连续准时卸货次数)
         DriverConductRulesVO driverRulesVO = remoteFleetService.findDriverConductRulesByEntId(waybillOrder.getEntId());
         if (driverRulesVO == null) {
@@ -4014,7 +3988,7 @@ public class KwtWaybillOrderV1Service {
         List<Long> nodeIds = new ArrayList<>();
         for (KwtWaybillOrderNode orderNode : waybillOrderNodeList) {
             KwtWaybillOrder wOrder = kwtWaybillOrderRepository.queryByBillOrderId(orderNode.getWOrderId());
-            Boolean timeOut = isTimeOut(wOrder, addressMap, BigDecimal.ZERO);
+            Boolean timeOut = isTimeOut(wOrder, logisticsOrder, BigDecimal.ZERO);
             if (timeOut) {
                 log.info("司机{}存在超时情况,运单id:{}", orderNode.getDriverId(), orderNode.getWOrderId());
                 return;

+ 1 - 6
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/app/WaybillOrderService.java

@@ -769,12 +769,7 @@ public class WaybillOrderService {
         wbOrderResp.setUnloadLng(takeAddress.getLng());
         wbOrderResp.setUnloadLat(takeAddress.getLat());
         //装卸地之间距离
-        double distanceKm = DistanceUtils.calculateDistance(
-                Optional.ofNullable(shipmentAddress.getLng()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(shipmentAddress.getLat()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(takeAddress.getLng()).map(Double::valueOf).orElse(null),
-                Optional.ofNullable(takeAddress.getLat()).map(Double::valueOf).orElse(null));
-        wbOrderResp.setDistanceKm(distanceKm);
+        wbOrderResp.setDistanceKm(logOrder.getDistance());
 
         //皮重
         KwtWaybillOrderTicket tareAmountTicket = ticketMap.getOrDefault(wbOrder.getId() + "-" + AddressTypeEnum.SHIPMENT.getCode(), new KwtWaybillOrderTicket());