From 803efc7790570379aea16e3fc5b658c2fe899261 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Tue, 27 Feb 2024 16:11:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/queryies/OrderQuery.java | 8 ++- .../chint/domain/aggregates/order/Leg.java | 5 +- .../amount_estimate/CTripEstimate.java | 59 ++++++++++++++++++- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/chint/application/queryies/OrderQuery.java b/src/main/java/com/chint/application/queryies/OrderQuery.java index b26926f3..1b16c9cc 100644 --- a/src/main/java/com/chint/application/queryies/OrderQuery.java +++ b/src/main/java/com/chint/application/queryies/OrderQuery.java @@ -14,6 +14,7 @@ import com.chint.domain.repository.CityRepository; import com.chint.domain.repository.RouteRepository; import com.chint.domain.repository.UserRepository; import com.chint.domain.service.OrderDomainService; +import com.chint.domain.service.amount_estimate.EstimateAdapter; import com.chint.domain.value_object.*; import com.chint.infrastructure.constant.FSSCConstant; import com.chint.infrastructure.constant.LegConstant; @@ -30,6 +31,9 @@ import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.Stream; +import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_C_TRIP; +import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_L_Y; + @Service public class OrderQuery { @@ -48,6 +52,8 @@ public class OrderQuery { @Autowired private UserRepository userRepository; + @Autowired + private EstimateAdapter estimateAdapter; public RouteOrder queryByOrderId(OrderQueryData queryData) { return routeRepository.queryById(queryData.getRouteId()).reloadStatus(); @@ -246,7 +252,7 @@ public class OrderQuery { .endDate(simpleFormatter.format(leg.getEndTime())) .systemStatus(FSSCConstant.TRIP_CALLBACK_RECEIPT_STATUS) .parentScheduleNum(leg.getLegNo()) - .amount(leg.getAmount()) + .amount(leg.queryEstimateAmount(estimateAdapter,SUPPLIER_C_TRIP).getEstimateAmount()) .reserveCount("1") .quoteGroupNum("0") .extStatus(0) diff --git a/src/main/java/com/chint/domain/aggregates/order/Leg.java b/src/main/java/com/chint/domain/aggregates/order/Leg.java index 4a83322e..0c971028 100644 --- a/src/main/java/com/chint/domain/aggregates/order/Leg.java +++ b/src/main/java/com/chint/domain/aggregates/order/Leg.java @@ -82,12 +82,11 @@ public class Leg { } public Leg queryEstimateAmount(EstimateAdapter estimateAdapter, String supplierName) { - if (this.legStatus >= (LegConstant.LEG_STATUS_NOT_ORDERED)) { - this.estimateAmount = estimateAdapter.of(supplierName).amountEstimate(this); - } + this.estimateAmount = estimateAdapter.of(supplierName).amountEstimate(this); return this; } + public Leg reloadStatus() { if (eventList == null || eventList.isEmpty()) { this.legStatus = LegConstant.LEG_STATUS_PREPARE; 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 75029767..114dcdb4 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 @@ -1,26 +1,79 @@ 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.OrderDomainService; +import com.chint.domain.value_object.FlightPriceData; +import com.chint.domain.value_object.HotelPriceData; +import com.chint.domain.value_object.PriceQueryData; +import com.chint.domain.value_object.TrainPriceData; import com.chint.interfaces.rest.ctrip.CTripEstimateRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.time.format.DateTimeFormatter; +import java.util.List; + +import static com.chint.infrastructure.constant.LegConstant.*; + @Component public class CTripEstimate implements AmountEstimate { @Autowired private CTripEstimateRequest cTripEstimateRequest; + + @Autowired + private EstimatePrice estimatePrice; + + @Autowired + private OrderDomainService orderDomainService; + + @Override public String amountEstimate(Leg leg) { -// cTripEstimateRequest.generateBaseRequest(null,) - - return null; + Integer legType = leg.getLegType(); + return switch (legType) { + case LEG_TYPE_TRAIN -> queryTrainPrice(leg); + case LEG_TYPE_AIRPLANE -> queryTrainPrice(leg); + case LEG_TYPE_HOTEL -> queryTrainPrice(leg); + default -> throw new IllegalStateException("Unexpected value: " + legType); + }; } @Override public String amountEstimate(RouteOrder routeOrder) { return null; } + + + private String queryFlightPrice(Leg leg) { + PriceQueryData queryData = getQueryData(leg); + FlightPriceData flightPriceData = estimatePrice.queryFlightPrice(queryData); + return flightPriceData.getMaxPrice(); + } + + private String queryHotelPrice(Leg leg) { + PriceQueryData queryData = getQueryData(leg); + HotelPriceData hotelPriceData = estimatePrice.queryHotelPrice(queryData); + return hotelPriceData.getMaxPrice(); + } + + private String queryTrainPrice(Leg leg) { + PriceQueryData queryData = getQueryData(leg); + TrainPriceData trainPriceData = estimatePrice.queryTrainPrice(queryData); + return trainPriceData.getMaxPrice(); + } + + + private PriceQueryData getQueryData(Leg leg) { + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + PriceQueryData priceQueryData = new PriceQueryData(); + leg = orderDomainService.queryLocation(List.of(leg)).get(0); + priceQueryData.setArriveCity(leg.getDestinationLocation().getLocationName()); + priceQueryData.setDepartCity(leg.getOriginLocation().getLocationName()); + priceQueryData.setDepartDate(dateTimeFormatter.format(leg.getStartTime())); + return priceQueryData; + } }