DECLARE done INT DEFAULT 0;
DECLARE curl CURSOR FOR select a.pursuerid,a.personid,a.personcode,a.crfversion,b.pursuercode from edm_person a
join edm_pursuer b on a.projectid=b.projectid and a.pursuerid=b.pursuerid where a.projectid =p_projectid and if(CHAR_LENGTH(p_personcode)>0,a.personcode=p_personcode,1=1) LIMIT pageNum,pageSize;
DECLARE cur2 cursor for SELECT periodid,name,periodtype from edm_period where projectid =p_projectid ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
-- 插入表单
OPEN curl;
my_loop:LOOP
FETCH curl INTO v_pursuerid,v_personid,v_personcode,v_crfversion,v_pursuername;
IF done=1 THEN
LEAVE my_loop;
END IF;
begin
declare _inner tinyint(1) default 0;
declare cur_param cursor for SELECT periodid,periodseq from
(select projectid,periodid,0 as periodseq from edm_period where projectid=p_projectid and periodtype=0 union
select projectid,periodid,periodseq from edm_form_status where projectid=p_projectid and personid=v_personid and periodseq>0 and formid=0 ) a ;
declare continue handler for not found set _inner = 1;
open cur_param;
loop_yyy:loop
fetch cur_param into v_periodid,v_periodseq;
if _inner=1 then
leave loop_yyy;
end if;
INSERT into temp_visit_status_list(projectid,statustype,pursuerid,pursuername,personid,crfversion,personcode,periodid,periodcode,periodseq,flag)
VALUES(p_projectid,p_stautstype,v_pursuerid,v_pursuername,v_personid,v_crfversion,v_personcode,v_periodid,CONCAT(v_periodid,v_periodseq),v_periodseq,v_flag);
set _inner = 0;
end loop loop_yyy;
end ;
set done=0;
END LOOP;
CLOSE curl;