作者:刘浩不来丷上海594865126 | 来源:互联网 | 2023-05-19 04:39
需求: 需要将t_app_message中的消息(将要被发送的消息)给每一个学生发送一遍,并且在发送完成后,将消息置为已发送状态已发送状态。一言不合上代码1*删除存储过程*2dr
需求:
需要将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; /*调用存储过程*/
![]()
1 查看event是否开启 : SHOW VARIABLES LIKE '%event_sche%';
2 将事件计划开启 : SET GLOBAL event_scheduler = 1;
3 将事件计划关闭 : SET GLOBAL event_scheduler = 0;
4 关闭事件任务 : ALTER EVENT eventName ON COMPLETION PRESERVE DISABLE;
5 开启事件任务 : ALTER EVENT eventName ON COMPLETION PRESERVE ENABLE;
6 查看事件任务 : SHOW EVENTS ;
View Code