diff --git a/src/main/java/com/chint/application/queryies/OrderQuery.java b/src/main/java/com/chint/application/queryies/OrderQuery.java index 8b34c68b..f0c16d39 100644 --- a/src/main/java/com/chint/application/queryies/OrderQuery.java +++ b/src/main/java/com/chint/application/queryies/OrderQuery.java @@ -166,6 +166,7 @@ public class OrderQuery { List byEmployeeNoIn = userRepository.findByEmployeeNoIn(employeeNoSet); Map userMap = byEmployeeNoIn .stream() + .distinct() .collect(Collectors.toMap(User::getEmployeeNo, Function.identity())); List orders = routeOrders .stream() diff --git a/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java b/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java index 10016e16..3ee51b3a 100644 --- a/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java +++ b/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java @@ -82,7 +82,10 @@ public class RouteCacheService { // return routeListByIds; } else { List routeOrders = jdbcRouteRepository.findByUserIdOrApproveOrderNo_Creator(employeeNo, employeeNo); - routeCacheManage.getRouteIdsByEmployeeNo(employeeNo, routeOrders, null); + CompletableFuture.runAsync(()->{ + routeCacheManage.getRouteIdsByEmployeeNo(employeeNo, routeOrders, null); + routeOrders.forEach(this::updateRouteCache); + }); return routeOrders; } } diff --git a/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java index de2a796d..be58a8f5 100644 --- a/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java @@ -17,7 +17,6 @@ import org.springframework.stereotype.Repository; import java.time.LocalDateTime; import java.util.List; -import java.util.Objects; import java.util.concurrent.TimeUnit; @Repository @@ -57,25 +56,26 @@ public class RouteRepositoryImpl implements RouteRepository { @Override public List queryByIdIn(List routeIds) { - List routeOrders = new java.util.ArrayList<>(routeCacheService.queryByIdIn(routeIds) - .stream() - .filter(Objects::nonNull) - .toList()); - List existedRouteIds = routeOrders - .stream() - .filter(Objects::nonNull) - .map(RouteOrder::getRouteId) - .toList(); - List needQueryFromDB = routeIds - .stream() - .filter(id -> !existedRouteIds.contains(id)) - .toList(); - List byRouteIdIn = jdbcRouteRepository - .findByRouteIdIn(needQueryFromDB); - //将查询出来的行程规划单缓存到数据库 - byRouteIdIn.forEach(route -> routeCacheService.cacheRouteOrder(route)); - routeOrders.addAll(byRouteIdIn); - return routeOrders; + return routeCacheService.queryByIdIn(routeIds); +// List routeOrders = new java.util.ArrayList<>(routeCacheService.queryByIdIn(routeIds) +// .stream() +// .filter(Objects::nonNull) +// .toList()); +// List existedRouteIds = routeOrders +// .stream() +// .filter(Objects::nonNull) +// .map(RouteOrder::getRouteId) +// .toList(); +// List needQueryFromDB = routeIds +// .stream() +// .filter(id -> !existedRouteIds.contains(id)) +// .toList(); +// List byRouteIdIn = jdbcRouteRepository +// .findByRouteIdIn(needQueryFromDB); +// //将查询出来的行程规划单缓存到数据库 +// byRouteIdIn.forEach(route -> routeCacheService.cacheRouteOrder(route)); +// routeOrders.addAll(byRouteIdIn); +// return routeOrders; } @Override @@ -188,7 +188,6 @@ public class RouteRepositoryImpl implements RouteRepository { @Override public List findAllByEmployeeNo(String employeeNo) { return routeCacheService.getUserRoutes(employeeNo); -// return jdbcRouteRepository.findByUserIdAndApproveOrderNo_ActualOrderNoNotNullOrApproveOrderNo_CreatorAndApproveOrderNo_ActualOrderNoNotNull(employeeNo, employeeNo); } @Override