From b7e1734ec751ca856c52111402534b4dc5ed6eea Mon Sep 17 00:00:00 2001 From: lulz1 Date: Tue, 9 Jul 2024 13:47:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=EF=BC=8C=E5=9B=A0=E7=BC=93=E5=AD=98=E7=A1=AE?= =?UTF-8?q?=E5=AE=9E=E5=AF=BC=E8=87=B4=E6=97=A0=E6=B3=95=E6=9F=A5=E5=88=B0?= =?UTF-8?q?=E8=A1=8C=E7=A8=8B=E8=A7=84=E5=88=92=E5=8D=95=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructure/cache/RouteCacheService.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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); + } }