activiti 增加节点的逻辑能讲一下吗

public void addActivity(String taskId, String newActivityId){
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
ProcessInstance instance = runtimeService
.createProcessInstanceQuery()
.processInstanceId(task.getProcessInstanceId())
.singleResult();
ProcessDefinitionEntity definition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
.getDeployedProcessDefinition(task.getProcessDefinitionId());
List activities = ((ProcessDefinitionImpl) definition).getActivities();
// 取得当前活动节点
ActivityImpl currActivity = ((ProcessDefinitionImpl) definition).findActivity(task.getTaskDefinitionKey());

    //创建新活动
    ActivityImpl clone = definition.createActivity(newActivityId);

    List<ActivityImpl> list = getNextActivity(taskId);
    //清除原先的路径  
    List<PvmTransition> cacheTran = currActivity.getOutgoingTransitions();  
    currActivity.getOutgoingTransitions().clear();  
    //创建新路径  
    TransitionImpl tran = currActivity.createOutgoingTransition();  
    tran.setDestination(clone); 

    for(ActivityImpl ActivityImpl :list){
        TransitionImpl tran1 = clone.createOutgoingTransition();
        tran1.setDestination(ActivityImpl);
    }
    runtimeService.startProcessInstanceById(definition.getId());

     final ExecutionEntity execution = (ExecutionEntity) runtimeService.createExecutionQuery()  
                .executionId(task.getExecutionId()).singleResult();  


        //包装一个Command对象  
        ((RuntimeServiceImpl)runtimeService).getCommandExecutor().execute(  
            new Command<java.lang.Void>()  
            {  
                @Override  
                public Void execute(CommandContext commandContext)  
                {  
                    //创建新任务  
                    execution.setActivity(clone);  

// execution.executeActivity(clone);

                    //删除当前的任务  
                    //不能删除当前正在执行的任务,所以要先清除掉关联  

// currentTaskEntity.setExecutionId(null);

// taskService.saveTask(currentTaskEntity);

// taskService.deleteTask(currentTaskEntity.getId(), true);

                    return null;  
                }  
            });  
}

1个回答

就是按照顺序创建的,看下创建。

zhangke_ah
鹿城NO1 创建之后怎么保存啊
接近 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐