jbpm4.4 实现撤回功能

环境:spring jbpm

主要实现类:

//撤回
	private void cancelApply(ApplyForCard applyForCard) {
		//撤回流程
		 //1、获取当前流程执行的节点任务
		TaskService taskService = processEngine.getTaskService();
		Task task = taskService.createTaskQuery().processInstanceId(ProvideUtils.AppcardJbpm+"."+applyForCard.getId()).uniqueResult();
		//2、创建一个指向行业科员的流程
		RepositoryService repositoryService = processEngine.getRepositoryService();  
		ExecutionService executionService = processEngine.getExecutionService();
		ProcessInstance processInstance = executionService.findProcessInstanceById(ProvideUtils.AppcardJbpm+"."+applyForCard.getId());
		String processDefinitionId = processInstance.getProcessDefinitionId();
		 ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).uniqueResult();  
		 ProcessDefinitionImpl pdi = (ProcessDefinitionImpl)pd; 
		 ActivityImpl sourceActivity =  pdi.findActivity(task.getActivityName());
		 //撤回的目标
		 ActivityImpl destActivity=pdi.findActivity("行业科员");  
		 //创建连接
		 TransitionImpl transition = sourceActivity.createOutgoingTransition();  
		 transition.setName("to"+"行业科员");
		 transition.setDestination(destActivity);
		 //添加
		 sourceActivity.addOutgoingTransition(transition);
		 //执行撤回
		 taskService.completeTask(task.getId(),transition.getName());  
	}



说明:参数ApplyForCard是业务对象,绑定在某个流程实例中;

产生流程实例的方式:

ProcessInstance processInstance = processEngine.getExecutionService()
				.startProcessInstanceByKey(ProvideUtils.AppcardJbpm, ProvideUtils.getApplyRoles(), entity.getId());



说明:ProvideUtils.AppcardJbpm是常量,保存的是流程图xml文件的key值;

你可能感兴趣的:(jbpm撤回)