1. 程式人生 > >Activiti5.14 流程跳躍/退回/駁回/自定義流轉(中國式退回)

Activiti5.14 流程跳躍/退回/駁回/自定義流轉(中國式退回)

跳躍: 從一個節點跳躍到任意節點,不受線路的限制。 而且 complete 事件不能受影響。

退回: 與 跳躍的差別就是在處理之前檢查下任務是否處理過。

駁回: 與退回一致,只是發起這不一樣。

以上都建立在單執行線路上。

import java.util.Map;

import org.activiti.engine.ActivitiException;
import org.activiti.engine.impl.RepositoryServiceImpl;
import org.activiti.engine.impl.cmd.NeedsActiveTaskCmd;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl;

/**
 * 任務提交到任意節點
 * @author wangzhe
 * @date 2014-5-14
 */
public class TaskCommitCmd  extends NeedsActiveTaskCmd<Void>{

	private static final long serialVersionUID = 1L;
    
    /**
     * 目標任務的定義Id 
     */
    private String toTaskKey;
    /**
     * 引數
     */
    protected Map variables;
    /**
     * jump跳躍 ,turnback 退回()
     */
    protected String type;  
    
    
    public TaskCommitCmd(String _taskId, String _toTaskKey,String _type,Map _variables) {
        super(_taskId);
        this.toTaskKey = _toTaskKey;
        this.type = _type;
        this.variables = _variables;
        
    }

    @Override
    protected Void execute(CommandContext commandContext, TaskEntity task) {
    	
    	if(variables != null) task.setExecutionVariables(variables);
    	
        ExecutionEntity execution = task.getExecution();
    	//流程定義id      
    	String procDefId = execution.getProcessDefinitionId();   
    	//獲取服務       
    	RepositoryServiceImpl repositoryService =  (RepositoryServiceImpl)execution.getEngineServices().getRepositoryService(); 
    	//獲取流程定義的所有節點
    	ProcessDefinitionImpl processDefinitionImpl =  (ProcessDefinitionImpl)repositoryService.getDeployedProcessDefinition(procDefId);
    	//獲取需要提交的節點
    	ActivityImpl toActivityImpl = processDefinitionImpl.findActivity(this.toTaskKey);
    	 
    	if(toActivityImpl == null ){ 
    		throw new ActivitiException(this.toTaskKey+" to ActivityImpl is null!");
    	}else{
    		task.fireEvent("complete");
        	Context.getCommandContext().getTaskEntityManager().deleteTask(task,this.type, false); 
        	execution.removeTask(task);//執行規劃的線
        	execution.executeActivity(toActivityImpl);
    	}
        return null ;
    }

}