查询教练特定日期的约课安排
<p>{"@GetMapping":""/queryCourseByCoachIDByDate"","public":" Result<Object> queryCourseByCoachIDByDate(Coach coach, String date, HttpServletRequest request) throws ParseException {\n\n // 权限验证\n String token = (String) request.getAttribute("claims_coach");\n\n if (token == null || "".equals(token)) {\n throw new RuntimeException("权限不足!");\n }\n\n if (coach.getCoachId() == null) {\n log.info("coachId为null");\n return new Result<>(ResultCode.FAIL);\n }\n\n // 转换前端传递日期格式\n Date convertedDate = RcqtUtils.getconvertedDate(date);\n\n Map<String, Object> map = new HashMap<>();\n // 查询日期对应的数据\n List<UpdateTime> updateTimeList = updateTimeService.queryUpdateTimeByDate(coach.getCoachId(), convertedDate);\n\n if (CollectionUtils.isEmpty(updateTimeList)) {\n log.info("查询当前日期数据为空!");\n // 查询教练自己设置的默认时间段\n List<DefaultTime> defaultTimes = defaultTimeService.queryDefaultTimeByCoachID(coach.getCoachId());\n\n if (!defaultTimes.isEmpty()) {\n List<UpdateTime> updateTimes = defaultTimes.stream()\n .filter(defaultTime -> defaultTime.getStartReservationTime() != null && defaultTime.getEndReservationTime() != null)\n .map(defaultTime -> {\n UpdateTime updateTime = new UpdateTime();\n updateTime.setCoachId(coach.getCoachId());\n updateTime.setProjectType(defaultTime.getProjectType());\n updateTime.setCourseDate(convertedDate);\n updateTime.setStartReservationTime(defaultTime.getStartReservationTime());\n updateTime.setEndReservationTime(defaultTime.getEndReservationTime());\n updateTime.setMaxReservation(defaultTime.getMaxReservation());\n updateTime.setCourseStatus(false);// 人数未满\n updateTime.setCurrentReservation(0);// 当前预约人数0\n SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");\n String currentDate = dateFormat.format(convertedDate);\n String week = RcqtUtils.getDayOfWeek(currentDate);// 得到当前日期对应周几\n if (!StringUtils.isEmpty(week)) {\n updateTime.setIsBreakDate(defaultTime.getRestDay().contains(week));\n }\n return updateTime;\n })\n .collect(Collectors.toList());\n\n // Batch save the updateTimes\n boolean b = updateTimeService.saveBatch(updateTimes);\n if (!b) {\n log.info("新增失败");\n return new Result<>(ResultCode.FAIL);\n }\n List<Long> updateTimeIds = updateTimes.stream().map(UpdateTime::getUpdateTimeId).collect(Collectors.toList());\n\n // Parallel stream to query courseInfos\n List<CourseInfo> courseInfos = courseInfoService.queryCourseByUpdateTimeIds(updateTimeIds);\n Map<Long, List<CarUser>> courseInfoMap = courseInfos.parallelStream()\n .collect(Collectors.groupingByConcurrent(CourseInfo::getUpdateTimeId,\n Collectors.mapping(courseInfo -> carUserService.queryOneCarUserById(courseInfo.getUserId()), Collectors.toList())));\n\n updateTimeList = updateTimes.stream()\n .map(updateTime -> {\n UpdateTimeDto updateTimeDto = new UpdateTimeDto();\n BeanUtils.copyProperties(updateTime, updateTimeDto);\n List<CarUser> carUserList = courseInfoMap.get(updateTime.getUpdateTimeId());\n if (carUserList != null) {\n updateTimeDto.setCurrentReservation(carUserList.size());// 当前预约人数\n updateTimeDto.setCarUserList(carUserList);\n if (carUserList.size() == updateTime.getMaxReservation()) {\n updateTimeDto.setCourseStatus(true);// 设置课程状态为已满\n }\n }\n if (updateTimeDto.getCourseDate().equals(RcqtUtils.getDay()) && updateTimeDto.getStartReservationTime() != null) {\n updateTimeDto.setIsTimeOut(LocalTime.now().isAfter(updateTimeDto.getStartReservationTime().toLocalTime()));\n }\n return updateTimeDto;\n })\n .collect(Collectors.toList());\n }\n } else {\n List<Long> updateTimeIds = updateTimeList.stream().map(UpdateTime::getUpdateTimeId).collect(Collectors.toList());\n // Parallel stream to query courseInfos\n List<CourseInfo> courseInfos = courseInfoService.queryCourseByUpdateTimeIds(updateTimeIds);\n Map<Long, List<CarUser>> courseInfoMap = courseInfos.parallelStream()\n .collect(Collectors.groupingByConcurrent(CourseInfo::getUpdateTimeId,\n Collectors.mapping(courseInfo -> carUserService.queryOneCarUserById(courseInfo.getUserId()), Collectors.toList())));\n\n updateTimeList = updateTimeList.stream()\n .map(updateTime -> {\n UpdateTimeDto updateTimeDto = new UpdateTimeDto();\n BeanUtils.copyProperties(updateTime, updateTimeDto);\n List<CarUser> carUserList = courseInfoMap.get(updateTime.getUpdateTimeId());\n if (carUserList != null) {\n updateTimeDto.setCurrentReservation(carUserList.size());// 当前预约人数\n updateTimeDto.setCarUserList(carUserList);\n if (carUserList.size() == updateTime.getMaxReservation()) {\n updateTimeDto.setCourseStatus(true);// 设置课程状态为已满\n }\n }\n if (updateTimeDto.getCourseDate().equals(RcqtUtils.getDay()) && updateTimeDto.getStartReservationTime() != null) {\n updateTimeDto.setIsTimeOut(LocalTime.now().isAfter(updateTimeDto.getStartReservationTime().toLocalTime()));\n }\n return updateTimeDto;\n })\n .collect(Collectors.toList());\n }\n\n for (UpdateTimeDto updateTimeDto : updateTimeList) {\n if (updateTimeDto.getIsTimeOut() != null && updateTimeDto.getIsTimeOut()) {\n map.put("isTimeOutAll");\n break;\n }\n }\n\n map.put("isBreakDate");\n map.put("updateTimeList");\n log.info("通过日期查询约课安排成功!");\n return new Result<>(ResultCode.SUCCESS, map);\n }</p>
原文地址: https://www.cveoy.top/t/topic/p6Dy 著作权归作者所有。请勿转载和采集!