fix:修复分页查询时因为用户数据重复问题

This commit is contained in:
lulz1 2024-07-10 09:20:37 +08:00
parent 70361bc150
commit 5feaadc21d
3 changed files with 25 additions and 22 deletions

View File

@ -166,6 +166,7 @@ public class OrderQuery {
List<User> byEmployeeNoIn = userRepository.findByEmployeeNoIn(employeeNoSet);
Map<String, User> userMap = byEmployeeNoIn
.stream()
.distinct()
.collect(Collectors.toMap(User::getEmployeeNo, Function.identity()));
List<RouteOrderPageRes> orders = routeOrders
.stream()

View File

@ -82,7 +82,10 @@ public class RouteCacheService {
// return routeListByIds;
} else {
List<RouteOrder> routeOrders = jdbcRouteRepository.findByUserIdOrApproveOrderNo_Creator(employeeNo, employeeNo);
routeCacheManage.getRouteIdsByEmployeeNo(employeeNo, routeOrders, null);
CompletableFuture.runAsync(()->{
routeCacheManage.getRouteIdsByEmployeeNo(employeeNo, routeOrders, null);
routeOrders.forEach(this::updateRouteCache);
});
return routeOrders;
}
}

View File

@ -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<RouteOrder> queryByIdIn(List<Long> routeIds) {
List<RouteOrder> routeOrders = new java.util.ArrayList<>(routeCacheService.queryByIdIn(routeIds)
.stream()
.filter(Objects::nonNull)
.toList());
List<Long> existedRouteIds = routeOrders
.stream()
.filter(Objects::nonNull)
.map(RouteOrder::getRouteId)
.toList();
List<Long> needQueryFromDB = routeIds
.stream()
.filter(id -> !existedRouteIds.contains(id))
.toList();
List<RouteOrder> byRouteIdIn = jdbcRouteRepository
.findByRouteIdIn(needQueryFromDB);
//将查询出来的行程规划单缓存到数据库
byRouteIdIn.forEach(route -> routeCacheService.cacheRouteOrder(route));
routeOrders.addAll(byRouteIdIn);
return routeOrders;
return routeCacheService.queryByIdIn(routeIds);
// List<RouteOrder> routeOrders = new java.util.ArrayList<>(routeCacheService.queryByIdIn(routeIds)
// .stream()
// .filter(Objects::nonNull)
// .toList());
// List<Long> existedRouteIds = routeOrders
// .stream()
// .filter(Objects::nonNull)
// .map(RouteOrder::getRouteId)
// .toList();
// List<Long> needQueryFromDB = routeIds
// .stream()
// .filter(id -> !existedRouteIds.contains(id))
// .toList();
// List<RouteOrder> 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<RouteOrder> findAllByEmployeeNo(String employeeNo) {
return routeCacheService.getUserRoutes(employeeNo);
// return jdbcRouteRepository.findByUserIdAndApproveOrderNo_ActualOrderNoNotNullOrApproveOrderNo_CreatorAndApproveOrderNo_ActualOrderNoNotNull(employeeNo, employeeNo);
}
@Override