2021-07-17

退座功能实现

判断签到时间,进行退座处理,并添加一条退座消息

Controller层实现

在这里插入图片描述

@RestController
@RequestMapping("/withdraw")
public class UserWithdrawSeatController {
    @Autowired
    UserWithdrawSeatService userWithdrawSeatService;

    @GetMapping("/withdrawSeat")
    public int withdrawSeat(HttpServletRequest request, int act_id,String room_name, int seat_no){
        String user_openid = (String) request.getAttribute("openid");
        return userWithdrawSeatService.userWithdrawPick(user_openid,act_id,room_name,seat_no);
    }
}

Service层实现

在这里插入图片描述

@Service
public class UserWithdrawSeatService {

    @Autowired
    UserWithdrawSeatMapper userWithdrawSeatMapper;

    public int userWithdrawPick(String user_openid,int act_id,String room_name,int seat_no) {
        Date date = new Date();
        System.out.println(userWithdrawSeatMapper.getSigninTime(act_id));
        int compareTo = date.compareTo(userWithdrawSeatMapper.getSigninTime(act_id));
        System.out.println(compareTo);//比较退座时间和活动开始时间
        //date1小于date2返回-1,date1大于date2返回1,相等返回0
        if (compareTo<1) {
            int seat_id = userWithdrawSeatMapper.getSeatId(room_name,seat_no);
            int act_room_seat_id = userWithdrawSeatMapper.getActRoomSeatId(act_id,seat_id);
            String act_name = userWithdrawSeatMapper.getActName(act_id);
            userWithdrawSeatMapper.userWithdrawSeat(user_openid, act_room_seat_id);
            return userWithdrawSeatMapper.addWithdrawMessage(user_openid, "退座申请结果", act_name + "座位" + seat_no + "退座成功", date);
        }
        else
            userWithdrawSeatMapper.addWithdrawMessage(user_openid,"退座申请结果","已超时,退座失败",date);
            return 0;
    }
}

Mapper层实现

在这里插入图片描述

@Mapper
public interface UserWithdrawSeatMapper {

    @Select("SELECT seat_id FROM seat WHERE room_name = #{room_name} and seat_no = #{seat_no}")
    int getSeatId(String room_name,int seat_no);
    //查询seat_id

    @Select("SELECT act_room_seat_id FROM act_room_seat WHERE act_id = #{act_id} and seat_id = #{seat_id}")
    int getActRoomSeatId(int act_id,int seat_id);
    //查询act_room_seat_id

    @Select("SELECT act_start_time FROM activity WHERE act_id = (#{act_id})")
    Date getSigninTime(int act_id);
    //获得活动开始时间

    @Delete("DELETE FROM user_pick_seat WHERE user_openid = #{user_openid} and act_room_seat_id = #{act_room_seat_id}")
    int userWithdrawSeat(String user_openid,int act_room_seat_id);
    //退座,删除记录

    @Select("SELECT act_name FROM activity WHERE act_id = #{act_id}")
    String getActName(int act_id);
    //查询活动名

    @Insert("INSERT INTO message (user_openid,message_title,message_content,time) VALUES (#{user_openid},#{message_title},#{message_content},#{time})")
    int addWithdrawMessage(String user_openid,String message_title,String message_content,Date time);
    //插入message记录
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值