专注毕业设计领域5年
做最优质的毕业设计指南

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

给同学们的一些建议:为什么卖系统的那么多,更多人互相推荐选择我们?原因有四。第一,全网唯一提供在线演示站。将优缺点一览无余的暴露,更直观看到项目功能,防止被骗;第二,看的懂。通过我们的讲解视频能很快熟悉原理,并快速看懂系统;第三,服务全。有远程部署,不明白的代码有售后答疑,妥妥的全包,而其他地方只给你一个源码,没基础没人指导搞很久也很难看懂;第四,企业运营品牌好。我们是企业运营,品牌即是信誉,意味着不会被骗。网站、B站等平台多年运营,多客服同时服务。更全面的了解,可以扫一扫微信添加咨询。

工作流版本使用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) 打赏
未经允许不得转载:猫头鹰源码-毕业设计 » 工作流(Activiti 6.0)之自由驳回任务实现
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏