Activiti6.0节点驳回,自由跳转核心代码

//获取流程定义
Process process = repositoryService.getBpmnModel(processDefinitionId).getMainProcess();
//获取目标节点定义
FlowNode targetNode = (FlowNode) process.getFlowElement(flowElementId);
List<Execution> executionList = runtimeService.createExecutionQuery().parentId(taskList.get(0).getProcessInstanceId()).list();
//并行网关会有多个主execution 选取isActive =true的execution驳回,否则会导致网关判断失败
Execution remainExecution = null;
boolean isChoose = false;
List<Execution> deleteList = Lists.newArrayList();
for (Execution e : executionList) {
    ExecutionEntityImpl executionEntity = (ExecutionEntityImpl) e;
    if (executionEntity.isActive() && !isChoose) {
        remainExecution = executionEntity;
        isChoose = true;
    } else {
        deleteList.add(e);
    }
    deleteList.addAll(runtimeService.createExecutionQuery().parentId(e.getId()).list());
}
if (remainExecution == null) {
    ActivitiAssert.EXECUTION_NOT_SINGLE.assertFail();
}
//流程执行到来源节点
managementService.executeCommand(new SetNodeAndGoCmd(targetNode, remainExecution.getId()));
if (CollectionUtil.isNotEmpty(deleteList)) {
    List<String> ids = deleteList.stream().map(Execution::getId).collect(Collectors.toList());
    managementService.executeCommand(new DeleteExecutionCmd(ids));
}
//删除当前运行任务
for (Task currentTask : taskList) {
    managementService.executeCommand(new DeleteTaskCmd(currentTask.getId()));
}

 

public class SetNodeAndGoCmd implements Command<Void> {

    private FlowNode flowElement;
    private String executionId;
    private String executionName;
    private String startUserId;

    public SetNodeAndGoCmd(FlowNode flowElement, String executionId) {
        this.flowElement = flowElement;
        this.executionId = executionId;
    }

    public SetNodeAndGoCmd(FlowNode flowElement, String executionId, String executionName, String startUserId) {
        this.flowElement = flowElement;
        this.executionId = executionId;
        this.executionName = executionName;
        this.startUserId = startUserId;
    }

    @Override
    public Void execute(CommandContext commandContext) {
        //获取目标节点的来源连线
        List<SequenceFlow> flows = flowElement.getIncomingFlows();
        if (flows == null || flows.size() < 1) {
            throw new ActivitiException("回退错误,目标节点没有来源连线");
        }

        //随便流程当前的主线,时当前执行计划为,从连线流转到目标节点,实现跳转
        ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findById(executionId);
        executionEntity.setCurrentFlowElement(flows.get(0));
        if (StrUtil.isNotEmpty(executionName)) {
            executionEntity.setName(executionName);
        }
        if (StrUtil.isNotEmpty(startUserId)) {
            executionEntity.setStartUserId(startUserId);
        }
        log.info("SetNodeAndGoCmd执行节点跳转:processInstanceId:{},来源:{},出线:{}", executionEntity.getProcessInstanceId(), flows.get(0).getSourceRef(), flows.get(0).getTargetRef());
        commandContext.getAgenda().planTakeOutgoingSequenceFlowsOperation(executionEntity, true);
        return null;
    }
}

 

 

public class DeleteExecutionCmd implements Command<Void>, Serializable {

    private List<String> executionIds;

    public DeleteExecutionCmd(List<String> executionIds) {
        super();
        this.executionIds = executionIds;
    }

    /**
     * @param
     * @param
     * @return
     */
    @Override
    public Void execute(CommandContext commandContext) {
        //删除当前任务,来源任务
        ExecutionEntityManager executionEntityManager = (ExecutionEntityManagerImpl) commandContext.getExecutionEntityManager();
        for (String id : executionIds) {
            executionEntityManager.delete(id);
        }
        return null;
    }

}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值