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());
    List<Admin> admins = adminMapper.selectList(queryWrapper);
    List<CoachDto> coachList = new ArrayList<>();

    for (Admin admin2 : admins) {
        List<Coach> coaches = queryAllCoachByAdminId(admin2.getAdminId());

        if (!CollectionUtils.isEmpty(coaches)) {
            Date date = RcqtUtils.getDay();

            List<CourseDto> courseDtoList = courseInfoService.queryCourseByCoachId(coach.getCoachId(), date);
            boolean isWorking = courseDtoList.stream()
                    .anyMatch(c -> LocalTime.now().isAfter(c.getStartReservationTime().toLocalTime()) && LocalTime.now().isBefore(c.getEndReservationTime().toLocalTime()));

            for (Coach coach : coaches) {
                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());

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

if (!CollectionUtils.isEmpty(coaches)) {
    for (Coach coach : coaches) {
        Date date = RcqtUtils.getDay();

        List<CourseDto> courseDtoList = courseInfoService.queryCourseByCoachId(coach.getCoachId(), date);
        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/qgkA 著作权归作者所有。请勿转载和采集!

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