退座功能实现
判断签到时间,进行退座处理,并添加一条退座消息
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记录
}