diff --git a/src/main/java/com/chint/application/queryies/OrderQuery.java b/src/main/java/com/chint/application/queryies/OrderQuery.java index 87e3aa9f..d2b99264 100644 --- a/src/main/java/com/chint/application/queryies/OrderQuery.java +++ b/src/main/java/com/chint/application/queryies/OrderQuery.java @@ -152,7 +152,7 @@ public class OrderQuery { .skip((long) (pageNum - 1) * pageSize) .limit(pageSize) .map(routeOrder -> { - orderDomainService.queryLocation(routeOrder.getLegItems()); + legDomainService.queryLocation(routeOrder.getLegItems()); User user = userRepository.findByUserEmployeeNo(routeOrder.getUserId()); return getRouteOrderPageRes(routeOrder, user); }) @@ -318,7 +318,7 @@ public class OrderQuery { public RouteOrder queryById(Long routeId) { RouteOrder routeOrder = routeRepository.queryById(routeId); if (routeOrder.getLegItems() != null && routeOrder.getLegItems().isEmpty()) { - orderDomainService.queryLocation(routeOrder.getLegItems()); + legDomainService.queryLocation(routeOrder.getLegItems()); } return routeOrder; } @@ -356,7 +356,7 @@ public class OrderQuery { userRepository.findByUserEmployeeNo(routeOrder.getUserId()) ); List legItems = - orderDomainService.queryLocation(routeOrder.getLegItems()); + legDomainService.queryLocation(routeOrder.getLegItems()); legItems.forEach(leg -> { @@ -523,7 +523,7 @@ public class OrderQuery { if (legItems != null && !legItems.isEmpty()) { //这里使用领域事件进行检查leg的订单状态 ,用户每次想要查看行程都会进行一次检查 legItems.forEach(leg -> legDomainService.legCheckOrder(leg)); - orderDomainService.queryLocation(legItems); + legDomainService.queryLocation(legItems); List list = legItems.stream().map(LegRes::copyFrom).toList(); routeOrderRes.setLegResList(list); List orderDetailResList = routeOrder @@ -548,7 +548,7 @@ public class OrderQuery { List routeOrders = routeRepository.findAllByEmployeeNo(currentUser.getEmployeeNo()); routeOrders = routeOrders.stream().filter(it -> it.getUserId().equals(currentUser.getEmployeeNo())).toList(); routeOrders.forEach(route -> { - orderDomainService.queryLocation(route.getLegItems()); + legDomainService.queryLocation(route.getLegItems()); orderDomainService.checkRouteOrderStatus(route); }); Stream stream = routeOrders.stream(); diff --git a/src/main/java/com/chint/application/services/OrderApplicationService.java b/src/main/java/com/chint/application/services/OrderApplicationService.java index b1019080..3661d20a 100644 --- a/src/main/java/com/chint/application/services/OrderApplicationService.java +++ b/src/main/java/com/chint/application/services/OrderApplicationService.java @@ -93,7 +93,7 @@ public class OrderApplicationService { checkLegDataTime(addLegData, order); LegData legData = addLegData.getLegData(); List legs = processLegData(legData, order); - orderDomainService.queryLocation(legs); + legDomainService.queryLocation(legs); RouteOrder routeOrder = orderDomainService.saveOrder(order); legs.forEach(leg -> { leg.reloadStatus(); @@ -166,7 +166,7 @@ public class OrderApplicationService { } } - orderDomainService.queryLocation(List.of(oldLeg, leg)); + legDomainService.queryLocation(List.of(oldLeg, leg)); //保存变更事件理由 leg = legDomainService.addChangeEvent(leg, legData.getChangeReason()); 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 3a4f88bd..d70fa10f 100644 --- a/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java +++ b/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java @@ -3,6 +3,7 @@ package com.chint.domain.aggregates.order; import com.chint.application.commands.LegOrderedCommand; import com.chint.domain.factoriy.leg.LegFactory; +import com.chint.domain.service.LegDomainService; import com.chint.domain.service.OrderDomainService; import com.chint.domain.service.amount_estimate.EstimateAdapter; import com.chint.domain.service.supplier.SupplierConstantUtil; @@ -456,12 +457,12 @@ public class RouteOrder implements Serializable { return this; } - public OrderDetail matchOrderWithLeg(OrderDetail orderDetail, OrderDomainService orderDomainService) { + public OrderDetail matchOrderWithLeg(OrderDetail orderDetail, LegDomainService legDomainService) { if (this.legItems.isEmpty()) { return orderDetail; } - orderDomainService.queryLocation(this.legItems); + legDomainService.queryLocation(this.legItems); // 定义时间容差(例如1天) long tolerance = Duration.ofDays(2).toMillis(); diff --git a/src/main/java/com/chint/domain/service/LegDomainService.java b/src/main/java/com/chint/domain/service/LegDomainService.java index a031b512..df59af84 100644 --- a/src/main/java/com/chint/domain/service/LegDomainService.java +++ b/src/main/java/com/chint/domain/service/LegDomainService.java @@ -8,8 +8,7 @@ import com.chint.domain.repository.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_CHANGE_MAX_ERROR; import static com.chint.infrastructure.constant.LegConstant.*; @@ -129,21 +128,24 @@ public class LegDomainService { public List queryLocation(List list) { list.forEach(leg -> { LegExtensionField legExtensionField = leg.getLegExtensionField(); - if (legExtensionField != null && legExtensionField.getLocationIds() != null) { + if (legExtensionField != null && legExtensionField.getLocationIds() != null ) { List locationIdsAsLong; if (legExtensionField.getLocationIds().startsWith("[")) { locationIdsAsLong = legExtensionField.getLocationIdsAsLongFromArray(); } else { locationIdsAsLong = legExtensionField.getLocationIdsAsLong(); } - List byNameList = locationRepository.findByNameList(locationIdsAsLong); - legExtensionField.setLocationList(byNameList); + List locationList = legExtensionField.getLocationList(); + if (locationList == null || locationList.size() != locationIdsAsLong.size()) { + List byNameList = locationRepository.findByNameList(locationIdsAsLong); + legExtensionField.setLocationList(byNameList); + } } - if (leg.getOriginId() != null) { + if (leg.getOriginId() != null && leg.getOriginLocation() == null) { leg.setOriginLocation(locationRepository.findByLocationId(leg.getOriginId())); } - if (leg.getDestinationId() != null) { + if (leg.getDestinationId() != null && leg.getDestinationLocation() == null) { leg.setDestinationLocation(locationRepository.findByLocationId(leg.getDestinationId())); } }); diff --git a/src/main/java/com/chint/domain/service/OrderDomainService.java b/src/main/java/com/chint/domain/service/OrderDomainService.java index 47b4633d..b17aa300 100644 --- a/src/main/java/com/chint/domain/service/OrderDomainService.java +++ b/src/main/java/com/chint/domain/service/OrderDomainService.java @@ -129,31 +129,6 @@ public class OrderDomainService { } } - public List queryLocation(List list) { - list.forEach(leg -> { - LegExtensionField legExtensionField = leg.getLegExtensionField(); - if (legExtensionField != null && legExtensionField.getLocationIds() != null) { - List locationIdsAsLong; - if (legExtensionField.getLocationIds().startsWith("[")) { - locationIdsAsLong = legExtensionField.getLocationIdsAsLongFromArray(); - } else { - locationIdsAsLong = legExtensionField.getLocationIdsAsLong(); - } - List byNameList = locationRepository.findByNameList(locationIdsAsLong); - legExtensionField.setLocationList(byNameList); - } - if (leg.getOriginId() != null) { - leg.setOriginLocation(locationRepository.findByLocationId(leg.getOriginId())); - } - - if (leg.getDestinationId() != null) { - leg.setDestinationLocation(locationRepository.findByLocationId(leg.getDestinationId())); - } - }); - return list; - } - - @ListenTo(command = "OrderCreateCommand", order = 0) public RouteOrder createOrder(OrderCreateCommand command) { User user = command.getUser(); diff --git a/src/main/java/com/chint/domain/service/amount_estimate/CTripEstimate.java b/src/main/java/com/chint/domain/service/amount_estimate/CTripEstimate.java index d9a1a304..2b25d869 100644 --- a/src/main/java/com/chint/domain/service/amount_estimate/CTripEstimate.java +++ b/src/main/java/com/chint/domain/service/amount_estimate/CTripEstimate.java @@ -3,6 +3,7 @@ package com.chint.domain.service.amount_estimate; import com.chint.application.queryies.estimate.EstimatePrice; import com.chint.domain.aggregates.order.Leg; import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.domain.service.LegDomainService; import com.chint.domain.service.OrderDomainService; import com.chint.domain.value_object.FlightPriceData; import com.chint.domain.value_object.HotelPriceData; @@ -29,6 +30,9 @@ public class CTripEstimate implements AmountEstimate { @Autowired private OrderDomainService orderDomainService; + @Autowired + private LegDomainService legDomainService; + @Override public String amountEstimate(Leg leg) { @@ -69,7 +73,7 @@ public class CTripEstimate implements AmountEstimate { private PriceQueryData getQueryData(Leg leg) { DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); PriceQueryData priceQueryData = new PriceQueryData(); - leg = orderDomainService.queryLocation(List.of(leg)).get(0); + leg = legDomainService.queryLocation(List.of(leg)).get(0); priceQueryData.setArriveCity(leg.getDestinationLocation().getLocationId()); priceQueryData.setDepartCity(leg.getOriginLocation().getLocationId()); priceQueryData.setDepartDate(dateTimeFormatter.format(leg.getStartTime())); diff --git a/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java b/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java index bd72f340..0502fa22 100644 --- a/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java +++ b/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java @@ -12,6 +12,7 @@ import com.chint.domain.factoriy.leg_event.LegEventFactory; import com.chint.domain.factoriy.order.RouteOrderFactory; import com.chint.domain.factoriy.order_detail.OrderDetailFactory; import com.chint.domain.repository.*; +import com.chint.domain.service.LegDomainService; import com.chint.domain.service.OrderDomainService; import com.chint.domain.service.RouteRequestDomainService; import com.chint.domain.service.order_sync.SyncAdapter; @@ -91,6 +92,9 @@ public class LegEventHandler implements LegEventService { @Autowired private RouteRequestDomainService routeRequestDomainService; + @Autowired + private LegDomainService legDomainService; + @Value("${chint.envMark}") private String envMark; @@ -229,7 +233,7 @@ public class LegEventHandler implements LegEventService { first.isPresent() ) { orderDetail = first.get(); - orderDetail = routeOrder.matchOrderWithLeg(orderDetail, orderDomainService); + orderDetail = routeOrder.matchOrderWithLeg(orderDetail, legDomainService); } } else { orderDetail = byOrderNo.get(); diff --git a/src/main/java/com/chint/domain/service/order_sync/CTripOrderSyncAdapter.java b/src/main/java/com/chint/domain/service/order_sync/CTripOrderSyncAdapter.java index 31ca1734..93c89027 100644 --- a/src/main/java/com/chint/domain/service/order_sync/CTripOrderSyncAdapter.java +++ b/src/main/java/com/chint/domain/service/order_sync/CTripOrderSyncAdapter.java @@ -5,6 +5,7 @@ import com.chint.domain.aggregates.location.basedata.DistrictPOIInfoEntity; import com.chint.domain.aggregates.location.basedata.PrefectureLevelCityInfoEntity; import com.chint.domain.aggregates.order.*; import com.chint.domain.repository.*; +import com.chint.domain.service.LegDomainService; import com.chint.domain.service.LocationDomainService; import com.chint.domain.service.OrderDomainService; import com.chint.interfaces.rest.ctrip.CTripApprovalRequest; @@ -63,6 +64,9 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync { @Autowired private DistrictInfoRepository districtInfoRepository; + @Autowired + private LegDomainService legDomainService; + @Override public boolean syncSupplierOrder(RouteOrder order) { log.info("开始同步携程订单"); @@ -113,7 +117,7 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync { } private ApprovalRequest generateApprovalRequestLegInfo(List legList, String employeeNo, ApprovalRequest approvalRequestParam) { - Map> collect = orderDomainService.queryLocation( + Map> collect = legDomainService.queryLocation( legList.stream() .filter(leg -> leg.getLegType().equals(LEG_TYPE_HOTEL) || leg.getLegType().equals(LEG_TYPE_AIRPLANE) || diff --git a/src/main/java/com/chint/domain/service/order_sync/LYOrderSyncAdapter.java b/src/main/java/com/chint/domain/service/order_sync/LYOrderSyncAdapter.java index cad425de..39d6daf0 100644 --- a/src/main/java/com/chint/domain/service/order_sync/LYOrderSyncAdapter.java +++ b/src/main/java/com/chint/domain/service/order_sync/LYOrderSyncAdapter.java @@ -5,6 +5,7 @@ import com.chint.domain.aggregates.user.User; import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.repository.LocationRepository; import com.chint.domain.repository.UserRepository; +import com.chint.domain.service.LegDomainService; import com.chint.domain.service.OrderDomainService; import com.chint.interfaces.rest.ly.LYPostRequest; import com.chint.interfaces.rest.ly.dto.applyordersync.*; @@ -42,6 +43,8 @@ public class LYOrderSyncAdapter implements SupplierOrderSync { @Value("${ly.baseUrl}") private String lyBaseUrl; + @Autowired + private LegDomainService legDomainService; @Override public boolean syncSupplierOrder(RouteOrder order) { @@ -288,7 +291,7 @@ public class LYOrderSyncAdapter implements SupplierOrderSync { LocalDateTime endDate = LocalDateTime.MIN; StringBuilder departCityStr = new StringBuilder(); StringBuilder arriveCityStr = new StringBuilder(); - orderDomainService.queryLocation(legItems); + legDomainService.queryLocation(legItems); for (Leg leg : legItems) { //开始时间 LocalDateTime startTime = leg.getStartTime();