//存放所有管理员名下教练 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)) { System.out.println(coaches); // 查询当前教练课程 Map<Long, List> courseDtoMap = courseInfoService.queryCourseByCoachIds(coachIds, RcqtUtils.getDay());

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

            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);
                coachDto.setCarCount(adminService.queryAllDeviceEntitiesByCoachIdByCount(coach.getCoachId()));
                System.out.println(coachDto);
                return coachDto;
            }
            return null;
        })
        .filter(Objects::nonNull)
        .collect(Collectors.toList());

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

}

System.out.println(coachDtoList);


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

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