|
@@ -9,6 +9,9 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
@Service
|
|
|
public class FlashDeliveryRouteService {
|
|
public class FlashDeliveryRouteService {
|
|
|
private static final double EARTH_RADIUS_METERS = 6_371_000D;
|
|
private static final double EARTH_RADIUS_METERS = 6_371_000D;
|
|
|
|
|
+ private static final int MOTORCYCLE_FALLBACK_SPEED_KPH = 25;
|
|
|
|
|
+ private static final int CAR_FALLBACK_SPEED_KPH = 30;
|
|
|
|
|
+ private static final int MINIMUM_FALLBACK_DURATION_SECONDS = 60;
|
|
|
private static final Logger log = LoggerFactory.getLogger(FlashDeliveryRouteService.class);
|
|
private static final Logger log = LoggerFactory.getLogger(FlashDeliveryRouteService.class);
|
|
|
private final RouteDistanceProvider provider;
|
|
private final RouteDistanceProvider provider;
|
|
|
|
|
|
|
@@ -43,7 +46,19 @@ public class FlashDeliveryRouteService {
|
|
|
+ Math.cos(lat1) * Math.cos(lat2)
|
|
+ Math.cos(lat1) * Math.cos(lat2)
|
|
|
* Math.sin(deltaLon / 2) * Math.sin(deltaLon / 2);
|
|
* Math.sin(deltaLon / 2) * Math.sin(deltaLon / 2);
|
|
|
int meters = (int) Math.round(EARTH_RADIUS_METERS * 2D * Math.atan2(Math.sqrt(a), Math.sqrt(1D - a)));
|
|
int meters = (int) Math.round(EARTH_RADIUS_METERS * 2D * Math.atan2(Math.sqrt(a), Math.sqrt(1D - a)));
|
|
|
- return new RouteDistance(Math.max(1, meters), null, "STRAIGHT_LINE");
|
|
|
|
|
|
|
+ int straightLineMeters = Math.max(1, meters);
|
|
|
|
|
+ return new RouteDistance(straightLineMeters, calculateFallbackDurationSeconds(straightLineMeters, selectedVehicle),
|
|
|
|
|
+ "STRAIGHT_LINE");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 地图路线不可用时,按车型保守平均速度估算履约展示时长;该值不参与闪送计价。
|
|
|
|
|
+ */
|
|
|
|
|
+ private int calculateFallbackDurationSeconds(int distanceMeters, int vehicleType) {
|
|
|
|
|
+ int speedKph = vehicleType == FlashDeliveryVehicleType.CAR
|
|
|
|
|
+ ? CAR_FALLBACK_SPEED_KPH : MOTORCYCLE_FALLBACK_SPEED_KPH;
|
|
|
|
|
+ double seconds = distanceMeters * 3_600D / (speedKph * 1_000D);
|
|
|
|
|
+ return Math.max(MINIMUM_FALLBACK_DURATION_SECONDS, (int) Math.ceil(seconds));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void validate(GeoPoint point) {
|
|
private void validate(GeoPoint point) {
|