同步代码
This commit is contained in:
parent
1de351fa10
commit
8aeb194824
|
@ -73,15 +73,29 @@ public class OrderApplicationService {
|
|||
RouteOrder order = Optional.ofNullable(routeRepository.queryById(addLegData.getRouteId()))
|
||||
.orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND));
|
||||
order.reloadStatus();
|
||||
if (!order.getOrderStatus().equals(ORDER_STATUS_PREPARE)) {
|
||||
throw new OrderException(ORDER_STATUS_ERROR);
|
||||
}
|
||||
// if (!order.getOrderStatus().equals(ORDER_STATUS_PREPARE)) {
|
||||
// throw new OrderException(ORDER_STATUS_ERROR);
|
||||
// }
|
||||
List<Leg> legs = processLegData(addLegData.getLegData(), order);
|
||||
RouteOrder routeOrder = orderDomainService.saveOrder(order);
|
||||
legs.forEach(leg -> Command.of(LegPrepareCommand.class).legId(leg.getLegId()).sendToQueue());
|
||||
return routeOrder; // 仅在所有操作完成后保存一次
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void changeLeg(AddLegData addLegData) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
|
||||
LegData legData = addLegData.getLegData();
|
||||
Leg byLegId = Optional.ofNullable(
|
||||
legRepository.findByLegId(legData.getLegId())
|
||||
).orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND));
|
||||
byLegId.setStartTime(LocalDateTime.parse(legData.getStartTime(), formatter));
|
||||
byLegId.setEndTime(LocalDateTime.parse(legData.getEndTime(), formatter));
|
||||
byLegId.setOriginId(legData.getOriginId());
|
||||
byLegId.setDestinationId(legData.getDestinationId());
|
||||
legRepository.save(byLegId);
|
||||
}
|
||||
|
||||
private List<Leg> processLegData(LegData legData, RouteOrder order) {
|
||||
List<Leg> legs = switch (legData.legType) {
|
||||
case LegConstant.LEG_TYPE_TRAIN -> legFactory.createTrainLeg(legData);
|
||||
|
@ -156,15 +170,5 @@ public class OrderApplicationService {
|
|||
public void updateLegToOrder(AddLegData addLegData) {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void changeLeg(AddLegData addLegData) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
|
||||
LegData legData = addLegData.getLegData();
|
||||
Leg byLegId = legRepository.findByLegId(legData.getLegId());
|
||||
byLegId.setStartTime(LocalDateTime.parse(legData.getStartTime(), formatter));
|
||||
byLegId.setEndTime(LocalDateTime.parse(legData.getEndTime(), formatter));
|
||||
byLegId.setOriginId(legData.getOriginId());
|
||||
byLegId.setDestinationId(legData.getDestinationId());
|
||||
legRepository.save(byLegId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@ import java.time.LocalDateTime;
|
|||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_OTHER;
|
||||
import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_TAXI;
|
||||
|
||||
@Slf4j
|
||||
@Data
|
||||
@Table("leg")
|
||||
|
@ -82,7 +85,11 @@ public class Leg {
|
|||
}
|
||||
|
||||
public Leg queryEstimateAmount(EstimateAdapter estimateAdapter, String supplierName) {
|
||||
if (this.getLegType().equals(LEG_TYPE_OTHER) || this.getLegType().equals(LEG_TYPE_TAXI)) {
|
||||
|
||||
} else {
|
||||
this.estimateAmount = estimateAdapter.of(supplierName).amountEstimate(this);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -146,8 +153,8 @@ public class Leg {
|
|||
case LegConstant.LEG_TYPE_TRAIN -> LegConstant.LEG_TYPE_TRAIN_NAME;
|
||||
case LegConstant.LEG_TYPE_AIRPLANE -> LegConstant.LEG_TYPE_AIRPLANE_NAME;
|
||||
case LegConstant.LEG_TYPE_HOTEL -> LegConstant.LEG_TYPE_HOTEL_NAME;
|
||||
case LegConstant.LEG_TYPE_TAXI -> LegConstant.LEG_TYPE_TAXI_NAME;
|
||||
case LegConstant.LEG_TYPE_OTHER -> LegConstant.LEG_TYPE_OTHER_NAME;
|
||||
case LEG_TYPE_TAXI -> LegConstant.LEG_TYPE_TAXI_NAME;
|
||||
case LEG_TYPE_OTHER -> LegConstant.LEG_TYPE_OTHER_NAME;
|
||||
default -> "未知类型";
|
||||
};
|
||||
}
|
||||
|
@ -157,8 +164,8 @@ public class Leg {
|
|||
case LegConstant.LEG_TYPE_TRAIN -> LegConstant.LEG_TYPE_TRAIN_EN_NAME;
|
||||
case LegConstant.LEG_TYPE_AIRPLANE -> LegConstant.LEG_TYPE_AIRPLANE_EN_NAME;
|
||||
case LegConstant.LEG_TYPE_HOTEL -> LegConstant.LEG_TYPE_HOTEL_EN_NAME;
|
||||
case LegConstant.LEG_TYPE_TAXI -> LegConstant.LEG_TYPE_TAXI_EN_NAME;
|
||||
case LegConstant.LEG_TYPE_OTHER -> LegConstant.LEG_TYPE_OTHER_EN_NAME;
|
||||
case LEG_TYPE_TAXI -> LegConstant.LEG_TYPE_TAXI_EN_NAME;
|
||||
case LEG_TYPE_OTHER -> LegConstant.LEG_TYPE_OTHER_EN_NAME;
|
||||
default -> "未知类型";
|
||||
};
|
||||
}
|
||||
|
@ -192,7 +199,7 @@ public class Leg {
|
|||
if (!eventList.isEmpty()) {
|
||||
LegEvent lastEvent = eventList.get(eventList.size() - 1);
|
||||
int lastEventType = lastEvent.getEventType();
|
||||
if (newEventType != lastEventType && Math.abs(newEventType - lastEventType) > 1) {
|
||||
if (newEventType != lastEventType && Math.abs(newEventType - lastEventType) > 5) {
|
||||
throw new LegEventException("New event must be the same as, immediately before, or immediately after the last event type.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@ public class OrderDetailFactoryImpl implements OrderDetailFactory {
|
|||
orderDetail.setCurrencyType(CurrencyType.getByCode(orderLegData.getCurrencyCode()));
|
||||
orderDetail.setDestinationId(orderLegData.getDestinationId());
|
||||
orderDetail.setOriginId(orderLegData.getOriginId());
|
||||
orderDetail
|
||||
.price(orderLegData.getPrice())
|
||||
.productType(orderLegData.getProductType());
|
||||
return orderDetail;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@ public class CTripEstimate implements AmountEstimate {
|
|||
|
||||
@Override
|
||||
public String amountEstimate(Leg leg) {
|
||||
|
||||
Integer legType = leg.getLegType();
|
||||
return switch (legType) {
|
||||
case LEG_TYPE_TRAIN -> queryTrainPrice(leg);
|
||||
|
|
|
@ -106,13 +106,14 @@ public class LegEventHandler implements LegEventService {
|
|||
public void syncLeg(LegSyncCommand command) {
|
||||
SyncLegData data = command.getData();
|
||||
RouteOrder routeOrder = routeRepository.queryById(data.getRouteId()).reloadStatus();
|
||||
if (routeOrder.getOrderStatus() > (RouteConstant.ORDER_STATUS_APPROVAL)) {
|
||||
throw new CommandException("订单已同步");
|
||||
}
|
||||
// if (routeOrder.getOrderStatus() > (RouteConstant.ORDER_STATUS_APPROVAL)) {
|
||||
// throw new CommandException("订单已同步");
|
||||
// }
|
||||
if (routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE)) {
|
||||
throw new CommandException("订单未提交审批");
|
||||
}
|
||||
if (routeOrder.getOrderStatus().equals(RouteConstant.ORDER_STATUS_APPROVAL)) {
|
||||
//这里暂时的策略是只要订单状态是大于提交审批状态 , 就可以同步
|
||||
if (routeOrder.getOrderStatus() >= RouteConstant.ORDER_STATUS_APPROVAL) {
|
||||
String supplierName = data.getSupplierName();
|
||||
routeOrder.setSupplierName(supplierName);
|
||||
//这里order所有的leg触发sync事件
|
||||
|
@ -153,15 +154,10 @@ public class LegEventHandler implements LegEventService {
|
|||
if (byOrderNo.isEmpty()) {
|
||||
//否则创建新的订单添加到routeOrder
|
||||
orderDetail = orderDetailFactory.create(data)
|
||||
.price(data.getPrice()).productType(data.getProductType())
|
||||
.employeeNo(routeOrder.getUserId());
|
||||
routeOrder.addOrderDetail(orderDetail);
|
||||
routeOrder = routeRepository.save(routeOrder);
|
||||
// OrderDetail orderDetail = routeOrder
|
||||
// .getOrderDetails()
|
||||
// .stream()
|
||||
// .max(Comparator.comparing(OrderDetail::getCreateTime))
|
||||
// .orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND));
|
||||
|
||||
//为订单添加订单已下单事件,这里需要发出额外的命令进行处理
|
||||
orderDetail = routeOrder.matchOrderWithLeg(orderDetail);
|
||||
} else {
|
||||
|
|
|
@ -5,7 +5,7 @@ public class RouteConstant {
|
|||
public static final int ORDER_STATUS_PREPARE = 0;
|
||||
public static final String ORDER_STATUS_PREPARE_NAME = "规划中";
|
||||
public static final int ORDER_STATUS_APPROVAL = 1;
|
||||
public static final String ORDER_STATUS_APPROVAL_NAME = "提交审批";
|
||||
public static final String ORDER_STATUS_APPROVAL_NAME = "未同步";
|
||||
public static final int ORDER_STATUS_NOT_ORDERED = 2;
|
||||
public static final String ORDER_STATUS_NOT_ORDERED_NAME = "未下单";
|
||||
public static final int ORDER_STATUS_ORDERED = 3;
|
||||
|
|
Loading…
Reference in New Issue