diff --git a/pom.xml b/pom.xml
index ec7065af..f69df198 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,4 +106,11 @@
+
+
+ central
+ 新正泰集团公共仓库
+ https://newmaven.chint.com/repository/maven-public/
+
+
diff --git a/src/main/java/com/chint/application/services/OrderApplicationService.java b/src/main/java/com/chint/application/services/OrderApplicationService.java
index 2feac52a..e7fdef23 100644
--- a/src/main/java/com/chint/application/services/OrderApplicationService.java
+++ b/src/main/java/com/chint/application/services/OrderApplicationService.java
@@ -26,8 +26,9 @@ import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
-import static com.chint.infrastructure.constant.CommonMessageConstant.ORDER_STATUS_ERROR;
+import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_NOT_ORDERED;
import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_PREPARE;
@Service
@@ -73,12 +74,20 @@ 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);
-// }
+
List legs = processLegData(addLegData.getLegData(), order);
RouteOrder routeOrder = orderDomainService.saveOrder(order);
legs.forEach(leg -> Command.of(LegPrepareCommand.class).legId(leg.getLegId()).sendToQueue());
+
+ //异步操作-如果是当前的状态已经进行过匹配,那么就要订单同步到供应商一次
+ if (order.getOrderStatus() >= ORDER_STATUS_NOT_ORDERED) {
+ CompletableFuture.runAsync(() -> {
+ Command
+ .of(LegSyncCommand.class)
+ .data(SyncLegData.of(routeOrder.getRouteId(), routeOrder.getSupplierName()))
+ .sendToQueue();
+ });
+ }
return routeOrder; // 仅在所有操作完成后保存一次
}
@@ -94,6 +103,19 @@ public class OrderApplicationService {
byLegId.setOriginId(legData.getOriginId());
byLegId.setDestinationId(legData.getDestinationId());
legRepository.save(byLegId);
+
+ //异步操作-如果是当前的状态已经进行过匹配,那么就要订单同步到供应商一次
+ CompletableFuture.runAsync(() -> {
+ Long routeId = byLegId.getRouteId();
+ RouteOrder order = Optional.ofNullable(routeRepository.queryById(routeId))
+ .orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND)).reloadStatus();
+ if (order.getOrderStatus() >= ORDER_STATUS_NOT_ORDERED) {
+ Command
+ .of(LegSyncCommand.class)
+ .data(SyncLegData.of(order.getRouteId(), order.getSupplierName()))
+ .sendToQueue();
+ }
+ });
}
private List processLegData(LegData legData, RouteOrder order) {
diff --git a/src/main/java/com/chint/domain/value_object/SyncLegData.java b/src/main/java/com/chint/domain/value_object/SyncLegData.java
index d3664a4a..cf09311c 100644
--- a/src/main/java/com/chint/domain/value_object/SyncLegData.java
+++ b/src/main/java/com/chint/domain/value_object/SyncLegData.java
@@ -9,4 +9,10 @@ public class SyncLegData {
private Long routeId;
private List routeIds;
private String supplierName;
+ public static SyncLegData of( Long routeId,String supplierName){
+ SyncLegData syncLegData = new SyncLegData();
+ syncLegData.setSupplierName(supplierName);
+ syncLegData.setRouteId(routeId);
+ return syncLegData;
+ }
}