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 ;


[size=large][color=red] call cl(curid);[/color][/size]

子过程 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 ;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值