activiti 接收活动任务传递参数(九)

1.流程图

activiti 接收活动任务传递参数(九)_第1张图片


2. 代码实现

package com.hxzq.workflow.receive;

import java.io.InputStream;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.runtime.Execution;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;

/**
 * 接收活动任务,传递参数
 * 
 * @author ZHEN.L
 * 
 */
public class ReceiveTask {

	ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

	/**
	 * 部署流程定义
	 */
	@Test
	public void deploymentProcessDefinition() {
		InputStream bpmn = this.getClass().getResourceAsStream(
				"ReceiveTask.bpmn");
		InputStream png = this.getClass()
				.getResourceAsStream("ReceiveTask.png");
		processEngine.getRepositoryService().createDeployment()
				.addInputStream("ReceiveTask.bpmn", bpmn)
				.addInputStream("ReceiveTask.png", png).name("接收活动任务").deploy();
	}

	/**
	 * 启动流程实例
	 */
	@Test
	public void startProcessInstance() {
		String processInstanceKey = "receiveTask";
		String variableName = "汇总金额";
		// 启动流程实例
		ProcessInstance processInstance = processEngine.getRuntimeService()
				.startProcessInstanceByKey(processInstanceKey);
		// 查询执行对象
		Execution execution = processEngine.getRuntimeService().createExecutionQuery().processInstanceId(processInstance.getId()) // 流程实例ID
			.activityId("receivetask1").singleResult(); // 活动ID
		// 设置参数,传递参数
		processEngine.getRuntimeService().setVariable(execution.getId(), variableName, 10000);
		// 向后执行
		processEngine.getRuntimeService().signal(execution.getId());
		
		// 获取执行对象
		Execution execution2 = processEngine.getRuntimeService().createExecutionQuery().processInstanceId(processInstance.getId()).activityId("receivetask2").singleResult();
		Integer value = (Integer) processEngine.getRuntimeService().getVariable(execution2.getId(), variableName);
		System.out.println(value);
		// 向后执行
		processEngine.getRuntimeService().signal(execution2.getId());
	}
}


你可能感兴趣的:(activiti 接收活动任务传递参数(九))