工作流(Activiti 6.0)之自由驳回任务实现

简介: 工作流版本使用6.0,参数为任务id(task中主键),目标节点ID(比如userTask1),以及业务主键信息(businessKey)。

工作流版本使用6.0,参数为任务id(task中主键),目标节点ID(比如userTask1),以及业务主键信息(businessKey)。


  /**
   * 任务节点跳转
   * @param taskId 当前任务id
   * @param flowElementId 跳转的目标节点的id
   */
  public void taskBack(String taskId,String flowElementId,Map<String, Object> variables){
    ProcessEngine processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml").buildProcessEngine();
    //当前任务
    Task currentTask = processEngine.getTaskService().createTaskQuery().taskId(taskId).singleResult();
    //更新业务信息
    processEngine.getTaskService().setVariables(taskId , variables);
    //获取流程定义
    org.activiti.bpmn.model.Process process = processEngine.getRepositoryService().getBpmnModel(currentTask.getProcessDefinitionId()).getMainProcess();
    //获取目标节点定义
    FlowNode targetNode = (FlowNode)process.getFlowElement(flowElementId);
    //删除当前运行任务
    String executionEntityId =processEngine.getManagementService().executeCommand(new DeleteTaskCommand(currentTask.getId()));
    //流程执行到来源节点
    processEngine.getManagementService().executeCommand(new JumpCommand(targetNode, executionEntityId));
  }
  /**
   * 删除当前运行时任务命令
   * 这里继承了NeedsActiveTaskCmd,主要是很多跳转业务场景下,要求不能时挂起任务。可以直接继承Command即可
   */
  public class DeleteTaskCommand extends NeedsActiveTaskCmd<String> {
    public DeleteTaskCommand(String taskId){
      super(taskId);
    }
    @Override
    public String execute(CommandContext commandContext, TaskEntity currentTask){
      //获取所需服务
      TaskEntityManagerImpl taskEntityManager = (TaskEntityManagerImpl)commandContext.getTaskEntityManager();
      //获取当前任务的来源任务及来源节点信息
      ExecutionEntity executionEntity = currentTask.getExecution();
      //删除当前任务,来源任务
      taskEntityManager.deleteTask(currentTask, "jumpReason", false, false);
      return executionEntity.getId();
    }
    @Override
    public String getSuspendedTaskException() {
      return "挂起的任务不能跳转";
    }
  }
  /**
   * 根据提供节点和执行对象id,进行跳转命令
   */
  public class JumpCommand implements Command<Void> {
    private FlowNode flowElement;
    private String executionId;
    public JumpCommand(FlowNode flowElement, String executionId){
      this.flowElement = flowElement;
      this.executionId = executionId;
    }
    @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));
      commandContext.getAgenda().planTakeOutgoingSequenceFlowsOperation(executionEntity, true);
      return null;
    }
  }


相关文章
|
4月前
|
前端开发
基于jeecgboot的flowable流程支持退回到发起人节点表单修改功能
基于jeecgboot的flowable流程支持退回到发起人节点表单修改功能
466 0
|
4月前
|
移动开发 前端开发
基于jeecg-boot的flowable流程自定义业务退回撤回或驳回到发起人后的再次流程提交
基于jeecg-boot的flowable流程自定义业务退回撤回或驳回到发起人后的再次流程提交
150 0
|
4月前
|
监控 前端开发 NoSQL
基于jeecgboot的flowable复杂会签加用户选择流程实现
基于jeecgboot的flowable复杂会签加用户选择流程实现
105 2
|
4月前
基于jeecgboot的flowable流程支持online表单审批线上发布
基于jeecgboot的flowable流程支持online表单审批线上发布
60 1
|
4月前
|
前端开发
基于jeecgboot的flowable流程并行审批的bug修复
基于jeecgboot的flowable流程并行审批的bug修复
63 2
|
4月前
|
前端开发
基于jeecgboot的flowable流程设计器的用户选择问题修复
基于jeecgboot的flowable流程设计器的用户选择问题修复
66 1
|
4月前
|
安全
[AIGC] 如何设计和实现工作流的审批项目?
[AIGC] 如何设计和实现工作流的审批项目?
|
4月前
|
SQL 前端开发
基于jeecgboot的flowable驳回修改以及发起人设置
基于jeecgboot的flowable驳回修改以及发起人设置
132 0
|
4月前
基于jeecgboot的flowable流程综合会签功能演示平台已经发布
基于jeecgboot的flowable流程综合会签功能演示平台已经发布
23 0
|
4月前
Flowable流程中自定义业务表单并行审批的bug修复
Flowable流程中自定义业务表单并行审批的bug修复
91 0