Activiti7工作流引擎:高阶篇 多实例

Posted vbirdbest

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Activiti7工作流引擎:高阶篇 多实例相关的知识,希望对你有一定的参考价值。

一:多实例基本示例

@Test
void testStartAndComplete() 
	Map<String, Object> variables = new HashMap<>();
	variables.put("approveUserList", Arrays.asList("zhaomin", "xiaozhao", "zhouzhiruo"));
	runtimeService.startProcessInstanceByKey("multiInstance", variables);

	Task task = taskService.createTaskQuery().processDefinitionKey("multiInstance").singleResult();
	taskService.setAssignee(task.getId(),"zhangwuji");
	taskService.complete(task.getId());

二:多实例退回

  1. 删除act_ru_variable
  2. 删除act_ru_task
  3. 删除act_ru_execution
  4. 删除act_ru_identitylink
public class MultiInstanceMoveCommand implements Command<Object> 
    private String currentTaskId;
    private String targetTaskDefKey;


    public MultiInstanceMoveCommand(String currentTaskId, String targetTaskDefKey) 
        this.currentTaskId = currentTaskId;
        this.targetTaskDefKey = targetTaskDefKey;
    

    @Override
    public Object execute(CommandContext commandContext) 
        TaskEntityManager taskEntityManager = commandContext.getTaskEntityManager();
        TaskEntity taskEntity = taskEntityManager.findById(currentTaskId);

        ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
        // act_ru_execution.id_=30
        ExecutionEntity executionEntity = executionEntityManager.findById(taskEntity.getExecutionId());
        // act_ru_execution.id_=15
        ExecutionEntity parentExecutionEntity = executionEntityManager.findById(executionEntity.getParentId());
        // act_ru_execution.id_=(30, 31, 32)
        List<ExecutionEntity> childExecutionEntityList = executionEntityManager.findChildExecutionsByParentExecutionId(parentExecutionEntity.getId());

        // act_ru_execution.id_=[15, 30, 31, 32]
        Set<String> executionIdSet = new HashSet<>();
        executionIdSet.add(parentExecutionEntity.getId());
        for (ExecutionEntity childExecutionEntity : childExecutionEntityList) 
            executionIdSet.add(childExecutionEntity.getId());
        

        IdentityLinkEntityManager identityLinkEntityManager = commandContext.getIdentityLinkEntityManager();
        identityLinkEntityManager.deleteIdentityLink(executionEntity, null, null, null);
        identityLinkEntityManager.deleteIdentityLink(parentExecutionEntity, null, null, null);

        VariableInstanceEntityManager variableInstanceEntityManager = commandContext.getVariableInstanceEntityManager();
        List<VariableInstanceEntity> variableInstanceEntityList = variableInstanceEntityManager.findVariableInstancesByExecutionIds(executionIdSet);
        for (VariableInstanceEntity variableInstanceEntity : variableInstanceEntityList) 
            variableInstanceEntityManager.delete(variableInstanceEntity);
        

        taskEntityManager.deleteTasksByProcessInstanceId(taskEntity.getProcessInstanceId(), "删除子节点", true);
        executionEntityManager.deleteChildExecutions(parentExecutionEntity, "", true);


        FlowElement targetFlowElement = ProcessDefinitionUtil.getProcess(executionEntity.getProcessDefinitionId()).getFlowElement(targetTaskDefKey);
        parentExecutionEntity.setCurrentFlowElement(targetFlowElement);

        commandContext.getAgenda().planContinueProcessInCompensation(parentExecutionEntity);

        return null;
    


    public String getCurrentTaskId() 
        return currentTaskId;
    

    public void setCurrentTaskId(String currentTaskId) 
        this.currentTaskId = currentTaskId;
    

    public String getTargetTaskDefKey() 
        return targetTaskDefKey;
    

    public void setTargetTaskDefKey(String targetTaskDefKey) 
        this.targetTaskDefKey = targetTaskDefKey;
    


@Test
public void testMoveTask() 
	String currentTaskId = "46";
	String targetTaskDefKey = "apply";

	MultiInstanceMoveCommand moveTaskCommand = new MultiInstanceMoveCommand(currentTaskId, targetTaskDefKey);
	managementService.executeCommand(moveTaskCommand);

以上是关于Activiti7工作流引擎:高阶篇 多实例的主要内容,如果未能解决你的问题,请参考以下文章

Activiti7工作流引擎:高阶篇 前进和后退任务

Activiti7工作流引擎:高阶篇 ProcessDefinitionUtil

Activiti7工作流引擎:高阶篇 ProcessDefinitionUtil

Activiti7工作流引擎:高阶篇 ManualTask

Activiti7工作流引擎:进阶篇 多实例

Activiti7工作流引擎:高阶篇 ScriptTask