From 54022987a4a64222b4a2e41b51c4ca4a1631c8fb Mon Sep 17 00:00:00 2001 From: lulz1 Date: Thu, 30 May 2024 09:21:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=80=BB=E8=AE=A2=E5=8D=95=E6=98=8E?= =?UTF-8?q?=E7=BB=86=E8=A1=A8=EF=BC=8C=E9=AB=98=E5=BE=B7=E6=89=93=E8=BD=A6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=9B=AE=E7=9A=84=E5=9C=B0=E5=92=8C=E5=87=BA?= =?UTF-8?q?=E5=8F=91=E5=9C=B0=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/aggregates/order/RouteOrder.java | 41 +++++++++++-------- .../domain/repository/LocationRepository.java | 1 + .../supplier/AmapOrderDataAdapter.java | 23 +++++++++++ .../repository/LocationRepositoryImpl.java | 5 +++ .../jdbc/JdbcLocationRepository.java | 3 ++ src/test/java/com/chint/AmapTest.java | 5 ++- 6 files changed, 58 insertions(+), 20 deletions(-) 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)); } /**