完善订单详情字段
This commit is contained in:
parent
89ca5cb54f
commit
c79f61e23e
|
@ -7,10 +7,10 @@ import lombok.Data;
|
|||
import static com.chint.infrastructure.constant.Constant.LEG_EVENT_ORDERED;
|
||||
|
||||
@Data
|
||||
public class RouteAddOrderCommand extends Command {
|
||||
public class RouteUpdateOrderCommand extends Command {
|
||||
private Integer LegEventType = LEG_EVENT_ORDERED;
|
||||
private OrderLegData data;
|
||||
public RouteAddOrderCommand data(OrderLegData data) {
|
||||
public RouteUpdateOrderCommand data(OrderLegData data) {
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
|
@ -87,7 +87,7 @@ public class OrderApplicationService {
|
|||
|
||||
@Transactional
|
||||
public void ordered(OrderLegData data) {
|
||||
Command.of(RouteAddOrderCommand.class).data(data).sendToQueue();
|
||||
Command.of(RouteUpdateOrderCommand.class).data(data).sendToQueue();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -38,6 +38,21 @@ public class OrderDetail {
|
|||
@MappedCollection(idColumn = "order_id", keyColumn = "order_key")
|
||||
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
|
||||
private String orderStatus;
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ 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")
|
||||
|
@ -32,6 +31,7 @@ public class OrderEvent {
|
|||
case ORDER_EVENT_CHANGE -> ORDER_EVENT_CHANGE_NAME;
|
||||
case ORDER_EVENT_CANCEL -> ORDER_EVENT_CANCEL_NAME;
|
||||
case ORDER_EVENT_ORDERED -> ORDER_EVENT_ORDERED_NAME;
|
||||
case ORDER_EVENT_REFUND -> ORDER_EVENT_REFUND_NAME;
|
||||
default -> "未知事件";
|
||||
};
|
||||
}
|
||||
|
@ -40,4 +40,10 @@ public class OrderEvent {
|
|||
this.setEventName(translateOrderEvent(this.eventType));
|
||||
return this;
|
||||
}
|
||||
|
||||
public OrderEvent of(Integer eventType) {
|
||||
OrderEvent orderEvent = new OrderEvent();
|
||||
orderEvent.setEventType(eventType);
|
||||
return orderEvent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -1,8 +1,11 @@
|
|||
package com.chint.domain.factoriy.order_detail;
|
||||
|
||||
import com.chint.domain.aggregates.order.OrderDetail;
|
||||
import com.chint.domain.aggregates.order.OrderEvent;
|
||||
import com.chint.domain.value_object.OrderLegData;
|
||||
|
||||
public interface OrderDetailFactory {
|
||||
OrderDetail create(OrderLegData orderLegData);
|
||||
|
||||
OrderEvent createEvent(Integer eventType);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.chint.domain.factoriy.order_detail;
|
||||
|
||||
import com.chint.domain.aggregates.order.OrderDetail;
|
||||
import com.chint.domain.aggregates.order.OrderEvent;
|
||||
import com.chint.domain.value_object.OrderLegData;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
@ -10,4 +11,9 @@ public class OrderDetailFactoryImpl implements OrderDetailFactory {
|
|||
public OrderDetail create(OrderLegData orderLegData) {
|
||||
return OrderDetail.of(orderLegData.getOrderNo(), orderLegData.getSupplierName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderEvent createEvent(Integer eventType) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,10 @@ package com.chint.domain.repository;
|
|||
|
||||
import com.chint.domain.aggregates.order.OrderDetail;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface OrderDetailRepository {
|
||||
OrderDetail findById(Long orderDetailId);
|
||||
|
||||
Optional<OrderDetail> findByOrderNo(String orderNo);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ 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.factoriy.order.RouteOrderFactory;
|
||||
import com.chint.domain.factoriy.order_detail.OrderDetailFactory;
|
||||
import com.chint.domain.repository.LegRepository;
|
||||
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.transaction.annotation.Transactional;
|
||||
|
||||
import static com.chint.infrastructure.constant.Constant.ORDER_STATUS_APPROVAL;
|
||||
import static com.chint.infrastructure.constant.Constant.ORDER_STATUS_PREPARE;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.chint.infrastructure.constant.Constant.*;
|
||||
|
||||
@Service
|
||||
public class LegEventHandler implements LegEventService {
|
||||
|
@ -38,6 +40,9 @@ public class LegEventHandler implements LegEventService {
|
|||
@Autowired
|
||||
private OrderDetailFactory orderDetailFactory;
|
||||
|
||||
@Autowired
|
||||
private RouteOrderFactory routeOrderFactory;
|
||||
|
||||
@Autowired
|
||||
private OrderDetailRepository orderDetailRepository;
|
||||
|
||||
|
@ -99,13 +104,27 @@ public class LegEventHandler implements LegEventService {
|
|||
|
||||
@Transactional
|
||||
@Override
|
||||
public void routeAddOrder(RouteAddOrderCommand command) {
|
||||
public void routeUpdateOrder(RouteUpdateOrderCommand command) {
|
||||
OrderLegData data = command.getData();
|
||||
//首先查询到 行程规划订单 , 为形成规划订单添加 外部订单信息
|
||||
OrderDetail orderDetail = orderDetailFactory.create(data)
|
||||
.price(data.getPrice()).productType(data.getProductType());
|
||||
String actualOrderNo = data.getActualOrderNo();
|
||||
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);
|
||||
//结合外部订单信息,筛选最合适的leg节点 ,触发下单事件 ;
|
||||
routeOrder.getLegItems()
|
||||
|
@ -121,6 +140,7 @@ public class LegEventHandler implements LegEventService {
|
|||
legEvent.addOrderDetail(orderDetail);
|
||||
leg.addEvent(legEvent);
|
||||
});
|
||||
}
|
||||
routeRepository.save(routeOrder);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ public interface LegEventService {
|
|||
//下单事件
|
||||
void orderLeg(LegOrderedCommand command);
|
||||
|
||||
void routeAddOrder(RouteAddOrderCommand command);
|
||||
void routeUpdateOrder(RouteUpdateOrderCommand command);
|
||||
|
||||
//付款
|
||||
void payForLeg(LegPayedCommand command);
|
||||
|
|
|
@ -1,24 +1,10 @@
|
|||
package com.chint.domain.service.leg_event;
|
||||
|
||||
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.TransitionTo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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
|
||||
public class LegEventServiceImpl implements LegEventService {
|
||||
|
@ -57,10 +43,10 @@ public class LegEventServiceImpl implements LegEventService {
|
|||
legEventHandler.orderLeg(command);
|
||||
}
|
||||
|
||||
@ListenTo(command = "RouteAddOrderCommand", order = 0)
|
||||
@ListenTo(command = "RouteUpdateOrderCommand", order = 0)
|
||||
@Override
|
||||
public void routeAddOrder(RouteAddOrderCommand command) {
|
||||
legEventHandler.routeAddOrder(command);
|
||||
public void routeUpdateOrder(RouteUpdateOrderCommand command) {
|
||||
legEventHandler.routeUpdateOrder(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -110,4 +110,31 @@ public class CTripOrderDataAdapter implements OrderDataAdapter {
|
|||
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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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.infrastructure.echo_framework.command.Command;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -18,6 +18,6 @@ public class SupplierServiceImpl implements SupplierService {
|
|||
.of(callbackData.getSupplierName())
|
||||
.adapt(callbackData)
|
||||
.ifPresent(data ->
|
||||
Command.of(RouteAddOrderCommand.class).data(data).sendToQueue());
|
||||
Command.of(RouteUpdateOrderCommand.class).data(data).sendToQueue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ public class OrderLegData {
|
|||
private Integer productType;
|
||||
private String price;
|
||||
private Integer orderStatus;
|
||||
private String originOrderStatus;
|
||||
|
||||
private OrderLegData(Builder builder) {
|
||||
this.actualOrderNo = builder.actualOrderNo;
|
||||
|
@ -35,6 +36,7 @@ public class OrderLegData {
|
|||
private Integer productType;
|
||||
private String price;
|
||||
private Integer orderStatus;
|
||||
private String originOrderStatus;
|
||||
|
||||
public Builder() {
|
||||
}
|
||||
|
@ -70,6 +72,11 @@ public class OrderLegData {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder originOrderStatus(String originOrderStatus) {
|
||||
this.originOrderStatus = originOrderStatus;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OrderLegData build() {
|
||||
return new OrderLegData(this);
|
||||
}
|
||||
|
|
|
@ -110,6 +110,8 @@ public class Constant {
|
|||
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_REFUND = 4;
|
||||
public static final String ORDER_EVENT_REFUND_NAME = "退票";
|
||||
public static final int ORDER_EVENT_CANCEL = -1;
|
||||
public static final String ORDER_EVENT_CANCEL_NAME = "取消";
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ import com.chint.infrastructure.repository.jdbc.JdbcOrderDetailRepository;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.chint.infrastructure.constant.Constant.NOT_FOUND;
|
||||
|
||||
@Repository
|
||||
|
@ -18,4 +20,9 @@ public class OrderDetailRepositoryImpl implements OrderDetailRepository {
|
|||
public OrderDetail findById(Long orderDetailId) {
|
||||
return orderDetailRepository.findById(orderDetailId).orElseThrow(() -> new NotFoundException(NOT_FOUND));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<OrderDetail> findByOrderNo(String orderNo) {
|
||||
return Optional.ofNullable(orderDetailRepository.findByOrderNo(orderNo));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,4 +6,6 @@ import org.springframework.stereotype.Repository;
|
|||
|
||||
@Repository
|
||||
public interface JdbcOrderDetailRepository extends CrudRepository<OrderDetail, Long> {
|
||||
|
||||
OrderDetail findByOrderNo(String orderNo);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue