diff --git a/src/main/java/com/chint/application/out/OrderOutController.java b/src/main/java/com/chint/application/out/OrderOutController.java index 86f8b14b..93a99cfc 100644 --- a/src/main/java/com/chint/application/out/OrderOutController.java +++ b/src/main/java/com/chint/application/out/OrderOutController.java @@ -3,6 +3,7 @@ package com.chint.application.out; import com.chint.application.queryies.OrderQuery; import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.domain.value_object.FlightPriceData; import com.chint.domain.value_object.OrderQueryData; import com.chint.domain.value_object.PriceQueryData; import com.chint.domain.value_object.TrainPriceData; @@ -51,4 +52,10 @@ public class OrderOutController { return Result.Success(SUCCESS, orderQuery.queryTrainPrice(priceQueryData)); } + @ApiOperation("查询飞机估算价格") + @PostMapping("/estimate/flight") + public Result estimateFlightPrice(@RequestBody PriceQueryData priceQueryData) { + return Result.Success(SUCCESS, orderQuery.queryFlightPrice(priceQueryData)); + } + } diff --git a/src/main/java/com/chint/application/queryies/estimate/CTripEstimatePrice.java b/src/main/java/com/chint/application/queryies/estimate/CTripEstimatePrice.java index 4fa3338f..b47ecd9b 100644 --- a/src/main/java/com/chint/application/queryies/estimate/CTripEstimatePrice.java +++ b/src/main/java/com/chint/application/queryies/estimate/CTripEstimatePrice.java @@ -6,6 +6,8 @@ import com.chint.domain.value_object.PriceQueryData; import com.chint.domain.value_object.TrainPriceData; import com.chint.interfaces.rest.ctrip.CTripEstimateRequest; import com.chint.interfaces.rest.ctrip.dto.estimate.request.BookingRelatedApiRequest; +import com.chint.interfaces.rest.ctrip.dto.estimate.request.FlightProductInfo; +import com.chint.interfaces.rest.ctrip.dto.estimate.request.RouteInfo; import com.chint.interfaces.rest.ctrip.dto.estimate.request.TrainProductInfo; import com.chint.interfaces.rest.ctrip.dto.estimate.response.BookingRelatedApiResponse; import com.chint.interfaces.rest.ctrip.dto.estimate.response.CTripSeatType; @@ -13,6 +15,9 @@ import com.chint.interfaces.rest.ctrip.dto.estimate.response.TrainValuationResul import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.List; +import java.util.Optional; + @Component public class CTripEstimatePrice implements EstimatePrice { @@ -31,6 +36,7 @@ public class CTripEstimatePrice implements EstimatePrice { trainProductInfo.setDepartCityID( cityRepository.findByCityName(priceQueryData.getDepartCity()).getCity() ); + trainProductInfo.setDepartDate(priceQueryData.getDepartDate()); trainProductInfo.setReturnNoTicket(true); @@ -53,7 +59,29 @@ public class CTripEstimatePrice implements EstimatePrice { @Override public FlightPriceData queryFlightPrice(PriceQueryData priceQueryData) { + FlightProductInfo flightProductInfo = new FlightProductInfo(); + flightProductInfo.setClassType("F"); + RouteInfo routeInfo = new RouteInfo(); + routeInfo.setArriveCityID( + cityRepository.findByCityName(priceQueryData.getArriveCity()).getCity()); + routeInfo.setDepartCityID( + cityRepository.findByCityName(priceQueryData.getDepartCity()).getCity()); + routeInfo.setDepartDate(priceQueryData.getDepartDate()); + flightProductInfo.setRoutes(List.of(routeInfo)); + BookingRelatedApiRequest bookingRelatedApiRequest = cTripEstimateRequest + .generateBaseRequest(flightProductInfo, null); + BookingRelatedApiResponse estimate = cTripEstimateRequest.estimate(bookingRelatedApiRequest); + FlightPriceData flightPriceData = new FlightPriceData(); - return null; + Optional.ofNullable( + estimate.getData().getFlightValuationResult().getMaxPrice() + ).ifPresentOrElse(price -> { + flightPriceData.setSuccess(true); + flightPriceData.setMaxPrice(String.valueOf(price)); + }, () -> { + flightPriceData.setSuccess(false); + flightPriceData.setMaxPrice("无估算价格"); + }); + return flightPriceData; } } diff --git a/src/main/java/com/chint/domain/aggregates/order/OrderDetail.java b/src/main/java/com/chint/domain/aggregates/order/OrderDetail.java index c7684599..6456bc86 100644 --- a/src/main/java/com/chint/domain/aggregates/order/OrderDetail.java +++ b/src/main/java/com/chint/domain/aggregates/order/OrderDetail.java @@ -2,9 +2,17 @@ package com.chint.domain.aggregates.order; import lombok.Data; import org.springframework.data.annotation.Id; +import org.springframework.data.annotation.Transient; +import org.springframework.data.relational.core.mapping.MappedCollection; import org.springframework.data.relational.core.mapping.Table; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import static com.chint.infrastructure.constant.Constant.LEG_EVENT_ORDERED; +import static com.chint.infrastructure.constant.Constant.ORDER_EVENT_PREPARE_NAME; @Data @Table("order_detail") @@ -24,6 +32,11 @@ public class OrderDetail { private LocalDateTime createTime; private LocalDateTime updateTime; // 根据需要添加构造函数、getter、setter等 + @MappedCollection(idColumn = "order_id", keyColumn = "order_key") + private List orderEventList; + + @Transient + private String orderStatus; public static OrderDetail of(String orderNo, String supplierName) { OrderDetail orderDetail = new OrderDetail(); @@ -38,4 +51,29 @@ public class OrderDetail { this.setProductType(productType); return this; } + + public OrderDetail reloadStatus() { + if (this.getOrderEventList() != null && !this.orderEventList.isEmpty()) { + this.orderEventList.stream() + .filter(orderEvent -> orderEvent.getEventType().equals(LEG_EVENT_ORDERED)) + .max(Comparator.comparingLong(OrderEvent::getOrderEventId)) + .ifPresent(event -> this.setOrderStatus(event.reloadStatus().getEventName())); + } else { + this.setOrderStatus(ORDER_EVENT_PREPARE_NAME); + } + return this; + } + + public OrderDetail addOrderEvent(OrderEvent orderEvent) { + if (this.getOrderEventList() == null) { + this.orderEventList = new ArrayList<>(); + } + this.orderEventList.add(orderEvent); + return this; + } + + public OrderDetail price(String price) { + this.price = price; + return this; + } } \ No newline at end of file diff --git a/src/main/java/com/chint/domain/aggregates/order/OrderEvent.java b/src/main/java/com/chint/domain/aggregates/order/OrderEvent.java new file mode 100644 index 00000000..ab7f29e3 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/order/OrderEvent.java @@ -0,0 +1,43 @@ +package com.chint.domain.aggregates.order; + +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.data.annotation.Transient; +import org.springframework.data.relational.core.mapping.Column; +import org.springframework.data.relational.core.mapping.Table; + +import java.time.LocalDateTime; + +import static com.chint.infrastructure.constant.Constant.*; +import static com.chint.infrastructure.constant.Constant.LEG_EVENT_REJECT_NAME; + +@Data +@Table("order_event") +public class OrderEvent { + @Id + private Long orderEventId; + @Column("leg_id") + private Long legId; + + private Integer eventType; + @Transient + private String eventName; + + private LocalDateTime happenTime; + + public String translateOrderEvent(int event) { + return switch (event) { + case ORDER_EVENT_PREPARE -> ORDER_EVENT_PREPARE_NAME; + case ORDER_EVENT_PAYED -> ORDER_EVENT_PAYED_NAME; + case ORDER_EVENT_CHANGE -> ORDER_EVENT_CHANGE_NAME; + case ORDER_EVENT_CANCEL -> ORDER_EVENT_CANCEL_NAME; + case ORDER_EVENT_ORDERED -> ORDER_EVENT_ORDERED_NAME; + default -> "未知事件"; + }; + } + + public OrderEvent reloadStatus() { + this.setEventName(translateOrderEvent(this.eventType)); + return this; + } +} 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 88f0da10..ddd3f1af 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 @@ -102,7 +102,8 @@ public class LegEventHandler implements LegEventService { public void routeAddOrder(RouteAddOrderCommand command) { OrderLegData data = command.getData(); //首先查询到 行程规划订单 , 为形成规划订单添加 外部订单信息 - OrderDetail orderDetail = orderDetailFactory.create(data).productType(data.getProductType()); + OrderDetail orderDetail = orderDetailFactory.create(data) + .price(data.getPrice()).productType(data.getProductType()); String actualOrderNo = data.getActualOrderNo(); RouteOrder routeOrder = routeRepository.findByActualOrderNo(actualOrderNo); routeOrder.addOrderDetail(orderDetail); diff --git a/src/main/java/com/chint/domain/service/supplier/CTripOrderDataAdapter.java b/src/main/java/com/chint/domain/service/supplier/CTripOrderDataAdapter.java index b1b0d141..144f4a9c 100644 --- a/src/main/java/com/chint/domain/service/supplier/CTripOrderDataAdapter.java +++ b/src/main/java/com/chint/domain/service/supplier/CTripOrderDataAdapter.java @@ -1,5 +1,6 @@ package com.chint.domain.service.supplier; +import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.value_object.OrderLegData; import com.chint.domain.value_object.SupplierCallbackData; import com.chint.interfaces.rest.ctrip.dto.search.ItineraryEntity; @@ -78,4 +79,35 @@ public class CTripOrderDataAdapter implements OrderDataAdapter { // 如果没有找到任何只含一个元素的列表,返回null return null; } + + private Integer translateTrainOrderStatus(String trainOrderStatus) { + return switch (trainOrderStatus) { + case "N" -> ORDER_EVENT_PREPARE; //未提交 + case "WP" -> ORDER_EVENT_ORDERED; //待支付 + case "PP" -> ORDER_EVENT_ORDERED; //支付处理中 + case "PF" -> ORDER_EVENT_ORDERED; //支付失败 + case "WA" -> ORDER_EVENT_ORDERED; //待授权 + case "AR" -> ORDER_EVENT_ORDERED; //授权拒绝 + case "WT" -> ORDER_EVENT_ORDERED; //待出票 + case "TP" -> ORDER_EVENT_ORDERED; //购票中 + case "TD" -> ORDER_EVENT_PAYED; //已购票 + case "TF" -> ORDER_EVENT_ORDERED; //出票失败 + case "C" -> ORDER_EVENT_CANCEL; //已取消 + case "CP" -> ORDER_EVENT_ORDERED; //取消中 + default -> throw new NotFoundException(NOT_FOUND); + }; + } + + private Integer translateHotelOrderStatus(String hotelOrderStatus){ + return switch (hotelOrderStatus) { + case "Submitted" -> ORDER_EVENT_PREPARE; //已提交 + case "Wait" -> ORDER_EVENT_ORDERED; //确认中 + case "Confirmed" -> ORDER_EVENT_ORDERED; //已确认 + case "Paid" -> ORDER_EVENT_PAYED; //已付款 + case "Dealed" -> ORDER_EVENT_PAYED; //已成交 + case "Cancelled" -> ORDER_EVENT_CANCEL; //已取消 + case "UnSubmit" -> ORDER_EVENT_CANCEL; //未提交 + default -> throw new NotFoundException(NOT_FOUND); + }; + } } diff --git a/src/main/java/com/chint/domain/value_object/FlightPriceData.java b/src/main/java/com/chint/domain/value_object/FlightPriceData.java index 521fe8f5..9021bddb 100644 --- a/src/main/java/com/chint/domain/value_object/FlightPriceData.java +++ b/src/main/java/com/chint/domain/value_object/FlightPriceData.java @@ -4,5 +4,6 @@ import lombok.Data; @Data public class FlightPriceData { + private boolean success; private String maxPrice; } diff --git a/src/main/java/com/chint/domain/value_object/OrderLegData.java b/src/main/java/com/chint/domain/value_object/OrderLegData.java index 735cbd91..f006b301 100644 --- a/src/main/java/com/chint/domain/value_object/OrderLegData.java +++ b/src/main/java/com/chint/domain/value_object/OrderLegData.java @@ -13,6 +13,7 @@ public class OrderLegData { private String supplierName; private Integer productType; private String price; + private Integer orderStatus; private OrderLegData(Builder builder) { this.actualOrderNo = builder.actualOrderNo; @@ -33,6 +34,7 @@ public class OrderLegData { private String supplierName; private Integer productType; private String price; + private Integer orderStatus; public Builder() { } @@ -62,6 +64,12 @@ public class OrderLegData { return this; } + + public Builder orderStatus(Integer orderStatus) { + this.orderStatus = orderStatus; + return this; + } + public OrderLegData build() { return new OrderLegData(this); } diff --git a/src/main/java/com/chint/infrastructure/constant/Constant.java b/src/main/java/com/chint/infrastructure/constant/Constant.java index 7454615a..7b3a418d 100644 --- a/src/main/java/com/chint/infrastructure/constant/Constant.java +++ b/src/main/java/com/chint/infrastructure/constant/Constant.java @@ -99,6 +99,18 @@ public class Constant { public static final int LEG_EVENT_REJECT = -1; public static final String LEG_EVENT_REJECT_NAME = "拒绝事件"; + // 订单事件 + public static final int ORDER_EVENT_PREPARE = 0; + public static final String ORDER_EVENT_PREPARE_NAME = "未下单"; + public static final int ORDER_EVENT_ORDERED = 1; + public static final String ORDER_EVENT_ORDERED_NAME = "已下单"; + public static final int ORDER_EVENT_PAYED = 2; + public static final String ORDER_EVENT_PAYED_NAME = "已预定"; + public static final int ORDER_EVENT_CHANGE = 3; + public static final String ORDER_EVENT_CHANGE_NAME = "改签"; + public static final int ORDER_EVENT_CANCEL = -1; + public static final String ORDER_EVENT_CANCEL_NAME = "取消"; + // 金额 public static final String KEEP_TWO_DECIMAL_ZERO = "0.00"; diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/CTripOrderSearchRequest.java b/src/main/java/com/chint/interfaces/rest/ctrip/CTripOrderSearchRequest.java index 8b1f0a5f..ed0443ae 100644 --- a/src/main/java/com/chint/interfaces/rest/ctrip/CTripOrderSearchRequest.java +++ b/src/main/java/com/chint/interfaces/rest/ctrip/CTripOrderSearchRequest.java @@ -30,4 +30,17 @@ public class CTripOrderSearchRequest { .done(); return postRequest.post(searchUrl, request, SearchOrderResponse.class); } + + public SearchOrderResponse SearchOrderResponseByOrderId(String orderId){ + String ticket = ticketRequest.loadTicket(); + SearchOrderRequest request = SearchOrderRequest + .builder() + .authInfo() + .details(C_TRIP_APP_KEY, ticket) + .done() + .language(LANGUAGE_CN) + .orderId(orderId) + .done(); + return postRequest.post(searchUrl, request, SearchOrderResponse.class); + } } diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/dto/put/TrainTicketChangeNotification.java b/src/main/java/com/chint/interfaces/rest/ctrip/dto/put/CTripNotification.java similarity index 92% rename from src/main/java/com/chint/interfaces/rest/ctrip/dto/put/TrainTicketChangeNotification.java rename to src/main/java/com/chint/interfaces/rest/ctrip/dto/put/CTripNotification.java index f718c4e5..4d9386f9 100644 --- a/src/main/java/com/chint/interfaces/rest/ctrip/dto/put/TrainTicketChangeNotification.java +++ b/src/main/java/com/chint/interfaces/rest/ctrip/dto/put/CTripNotification.java @@ -6,7 +6,7 @@ import lombok.Data; import java.util.List; @Data -public class TrainTicketChangeNotification { +public class CTripNotification { private String businessId; private String businessType; private String content; diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/dto/search/SearchRequestBuilder.java b/src/main/java/com/chint/interfaces/rest/ctrip/dto/search/SearchRequestBuilder.java index 76526164..1a55ac00 100644 --- a/src/main/java/com/chint/interfaces/rest/ctrip/dto/search/SearchRequestBuilder.java +++ b/src/main/java/com/chint/interfaces/rest/ctrip/dto/search/SearchRequestBuilder.java @@ -16,6 +16,11 @@ public class SearchRequestBuilder { return this; } + public SearchRequestBuilder orderId(String orderId){ + request.setOrderId(orderId); + return this; + } + public SearchOrderRequest done() { return request; } diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/in/CTripNoteController.java b/src/main/java/com/chint/interfaces/rest/ctrip/in/CTripNoteController.java index 63129e7f..886901ec 100644 --- a/src/main/java/com/chint/interfaces/rest/ctrip/in/CTripNoteController.java +++ b/src/main/java/com/chint/interfaces/rest/ctrip/in/CTripNoteController.java @@ -1,7 +1,7 @@ package com.chint.interfaces.rest.ctrip.in; import com.chint.interfaces.rest.ctrip.dto.put.CTripNoteResponse; -import com.chint.interfaces.rest.ctrip.dto.put.TrainTicketChangeNotification; +import com.chint.interfaces.rest.ctrip.dto.put.CTripNotification; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -11,9 +11,17 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping("/public/CTrip") public class CTripNoteController { + + @PostMapping("/event") - public CTripNoteResponse noteEvent(@RequestBody TrainTicketChangeNotification trainTicketChangeNotification) { - if (trainTicketChangeNotification.getContent() != null) { + public CTripNoteResponse noteEvent(@RequestBody CTripNotification cTripNotification) { + if (cTripNotification.getContent() != null) { + //成功触发消息,需要查询对于的订单信息, + + //如果订单不存在需要保存到数据库以及对应的行程规划单下 + + //如果订单以及存在,那么只需要给对应的订单加入对应的事件 + return new CTripNoteResponse("0", "成功收到消息"); } return new CTripNoteResponse("1", "未收到消息"); diff --git a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java index 9b9f524e..9c879bf2 100644 --- a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java +++ b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java @@ -5,9 +5,7 @@ package com.chint.interfaces.rest.user; //import com.chint.dc.api.DataCenterResult; //import com.chint.dc.api.dto.DataCenterOption; //import com.chint.dc.api.service.DataCenterService; -import com.chint.dc.api.DataCenterResult; -import com.chint.dc.api.dto.DataCenterOption; -import com.chint.dc.api.service.DataCenterService; + import com.chint.domain.aggregates.user.User; import com.chint.interfaces.rest.base.PostRequest; import com.chint.interfaces.rest.user.dto.*; @@ -43,14 +41,14 @@ public class UserHttpRequestImpl implements UserHttpRequest { } private User loadSFAndRank(User user) { - List loadSFInfo = loadSFInfo(user); - String custManaLevel = loadSFInfo.get(0).getCust_manaLevel(); - String level = custManaLevel != null ? custManaLevel : "M0"; - if (level.contains("R")) { - level = level.substring(0, level.length() - 3) + "M0"; - } - TravelRankDTO loadTravelRank = loadTravelRank(new TravelRankParam(level)); - user.setRankCode(loadTravelRank.getLEVEL_MAPPING_CODE()); +// List loadSFInfo = loadSFInfo(user); +// String custManaLevel = loadSFInfo.get(0).getCust_manaLevel(); +// String level = custManaLevel != null ? custManaLevel : "M0"; +// if (level.contains("R")) { +// level = level.substring(0, level.length() - 3) + "M0"; +// } +// TravelRankDTO loadTravelRank = loadTravelRank(new TravelRankParam(level)); +// user.setRankCode(loadTravelRank.getLEVEL_MAPPING_CODE()); user.setRankCode("测试职级"); return user; } @@ -70,33 +68,33 @@ public class UserHttpRequestImpl implements UserHttpRequest { } private List loadSFInfo(User user) { - Gson gson = new Gson(); - AccessKeyDTO akSkLoad = akSkLoad(); - DataCenterOption option = new DataCenterOption(); - option.setSk(akSkLoad.sk); - option.setAk(akSkLoad.ak); - option.setUrl(OPENAI_BASE_URL); - DataCenterService dataCenterService = new DataCenterService(option); - LinkedHashMap map = new LinkedHashMap(); - map.put("LoginUsername", user.getEmployeeNo().toString()); - map.put("start", 0); - map.put("pageSize", 1); - DataCenterResult result = dataCenterService.post(USER_DATA_PATH, map); - Type type = new TypeToken>() { - }.getType(); - if (result.getData() != null) { - List fromJson = gson.fromJson(result.getData().toString(), type); - UserDataDTO userDataDTO = fromJson.get(0); - user.setCompanyCode(userDataDTO.getCompany()); - user.setWorkStatus(userDataDTO.getStatus()); - user.setGender(userDataDTO.getGender()); - user.setName(userDataDTO.getUname()); - user.setPhoneNumber(userDataDTO.getMobilePhone()); - return fromJson; - } else { - throw new RuntimeException("用户数据不存在"); - } -// return null; +// Gson gson = new Gson(); +// AccessKeyDTO akSkLoad = akSkLoad(); +// DataCenterOption option = new DataCenterOption(); +// option.setSk(akSkLoad.sk); +// option.setAk(akSkLoad.ak); +// option.setUrl(OPENAI_BASE_URL); +// DataCenterService dataCenterService = new DataCenterService(option); +// LinkedHashMap map = new LinkedHashMap(); +// map.put("LoginUsername", user.getEmployeeNo().toString()); +// map.put("start", 0); +// map.put("pageSize", 1); +// DataCenterResult result = dataCenterService.post(USER_DATA_PATH, map); +// Type type = new TypeToken>() { +// }.getType(); +// if (result.getData() != null) { +// List fromJson = gson.fromJson(result.getData().toString(), type); +// UserDataDTO userDataDTO = fromJson.get(0); +// user.setCompanyCode(userDataDTO.getCompany()); +// user.setWorkStatus(userDataDTO.getStatus()); +// user.setGender(userDataDTO.getGender()); +// user.setName(userDataDTO.getUname()); +// user.setPhoneNumber(userDataDTO.getMobilePhone()); +// return fromJson; +// } else { +// throw new RuntimeException("用户数据不存在"); +// } + return null; } private TravelRankDTO loadTravelRank(TravelRankParam travelRankParam) {