普通管理员查询教练列表 API 日期: 2024-12-11 标签: 常规 { "title": "//2.普通管理员\nList coaches = adminService.queryAllCoachByAdminId(admin.getAdminId());//查询当前管理员所有教练\nList coachDtoList = new ArrayList<>();\n\n//筛选教练\nfor (Coach coach : coaches) {\nif (!StringUtils.isEmpty(text) && coach.getRealName() != null && (coach.getRealName().contains(text) || coach.getCoachPhone().contains(text))) {\ncoachDtoList.add(generateCoachDto(coach));\n} else if (StringUtils.isEmpty(text)) {\ncoachDtoList.add(generateCoachDto(coach));\n}\n}\n\n//根据工作状态和科目筛选教练\nif (!StringUtils.isEmpty(workStatus) || !StringUtils.isEmpty(drivingProjectType)) {\nboolean isWorking = !StringUtils.isEmpty(workStatus) && Integer.parseInt(workStatus) == 1;\nList filteredList = coachDtoList.stream()\n\t\t.filter(coachDto -> coachDto.getWorkStatus() == isWorking && coachDto.getDrivingProjectType() != null && coachDto.getDrivingProjectType().contains(drivingProjectType))\n\t\t.collect(Collectors.toList());\ncoachDtoList = filteredList;\n}\n\n//按照姓名与工作状态排序\nComparator comparator = Comparator.comparing(CoachDto::getWorkStatus, Comparator.reverseOrder())\n\t\t.thenComparing((c1, c2) -> Collator.getInstance(Locale.CHINESE).compare(c1.getRealName(), c2.getRealName()));\ncoachDtoList.sort(comparator);\n\n//进行分页\nint total = coachDtoList.size();\nint start = (queryRequest.getPageNum() - 1) * queryRequest.getPageSize();\nint end = Math.min(start + queryRequest.getPageSize(), total);\nList coachDtoListByPage = coachDtoList.subList(start, end);\n\nmap.put("coaches", coachDtoListByPage);\nmap.put("total", total);\n\nreturn new Result<>(ResultCode.SUCCESS, map);\n\nprivate CoachDto generateCoachDto(Coach coach) {\nCoachDto coachDto = new CoachDto();\nBeanUtils.copyProperties(coach, coachDto);\n\n// 判断教练是否在工作中\nList courseDtoList = courseInfoService.queryCourseByCoachId(coach.getCoachId(), RcqtUtils.getDay());\nboolean isWorking = courseDtoList != null && courseDtoList.stream()\n\t\t.anyMatch(c -> {\n\t\t\tLocalTime currentTime = LocalTime.now();\n\t\t\treturn currentTime.isAfter(c.getStartReservationTime().toLocalTime()) && currentTime.isBefore(c.getEndReservationTime().toLocalTime());\n\t\t});\ncoachDto.setWorkStatus(isWorking);\n\nreturn coachDto;\n} } 原文地址: https://www.cveoy.top/t/topic/qhKD 著作权归作者所有。请勿转载和采集! 免费AI点我,无需注册和登录