完成协程数据回推部分内容

This commit is contained in:
Superdandan 2024-02-18 22:48:50 +08:00
parent 365daab0fe
commit 85cfbd5ec6
14 changed files with 238 additions and 44 deletions

View File

@ -3,6 +3,7 @@ package com.chint.application.out;
import com.chint.application.queryies.OrderQuery; import com.chint.application.queryies.OrderQuery;
import com.chint.domain.aggregates.order.RouteOrder; 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.OrderQueryData;
import com.chint.domain.value_object.PriceQueryData; import com.chint.domain.value_object.PriceQueryData;
import com.chint.domain.value_object.TrainPriceData; import com.chint.domain.value_object.TrainPriceData;
@ -51,4 +52,10 @@ public class OrderOutController {
return Result.Success(SUCCESS, orderQuery.queryTrainPrice(priceQueryData)); return Result.Success(SUCCESS, orderQuery.queryTrainPrice(priceQueryData));
} }
@ApiOperation("查询飞机估算价格")
@PostMapping("/estimate/flight")
public Result<FlightPriceData> estimateFlightPrice(@RequestBody PriceQueryData priceQueryData) {
return Result.Success(SUCCESS, orderQuery.queryFlightPrice(priceQueryData));
}
} }

View File

@ -6,6 +6,8 @@ import com.chint.domain.value_object.PriceQueryData;
import com.chint.domain.value_object.TrainPriceData; import com.chint.domain.value_object.TrainPriceData;
import com.chint.interfaces.rest.ctrip.CTripEstimateRequest; 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.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.request.TrainProductInfo;
import com.chint.interfaces.rest.ctrip.dto.estimate.response.BookingRelatedApiResponse; import com.chint.interfaces.rest.ctrip.dto.estimate.response.BookingRelatedApiResponse;
import com.chint.interfaces.rest.ctrip.dto.estimate.response.CTripSeatType; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Optional;
@Component @Component
public class CTripEstimatePrice implements EstimatePrice { public class CTripEstimatePrice implements EstimatePrice {
@ -31,6 +36,7 @@ public class CTripEstimatePrice implements EstimatePrice {
trainProductInfo.setDepartCityID( trainProductInfo.setDepartCityID(
cityRepository.findByCityName(priceQueryData.getDepartCity()).getCity() cityRepository.findByCityName(priceQueryData.getDepartCity()).getCity()
); );
trainProductInfo.setDepartDate(priceQueryData.getDepartDate()); trainProductInfo.setDepartDate(priceQueryData.getDepartDate());
trainProductInfo.setReturnNoTicket(true); trainProductInfo.setReturnNoTicket(true);
@ -53,7 +59,29 @@ public class CTripEstimatePrice implements EstimatePrice {
@Override @Override
public FlightPriceData queryFlightPrice(PriceQueryData priceQueryData) { 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;
} }
} }

View File

@ -2,9 +2,17 @@ package com.chint.domain.aggregates.order;
import lombok.Data; import lombok.Data;
import org.springframework.data.annotation.Id; 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 org.springframework.data.relational.core.mapping.Table;
import java.time.LocalDateTime; 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 @Data
@Table("order_detail") @Table("order_detail")
@ -24,6 +32,11 @@ public class OrderDetail {
private LocalDateTime createTime; private LocalDateTime createTime;
private LocalDateTime updateTime; private LocalDateTime updateTime;
// 根据需要添加构造函数gettersetter等 // 根据需要添加构造函数gettersetter等
@MappedCollection(idColumn = "order_id", keyColumn = "order_key")
private List<OrderEvent> orderEventList;
@Transient
private String orderStatus;
public static OrderDetail of(String orderNo, String supplierName) { public static OrderDetail of(String orderNo, String supplierName) {
OrderDetail orderDetail = new OrderDetail(); OrderDetail orderDetail = new OrderDetail();
@ -38,4 +51,29 @@ public class OrderDetail {
this.setProductType(productType); this.setProductType(productType);
return this; 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;
}
} }

View File

@ -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;
}
}

View File

@ -102,7 +102,8 @@ public class LegEventHandler implements LegEventService {
public void routeAddOrder(RouteAddOrderCommand command) { public void routeAddOrder(RouteAddOrderCommand command) {
OrderLegData data = command.getData(); 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(); String actualOrderNo = data.getActualOrderNo();
RouteOrder routeOrder = routeRepository.findByActualOrderNo(actualOrderNo); RouteOrder routeOrder = routeRepository.findByActualOrderNo(actualOrderNo);
routeOrder.addOrderDetail(orderDetail); routeOrder.addOrderDetail(orderDetail);

View File

@ -1,5 +1,6 @@
package com.chint.domain.service.supplier; 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.OrderLegData;
import com.chint.domain.value_object.SupplierCallbackData; import com.chint.domain.value_object.SupplierCallbackData;
import com.chint.interfaces.rest.ctrip.dto.search.ItineraryEntity; import com.chint.interfaces.rest.ctrip.dto.search.ItineraryEntity;
@ -78,4 +79,35 @@ public class CTripOrderDataAdapter implements OrderDataAdapter {
// 如果没有找到任何只含一个元素的列表返回null // 如果没有找到任何只含一个元素的列表返回null
return 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);
};
}
} }

View File

@ -4,5 +4,6 @@ import lombok.Data;
@Data @Data
public class FlightPriceData { public class FlightPriceData {
private boolean success;
private String maxPrice; private String maxPrice;
} }

View File

@ -13,6 +13,7 @@ public class OrderLegData {
private String supplierName; private String supplierName;
private Integer productType; private Integer productType;
private String price; private String price;
private Integer orderStatus;
private OrderLegData(Builder builder) { private OrderLegData(Builder builder) {
this.actualOrderNo = builder.actualOrderNo; this.actualOrderNo = builder.actualOrderNo;
@ -33,6 +34,7 @@ public class OrderLegData {
private String supplierName; private String supplierName;
private Integer productType; private Integer productType;
private String price; private String price;
private Integer orderStatus;
public Builder() { public Builder() {
} }
@ -62,6 +64,12 @@ public class OrderLegData {
return this; return this;
} }
public Builder orderStatus(Integer orderStatus) {
this.orderStatus = orderStatus;
return this;
}
public OrderLegData build() { public OrderLegData build() {
return new OrderLegData(this); return new OrderLegData(this);
} }

View File

@ -99,6 +99,18 @@ public class Constant {
public static final int LEG_EVENT_REJECT = -1; public static final int LEG_EVENT_REJECT = -1;
public static final String LEG_EVENT_REJECT_NAME = "拒绝事件"; 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"; public static final String KEEP_TWO_DECIMAL_ZERO = "0.00";

View File

@ -30,4 +30,17 @@ public class CTripOrderSearchRequest {
.done(); .done();
return postRequest.post(searchUrl, request, SearchOrderResponse.class); 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);
}
} }

View File

@ -6,7 +6,7 @@ import lombok.Data;
import java.util.List; import java.util.List;
@Data @Data
public class TrainTicketChangeNotification { public class CTripNotification {
private String businessId; private String businessId;
private String businessType; private String businessType;
private String content; private String content;

View File

@ -16,6 +16,11 @@ public class SearchRequestBuilder {
return this; return this;
} }
public SearchRequestBuilder orderId(String orderId){
request.setOrderId(orderId);
return this;
}
public SearchOrderRequest done() { public SearchOrderRequest done() {
return request; return request;
} }

View File

@ -1,7 +1,7 @@
package com.chint.interfaces.rest.ctrip.in; package com.chint.interfaces.rest.ctrip.in;
import com.chint.interfaces.rest.ctrip.dto.put.CTripNoteResponse; 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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -11,9 +11,17 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/public/CTrip") @RequestMapping("/public/CTrip")
public class CTripNoteController { public class CTripNoteController {
@PostMapping("/event") @PostMapping("/event")
public CTripNoteResponse noteEvent(@RequestBody TrainTicketChangeNotification trainTicketChangeNotification) { public CTripNoteResponse noteEvent(@RequestBody CTripNotification cTripNotification) {
if (trainTicketChangeNotification.getContent() != null) { if (cTripNotification.getContent() != null) {
//成功触发消息需要查询对于的订单信息
//如果订单不存在需要保存到数据库以及对应的行程规划单下
//如果订单以及存在那么只需要给对应的订单加入对应的事件
return new CTripNoteResponse("0", "成功收到消息"); return new CTripNoteResponse("0", "成功收到消息");
} }
return new CTripNoteResponse("1", "未收到消息"); return new CTripNoteResponse("1", "未收到消息");

View File

@ -5,9 +5,7 @@ package com.chint.interfaces.rest.user;
//import com.chint.dc.api.DataCenterResult; //import com.chint.dc.api.DataCenterResult;
//import com.chint.dc.api.dto.DataCenterOption; //import com.chint.dc.api.dto.DataCenterOption;
//import com.chint.dc.api.service.DataCenterService; //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.domain.aggregates.user.User;
import com.chint.interfaces.rest.base.PostRequest; import com.chint.interfaces.rest.base.PostRequest;
import com.chint.interfaces.rest.user.dto.*; import com.chint.interfaces.rest.user.dto.*;
@ -43,14 +41,14 @@ public class UserHttpRequestImpl implements UserHttpRequest {
} }
private User loadSFAndRank(User user) { private User loadSFAndRank(User user) {
List<UserDataDTO> loadSFInfo = loadSFInfo(user); // List<UserDataDTO> loadSFInfo = loadSFInfo(user);
String custManaLevel = loadSFInfo.get(0).getCust_manaLevel(); // String custManaLevel = loadSFInfo.get(0).getCust_manaLevel();
String level = custManaLevel != null ? custManaLevel : "M0"; // String level = custManaLevel != null ? custManaLevel : "M0";
if (level.contains("R")) { // if (level.contains("R")) {
level = level.substring(0, level.length() - 3) + "M0"; // level = level.substring(0, level.length() - 3) + "M0";
} // }
TravelRankDTO loadTravelRank = loadTravelRank(new TravelRankParam(level)); // TravelRankDTO loadTravelRank = loadTravelRank(new TravelRankParam(level));
user.setRankCode(loadTravelRank.getLEVEL_MAPPING_CODE()); // user.setRankCode(loadTravelRank.getLEVEL_MAPPING_CODE());
user.setRankCode("测试职级"); user.setRankCode("测试职级");
return user; return user;
} }
@ -70,33 +68,33 @@ public class UserHttpRequestImpl implements UserHttpRequest {
} }
private List<UserDataDTO> loadSFInfo(User user) { private List<UserDataDTO> loadSFInfo(User user) {
Gson gson = new Gson(); // Gson gson = new Gson();
AccessKeyDTO akSkLoad = akSkLoad(); // AccessKeyDTO akSkLoad = akSkLoad();
DataCenterOption option = new DataCenterOption(); // DataCenterOption option = new DataCenterOption();
option.setSk(akSkLoad.sk); // option.setSk(akSkLoad.sk);
option.setAk(akSkLoad.ak); // option.setAk(akSkLoad.ak);
option.setUrl(OPENAI_BASE_URL); // option.setUrl(OPENAI_BASE_URL);
DataCenterService dataCenterService = new DataCenterService(option); // DataCenterService dataCenterService = new DataCenterService(option);
LinkedHashMap map = new LinkedHashMap<String, Object>(); // LinkedHashMap map = new LinkedHashMap<String, Object>();
map.put("LoginUsername", user.getEmployeeNo().toString()); // map.put("LoginUsername", user.getEmployeeNo().toString());
map.put("start", 0); // map.put("start", 0);
map.put("pageSize", 1); // map.put("pageSize", 1);
DataCenterResult result = dataCenterService.post(USER_DATA_PATH, map); // DataCenterResult result = dataCenterService.post(USER_DATA_PATH, map);
Type type = new TypeToken<List<UserDataDTO>>() { // Type type = new TypeToken<List<UserDataDTO>>() {
}.getType(); // }.getType();
if (result.getData() != null) { // if (result.getData() != null) {
List<UserDataDTO> fromJson = gson.fromJson(result.getData().toString(), type); // List<UserDataDTO> fromJson = gson.fromJson(result.getData().toString(), type);
UserDataDTO userDataDTO = fromJson.get(0); // UserDataDTO userDataDTO = fromJson.get(0);
user.setCompanyCode(userDataDTO.getCompany()); // user.setCompanyCode(userDataDTO.getCompany());
user.setWorkStatus(userDataDTO.getStatus()); // user.setWorkStatus(userDataDTO.getStatus());
user.setGender(userDataDTO.getGender()); // user.setGender(userDataDTO.getGender());
user.setName(userDataDTO.getUname()); // user.setName(userDataDTO.getUname());
user.setPhoneNumber(userDataDTO.getMobilePhone()); // user.setPhoneNumber(userDataDTO.getMobilePhone());
return fromJson; // return fromJson;
} else { // } else {
throw new RuntimeException("用户数据不存在"); // throw new RuntimeException("用户数据不存在");
} // }
// return null; return null;
} }
private TravelRankDTO loadTravelRank(TravelRankParam travelRankParam) { private TravelRankDTO loadTravelRank(TravelRankParam travelRankParam) {