status为2表示取消预约
/** * 查询取消预约数量 * @param userId * @return */ @Override public Integer getCancelledReservationCount(Long userId) { Integer num = reservationMapper.countCancelledReservations(userId, LocalDateTime.now().withHour(0).withMinute(0).withSecond(0), LocalDateTime.now().withHour(23).withMinute(59).withSecond(59)); return num; } /** * 查询每个时间段剩余预约次数 * @param time * @return */ @Override public List<TimeCountVo> countReservationsForEachTimeWithinTimeRange(LocalDateTime time) { LocalDateTime endTime = time.plusHours(24); List<TimeCountVo> timeCountVos = reservationMapper.countAvailableReservations(time,endTime); return timeCountVos; } /** * 新增预约 * @param reservationDto */ @Override public void add(ReservationDto reservationDto) { Long userId = UserThreadLocal.getUserId(); // 如果已经预约的次数超过3次,则不能再进行预约 Integer count = getCancelledReservationCount(userId); if (count >= 3) { throw new BaseException("今天取消次数已达上限,不可进行预约"); } //类型转换 Reservation reservation = new Reservation(); BeanUtils.copyProperties(reservationDto, reservation); //设置状态 待报到 reservation.setStatus(ReservationStatus.PENDING.getOrdinal()); //设置创建人 reservation.setCreateBy(userId); //手机号唯一 try { reservationMapper.insert(reservation); } catch (Exception e) { throw new RuntimeException("此手机号已预约该时间"); } }