BEGIN
DECLARE v_depend_count TINYINT DEFAULT 1;
DECLARE v_work_times TINYINT DEFAULT 1;
declare v_schema_name varchar(100) default 'XXXX'; #该存储过程所属schema
declare v_object_name varchar(100) default 'XXXXXXXX'; #该存储过程名字
declare ac_report_date date;
set ac_report_date=date_add(current_date(),interval -1 day);
first_lable:BEGIN
delete from loan.object_work_log where etl_date=ac_report_date and v_object_name=v_object_name;
#判断 有无待推送数据
SELECT
sum(CASE WHEN t.`status` IS NULL OR t.`status` <> 'valid' THEN 1 WHEN t.etl_date <> DATE_ADD(CURDATE(),INTERVAL -1 day) THEN 1 ELSE 0 END) into v_depend_count
FROM
mddb.etl_object_exec_log t
WHERE
t.table_comment in ('BIGDATA_DW_WF');
while v_depend_count>=1 DO -- 循环开始
delete from loan.object_work_log where etl_date=ac_report_date and v_object_name=v_object_name and v_work_times=v_work_times;
set v_work_times=v_work_times+1 ;
select SLEEP(50);
SELECT
sum(CASE WHEN t.`status` IS NULL OR t.`status` <> 'valid' THEN 1 WHEN t.etl_date <> DATE_ADD(CURDATE(),INTERVAL -1 day) THEN 1 ELSE 0 END) into v_depend_count
FROM
mddb.etl_object_exec_log t
WHERE
t.table_comment in ('BIGDATA_DW_WF');
-- 超过预定时间,跳出循环,执行调度存储过程
if (DATE_FORMAT(CURRENT_TIME(),'%H:%i') >= '06:30') then
set v_depend_count = 0 ;
END if;
end while; -- 循环结束
insert into loan.object_work_log values(ac_report_date,v_schema_name,v_object_name,CURRENT_TIMESTAMP(),v_work_times) ;
-- -- -- begin 调度存储过程-------------------------------------------------
-- -- -- end -------------------------------------------------
END first_lable;
END