diff --git a/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java b/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java index 94e4f5b2..67f8270a 100644 --- a/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java +++ b/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java @@ -41,7 +41,7 @@ public class RouteCacheService { .orElse(List.of()) .stream().filter(Objects::nonNull).toList(); if (!routeIdsByEmployeeNo.isEmpty()) { - return routeCacheManage.getRouteListByIds(routeIdsByEmployeeNo); + return queryByIdIn(routeIdsByEmployeeNo); } log.info("开始缓存用户行程规划单"); List routeOrders = jdbcRouteRepository.findByUserIdOrApproveOrderNo_Creator(employeeNo, employeeNo); @@ -215,9 +215,22 @@ public class RouteCacheService { public List queryByIdIn(List routeIds) { if (routeIds != null && !routeIds.isEmpty()) { - return routeCacheManage.getRouteListByIds(routeIds); + List inCacheRouteOrder = routeCacheManage.getRouteListByIds(routeIds); + List inCacheRouteIds = inCacheRouteOrder.stream().filter(Objects::nonNull) + .map(RouteOrder::getRouteId).toList(); + List notInCacheRouteIds = routeIds.stream().filter(it -> !inCacheRouteIds.contains(it)) + .toList(); + List byRouteIdIn = jdbcRouteRepository.findByRouteIdIn(notInCacheRouteIds); + CompletableFuture.runAsync(() -> byRouteIdIn.forEach(this::updateRouteCache)); + inCacheRouteOrder.addAll(byRouteIdIn); + return inCacheRouteOrder; } else { return List.of(); } } + + private void updateRouteCache(RouteOrder routeOrder) { + routeCacheManage.invalidateRouteCache(routeOrder.getRouteId()); + routeCacheManage.cacheRouteOrder(routeOrder); + } }