可用的activiti工作流退回功能(退回到上一节点)(SQL、存储过程)

CREATE PROCEDURE workflow_go_back(IN proc_inst_id VARCHAR(64))
BEGIN
	DECLARE v_id_ VARCHAR(64);
	DECLARE v_proc_def_id_ VARCHAR(64);
	DECLARE v_task_def_key_ VARCHAR(255);
	DECLARE v_name_ VARCHAR(255);
	DECLARE v_assignee_ VARCHAR(255);
	DECLARE cur_act_hi_taskinst CURSOR FOR SELECT ID_,PROC_DEF_ID_,TASK_DEF_KEY_,NAME_,ASSIGNEE_ 
	FROM act_hi_taskinst
	where PROC_INST_ID_ = proc_inst_id and TASK_DEF_KEY_ is not null
	order by START_TIME_ desc  ;
OPEN cur_act_hi_taskinst;
		set @i = 0;
		label: LOOP
		SET @i = @i + 1;
		FETCH cur_act_hi_taskinst INTO v_id_, v_proc_def_id_, v_task_def_key_, v_name_, v_assignee_;
		IF @i = 1 THEN
		-- 1、处理历史任务 将当前任务设置为完成状态
		UPDATE ACT_HI_TASKINST SET END_TIME_ = now(),duration_ = 1 ,DELETE_REASON_ = 'completed' where id_ = v_id_;
		ELSEIF @i = 2 THEN
		-- 2、处理历史任务 添加当前新任务
		INSERT INTO ACT_HI_TASKINST (id_	,proc_def_id_	,task_def_key_,proc_inst_id_,execution_id_
		,name_,assignee_,start_time_,priority_) 
		values 	(uuid(),v_proc_def_id_,v_task_def_key_,proc_inst_id,proc_inst_id
		,v_name_,v_assignee_,now(),50);
		LEAVE label;
		ELSE
		LEAVE label;
		END IF;
		END LOOP label;
CLOSE cur_act_hi_taskinst;
-- 3、修改当前执行信息
UPDATE ACT_RU_EXECUTION SET rev_ = rev_ + 1 , ACT_ID_ = v_task_def_key_   where  PROC_INST_ID_ = proc_inst_id;
-- 4、修改当前任务信息	
UPDATE act_ru_task SET name_ = v_name_,TASK_DEF_KEY_ = v_task_def_key_,ASSIGNEE_ = v_assignee_ where PROC_INST_ID_ = proc_inst_id;
END

参数:流程执行实例ID

你可能感兴趣的:(工作流)