OSWorlflow 工作流回退办法

使用osworkflow 回退是个难题,我从数据库层使用存储过程解决回退问题,用户可以调用就可以实现回退,一次回退一个步骤,遇到join fork 自动返回前一步骤
数据库是基于mysql 5.0.45 的。前面版本对存储过程支持不是很好

主过程 rl

   DELIMITER $$

DROP PROCEDURE IF EXISTS `assess`.`rl`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE  `assess`.`rl`(entryid bigint)
BEGIN
   DECLARE curid BIGINT;
   DECLARE c_previd bigint;
   DECLARE hisid BIGINT;
   DECLARE done INT default 0;
   DECLARE curcount int;
   DECLARE cur1 CURSOR FOR select id from os_currentstep where entry_id=entryid;
   DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
   SET AUTOCOMMIT = 0;
   
   select count(*)  into curcount from os_currentstep;
   if curcount > 1 then
      START TRANSACTION;
      
      
      select id into curid from os_currentstep where entry_id=entryid group by entry_id;
      
      select previous_id into hisid from os_currentstep_prev where id = curid;
      
      OPEN cur1;
      REPEAT
        fetch cur1 into c_previd;
        delete from os_currentstep_prev where id=c_previd;
        delete from os_stepids where id=c_previd;
      UNTIL done END REPEAT;
      CLOSE cur1;
      
      delete from os_currentstep where entry_id=entryid;
      
      insert into os_currentstep select * from os_historystep where id=hisid;
      
      update os_currentstep  set status='Underway' where id=hisid;

      
      insert into os_currentstep_prev(previous_id,id) select previous_id,id from os_historystep_prev where id=hisid;
      
      delete from os_historystep_prev where id=hisid;
      delete from os_historystep where id=hisid;

      
      update os_wfentry set state=1 where id=entryid;
      COMMIT;
    elseif curcount = 1 then
     select id into curid from os_currentstep where entry_id=entryid;
     call cl(curid);
     update os_wfentry set state=1 where id=entryid;

   end if;
   SET AUTOCOMMIT = 1;
   select id from os_stepids where id=0;
END $$

DELIMITER ;


call cl(curid);

子过程 cl
DELIMITER $$

DROP PROCEDURE IF EXISTS `assess`.`cl`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE  `assess`.`cl`(cid bigint(20))
BEGIN
   
   DECLARE cdone INT default 0;
   DECLARE hisid BIGINT(20);
   DECLARE cur2 CURSOR FOR select previous_id from os_currentstep_prev where id=cid;
   DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET cdone = 1;
   SET AUTOCOMMIT = 0;
   START TRANSACTION;
   open cur2;
   repeat
     fetch cur2 INTO hisid;
     insert INTO os_currentstep select * from os_historystep where id=hisid;
     update os_currentstep set status='Underway' where id=hisid;
     insert INTO os_currentstep_prev(previous_id,id) select previous_id,id from os_historystep_prev where id=hisid;
     delete from os_historystep_prev where id=hisid;
     delete from os_currentstep_prev where id=cid;
     delete from os_historystep where id=hisid;
   UNTIL cdone END REPEAT;
   close cur2;
   delete from os_currentstep where id=cid;
   delete from os_stepids where id=cid;
   COMMIT;
END $$

DELIMITER ;


你可能感兴趣的:(sql,c,工作,mysql,OS)