diff --git a/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java b/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java index 862bc7e7..f974681a 100644 --- a/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java +++ b/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java @@ -519,26 +519,28 @@ public class RouteOrder implements Serializable { public Long matchOrderWithLegId(OrderDetail orderDetail) { - if (this.legItems.isEmpty()) { + if (this.legItems == null || this.legItems.isEmpty()) { return null; } - // 定义时间容差(例如1天) + + // Handle taxi legs separately + for (Leg leg : this.legItems) { + if (leg.getLegType().equals(LEG_TYPE_TAXI) && orderDetail.getProductType().equals(LEG_TYPE_TAXI)) { + if (leg.getLegExtensionField() != null && leg.getLegExtensionField().getLocationIdsAsLong() != null) { + if (leg.getLegExtensionField().getLocationIdsAsLong().contains(orderDetail.getOriginId()) || + leg.getLegExtensionField().getLocationIdsAsLong().contains(orderDetail.getDestinationId())) { + return leg.getLegId(); + } + } + } + } + + // Define time tolerance (e.g., 2 days) long tolerance = Duration.ofDays(2).toMillis(); List potentialMatches = this.legItems.stream() .filter(leg -> { - if (leg.getLegType().equals(LEG_TYPE_TAXI) && orderDetail.getProductType().equals(LEG_TYPE_TAXI)) { - if (leg.getLegExtensionField() != null && leg.getLegExtensionField().getLocationIdsAsLong() != null) { - if (leg.getLegExtensionField().getLocationIdsAsLong().contains(orderDetail.getOriginId()) || - leg.getLegExtensionField().getLocationIdsAsLong().contains(orderDetail.getDestinationId())) { - orderDetail.setLegId(leg.getLegId()); - return false; - } - } else { - return false; - } - } - + // Skip taxi legs already handled if (leg.getLegType().equals(LEG_TYPE_TAXI)) { return false; } @@ -547,14 +549,17 @@ public class RouteOrder implements Serializable { Location destinationLocation = leg.getDestinationLocation(); Long orderDetailOriginId = orderDetail.getOriginId(); Long orderDetailDestinationId = orderDetail.getDestinationId(); - return leg.getLegType().equals(orderDetail.getProductType()) && - (originLocation.getLocationId().equals(orderDetailOriginId) || - originLocation.getParentLocationId().equals(orderDetailOriginId) || - originLocation.getLocationPath().contains(String.valueOf(orderDetailOriginId))) + + boolean typeMatches = leg.getLegType().equals(orderDetail.getProductType()); + boolean locationMatches = (originLocation.getLocationId().equals(orderDetailOriginId) || + originLocation.getParentLocationId().equals(orderDetailOriginId) || + originLocation.getLocationPath().contains(String.valueOf(orderDetailOriginId))) && (destinationLocation.getLocationId().equals(orderDetailDestinationId) || destinationLocation.getParentLocationId().equals(orderDetailDestinationId) || destinationLocation.getLocationPath().contains(String.valueOf(orderDetailDestinationId))); + + return typeMatches && locationMatches; }) .toList(); diff --git a/src/main/java/com/chint/domain/repository/LocationRepository.java b/src/main/java/com/chint/domain/repository/LocationRepository.java index 96ac9b13..e870013e 100644 --- a/src/main/java/com/chint/domain/repository/LocationRepository.java +++ b/src/main/java/com/chint/domain/repository/LocationRepository.java @@ -59,4 +59,5 @@ public interface LocationRepository { List findNotChintCityByLevel(String locationNames, Integer level); + List findByLocationNameContainingAndIfInternal(String locationName,Integer ifInternal); } \ No newline at end of file diff --git a/src/main/java/com/chint/domain/service/supplier/AmapOrderDataAdapter.java b/src/main/java/com/chint/domain/service/supplier/AmapOrderDataAdapter.java index b5ab8828..7e91af4f 100644 --- a/src/main/java/com/chint/domain/service/supplier/AmapOrderDataAdapter.java +++ b/src/main/java/com/chint/domain/service/supplier/AmapOrderDataAdapter.java @@ -40,6 +40,7 @@ public class AmapOrderDataAdapter implements OrderDataAdapter { @Autowired private AmapOrderDetailRequest orderDetailRequest; + @Override public Optional adapt(SupplierCallbackData supplierData) { AmapOrderDetailResponse amapOrderDetailResponse = (AmapOrderDetailResponse) supplierData.getData(); @@ -58,6 +59,15 @@ public class AmapOrderDataAdapter implements OrderDataAdapter { Integer personAmount = data.getPersonAmount(); price = String.valueOf((enterpriseAmount == null ? 0 : enterpriseAmount) + (personAmount == null ? 0 : personAmount)); } + + Optional startLocationId = locationRepository + .findByLocationNameContainingAndIfInternal(handlerLocationName(data.getStartCity()), 1).stream().findFirst() + .flatMap(it -> Optional.ofNullable(it.getLocationId())); + + Optional endCityLocationId = locationRepository + .findByLocationNameContainingAndIfInternal(handlerLocationName(data.getEndCity()), 1).stream().findFirst() + .flatMap(it -> Optional.ofNullable(it.getLocationId())); + return Optional.of( OrderLegData.builder() .productType(LEG_TYPE_TAXI) @@ -75,6 +85,8 @@ public class AmapOrderDataAdapter implements OrderDataAdapter { .originOrderStatus(supplierData.getOutOrderStatus()) .destinationName(data.getEndName()) .supplierName(SUPPLIER_AMAP) + .originId(startLocationId.orElse(null)) + .originId(endCityLocationId.orElse(null)) .build()); } @@ -104,6 +116,17 @@ public class AmapOrderDataAdapter implements OrderDataAdapter { } + private String handlerLocationName(String locationName) { + if (locationName == null) { + return null; + } + //如果最后一位是市,去掉最后一位 + if (locationName.endsWith("市")) { + return locationName.substring(0, locationName.length() - 2); + } + return locationName; + } + // AmapOrderDetailResponse response = amapOrderDetailRequest.queryOrderDetail(amapNoteParam.getAmapOrderId()); // AmapOrderDetailResponse.Data data = response.getData(); // diff --git a/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java index bb6b2daa..4bcec56e 100644 --- a/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java @@ -214,5 +214,10 @@ public class LocationRepositoryImpl implements LocationRepository { return hotCities; } + @Override + public List findByLocationNameContainingAndIfInternal(String locationName, Integer ifInternal) { + return jdbcLocationRepository.findByLocationNameContainingAndIsInternal(locationName, ifInternal); + } + } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java index 282bd334..0a833924 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLocationRepository.java @@ -13,9 +13,11 @@ import java.util.List; public interface JdbcLocationRepository extends CrudRepository { Location findByCityIdAndLocationShortName(Long cityId, String locationShortName); + List findByLocationType(Integer locationType); List findByCityIdAndLocationType(Long cityId, Integer locationType); + List findByCityId(Long cityId); Location findByLocationId(Long locationId); @@ -68,4 +70,5 @@ public interface JdbcLocationRepository extends CrudRepository { List findByLevelAndIsInternal(Integer level, Integer isInternal); + List findByLocationNameContainingAndIsInternal(String locationName, Integer isInternal); } diff --git a/src/test/java/com/chint/AmapTest.java b/src/test/java/com/chint/AmapTest.java index a537fdab..607b4aeb 100644 --- a/src/test/java/com/chint/AmapTest.java +++ b/src/test/java/com/chint/AmapTest.java @@ -95,8 +95,9 @@ public class AmapTest { */ @Test public void queryorderDetail() { - AmapOrderDetailResponse orderDetailResponse = orderDetailRequest.queryOrderDetail("40920084001340019626730137"); - System.out.println("orderDetailResponse = " + orderDetailResponse); + Gson gson = new Gson(); + AmapOrderDetailResponse orderDetailResponse = orderDetailRequest.queryOrderDetail("40184156001340013649231865"); + System.out.println(gson.toJson(orderDetailResponse)); } /**