需求:
需要将t_app_message中的消息(将要被发送的消息)给每一个学生发送一遍,并且在发送完成后,将消息置为已发送状态已发送状态。
一言不合上代码
1 /*删除存储过程*/ 2 drop procedure if exists proc_sendAllMsg; 3 /*创建存储过程*/ 4 CREATE PROCEDURE proc_sendAllMsg() 5 BEGIN 6 /*先插入*/ 7 INSERT t_base_message (sid,mid) 8 SELECT a.id,b.id from t_base_student a 9 INNER JOIN t_app_message b 10 where a.School_id = 1 and b.sendtime<=NOW() and b.sendstatus = 0; 11 UPDATE t_app_message SET sendstatus = 1 where sendtime <=NOW(); 12 UPDATE t_app_message SET showstatus = 1 where endtime <=NOW(); 13 end 14 15 /*指定数据库*/ 16 use xscp; 17 /*删除原有的定时任务*/ 18 drop event if exists event_sendAllMsg; 19 20 CREATE EVENT event_sendAllMsg ON SCHEDULE EVERY 30 second starts ‘2017-12-11 00:00:00‘ 21 DO 22 CALL proc_sendAllMsg; /*调用存储过程*/