更新事件

This commit is contained in:
lulz1 2024-02-24 21:00:33 +08:00
parent f09dd77636
commit d3ec32a867
17 changed files with 177 additions and 84 deletions

View File

@ -2,10 +2,10 @@ package com.chint.domain.aggregates.order;
import com.chint.domain.exceptions.LegEventException; import com.chint.domain.exceptions.LegEventException;
import com.chint.domain.repository.OrderDetailRepository;
import com.chint.domain.service.amount_estimate.EstimateAdapter; import com.chint.domain.service.amount_estimate.EstimateAdapter;
import com.chint.domain.value_object.LegData; import com.chint.domain.value_object.LegData;
import com.chint.domain.value_object.enums.CurrencyType; import com.chint.domain.value_object.enums.CurrencyType;
import com.chint.infrastructure.util.BigDecimalCalculator;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -100,24 +100,6 @@ public class Leg {
// Set the legStatus based on the type of the latest event // Set the legStatus based on the type of the latest event
this.legStatus = latestEvent.getEventType(); 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); this.legStatusName = translateLegStatus(this.legStatus);
@ -129,6 +111,8 @@ public class Leg {
if (this.getLegExtensionField() != null && this.getLegExtensionField().getAmountType() != null) { if (this.getLegExtensionField() != null && this.getLegExtensionField().getAmountType() != null) {
this.getLegExtensionField().reloadStatus(); this.getLegExtensionField().reloadStatus();
} }
//
return this; return this;
} }
@ -205,12 +189,12 @@ public class Leg {
return this; return this;
} }
// 如果列表不为空确保新事件的类型是按顺序的或者与最后一个事件类型相同 // 如果列表不为空确保新事件的类型是按顺序的与最后一个事件类型相同或者浮动为1
if (!eventList.isEmpty()) { if (!eventList.isEmpty()) {
LegEvent lastEvent = eventList.get(eventList.size() - 1); LegEvent lastEvent = eventList.get(eventList.size() - 1);
int lastEventType = lastEvent.getEventType(); int lastEventType = lastEvent.getEventType();
if (newEventType != lastEventType && newEventType != lastEventType + 1) { if (newEventType != lastEventType && Math.abs(newEventType - lastEventType) > 1) {
throw new LegEventException("New event must be the same as the last event type or the next in sequence."); throw new LegEventException("New event must be the same as, immediately before, or immediately after the last event type.");
} }
} }

View File

@ -4,7 +4,6 @@ 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.annotation.Transient;
import org.springframework.data.relational.core.mapping.Column; 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 org.springframework.data.relational.core.mapping.Table;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -27,8 +26,8 @@ public class LegEvent {
private LocalDateTime happenTime; private LocalDateTime happenTime;
@MappedCollection(idColumn = "leg_event_id",keyColumn = "leg_event_key") @Transient
private List<OrderDetail> orderDetails; private List<OrderDetail> orderDetailIds;
public String translateLegEvent(int event) { public String translateLegEvent(int event) {
return switch (event) { return switch (event) {
@ -47,12 +46,4 @@ public class LegEvent {
this.setEventName(translateLegEvent(this.eventType)); this.setEventName(translateLegEvent(this.eventType));
return this; return this;
} }
public LegEvent addOrderDetail(OrderDetail orderDetail){
if(this.orderDetails == null){
this.orderDetails = new ArrayList<>();
}
this.orderDetails.add(orderDetail);
return this;
}
} }

View File

@ -20,6 +20,7 @@ import static com.chint.infrastructure.constant.Constant.ORDER_EVENT_UNKNOWN;
public class OrderDetail { public class OrderDetail {
@Id @Id
private Long orderId; // 使用 order_id 作为主键 private Long orderId; // 使用 order_id 作为主键
private Long legId; // 使用行程节点关联leg
private String orderNo; private String orderNo;
private String supplierName; private String supplierName;
private Integer productType; // 商品类型 private Integer productType; // 商品类型

View File

@ -1,11 +1,13 @@
package com.chint.domain.aggregates.order; package com.chint.domain.aggregates.order;
import com.chint.application.commands.LegOrderedCommand;
import com.chint.domain.aggregates.base.BaseEntity; import com.chint.domain.aggregates.base.BaseEntity;
import com.chint.domain.factoriy.leg.LegFactory; import com.chint.domain.factoriy.leg.LegFactory;
import com.chint.domain.service.amount_estimate.EstimateAdapter; import com.chint.domain.service.amount_estimate.EstimateAdapter;
import com.chint.domain.value_object.LegData; import com.chint.domain.value_object.LegData;
import com.chint.domain.value_object.OrderSaveData; import com.chint.domain.value_object.OrderSaveData;
import com.chint.infrastructure.echo_framework.command.Command;
import com.chint.infrastructure.util.BigDecimalCalculator; import com.chint.infrastructure.util.BigDecimalCalculator;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
@ -337,4 +339,21 @@ public class RouteOrder extends BaseEntity {
default -> "未知供应商"; 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());
}
} }

View File

@ -13,9 +13,9 @@ public class OrderDetailFactoryImpl implements OrderDetailFactory {
@Override @Override
public OrderDetail create(OrderLegData orderLegData) { public OrderDetail create(OrderLegData orderLegData) {
OrderDetail orderDetail = OrderDetail.of(orderLegData.getOutOrderNo(), orderLegData.getSupplierName()); 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.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.setOrderDate(LocalDateTime.parse(orderLegData.getOrderTime(), dateTimeFormatter));
orderDetail.setCurrencyType(CurrencyType.getByCode(orderLegData.getCurrencyCode())); orderDetail.setCurrencyType(CurrencyType.getByCode(orderLegData.getCurrencyCode()));
orderDetail.setDestinationId(orderLegData.getDestinationId()); orderDetail.setDestinationId(orderLegData.getDestinationId());

View File

@ -2,11 +2,14 @@ package com.chint.domain.repository;
import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.aggregates.order.OrderDetail;
import java.util.List;
import java.util.Optional; import java.util.Optional;
public interface OrderDetailRepository { public interface OrderDetailRepository {
OrderDetail findById(Long orderDetailId); OrderDetail findById(Long orderDetailId);
List<OrderDetail> findByLegId(Long legId);
Optional<OrderDetail> findByOrderNo(String orderNo); Optional<OrderDetail> findByOrderNo(String orderNo);
OrderDetail save(OrderDetail orderDetail); OrderDetail save(OrderDetail orderDetail);

View File

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

View File

@ -98,4 +98,8 @@ public class OrderDomainService {
orderDetailRepository.save(orderDetail); orderDetailRepository.save(orderDetail);
}); });
} }
public void legAutoAddOrder(){
}
} }

View File

@ -4,6 +4,7 @@ import com.chint.application.commands.*;
import com.chint.domain.aggregates.order.*; import com.chint.domain.aggregates.order.*;
import com.chint.domain.aggregates.user.User; import com.chint.domain.aggregates.user.User;
import com.chint.domain.exceptions.CommandException; import com.chint.domain.exceptions.CommandException;
import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.exceptions.OrderException; import com.chint.domain.exceptions.OrderException;
import com.chint.domain.factoriy.leg_event.LegEventFactory; import com.chint.domain.factoriy.leg_event.LegEventFactory;
import com.chint.domain.factoriy.order.RouteOrderFactory; 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.RouteRepository;
import com.chint.domain.repository.UserRepository; import com.chint.domain.repository.UserRepository;
import com.chint.domain.service.order_sync.SyncAdapter; 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 com.chint.infrastructure.util.BaseContext;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Comparator;
import java.util.Optional; import java.util.Optional;
import static com.chint.infrastructure.constant.Constant.*; import static com.chint.infrastructure.constant.Constant.*;
@ -113,9 +119,13 @@ public class LegEventHandler implements LegEventService {
if (!syncAdapter.of(supplierName).syncSupplierOrder(routeOrder)) { if (!syncAdapter.of(supplierName).syncSupplierOrder(routeOrder)) {
throw new CommandException("订单提交失败"); throw new CommandException("订单提交失败");
} }
} else { }
if (routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE)) {
throw new CommandException("订单未提交审批"); throw new CommandException("订单未提交审批");
} }
if (routeOrder.getOrderStatus() > (ORDER_STATUS_APPROVAL)) {
throw new CommandException("订单已同步");
}
} }
@Transactional @Transactional
@ -133,39 +143,21 @@ public class LegEventHandler implements LegEventService {
.stream() .stream()
.filter(orderDetail -> orderDetail.getOrderNo().equals(data.getOutOrderNo())) .filter(orderDetail -> orderDetail.getOrderNo().equals(data.getOutOrderNo()))
.findFirst(); .findFirst();
if (byOrderNo.isEmpty()) if (byOrderNo.isEmpty()) {
// {
// //如果订单以及存在了对订单的状态进行更新
// OrderEvent event = orderDetailFactory.createEvent(data.getOrderStatus(), data.getOriginOrderStatus());
// OrderDetail orderDetail = byOrderNo.get();
// orderDetail.addOrderEvent(event);
// } else
{
//否则创建新的订单添加到routeOrder //否则创建新的订单添加到routeOrder
OrderDetail orderDetail = orderDetailFactory.create(data) OrderDetail orderDetail = orderDetailFactory.create(data)
.price(data.getPrice()).productType(data.getProductType()); .price(data.getPrice()).productType(data.getProductType());
//为订单添加订单已下单事件
// OrderEvent orderEvent = orderDetailFactory.createEvent(ORDER_EVENT_PREPARE, data.getOriginOrderStatus());
// orderDetail.addOrderEvent(orderEvent);
routeOrder.addOrderDetail(orderDetail); routeOrder.addOrderDetail(orderDetail);
//结合外部订单信息筛选最合适的leg节点 触发下单事件 //结合外部订单信息筛选最合适的leg节点 触发下单事件; 这里另外发送一个命令用于处理leg和orderDetail之间的关系
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);
});
} }
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 @Transactional
@ -173,25 +165,22 @@ public class LegEventHandler implements LegEventService {
public void orderLeg(LegOrderedCommand command) { public void orderLeg(LegOrderedCommand command) {
//如果筛选事件可能会是错误需要用户手动添加并修改事件 因此会进行额外出发修改下单事件 //如果筛选事件可能会是错误需要用户手动添加并修改事件 因此会进行额外出发修改下单事件
Leg leg = legRepository.findByLegId(Leg.of(command.getLegId())); Leg leg = legRepository.findByLegId(Leg.of(command.getLegId()));
//因为orderDetail已经进行持久化保存 只需要从数据库进行查询 //因为orderDetail已经进行持久化保存 只需要从数据库进行查询
OrderDetail orderDetail = orderDetailRepository.findById(command.getOrderDetailId()); OrderDetail orderDetail = orderDetailRepository.findById(command.getOrderDetailId());
LegEvent legEvent = legEventFactory LegEvent legEvent = legEventFactory
.creatLegEvent(command.getLegEventType()) .creatLegEvent(command.getLegEventType());
.addOrderDetail(orderDetail);
leg.addEvent(legEvent); leg.addEvent(legEvent);
orderDetail.setLegId(leg.getLegId());
legRepository.save(leg); legRepository.save(leg);
orderDetailRepository.save(orderDetail);
} }
@Transactional @Transactional
@Override @Override
public void payForLeg(LegPayedCommand command) { public void payForLeg(LegPayedCommand command) {
PayLegData data = command.getData(); // PayLegData data = command.getData();
Leg leg = legRepository.findByLegId(Leg.of(command.getLegId())); Leg leg = legRepository.findByLegId(Leg.of(command.getLegId()));
LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType()); LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType());
OrderDetail orderDetail = new OrderDetail();
legEvent.addOrderDetail(orderDetail);
leg.addEvent(legEvent); leg.addEvent(legEvent);
legRepository.save(leg); legRepository.save(leg);
} }

View File

@ -144,9 +144,9 @@ public class Constant {
public static final int ORDER_EVENT_CHANGE = 3; public static final int ORDER_EVENT_CHANGE = 3;
public static final String ORDER_EVENT_CHANGE_NAME = "改签"; public static final String ORDER_EVENT_CHANGE_NAME = "改签";
public static final int ORDER_EVENT_REFUND = 4; 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 int ORDER_EVENT_FINISH = 5;
public static final String ORDER_EVENT_FINISH_NAME = "已完成"; 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 int ORDER_EVENT_CANCEL = -1;
public static final String ORDER_EVENT_CANCEL_NAME = "取消"; public static final String ORDER_EVENT_CANCEL_NAME = "取消";
public static final int ORDER_EVENT_UNKNOWN = -99; public static final int ORDER_EVENT_UNKNOWN = -99;

View File

@ -1,7 +1,6 @@
package com.chint.infrastructure.echo_framework.manager; 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.ListenTo;
import com.chint.infrastructure.echo_framework.annotation.TransitionTo; import com.chint.infrastructure.echo_framework.annotation.TransitionTo;
import com.chint.infrastructure.echo_framework.command.Command; 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.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate; 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.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.*; import java.util.*;
@ -87,14 +84,17 @@ public class EventManager implements ApplicationContextAware, BeanNameAware, Ini
List<MethodContainer> containers = listenerMethods.getOrDefault(command.getCommandName(), Collections.emptyList()); List<MethodContainer> containers = listenerMethods.getOrDefault(command.getCommandName(), Collections.emptyList());
List<ResultContainer> resultContainers = new ArrayList<>(); List<ResultContainer> resultContainers = new ArrayList<>();
containers.forEach(container -> { containers.forEach(container -> {
Object result = null;
try { try {
Object result = container.getMethod().invoke(container.getBean(), command); result = container.getMethod().invoke(container.getBean(), command);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
if (result instanceof ResultContainer) { if (result instanceof ResultContainer) {
resultContainers.add((ResultContainer) result); resultContainers.add((ResultContainer) result);
} }
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace(); // Handle exceptions appropriately
}
}); });
return resultContainers; return resultContainers;
} }

View File

@ -8,7 +8,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.util.Optional; import java.lang.reflect.InvocationTargetException;
@RestControllerAdvice @RestControllerAdvice
@Slf4j @Slf4j
@ -37,4 +37,23 @@ public class GlobalExceptionHandler {
public Result<String> handleDuplicateException(HttpServletRequest request, DuplicateException e) { public Result<String> handleDuplicateException(HttpServletRequest request, DuplicateException e) {
return Result.error(e.getMessage()); return Result.error(e.getMessage());
} }
@ExceptionHandler(value = Exception.class)
public Result<String> 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);
// }
}
} }

View File

@ -7,6 +7,7 @@ import com.chint.infrastructure.repository.jdbc.JdbcOrderDetailRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import static com.chint.infrastructure.constant.Constant.NOT_FOUND; 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)); return orderDetailRepository.findById(orderDetailId).orElseThrow(() -> new NotFoundException(NOT_FOUND));
} }
@Override
public List<OrderDetail> findByLegId(Long legId) {
return orderDetailRepository.findByLegId(legId);
}
@Override @Override
public Optional<OrderDetail> findByOrderNo(String orderNo) { public Optional<OrderDetail> findByOrderNo(String orderNo) {
return Optional.ofNullable(orderDetailRepository.findByOrderNo(orderNo)); return Optional.ofNullable(orderDetailRepository.findByOrderNo(orderNo));

View File

@ -4,8 +4,12 @@ import com.chint.domain.aggregates.order.OrderDetail;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
@Repository @Repository
public interface JdbcOrderDetailRepository extends CrudRepository<OrderDetail, Long> { public interface JdbcOrderDetailRepository extends CrudRepository<OrderDetail, Long> {
OrderDetail findByOrderNo(String orderNo); OrderDetail findByOrderNo(String orderNo);
List<OrderDetail> findByLegId(Long legId);
} }

View File

@ -9,9 +9,12 @@ import com.chint.interfaces.rest.ly.dto.bpm.ExceedStandardDto;
import com.chint.interfaces.rest.ly.dto.bpm.RescheduleDto; import com.chint.interfaces.rest.ly.dto.bpm.RescheduleDto;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import static com.chint.infrastructure.constant.Constant.EXCEED_STANDARD_URL; import static com.chint.infrastructure.constant.Constant.EXCEED_STANDARD_URL;
@Service
public class BPMRequest { public class BPMRequest {
@Autowired @Autowired
@ -41,6 +44,4 @@ public class BPMRequest {
System.out.println("response = " + response); System.out.println("response = " + response);
return response; return response;
} }
} }

View File

@ -2,6 +2,8 @@ package com.chint;
import com.chint.domain.aggregates.user.User; import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.CityRepository; 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.infrastructure.util.BaseContext;
import com.chint.interfaces.rest.ctrip.*; import com.chint.interfaces.rest.ctrip.*;
import com.chint.interfaces.rest.ctrip.dto.estimate.request.BookingRelatedApiRequest; 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.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.chint.infrastructure.constant.Constant.SUPPLIER_C_TRIP;
@SpringBootTest @SpringBootTest
public class CTripTest { public class CTripTest {
@ -43,6 +47,9 @@ public class CTripTest {
@Autowired @Autowired
private CTripLoginRequest loginRequest; private CTripLoginRequest loginRequest;
@Autowired
private SupplierService supplierService;
private User user = new User(1L, 230615020L, 1, "卢麟哲", "1033719135@qq.com", "15857193365"); private User user = new User(1L, 230615020L, 1, "卢麟哲", "1033719135@qq.com", "15857193365");
//@Test //@Test
@ -141,4 +148,14 @@ public class CTripTest {
SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("30469349853"); SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("30469349853");
System.out.println(response); 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);
}
} }

View File

@ -12,6 +12,8 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
@SpringBootTest @SpringBootTest
@ -34,6 +36,13 @@ class RouteApplicationTests {
userHttpRequest.loadUserInfo(user); 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 @Test
void loginSign() { void loginSign() {
String sfno = "230615020"; String sfno = "230615020";