{/'title/':/'优化查询教练分页接口,提升查询效率/',/'description/':/'本接口用于根据条件分页查询教练信息,优化后提升了查询效率。/',/'keywords/':/'教练, 分页, 查询, 优化, 效率/',/'content/':/'public Map<String, Object> queryCoachByPageByParam(QueryRequest queryRequest, Admin admin) {//n Map<String, Object> map = new HashMap<>();//n Admin admin1 = adminMapper.selectById(admin.getAdminId());//n//n //总管理//n if (admin1.getTotalAdminId() != null && admin1.getTotalAdminId() == 0) {//n QueryWrapper queryWrapper = new QueryWrapper<>();//n queryWrapper.eq(/'total_admin_id/', admin.getAdminId());//n List admins = adminMapper.selectList(queryWrapper);//n//n List coachList = new ArrayList<>();//n//n for (Admin admin2 : admins) {//n List coaches = queryAllCoachByAdminId(admin2.getAdminId());//n//n if (!CollectionUtils.isEmpty(coaches)) {//n Date date = RcqtUtils.getDay();//n List coachIds = coaches.stream().map(Coach::getCoachId).collect(Collectors.toList());//n List courseDtoList = courseInfoService.queryCourseByCoachIds(coachIds, date);//n Map<Integer, Boolean> workingStatusMap = getWorkingStatusMap(courseDtoList);//n //n for (Coach coach : coaches) {//n boolean isWorking = workingStatusMap.getOrDefault(coach.getCoachId(), false);//n CoachDto coachDto = createCoachDto(coach, admin2, isWorking);//n coachList.add(coachDto);//n }//n }//n }//n//n Comparator comparator = Comparator.comparing(CoachDto::getWorkStatus, Comparator.reverseOrder())//n .thenComparing((c1, c2) -> Collator.getInstance(Locale.CHINESE).compare(c1.getRealName(), c2.getRealName()));//n//n coachList.sort(comparator);//n//n int total = coachList.size();//n int startIndex = (queryRequest.getPageNum() - 1) * queryRequest.getPageSize();//n int endIndex = Math.min(startIndex + queryRequest.getPageSize(), total);//n List coaches = coachList.subList(startIndex, endIndex);//n//n map.put(/'coaches/', coaches);//n map.put(/'total/', total);//n//n return map;//n }//n//n //1.查询条件//n QueryWrapper queryWrapper = new QueryWrapper<>();//n queryWrapper.eq(/'admin_id/', admin.getAdminId());//n//n List coaches = coachMapper.selectList(queryWrapper);//n List coachList = new ArrayList<>();//n//n if (!CollectionUtils.isEmpty(coaches)) {//n Date date = RcqtUtils.getDay();//n List coachIds = coaches.stream().map(Coach::getCoachId).collect(Collectors.toList());//n List courseDtoList = courseInfoService.queryCourseByCoachIds(coachIds, date);//n Map<Integer, Boolean> workingStatusMap = getWorkingStatusMap(courseDtoList);//n //n for (Coach coach : coaches) {//n boolean isWorking = workingStatusMap.getOrDefault(coach.getCoachId(), false);//n CoachDto coachDto = createCoachDto(coach, null, isWorking);//n coachList.add(coachDto);//n }//n }//n//n Comparator comparator = Comparator.comparing(CoachDto::getWorkStatus, Comparator.reverseOrder())//n .thenComparing((c1, c2) -> Collator.getInstance(Locale.CHINESE).compare(c1.getRealName(), c2.getRealName()));//n//n coachList.sort(comparator);//n int total = coachList.size();//n int startIndex = (queryRequest.getPageNum() - 1) * queryRequest.getPageSize();//n int endIndex = Math.min(startIndex + queryRequest.getPageSize(), total);//n List coachDtoList = coachList.subList(startIndex, endIndex);//n//n map.put(/'coaches/', coachDtoList);//n map.put(/'total/', total);//n//n return map;//n}//n//nprivate List queryAllCoachByAdminId(Integer adminId) {//n QueryWrapper queryWrapper = new QueryWrapper<>();//n queryWrapper.eq(/'admin_id/', adminId);//n return coachMapper.selectList(queryWrapper);//n}//n//nprivate List queryAllDeviceEntitiesByCoachIdByCount(Integer coachId) {//n // implementation of queryAllDeviceEntitiesByCoachIdByCount//n}//n//nprivate Map<Integer, Boolean> getWorkingStatusMap(List courseDtoList) {//n Date currentDate = RcqtUtils.getDay();//n LocalTime currentTime = LocalTime.now();//n//n return courseDtoList.stream()//n .collect(Collectors.toMap(CourseDto::getCoachId, c -> isWorking(currentDate, currentTime, c)));//n}//n//nprivate boolean isWorking(Date currentDate, LocalTime currentTime, CourseDto courseDto) {//n return currentTime.isAfter(courseDto.getStartReservationTime().toLocalTime()) && currentTime.isBefore(courseDto.getEndReservationTime().toLocalTime());//n}//n//nprivate CoachDto createCoachDto(Coach coach, Admin admin, boolean isWorking) {//n CoachDto coachDto = new CoachDto();//n BeanUtils.copyProperties(coach, coachDto);//n coachDto.setWorkStatus(isWorking);//n //n if (admin != null) {//n coachDto.setAdminRealName(admin.getRealName());//n coachDto.setAdminPhone(admin.getAdminPhone());//n }//n //n coachDto.setCarCount(queryAllDeviceEntitiesByCoachIdByCount(coach.getCoachId()));//n //n return coachDto;//n}/

优化查询教练分页接口,提升查询效率

原文地址: http://www.cveoy.top/t/topic/qgmp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录