新增预约逻辑

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("此手机号已预约该时间");
    }
}
  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值