完善订单详情字段

This commit is contained in:
Superdandan 2024-02-19 22:53:33 +08:00
parent 89ca5cb54f
commit c79f61e23e
21 changed files with 191 additions and 44 deletions

View File

@ -7,10 +7,10 @@ import lombok.Data;
import static com.chint.infrastructure.constant.Constant.LEG_EVENT_ORDERED; import static com.chint.infrastructure.constant.Constant.LEG_EVENT_ORDERED;
@Data @Data
public class RouteAddOrderCommand extends Command { public class RouteUpdateOrderCommand extends Command {
private Integer LegEventType = LEG_EVENT_ORDERED; private Integer LegEventType = LEG_EVENT_ORDERED;
private OrderLegData data; private OrderLegData data;
public RouteAddOrderCommand data(OrderLegData data) { public RouteUpdateOrderCommand data(OrderLegData data) {
this.data = data; this.data = data;
return this; return this;
} }

View File

@ -87,7 +87,7 @@ public class OrderApplicationService {
@Transactional @Transactional
public void ordered(OrderLegData data) { public void ordered(OrderLegData data) {
Command.of(RouteAddOrderCommand.class).data(data).sendToQueue(); Command.of(RouteUpdateOrderCommand.class).data(data).sendToQueue();
} }
@Transactional @Transactional

View File

@ -0,0 +1,12 @@
package com.chint.domain.aggregates.order;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;
@Data
@Table("car_order_detail")
public class CarOrderDetail {
@Id
private Long id;
}

View File

@ -0,0 +1,12 @@
package com.chint.domain.aggregates.order;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;
@Data
@Table("flight_order_detail")
public class FlightOrderDetail {
@Id
private Long id;
}

View File

@ -0,0 +1,13 @@
package com.chint.domain.aggregates.order;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;
@Data
@Table("hotel_order_detail")
public class HotelOrderDetail {
@Id
private Long id;
}

View File

@ -38,6 +38,21 @@ public class OrderDetail {
@MappedCollection(idColumn = "order_id", keyColumn = "order_key") @MappedCollection(idColumn = "order_id", keyColumn = "order_key")
private List<OrderEvent> orderEventList; private List<OrderEvent> orderEventList;
@MappedCollection(idColumn = "order_id")
private CarOrderDetail carOrderDetail;
@MappedCollection(idColumn = "order_id")
private FlightOrderDetail flightOrderDetail;
@MappedCollection(idColumn = "order_id")
private HotelOrderDetail hotelOrderDetail;
@MappedCollection(idColumn = "order_id")
private TrainOrderDetail trainOrderDetail;
@MappedCollection(idColumn = "order_id")
private OtherOrderDetail otherOrderDetail;
@Transient @Transient
private String orderStatus; private String orderStatus;

View File

@ -9,7 +9,6 @@ import org.springframework.data.relational.core.mapping.Table;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import static com.chint.infrastructure.constant.Constant.*; import static com.chint.infrastructure.constant.Constant.*;
import static com.chint.infrastructure.constant.Constant.LEG_EVENT_REJECT_NAME;
@Data @Data
@Table("order_event") @Table("order_event")
@ -32,6 +31,7 @@ public class OrderEvent {
case ORDER_EVENT_CHANGE -> ORDER_EVENT_CHANGE_NAME; case ORDER_EVENT_CHANGE -> ORDER_EVENT_CHANGE_NAME;
case ORDER_EVENT_CANCEL -> ORDER_EVENT_CANCEL_NAME; case ORDER_EVENT_CANCEL -> ORDER_EVENT_CANCEL_NAME;
case ORDER_EVENT_ORDERED -> ORDER_EVENT_ORDERED_NAME; case ORDER_EVENT_ORDERED -> ORDER_EVENT_ORDERED_NAME;
case ORDER_EVENT_REFUND -> ORDER_EVENT_REFUND_NAME;
default -> "未知事件"; default -> "未知事件";
}; };
} }
@ -40,4 +40,10 @@ public class OrderEvent {
this.setEventName(translateOrderEvent(this.eventType)); this.setEventName(translateOrderEvent(this.eventType));
return this; return this;
} }
public OrderEvent of(Integer eventType) {
OrderEvent orderEvent = new OrderEvent();
orderEvent.setEventType(eventType);
return orderEvent;
}
} }

View File

@ -0,0 +1,12 @@
package com.chint.domain.aggregates.order;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;
@Data
@Table("other_order_detail")
public class OtherOrderDetail {
@Id
private Long id;
}

View File

@ -0,0 +1,13 @@
package com.chint.domain.aggregates.order;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;
@Data
@Table("train_order_detail")
public class TrainOrderDetail {
@Id
private Long id;
}

View File

@ -1,8 +1,11 @@
package com.chint.domain.factoriy.order_detail; package com.chint.domain.factoriy.order_detail;
import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.aggregates.order.OrderDetail;
import com.chint.domain.aggregates.order.OrderEvent;
import com.chint.domain.value_object.OrderLegData; import com.chint.domain.value_object.OrderLegData;
public interface OrderDetailFactory { public interface OrderDetailFactory {
OrderDetail create(OrderLegData orderLegData); OrderDetail create(OrderLegData orderLegData);
OrderEvent createEvent(Integer eventType);
} }

View File

@ -1,6 +1,7 @@
package com.chint.domain.factoriy.order_detail; package com.chint.domain.factoriy.order_detail;
import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.aggregates.order.OrderDetail;
import com.chint.domain.aggregates.order.OrderEvent;
import com.chint.domain.value_object.OrderLegData; import com.chint.domain.value_object.OrderLegData;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -10,4 +11,9 @@ public class OrderDetailFactoryImpl implements OrderDetailFactory {
public OrderDetail create(OrderLegData orderLegData) { public OrderDetail create(OrderLegData orderLegData) {
return OrderDetail.of(orderLegData.getOrderNo(), orderLegData.getSupplierName()); return OrderDetail.of(orderLegData.getOrderNo(), orderLegData.getSupplierName());
} }
@Override
public OrderEvent createEvent(Integer eventType) {
return null;
}
} }

View File

@ -2,6 +2,10 @@ package com.chint.domain.repository;
import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.aggregates.order.OrderDetail;
import java.util.Optional;
public interface OrderDetailRepository { public interface OrderDetailRepository {
OrderDetail findById(Long orderDetailId); OrderDetail findById(Long orderDetailId);
Optional<OrderDetail> findByOrderNo(String orderNo);
} }

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.exceptions.CommandException; import com.chint.domain.exceptions.CommandException;
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_detail.OrderDetailFactory; import com.chint.domain.factoriy.order_detail.OrderDetailFactory;
import com.chint.domain.repository.LegRepository; import com.chint.domain.repository.LegRepository;
import com.chint.domain.repository.OrderDetailRepository; import com.chint.domain.repository.OrderDetailRepository;
@ -17,8 +18,9 @@ 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 static com.chint.infrastructure.constant.Constant.ORDER_STATUS_APPROVAL; import java.util.Optional;
import static com.chint.infrastructure.constant.Constant.ORDER_STATUS_PREPARE;
import static com.chint.infrastructure.constant.Constant.*;
@Service @Service
public class LegEventHandler implements LegEventService { public class LegEventHandler implements LegEventService {
@ -38,6 +40,9 @@ public class LegEventHandler implements LegEventService {
@Autowired @Autowired
private OrderDetailFactory orderDetailFactory; private OrderDetailFactory orderDetailFactory;
@Autowired
private RouteOrderFactory routeOrderFactory;
@Autowired @Autowired
private OrderDetailRepository orderDetailRepository; private OrderDetailRepository orderDetailRepository;
@ -99,13 +104,27 @@ public class LegEventHandler implements LegEventService {
@Transactional @Transactional
@Override @Override
public void routeAddOrder(RouteAddOrderCommand command) { public void routeUpdateOrder(RouteUpdateOrderCommand command) {
OrderLegData data = command.getData(); OrderLegData data = command.getData();
//首先查询到 行程规划订单 为形成规划订单添加 外部订单信息
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);
//首先查询到行程规划订单 从routOrder当中查询是否以及存在该订单
Optional<OrderDetail> byOrderNo = routeOrder.getOrderDetails()
.stream()
.filter(orderDetail -> orderDetail.getOrderNo().equals(data.getOrderNo()))
.findFirst();
if (byOrderNo.isPresent()) {
//如果订单以及存在了对订单的状态进行更新
OrderEvent event = orderDetailFactory.createEvent(data.getOrderStatus());
OrderDetail orderDetail = byOrderNo.get();
orderDetail.addOrderEvent(event);
} else {
//否则创建新的订单添加到routeOrder
OrderDetail orderDetail = orderDetailFactory.create(data)
.price(data.getPrice()).productType(data.getProductType());
//为订单添加订单已下单事件
OrderEvent orderEvent = orderDetailFactory.createEvent(ORDER_EVENT_PREPARE);
orderDetail.addOrderEvent(orderEvent);
routeOrder.addOrderDetail(orderDetail); routeOrder.addOrderDetail(orderDetail);
//结合外部订单信息筛选最合适的leg节点 触发下单事件 //结合外部订单信息筛选最合适的leg节点 触发下单事件
routeOrder.getLegItems() routeOrder.getLegItems()
@ -121,6 +140,7 @@ public class LegEventHandler implements LegEventService {
legEvent.addOrderDetail(orderDetail); legEvent.addOrderDetail(orderDetail);
leg.addEvent(legEvent); leg.addEvent(legEvent);
}); });
}
routeRepository.save(routeOrder); routeRepository.save(routeOrder);
} }

View File

@ -14,7 +14,7 @@ public interface LegEventService {
//下单事件 //下单事件
void orderLeg(LegOrderedCommand command); void orderLeg(LegOrderedCommand command);
void routeAddOrder(RouteAddOrderCommand command); void routeUpdateOrder(RouteUpdateOrderCommand command);
//付款 //付款
void payForLeg(LegPayedCommand command); void payForLeg(LegPayedCommand command);

View File

@ -1,24 +1,10 @@
package com.chint.domain.service.leg_event; package com.chint.domain.service.leg_event;
import com.chint.application.commands.*; import com.chint.application.commands.*;
import com.chint.domain.aggregates.order.*;
import com.chint.domain.exceptions.CommandException;
import com.chint.domain.factoriy.leg_event.LegEventFactory;
import com.chint.domain.repository.LegRepository;
import com.chint.domain.repository.RouteRepository;
import com.chint.domain.service.order_sync.SyncAdapter;
import com.chint.domain.value_object.ApproveLegData;
import com.chint.domain.value_object.OrderLegData;
import com.chint.domain.value_object.PayLegData;
import com.chint.domain.value_object.SyncLegData;
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 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 static com.chint.infrastructure.constant.Constant.ORDER_STATUS_APPROVAL;
import static com.chint.infrastructure.constant.Constant.ORDER_STATUS_PREPARE;
@Service @Service
public class LegEventServiceImpl implements LegEventService { public class LegEventServiceImpl implements LegEventService {
@ -57,10 +43,10 @@ public class LegEventServiceImpl implements LegEventService {
legEventHandler.orderLeg(command); legEventHandler.orderLeg(command);
} }
@ListenTo(command = "RouteAddOrderCommand", order = 0) @ListenTo(command = "RouteUpdateOrderCommand", order = 0)
@Override @Override
public void routeAddOrder(RouteAddOrderCommand command) { public void routeUpdateOrder(RouteUpdateOrderCommand command) {
legEventHandler.routeAddOrder(command); legEventHandler.routeUpdateOrder(command);
} }
@Override @Override

View File

@ -110,4 +110,31 @@ public class CTripOrderDataAdapter implements OrderDataAdapter {
default -> throw new NotFoundException(NOT_FOUND); default -> throw new NotFoundException(NOT_FOUND);
}; };
} }
private Integer translateCarOrderStatus(String carOrderStatus){
return switch (carOrderStatus) {
case "CreateOrder" -> ORDER_EVENT_PREPARE; //已下单
case "WaitReply" -> ORDER_EVENT_ORDERED; //等待应答
case "WaitService" -> ORDER_EVENT_ORDERED; //等待接驾
case "DriverArrived" -> ORDER_EVENT_ORDERED; //司机就位
case "InService" -> ORDER_EVENT_ORDERED; //正在服务
case "EndService" -> ORDER_EVENT_PAYED; //行程结束
case "Canceling" -> ORDER_EVENT_CANCEL; //取消中
case "Canceled" -> ORDER_EVENT_CANCEL; //已取消
case "Successful" -> ORDER_EVENT_CANCEL; //已成交
default -> throw new NotFoundException(NOT_FOUND);
};
}
private Integer translateFlightOrderStatus(String flightOrderStatus){
return switch (flightOrderStatus) {
case "W" -> ORDER_EVENT_PREPARE; //未处理
case "P" -> ORDER_EVENT_ORDERED; //处理中
case "C" -> ORDER_EVENT_CANCEL; //已取消
case "R" -> ORDER_EVENT_REFUND; //全部退票
case "T" -> ORDER_EVENT_REFUND; //部分退票
case "S" -> ORDER_EVENT_ORDERED; //已成交
default -> throw new NotFoundException(NOT_FOUND);
};
}
} }

View File

@ -1,6 +1,6 @@
package com.chint.domain.service.supplier; package com.chint.domain.service.supplier;
import com.chint.application.commands.RouteAddOrderCommand; import com.chint.application.commands.RouteUpdateOrderCommand;
import com.chint.domain.value_object.SupplierCallbackData; import com.chint.domain.value_object.SupplierCallbackData;
import com.chint.infrastructure.echo_framework.command.Command; import com.chint.infrastructure.echo_framework.command.Command;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -18,6 +18,6 @@ public class SupplierServiceImpl implements SupplierService {
.of(callbackData.getSupplierName()) .of(callbackData.getSupplierName())
.adapt(callbackData) .adapt(callbackData)
.ifPresent(data -> .ifPresent(data ->
Command.of(RouteAddOrderCommand.class).data(data).sendToQueue()); Command.of(RouteUpdateOrderCommand.class).data(data).sendToQueue());
} }
} }

View File

@ -14,6 +14,7 @@ public class OrderLegData {
private Integer productType; private Integer productType;
private String price; private String price;
private Integer orderStatus; private Integer orderStatus;
private String originOrderStatus;
private OrderLegData(Builder builder) { private OrderLegData(Builder builder) {
this.actualOrderNo = builder.actualOrderNo; this.actualOrderNo = builder.actualOrderNo;
@ -35,6 +36,7 @@ public class OrderLegData {
private Integer productType; private Integer productType;
private String price; private String price;
private Integer orderStatus; private Integer orderStatus;
private String originOrderStatus;
public Builder() { public Builder() {
} }
@ -70,6 +72,11 @@ public class OrderLegData {
return this; return this;
} }
public Builder originOrderStatus(String originOrderStatus) {
this.originOrderStatus = originOrderStatus;
return this;
}
public OrderLegData build() { public OrderLegData build() {
return new OrderLegData(this); return new OrderLegData(this);
} }

View File

@ -110,6 +110,8 @@ public class Constant {
public static final String ORDER_EVENT_PAYED_NAME = "已预定"; public static final String ORDER_EVENT_PAYED_NAME = "已预定";
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 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 = "取消";

View File

@ -7,6 +7,8 @@ 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.Optional;
import static com.chint.infrastructure.constant.Constant.NOT_FOUND; import static com.chint.infrastructure.constant.Constant.NOT_FOUND;
@Repository @Repository
@ -18,4 +20,9 @@ public class OrderDetailRepositoryImpl implements OrderDetailRepository {
public OrderDetail findById(Long orderDetailId) { public OrderDetail findById(Long orderDetailId) {
return orderDetailRepository.findById(orderDetailId).orElseThrow(() -> new NotFoundException(NOT_FOUND)); return orderDetailRepository.findById(orderDetailId).orElseThrow(() -> new NotFoundException(NOT_FOUND));
} }
@Override
public Optional<OrderDetail> findByOrderNo(String orderNo) {
return Optional.ofNullable(orderDetailRepository.findByOrderNo(orderNo));
}
} }

View File

@ -6,4 +6,6 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface JdbcOrderDetailRepository extends CrudRepository<OrderDetail, Long> { public interface JdbcOrderDetailRepository extends CrudRepository<OrderDetail, Long> {
OrderDetail findByOrderNo(String orderNo);
} }