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); List<User> byEmployeeNoIn = userRepository.findByEmployeeNoIn(employeeNoSet);
Map<String, User> userMap = byEmployeeNoIn Map<String, User> userMap = byEmployeeNoIn
.stream() .stream()
.distinct()
.collect(Collectors.toMap(User::getEmployeeNo, Function.identity())); .collect(Collectors.toMap(User::getEmployeeNo, Function.identity()));
List<RouteOrderPageRes> orders = routeOrders List<RouteOrderPageRes> orders = routeOrders
.stream() .stream()

View File

@ -82,7 +82,10 @@ public class RouteCacheService {
// return routeListByIds; // return routeListByIds;
} else { } else {
List<RouteOrder> routeOrders = jdbcRouteRepository.findByUserIdOrApproveOrderNo_Creator(employeeNo, employeeNo); 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; return routeOrders;
} }
} }

View File

@ -17,7 +17,6 @@ import org.springframework.stereotype.Repository;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Repository @Repository
@ -57,25 +56,26 @@ public class RouteRepositoryImpl implements RouteRepository {
@Override @Override
public List<RouteOrder> queryByIdIn(List<Long> routeIds) { public List<RouteOrder> queryByIdIn(List<Long> routeIds) {
List<RouteOrder> routeOrders = new java.util.ArrayList<>(routeCacheService.queryByIdIn(routeIds) return routeCacheService.queryByIdIn(routeIds);
.stream() // List<RouteOrder> routeOrders = new java.util.ArrayList<>(routeCacheService.queryByIdIn(routeIds)
.filter(Objects::nonNull) // .stream()
.toList()); // .filter(Objects::nonNull)
List<Long> existedRouteIds = routeOrders // .toList());
.stream() // List<Long> existedRouteIds = routeOrders
.filter(Objects::nonNull) // .stream()
.map(RouteOrder::getRouteId) // .filter(Objects::nonNull)
.toList(); // .map(RouteOrder::getRouteId)
List<Long> needQueryFromDB = routeIds // .toList();
.stream() // List<Long> needQueryFromDB = routeIds
.filter(id -> !existedRouteIds.contains(id)) // .stream()
.toList(); // .filter(id -> !existedRouteIds.contains(id))
List<RouteOrder> byRouteIdIn = jdbcRouteRepository // .toList();
.findByRouteIdIn(needQueryFromDB); // List<RouteOrder> byRouteIdIn = jdbcRouteRepository
//将查询出来的行程规划单缓存到数据库 // .findByRouteIdIn(needQueryFromDB);
byRouteIdIn.forEach(route -> routeCacheService.cacheRouteOrder(route)); // //将查询出来的行程规划单缓存到数据库
routeOrders.addAll(byRouteIdIn); // byRouteIdIn.forEach(route -> routeCacheService.cacheRouteOrder(route));
return routeOrders; // routeOrders.addAll(byRouteIdIn);
// return routeOrders;
} }
@Override @Override
@ -188,7 +188,6 @@ public class RouteRepositoryImpl implements RouteRepository {
@Override @Override
public List<RouteOrder> findAllByEmployeeNo(String employeeNo) { public List<RouteOrder> findAllByEmployeeNo(String employeeNo) {
return routeCacheService.getUserRoutes(employeeNo); return routeCacheService.getUserRoutes(employeeNo);
// return jdbcRouteRepository.findByUserIdAndApproveOrderNo_ActualOrderNoNotNullOrApproveOrderNo_CreatorAndApproveOrderNo_ActualOrderNoNotNull(employeeNo, employeeNo);
} }
@Override @Override