From d3ec32a8676cd0a1f0d9c4d4bb21d1d7cc45e567 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Sat, 24 Feb 2024 21:00:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chint/domain/aggregates/order/Leg.java | 28 ++------- .../domain/aggregates/order/LegEvent.java | 13 +--- .../domain/aggregates/order/OrderDetail.java | 1 + .../domain/aggregates/order/RouteOrder.java | 19 ++++++ .../order_detail/OrderDetailFactoryImpl.java | 4 +- .../repository/OrderDetailRepository.java | 3 + .../domain/service/LegDomainService.java | 46 ++++++++++++++ .../domain/service/OrderDomainService.java | 4 ++ .../service/leg_event/LegEventHandler.java | 63 ++++++++----------- .../infrastructure/constant/Constant.java | 2 +- .../echo_framework/manager/EventManager.java | 16 ++--- .../handler/GlobalExceptionHandler.java | 21 ++++++- .../repository/OrderDetailRepositoryImpl.java | 6 ++ .../jdbc/JdbcOrderDetailRepository.java | 4 ++ .../chint/interfaces/rest/ly/BPMRequest.java | 5 +- src/test/java/com/chint/CTripTest.java | 17 +++++ .../java/com/chint/RouteApplicationTests.java | 9 +++ 17 files changed, 177 insertions(+), 84 deletions(-) create mode 100644 src/main/java/com/chint/domain/service/LegDomainService.java 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 fd3398d0..121751f0 100644 --- a/src/main/java/com/chint/domain/aggregates/order/Leg.java +++ b/src/main/java/com/chint/domain/aggregates/order/Leg.java @@ -2,10 +2,10 @@ package com.chint.domain.aggregates.order; import com.chint.domain.exceptions.LegEventException; +import com.chint.domain.repository.OrderDetailRepository; import com.chint.domain.service.amount_estimate.EstimateAdapter; import com.chint.domain.value_object.LegData; import com.chint.domain.value_object.enums.CurrencyType; -import com.chint.infrastructure.util.BigDecimalCalculator; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.NoArgsConstructor; @@ -100,24 +100,6 @@ public class Leg { // Set the legStatus based on the type of the latest event this.legStatus = latestEvent.getEventType(); - - // If the latest event is an order event, update the amount - if (latestEvent.getEventType() >= LEG_EVENT_ORDERED) { - //获取最新的下单事件 - this.eventList - .stream() - .filter(legEvent -> legEvent.getEventType().equals(LEG_EVENT_ORDERED)) - .max(Comparator.comparingLong(LegEvent::getLegEventId)) - .flatMap(event -> Optional.ofNullable(event.getOrderDetails())) - .ifPresent(detail -> { - this.amount = detail.stream() - .map(OrderDetail::getPrice) - .reduce(BigDecimalCalculator::add) - .orElse(KEEP_TWO_DECIMAL_ZERO); - this.orderDetails = detail; - this.currencyType = detail.get(0).getCurrencyType(); - }); - } } this.legStatusName = translateLegStatus(this.legStatus); @@ -129,6 +111,8 @@ public class Leg { if (this.getLegExtensionField() != null && this.getLegExtensionField().getAmountType() != null) { this.getLegExtensionField().reloadStatus(); } + + // return this; } @@ -205,12 +189,12 @@ public class Leg { return this; } - // 如果列表不为空,确保新事件的类型是按顺序的或者与最后一个事件类型相同 + // 如果列表不为空,确保新事件的类型是按顺序的、与最后一个事件类型相同或者浮动为1 if (!eventList.isEmpty()) { LegEvent lastEvent = eventList.get(eventList.size() - 1); int lastEventType = lastEvent.getEventType(); - if (newEventType != lastEventType && newEventType != lastEventType + 1) { - throw new LegEventException("New event must be the same as the last event type or the next in sequence."); + if (newEventType != lastEventType && Math.abs(newEventType - lastEventType) > 1) { + throw new LegEventException("New event must be the same as, immediately before, or immediately after the last event type."); } } diff --git a/src/main/java/com/chint/domain/aggregates/order/LegEvent.java b/src/main/java/com/chint/domain/aggregates/order/LegEvent.java index 374d9f53..a67aa205 100644 --- a/src/main/java/com/chint/domain/aggregates/order/LegEvent.java +++ b/src/main/java/com/chint/domain/aggregates/order/LegEvent.java @@ -4,7 +4,6 @@ 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.MappedCollection; import org.springframework.data.relational.core.mapping.Table; import java.time.LocalDateTime; @@ -27,8 +26,8 @@ public class LegEvent { private LocalDateTime happenTime; - @MappedCollection(idColumn = "leg_event_id",keyColumn = "leg_event_key") - private List orderDetails; + @Transient + private List orderDetailIds; public String translateLegEvent(int event) { return switch (event) { @@ -47,12 +46,4 @@ public class LegEvent { this.setEventName(translateLegEvent(this.eventType)); return this; } - - public LegEvent addOrderDetail(OrderDetail orderDetail){ - if(this.orderDetails == null){ - this.orderDetails = new ArrayList<>(); - } - this.orderDetails.add(orderDetail); - return this; - } } 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 bad6daad..f20d5834 100644 --- a/src/main/java/com/chint/domain/aggregates/order/OrderDetail.java +++ b/src/main/java/com/chint/domain/aggregates/order/OrderDetail.java @@ -20,6 +20,7 @@ import static com.chint.infrastructure.constant.Constant.ORDER_EVENT_UNKNOWN; public class OrderDetail { @Id private Long orderId; // 使用 order_id 作为主键 + private Long legId; // 使用行程节点关联leg private String orderNo; private String supplierName; private Integer productType; // 商品类型 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 92262780..de6cf8f6 100644 --- a/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java +++ b/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java @@ -1,11 +1,13 @@ package com.chint.domain.aggregates.order; +import com.chint.application.commands.LegOrderedCommand; import com.chint.domain.aggregates.base.BaseEntity; import com.chint.domain.factoriy.leg.LegFactory; import com.chint.domain.service.amount_estimate.EstimateAdapter; import com.chint.domain.value_object.LegData; import com.chint.domain.value_object.OrderSaveData; +import com.chint.infrastructure.echo_framework.command.Command; import com.chint.infrastructure.util.BigDecimalCalculator; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; @@ -337,4 +339,21 @@ public class RouteOrder extends BaseEntity { default -> "未知供应商"; }; } + + public void matchOrderWithLeg(OrderDetail orderDetail) { + if (this.legItems.isEmpty()) { + return; + } + this.legItems.stream() + .filter(leg -> leg.getLegType().equals(orderDetail.getProductType()) + && leg.getDestinationId().equals(orderDetail.getDestinationId()) + && leg.getOriginId().equals(orderDetail.getOriginId()) + && leg.getStartTime().isBefore(orderDetail.getStartTime()) + && leg.getEndTime().isAfter(orderDetail.getEndTime())) + .findFirst() + .ifPresent(leg -> Command.of(LegOrderedCommand.class) + .legId(leg.getLegId()) + .orderDetailId(orderDetail.getOrderId()) + .sendToQueue()); + } } \ No newline at end of file diff --git a/src/main/java/com/chint/domain/factoriy/order_detail/OrderDetailFactoryImpl.java b/src/main/java/com/chint/domain/factoriy/order_detail/OrderDetailFactoryImpl.java index abf3b269..c737550b 100644 --- a/src/main/java/com/chint/domain/factoriy/order_detail/OrderDetailFactoryImpl.java +++ b/src/main/java/com/chint/domain/factoriy/order_detail/OrderDetailFactoryImpl.java @@ -13,9 +13,9 @@ public class OrderDetailFactoryImpl implements OrderDetailFactory { @Override public OrderDetail create(OrderLegData orderLegData) { OrderDetail orderDetail = OrderDetail.of(orderLegData.getOutOrderNo(), orderLegData.getSupplierName()); - DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd mm-hh-ss"); + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); orderDetail.setStartTime(LocalDateTime.parse(orderLegData.getStartTime(), dateTimeFormatter)); - orderDetail.setEndTime(LocalDateTime.parse(orderLegData.getEndTime())); + orderDetail.setEndTime(LocalDateTime.parse(orderLegData.getEndTime(), dateTimeFormatter)); orderDetail.setOrderDate(LocalDateTime.parse(orderLegData.getOrderTime(), dateTimeFormatter)); orderDetail.setCurrencyType(CurrencyType.getByCode(orderLegData.getCurrencyCode())); orderDetail.setDestinationId(orderLegData.getDestinationId()); diff --git a/src/main/java/com/chint/domain/repository/OrderDetailRepository.java b/src/main/java/com/chint/domain/repository/OrderDetailRepository.java index cc3ef97f..cb901e7f 100644 --- a/src/main/java/com/chint/domain/repository/OrderDetailRepository.java +++ b/src/main/java/com/chint/domain/repository/OrderDetailRepository.java @@ -2,11 +2,14 @@ package com.chint.domain.repository; import com.chint.domain.aggregates.order.OrderDetail; +import java.util.List; import java.util.Optional; public interface OrderDetailRepository { OrderDetail findById(Long orderDetailId); + List findByLegId(Long legId); + Optional findByOrderNo(String orderNo); OrderDetail save(OrderDetail orderDetail); diff --git a/src/main/java/com/chint/domain/service/LegDomainService.java b/src/main/java/com/chint/domain/service/LegDomainService.java new file mode 100644 index 00000000..a8fe9921 --- /dev/null +++ b/src/main/java/com/chint/domain/service/LegDomainService.java @@ -0,0 +1,46 @@ +package com.chint.domain.service; + +import com.chint.domain.aggregates.order.Leg; +import com.chint.domain.aggregates.order.LegEvent; +import com.chint.domain.aggregates.order.OrderDetail; +import com.chint.domain.factoriy.leg_event.LegEventFactory; +import com.chint.domain.repository.LegRepository; +import com.chint.domain.repository.OrderDetailRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +import static com.chint.infrastructure.constant.Constant.*; + +@Service +public class LegDomainService { + @Autowired + private OrderDetailRepository orderDetailRepository; + + @Autowired + private LegRepository legRepository; + + @Autowired + private LegEventFactory legEventFactory; + + public Leg legCheckOrder(Leg leg) { + List orderDetailList = orderDetailRepository.findByLegId(leg.getLegId()); + orderDetailList.forEach(OrderDetail::reloadStatus); + orderDetailList = orderDetailList.stream().filter(orderDetail -> + List.of(ORDER_EVENT_ORDERED, ORDER_EVENT_PAYED, ORDER_EVENT_CHANGE, ORDER_EVENT_FINISH) + .contains(orderDetail.getOrderStatus()) + ).toList(); + leg.setOrderDetails(orderDetailList); + //如果发现行程节点的状态和订单不匹配 , 那需要进行事件更新 + if (!orderDetailList.isEmpty() && leg.getLegStatus() < LEG_EVENT_ORDERED) { + LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_ORDERED); + leg.addEvent(legEvent); + } + if (orderDetailList.isEmpty() && leg.getLegStatus() >= LEG_EVENT_ORDERED) { + LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_NOT_ORDERED); + leg.addEvent(legEvent); + } + return legRepository.save(leg); + } +} diff --git a/src/main/java/com/chint/domain/service/OrderDomainService.java b/src/main/java/com/chint/domain/service/OrderDomainService.java index acb34138..9f93901d 100644 --- a/src/main/java/com/chint/domain/service/OrderDomainService.java +++ b/src/main/java/com/chint/domain/service/OrderDomainService.java @@ -98,4 +98,8 @@ public class OrderDomainService { orderDetailRepository.save(orderDetail); }); } + + public void legAutoAddOrder(){ + + } } 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 1af37a25..0723d507 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 @@ -4,6 +4,7 @@ import com.chint.application.commands.*; import com.chint.domain.aggregates.order.*; import com.chint.domain.aggregates.user.User; import com.chint.domain.exceptions.CommandException; +import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.exceptions.OrderException; import com.chint.domain.factoriy.leg_event.LegEventFactory; import com.chint.domain.factoriy.order.RouteOrderFactory; @@ -13,12 +14,17 @@ import com.chint.domain.repository.OrderDetailRepository; import com.chint.domain.repository.RouteRepository; import com.chint.domain.repository.UserRepository; import com.chint.domain.service.order_sync.SyncAdapter; -import com.chint.domain.value_object.*; +import com.chint.domain.value_object.ApprovalLegData; +import com.chint.domain.value_object.ApproveLegData; +import com.chint.domain.value_object.OrderLegData; +import com.chint.domain.value_object.SyncLegData; +import com.chint.infrastructure.echo_framework.command.Command; import com.chint.infrastructure.util.BaseContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Comparator; import java.util.Optional; import static com.chint.infrastructure.constant.Constant.*; @@ -113,9 +119,13 @@ public class LegEventHandler implements LegEventService { if (!syncAdapter.of(supplierName).syncSupplierOrder(routeOrder)) { throw new CommandException("订单提交失败"); } - } else { + } + if (routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE)) { throw new CommandException("订单未提交审批"); } + if (routeOrder.getOrderStatus() > (ORDER_STATUS_APPROVAL)) { + throw new CommandException("订单已同步"); + } } @Transactional @@ -133,39 +143,21 @@ public class LegEventHandler implements LegEventService { .stream() .filter(orderDetail -> orderDetail.getOrderNo().equals(data.getOutOrderNo())) .findFirst(); - if (byOrderNo.isEmpty()) -// { -// //如果订单以及存在了,对订单的状态进行更新, -// OrderEvent event = orderDetailFactory.createEvent(data.getOrderStatus(), data.getOriginOrderStatus()); -// OrderDetail orderDetail = byOrderNo.get(); -// orderDetail.addOrderEvent(event); -// } else - { + if (byOrderNo.isEmpty()) { //否则创建新的订单添加到routeOrder OrderDetail orderDetail = orderDetailFactory.create(data) - .price(data.getPrice()).productType(data.getProductType()); - - //为订单添加订单已下单事件 -// OrderEvent orderEvent = orderDetailFactory.createEvent(ORDER_EVENT_PREPARE, data.getOriginOrderStatus()); -// orderDetail.addOrderEvent(orderEvent); routeOrder.addOrderDetail(orderDetail); - //结合外部订单信息,筛选最合适的leg节点 ,触发下单事件 ; - routeOrder.getLegItems() - .stream() - .filter(leg -> leg.getLegType().equals(orderDetail.getProductType()) - && leg.getDestinationId().equals(orderDetail.getDestinationId()) - && leg.getOriginId().equals(orderDetail.getOriginId()) - && leg.getStartTime().isBefore(orderDetail.getStartTime()) - && leg.getEndTime().isAfter(orderDetail.getEndTime())) - .findFirst() - .ifPresent(leg -> { - LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType()); - legEvent.addOrderDetail(orderDetail); - leg.addEvent(legEvent); - }); + //结合外部订单信息,筛选最合适的leg节点 ,触发下单事件; 这里另外发送一个命令用于处理leg和orderDetail之间的关系 } - routeRepository.save(routeOrder); + routeOrder = routeRepository.save(routeOrder); + OrderDetail orderDetail = routeOrder + .getOrderDetails() + .stream() + .max(Comparator.comparing(OrderDetail::getCreateTime)) + .orElseThrow(() -> new NotFoundException(NOT_FOUND)); + //为订单添加订单已下单事件,这里需要发出额外的命令进行处理 + routeOrder.matchOrderWithLeg(orderDetail); } @Transactional @@ -173,25 +165,22 @@ public class LegEventHandler implements LegEventService { public void orderLeg(LegOrderedCommand command) { //如果筛选事件可能会是错误,需要用户手动添加并修改事件 , 因此会进行额外出发修改下单事件。 Leg leg = legRepository.findByLegId(Leg.of(command.getLegId())); - //因为orderDetail已经进行持久化保存 ,只需要从数据库进行查询 OrderDetail orderDetail = orderDetailRepository.findById(command.getOrderDetailId()); LegEvent legEvent = legEventFactory - .creatLegEvent(command.getLegEventType()) - .addOrderDetail(orderDetail); + .creatLegEvent(command.getLegEventType()); leg.addEvent(legEvent); - + orderDetail.setLegId(leg.getLegId()); legRepository.save(leg); + orderDetailRepository.save(orderDetail); } @Transactional @Override public void payForLeg(LegPayedCommand command) { - PayLegData data = command.getData(); +// PayLegData data = command.getData(); Leg leg = legRepository.findByLegId(Leg.of(command.getLegId())); LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType()); - OrderDetail orderDetail = new OrderDetail(); - legEvent.addOrderDetail(orderDetail); leg.addEvent(legEvent); legRepository.save(leg); } diff --git a/src/main/java/com/chint/infrastructure/constant/Constant.java b/src/main/java/com/chint/infrastructure/constant/Constant.java index 963c6677..95053e0d 100644 --- a/src/main/java/com/chint/infrastructure/constant/Constant.java +++ b/src/main/java/com/chint/infrastructure/constant/Constant.java @@ -144,9 +144,9 @@ public class Constant { public static final int ORDER_EVENT_CHANGE = 3; public static final String ORDER_EVENT_CHANGE_NAME = "改签"; public static final int ORDER_EVENT_REFUND = 4; + public static final String ORDER_EVENT_REFUND_NAME = "退票"; public static final int ORDER_EVENT_FINISH = 5; public static final String ORDER_EVENT_FINISH_NAME = "已完成"; - public static final String ORDER_EVENT_REFUND_NAME = "退票"; public static final int ORDER_EVENT_CANCEL = -1; public static final String ORDER_EVENT_CANCEL_NAME = "取消"; public static final int ORDER_EVENT_UNKNOWN = -99; diff --git a/src/main/java/com/chint/infrastructure/echo_framework/manager/EventManager.java b/src/main/java/com/chint/infrastructure/echo_framework/manager/EventManager.java index c5b57e20..4908733e 100644 --- a/src/main/java/com/chint/infrastructure/echo_framework/manager/EventManager.java +++ b/src/main/java/com/chint/infrastructure/echo_framework/manager/EventManager.java @@ -1,7 +1,6 @@ package com.chint.infrastructure.echo_framework.manager; -import com.chint.domain.service.leg_event.LegEventService; import com.chint.infrastructure.echo_framework.annotation.ListenTo; import com.chint.infrastructure.echo_framework.annotation.TransitionTo; import com.chint.infrastructure.echo_framework.command.Command; @@ -18,9 +17,7 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.support.TransactionTemplate; -import com.chint.domain.service.leg_event.LegEventServiceImpl; -import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.*; @@ -87,14 +84,17 @@ public class EventManager implements ApplicationContextAware, BeanNameAware, Ini List containers = listenerMethods.getOrDefault(command.getCommandName(), Collections.emptyList()); List resultContainers = new ArrayList<>(); containers.forEach(container -> { + + Object result = null; try { - Object result = container.getMethod().invoke(container.getBean(), command); - if (result instanceof ResultContainer) { - resultContainers.add((ResultContainer) result); - } + result = container.getMethod().invoke(container.getBean(), command); } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); // Handle exceptions appropriately + throw new RuntimeException(e); } + if (result instanceof ResultContainer) { + resultContainers.add((ResultContainer) result); + } + }); return resultContainers; } diff --git a/src/main/java/com/chint/infrastructure/handler/GlobalExceptionHandler.java b/src/main/java/com/chint/infrastructure/handler/GlobalExceptionHandler.java index d207e56a..734c31ab 100644 --- a/src/main/java/com/chint/infrastructure/handler/GlobalExceptionHandler.java +++ b/src/main/java/com/chint/infrastructure/handler/GlobalExceptionHandler.java @@ -8,7 +8,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; -import java.util.Optional; +import java.lang.reflect.InvocationTargetException; @RestControllerAdvice @Slf4j @@ -37,4 +37,23 @@ public class GlobalExceptionHandler { public Result handleDuplicateException(HttpServletRequest request, DuplicateException e) { return Result.error(e.getMessage()); } + + @ExceptionHandler(value = Exception.class) + public Result handleException(Exception ex) { + Throwable rootCause = ex; + // 检查是否是通过反射调用抛出的异常 + Throwable cause = rootCause.getCause(); + while (rootCause instanceof InvocationTargetException && cause != null) { + rootCause = cause; + } + return Result.error(cause.getCause().getMessage()); +// // 根据不同的异常类型进行处理 +// if (rootCause instanceof CommandException) { +// // 特定异常的处理逻辑 +// return new ResponseEntity<>("订单未提交审批", HttpStatus.BAD_REQUEST); +// } else { +// // 其他异常的处理逻辑 +// return new ResponseEntity<>("内部服务器错误", HttpStatus.INTERNAL_SERVER_ERROR); +// } + } } diff --git a/src/main/java/com/chint/infrastructure/repository/OrderDetailRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/OrderDetailRepositoryImpl.java index f06d3fec..5bb3aa86 100644 --- a/src/main/java/com/chint/infrastructure/repository/OrderDetailRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/OrderDetailRepositoryImpl.java @@ -7,6 +7,7 @@ import com.chint.infrastructure.repository.jdbc.JdbcOrderDetailRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Optional; import static com.chint.infrastructure.constant.Constant.NOT_FOUND; @@ -21,6 +22,11 @@ public class OrderDetailRepositoryImpl implements OrderDetailRepository { return orderDetailRepository.findById(orderDetailId).orElseThrow(() -> new NotFoundException(NOT_FOUND)); } + @Override + public List findByLegId(Long legId) { + return orderDetailRepository.findByLegId(legId); + } + @Override public Optional findByOrderNo(String orderNo) { return Optional.ofNullable(orderDetailRepository.findByOrderNo(orderNo)); diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderDetailRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderDetailRepository.java index 6b39f2e5..05b8df02 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderDetailRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderDetailRepository.java @@ -4,8 +4,12 @@ import com.chint.domain.aggregates.order.OrderDetail; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface JdbcOrderDetailRepository extends CrudRepository { OrderDetail findByOrderNo(String orderNo); + + List findByLegId(Long legId); } diff --git a/src/main/java/com/chint/interfaces/rest/ly/BPMRequest.java b/src/main/java/com/chint/interfaces/rest/ly/BPMRequest.java index 5b2a6c44..cca5bac3 100644 --- a/src/main/java/com/chint/interfaces/rest/ly/BPMRequest.java +++ b/src/main/java/com/chint/interfaces/rest/ly/BPMRequest.java @@ -9,9 +9,12 @@ import com.chint.interfaces.rest.ly.dto.bpm.ExceedStandardDto; import com.chint.interfaces.rest.ly.dto.bpm.RescheduleDto; import com.google.gson.Gson; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; import static com.chint.infrastructure.constant.Constant.EXCEED_STANDARD_URL; + +@Service public class BPMRequest { @Autowired @@ -41,6 +44,4 @@ public class BPMRequest { System.out.println("response = " + response); return response; } - - } diff --git a/src/test/java/com/chint/CTripTest.java b/src/test/java/com/chint/CTripTest.java index 3e53f897..85a86450 100644 --- a/src/test/java/com/chint/CTripTest.java +++ b/src/test/java/com/chint/CTripTest.java @@ -2,6 +2,8 @@ package com.chint; import com.chint.domain.aggregates.user.User; import com.chint.domain.repository.CityRepository; +import com.chint.domain.service.supplier.SupplierService; +import com.chint.domain.value_object.SupplierCallbackData; import com.chint.infrastructure.util.BaseContext; import com.chint.interfaces.rest.ctrip.*; import com.chint.interfaces.rest.ctrip.dto.estimate.request.BookingRelatedApiRequest; @@ -22,6 +24,8 @@ import org.springframework.boot.test.context.SpringBootTest; import java.util.List; import java.util.stream.Collectors; +import static com.chint.infrastructure.constant.Constant.SUPPLIER_C_TRIP; + @SpringBootTest public class CTripTest { @@ -43,6 +47,9 @@ public class CTripTest { @Autowired private CTripLoginRequest loginRequest; + @Autowired + private SupplierService supplierService; + private User user = new User(1L, 230615020L, 1, "卢麟哲", "1033719135@qq.com", "15857193365"); //@Test @@ -141,4 +148,14 @@ public class CTripTest { SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("30469349853"); System.out.println(response); } + + @Test + void searchAndHandlerData(){ + BaseContext.setCurrentUser(user); + SupplierCallbackData supplierCallbackData = + SupplierCallbackData.of(SUPPLIER_C_TRIP); + SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("30544187403"); + supplierCallbackData.data(response); + supplierService.handleSupplierCallback(supplierCallbackData); + } } diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index 30a8f503..545d14e9 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -12,6 +12,8 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.List; @SpringBootTest @@ -34,6 +36,13 @@ class RouteApplicationTests { userHttpRequest.loadUserInfo(user); } + +// @Test + void dataParse(){ + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + LocalDateTime parse = LocalDateTime.parse("2024-04-15 23:59:00", dateTimeFormatter); + System.out.println(parse); + } @Test void loginSign() { String sfno = "230615020";