定时事件——调用函数

函数config() 内容
BEGIN
DECLARE t_error INT DEFAULT 0; -- 事务执行错误标志
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=1;
    START TRANSACTION;
-- 断闸命令
insert into amp_command(dtuId,detectorNum,commandType,sendStatus,update_date,create_date,create_by) select left(machine_id,length(machine_id)-2),right(machine_id,2),1,0,NOW(),NOW(),create_by from amp_device_config where off_type = 1  and off_time <= now();
update amp_device_config set off_type = 0 where off_type = 1 and off_time <= now() ;
-- 合闸命令
insert into amp_command(dtuId,detectorNum,commandType,sendStatus,update_date,create_date,create_by) select left(machine_id,length(machine_id)-2),right(machine_id,2),2,0,NOW(),NOW(),create_by from amp_device_config where on_type = 1  and on_time <= now();
update amp_device_config set on_type = 0 where on_type = 1 and on_time <= now();

    -- SHOW ERRORS;
IF t_error = 1 THEN  
ROLLBACK;  
ELSE  
COMMIT;  
END IF;
select t_error;
END

 

posted @ 2018-06-01 15:43  吴大哥  阅读(207)  评论(0编辑  收藏  举报