From 5feaadc21d66978da42ca247447a0f003e96cfc3 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Wed, 10 Jul 2024 09:20:37 +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=E6=97=B6=E5=9B=A0=E4=B8=BA=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=87=8D=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/queryies/OrderQuery.java | 1 + .../cache/RouteCacheService.java | 5 ++- .../repository/RouteRepositoryImpl.java | 41 +++++++++---------- 3 files changed, 25 insertions(+), 22 deletions(-) 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