diff --git a/src/main/java/com/chint/application/services/OrderApplicationService.java b/src/main/java/com/chint/application/services/OrderApplicationService.java index 2fcca046..9a8b9721 100644 --- a/src/main/java/com/chint/application/services/OrderApplicationService.java +++ b/src/main/java/com/chint/application/services/OrderApplicationService.java @@ -85,11 +85,21 @@ public class OrderApplicationService { @Transactional public void addLegToOrder(AddLegData addLegData) { - //这里也先去redis查询如果没有的话 ,再查询数据库 + // First, attempt to retrieve the RouteOrder from the database RouteOrder routeOrder = Optional.ofNullable(routeRepository - .findTempRouteOrderBySysCodeAndBillCode(addLegData.getSysCode(), addLegData.getFakeOrderNo())) - .orElseGet(() -> Optional.ofNullable(routeRepository.queryById(addLegData.getRouteId())) - .orElseThrow(() -> new NotFoundException(NOT_FOUND))).reloadStatus(); + .findByFakeOrderNoAndSysCode(addLegData.getFakeOrderNo(), addLegData.getSysCode())) + .orElseGet(() -> { + // If not found in the database, attempt to retrieve from Redis + RouteOrder tempRouteOrder = routeRepository + .findTempRouteOrderBySysCodeAndBillCode(addLegData.getSysCode(), addLegData.getFakeOrderNo()); + // If not found in Redis, retrieve by ID from the database + if (tempRouteOrder == null) { + return Optional.ofNullable(routeRepository.queryById(addLegData.getRouteId())) + .orElseThrow(() -> new NotFoundException(NOT_FOUND)); + } + return tempRouteOrder; + }); + checkLegDataTime(addLegData, routeOrder); LegData legData = addLegData.getLegData(); List legs = processLegData(legData, routeOrder); //创建行程节点 @@ -101,7 +111,6 @@ public class OrderApplicationService { routeRepository.save(routeOrder); // 仅在所有操作完成后保存一次 } //如果行程变更成功,自动执行同步功能 -// Command.of(RouteAutoSyncCommand.class).route(routeOrder).async().sendToQueue(); } @Transactional