From d8a5ecf8abe27a3027f59d2bf86dd65a410b4583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E5=86=AC=E6=A2=85?= Date: Fri, 22 Feb 2019 14:19:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=BB=9F=E8=AE=A1=E8=A1=A8?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE=E7=9A=84=E5=AE=A1=E6=A0=B8?= =?UTF-8?q?=E6=97=B6=E9=97=B4audit=5Ftime,=E9=85=8D=E7=BD=AE=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E5=AD=98=E5=82=A8=E8=BF=87=E7=A8=8B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sql/20190221/alter_table_sysuser.sql | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 src/main/resources/sql/20190221/alter_table_sysuser.sql diff --git a/src/main/resources/sql/20190221/alter_table_sysuser.sql b/src/main/resources/sql/20190221/alter_table_sysuser.sql new file mode 100644 index 000000000..d0bc780c2 --- /dev/null +++ b/src/main/resources/sql/20190221/alter_table_sysuser.sql @@ -0,0 +1,143 @@ +#增加审核时间字段 +ALTER TABLE cfg_num_statistics ADD audit_time datetime DEFAULT null COMMENT '审核时间'; + +-- ---------------------------- +-- Procedure structure for proc_statistics_config +-- ---------------------------- +DROP PROCEDURE IF EXISTS `proc_statistics_config`; +delimiter ;; +CREATE DEFINER=`root`@`%` PROCEDURE `proc_statistics_config`() +BEGIN + + DECLARE ntime VARCHAR(40);/*当前时间*/ + + DECLARE otime VARCHAR(40);/*上次统计时间*/ + + DECLARE nRow VARCHAR(40);/*本次统计条数*/ + + DECLARE tabName VARCHAR(500); + + DECLARE description VARCHAR(500); + + DECLARE deleteSql VARCHAR(500); + + DECLARE done INT;/*游标标识*/ + + DECLARE flag INT;/*循环标识*/ + + DECLARE t_error INT;/*错误标识*/ + + DECLARE proc_log_table VARCHAR(100);/*存储过程日志表*/ + + DECLARE proc_name VARCHAR(100);/*存储过程名称*/ + + DECLARE icursor CURSOR FOR SELECT tab_name FROM statistics_tables where is_valid=1; + + DECLARE CONTINUE HANDLER FOR NOT found SET done=1; + + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION set t_error=1; + + select max(statistic_time) into otime from cfg_num_statistics; + + SET done=0; + + SET t_error=0; + + SET proc_log_table='proc_exec_log'; + + SET proc_name='proc_statistics_config'; + + SET ntime=DATE_FORMAT(SYSDATE(),'%Y-%m-%d %H:%i:%S'); + + OPEN icursor; + + loop_iloop:LOOP + + FETCH icursor INTO tabName; + + SET description=tabName; + + set @descriptionStart=concat(description,'表统计start'); + + /*统计当前配置表数据到统计表中start*/ + + set @v_log_sql1 := concat('insert into ',proc_log_table,'(proc_name,table_name,log_time,description) values(?,?,?,?)'); + + PREPARE execs FROM @v_log_sql1; + + EXECUTE execs using proc_name,proc_log_table,ntime,@descriptionStart; + + DEALLOCATE PREPARE execs; + + COMMIT; + + + + set @insert_statistics_sql := concat('insert into cfg_num_statistics(statistic_time,audit_time,function_id,service_id,action,compile_id,cfg_state) select ','''',ntime,'''',',','audit_time,function_id,service_id,action,compile_id,if(is_audit=3,3,if(is_audit=2,2,if(is_audit=1,1,if(is_valid=0,0,if(is_valid,-1,-1))))) cfg_state from ',tabName); + + + PREPARE execs FROM @insert_statistics_sql; + + EXECUTE execs; + + DEALLOCATE PREPARE execs; + + COMMIT; + + + + set @descriptionEnd=concat(description,'表统计end'); + + set @v_log_sql2 := concat('insert into ',proc_log_table,'(proc_name,table_name,log_time,description) values(?,?,?,?)'); + + PREPARE execs FROM @v_log_sql2; + + EXECUTE execs using proc_name,proc_log_table,ntime,@descriptionEnd; + + DEALLOCATE PREPARE execs; + + COMMIT; + + /*异常退出loop*/ + IF t_error=1 THEN + LEAVE loop_iloop; + END IF; + + /*循环结束退出loop*/ + IF done=1 THEN + + LEAVE loop_iloop; + + ELSE + + SET flag=0; + + END IF; + + IF flag=0 THEN + + SET done=0; + + END IF; + + END LOOP loop_iloop; + + CLOSE icursor; + /*取出本次统计条数*/ + SELECT count(statistic_time) INTO nRow from cfg_num_statistics where statistic_time=ntime; + + IF t_error=1 THEN /*如果异常清楚本次数据*/ + delete from cfg_num_statistics where statistic_time=ntime; + COMMIT; + ELSEIF nRow > 0 THEN /*判断本次统计是否有数据录入,如果有则删除上次统计数据,如果没有则不清除上次统计数据*/ + + delete from cfg_num_statistics where statistic_time=otime; + COMMIT; + END IF; + COMMIT; +END +;; +delimiter ; + +#执行存储过程 +call exec_procs();