//查询当前管理员所有教练 List coaches = adminService.queryAllCoachByAdminId(admin.getAdminId());

//(1)通过姓名和电话查询-普通管理员 if (!StringUtils.isEmpty(text)) { //存放所有管理员名下教练 List coachDtoList = new ArrayList<>(); List coachList = new ArrayList<>(); for (Coach coach : coaches) { if (coach.getRealName() != null && (coach.getRealName().contains(text) || coach.getCoachPhone().contains(text))) { coachList.add(coach); } }

if (!CollectionUtils.isEmpty(coachList)) {
    List<Long> coachIds = coachList.stream()
        .map(Coach::getCoachId)
        .collect(Collectors.toList());
    Map<Long, Coach> coachMap = coaches.stream().collect(Collectors.toMap(Coach::getCoachId, Function.identity()));

    // 查询当前教练课程
    Map<Long, List<CourseDto>> courseDtoMap = courseInfoService.queryCourseByCoachIds(coachIds, RcqtUtils.getDay());

    coachDtoList = coachIds.stream()
        .map(coachId -> {
            Coach coach = coachMap.get(coachId);

            if (coach != null) {
                CoachDto coachDto = new CoachDto();
                BeanUtils.copyProperties(coach, coachDto);

                // 判断教练是否在工作中
                List<CourseDto> courseDtoList = courseDtoMap.get(coachId);
                boolean isWorking = courseDtoList != null && courseDtoList.stream()
                    .anyMatch(c -> {
                        LocalTime currentTime = LocalTime.now();
                        return currentTime.isAfter(c.getStartReservationTime().toLocalTime()) && currentTime.isBefore(c.getEndReservationTime().toLocalTime());
                    });
                coachDto.setWorkStatus(isWorking);
                return coachDto;
            }
            return null;
        })
        .filter(Objects::nonNull)
        .collect(Collectors.toList());

}

//按照姓名与工作状态排序
Comparator<CoachDto> comparator = Comparator.comparing(CoachDto::getWorkStatus, Comparator.reverseOrder())
    .thenComparing((c1, c2) -> Collator.getInstance(Locale.CHINESE).compare(c1.getRealName(), c2.getRealName()));
coachDtoList.sort(comparator);

//进行分页
List<CoachDto> coachDtoListByPage = coachDtoList.stream()
    .skip((long) (queryRequest.getPageNum() - 1) * queryRequest.getPageSize())
    .limit(queryRequest.getPageSize())
    .collect(Collectors.toList());

map.put("coaches", coachDtoListByPage);
map.put("total", coachDtoList.size());

return new Result<>(ResultCode.SUCCESS, map);

}

//(2)查询所有教练-普通管理员 List coachDtoList = new ArrayList<>(); List coachIds = coaches.stream() .map(Coach::getCoachId) .collect(Collectors.toList()); Map<Long, Coach> coachMap = coaches.stream().collect(Collectors.toMap(Coach::getCoachId, Function.identity()));

if (!CollectionUtils.isEmpty(coaches)) { // 查询当前教练课程 Map<Long, List> courseDtoMap = courseInfoService.queryCourseByCoachIds(coachIds, RcqtUtils.getDay());

coachDtoList = coachIds.stream()
    .map(coachId -> {
        Coach coach = coachMap.get(coachId);

        if (coach != null) {
            CoachDto coachDto = new CoachDto();
            BeanUtils.copyProperties(coach, coachDto);

            // 判断教练是否在工作中
            List<CourseDto> courseDtoList = courseDtoMap.get(coachId);
            boolean isWorking = courseDtoList != null && courseDtoList.stream()
                .anyMatch(c -> {
                    LocalTime currentTime = LocalTime.now();
                    return currentTime.isAfter(c.getStartReservationTime().toLocalTime()) && currentTime.isBefore(c.getEndReservationTime().toLocalTime());
                });
            coachDto.setWorkStatus(isWorking);
            return coachDto;
        }
        return null;
    })
    .filter(Objects::nonNull)
    .collect(Collectors.toList());

//按照姓名与工作状态排序
Comparator<CoachDto> comparator = Comparator.comparing(CoachDto::getWorkStatus, Comparator.reverseOrder())
    .thenComparing((c1, c2) -> Collator.getInstance(Locale.CHINESE).compare(c1.getRealName(), c2.getRealName()));
coachDtoList.sort(comparator);

}

//(3)通过科目和工作状态-普通管理员 if (!StringUtils.isEmpty(workStatus) && !StringUtils.isEmpty(drivingProjectType)) { //前端传递工作状态为0、1 Boolean workStatusB = Integer.parseInt(workStatus) == 1; List filteredList = coachDtoList.stream() .filter(coachDto -> coachDto.getWorkStatus() == workStatusB && coachDto.getDrivingProjectType() != null && coachDto.getDrivingProjectType().contains(drivingProjectType)) .toList(); //分页查询 List coachDtos = filteredList.stream() .skip((long) (queryRequest.getPageNum() - 1) * queryRequest.getPageSize()) .limit(queryRequest.getPageSize()) .collect(Collectors.toList());

map.put("coachList", coachDtos);
map.put("total", filteredList.size());
return new Result<>(ResultCode.SUCCESS, map);

} else if (StringUtils.isEmpty(workStatus) && !StringUtils.isEmpty(drivingProjectType)) { List filteredList = coachDtoList.stream() .filter(coachDto -> coachDto.getDrivingProjectType() != null && coachDto.getDrivingProjectType().contains(drivingProjectType)) .toList(); //分页查询 List coachDtos = filteredList.stream() .skip((long) (queryRequest.getPageNum() - 1) * queryRequest.getPageSize()) .limit(queryRequest.getPageSize()) .collect(Collectors.toList());

map.put("coachList", coachDtos);
map.put("total", filteredList.size());
return new Result<>(ResultCode.SUCCESS, map);

} else if (!StringUtils.isEmpty(workStatus) && StringUtils.isEmpty(drivingProjectType)) { //前端传递工作状态为0、1 Boolean workStatusB = Integer.parseInt(workStatus) == 1; List filteredList = coachDtoList.stream() .filter(coachDto -> coachDto.getWorkStatus() == workStatusB) .toList(); //分页查询 List coachDtos = filteredList.stream() .skip((long) (queryRequest.getPageNum() - 1) * queryRequest.getPageSize()) .limit(queryRequest.getPageSize()) .collect(Collectors.toList());

map.put("coachList", coachDtos);
map.put("total", filteredList.size());
return new Result<>(ResultCode.SUCCESS, map);

}

//进行分页 List coachDtoListByPage = coachDtoList.stream() .skip((long) (queryRequest.getPageNum() - 1) * queryRequest.getPageSize()) .limit(queryRequest.getPageSize()) .collect(Collectors.toList());

map.put("coaches", coachDtoListByPage); map.put("total", coachDtoList.size());

return new Result<>(ResultCode.SUCCESS, map)

查询当前管理员所有教练 ListCoach coaches = adminServicequeryAllCoachByAdminIdadmingetAdminId; 1通过姓名和电话查询-普通管理员 if !StringUtilsisEmptytext 存放所有管理员名下教练 ListCoachDto coac

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

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