public Map<String, Object> queryCoachByPageByParam(QueryRequest queryRequest, Admin admin) { Map<String, Object> map = new HashMap<>(); Admin admin1 = adminMapper.selectById(admin.getAdminId());

    //总管理
    if (admin1.getTotalAdminId() != null && admin1.getTotalAdminId() == 0) {
        QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq('total_admin_id', admin.getAdminId()); // 添加索引 'total_admin_id'
        List<Admin> admins = adminMapper.selectList(queryWrapper);
        List<CoachDto> coachList = new ArrayList<>();

        // 批量查询所有admin_id对应的Admin对象
        List<Coach> coaches = coachMapper.selectBatchIds(admins.stream().map(Admin::getAdminId).collect(Collectors.toList())); // 添加索引 'admin_id'

        if (!CollectionUtils.isEmpty(coaches)) {
            Date date = RcqtUtils.getDay();
            for (Coach coach : coaches) {
                List<CourseDto> courseDtoList = courseInfoService.queryCourseByCoachId(coach.getCoachId(), date); // 添加索引 'coach_id'
                boolean isWorking = courseDtoList.stream()
                        .anyMatch(c -> LocalTime.now().isAfter(c.getStartReservationTime().toLocalTime()) && LocalTime.now().isBefore(c.getEndReservationTime().toLocalTime()));
                CoachDto coachDto = new CoachDto();
                BeanUtils.copyProperties(coach, coachDto);
                coachDto.setWorkStatus(isWorking);
                coachDto.setAdminRealName(admin2.getRealName());
                coachDto.setAdminPhone(admin2.getAdminPhone());
                coachDto.setCarCount(queryAllDeviceEntitiesByCoachIdByCount(coach.getCoachId()));
                coachList.add(coachDto);
            }
        }

        Comparator<CoachDto> comparator = Comparator.comparing(CoachDto::getWorkStatus, Comparator.reverseOrder())
                .thenComparing((c1, c2) -> Collator.getInstance(Locale.CHINESE).compare(c1.getRealName(), c2.getRealName()));

        coachList.sort(comparator);

        int total = coachList.size();
        int startIndex = (queryRequest.getPageNum() - 1) * queryRequest.getPageSize();
        int endIndex = Math.min(startIndex + queryRequest.getPageSize(), total);
        List<CoachDto> coaches = coachList.subList(startIndex, endIndex);

        map.put('coaches', coaches);
        map.put('total', total);

        return map;
    }

    //1.查询条件
    QueryWrapper<Coach> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq('admin_id', admin.getAdminId()); // 添加索引 'admin_id'

    List<Coach> coaches = coachMapper.selectList(queryWrapper);
    List<CoachDto> coachList = new ArrayList<>();

    if (!CollectionUtils.isEmpty(coaches)) {
        Date date = RcqtUtils.getDay();
        for (Coach coach : coaches) {
            List<CourseDto> courseDtoList = courseInfoService.queryCourseByCoachId(coach.getCoachId(), date); // 添加索引 'coach_id'
            boolean isWorking = courseDtoList.stream()
                    .anyMatch(c -> LocalTime.now().isAfter(c.getStartReservationTime().toLocalTime()) && LocalTime.now().isBefore(c.getEndReservationTime().toLocalTime()));
            CoachDto coachDto = new CoachDto();
            BeanUtils.copyProperties(coach, coachDto);
            coachDto.setWorkStatus(isWorking);
            coachDto.setCarCount(queryAllDeviceEntitiesByCoachIdByCount(coach.getCoachId()));
            coachList.add(coachDto);
        }
    }

    Comparator<CoachDto> comparator = Comparator.comparing(CoachDto::getWorkStatus, Comparator.reverseOrder())
            .thenComparing((c1, c2) -> Collator.getInstance(Locale.CHINESE).compare(c1.getRealName(), c2.getRealName()));

    coachList.sort(comparator);
    int total = coachList.size();
    int startIndex = (queryRequest.getPageNum() - 1) * queryRequest.getPageSize();
    int endIndex = Math.min(startIndex + queryRequest.getPageSize(), total);
    List<CoachDto> coachDtoList = coachList.subList(startIndex, endIndex);

    map.put('coaches', coachDtoList);
    map.put('total', total);

    return map;
}
分页查询教练信息 - 高效查询教练列表

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

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