Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
dengwc 2024-03-01 10:50:15 +08:00
commit 79dc530024
3 changed files with 39 additions and 4 deletions

View File

@ -106,4 +106,11 @@
</plugins> </plugins>
</build> </build>
<repositories>
<repository>
<id>central</id>
<name>新正泰集团公共仓库</name>
<url>https://newmaven.chint.com/repository/maven-public/</url>
</repository>
</repositories>
</project> </project>

View File

@ -26,8 +26,9 @@ import java.time.format.DateTimeFormatter;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; 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; import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_PREPARE;
@Service @Service
@ -73,12 +74,20 @@ public class OrderApplicationService {
RouteOrder order = Optional.ofNullable(routeRepository.queryById(addLegData.getRouteId())) RouteOrder order = Optional.ofNullable(routeRepository.queryById(addLegData.getRouteId()))
.orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND)); .orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND));
order.reloadStatus(); order.reloadStatus();
// if (!order.getOrderStatus().equals(ORDER_STATUS_PREPARE)) {
// throw new OrderException(ORDER_STATUS_ERROR);
// }
List<Leg> legs = processLegData(addLegData.getLegData(), order); List<Leg> legs = processLegData(addLegData.getLegData(), order);
RouteOrder routeOrder = orderDomainService.saveOrder(order); RouteOrder routeOrder = orderDomainService.saveOrder(order);
legs.forEach(leg -> Command.of(LegPrepareCommand.class).legId(leg.getLegId()).sendToQueue()); 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; // 仅在所有操作完成后保存一次 return routeOrder; // 仅在所有操作完成后保存一次
} }
@ -94,6 +103,19 @@ public class OrderApplicationService {
byLegId.setOriginId(legData.getOriginId()); byLegId.setOriginId(legData.getOriginId());
byLegId.setDestinationId(legData.getDestinationId()); byLegId.setDestinationId(legData.getDestinationId());
legRepository.save(byLegId); 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<Leg> processLegData(LegData legData, RouteOrder order) { private List<Leg> processLegData(LegData legData, RouteOrder order) {

View File

@ -9,4 +9,10 @@ public class SyncLegData {
private Long routeId; private Long routeId;
private List<Long> routeIds; private List<Long> routeIds;
private String supplierName; private String supplierName;
public static SyncLegData of( Long routeId,String supplierName){
SyncLegData syncLegData = new SyncLegData();
syncLegData.setSupplierName(supplierName);
syncLegData.setRouteId(routeId);
return syncLegData;
}
} }