activiti 排他网管(七)

1.  流程图

activiti 排他网管(七)_第1张图片


2. 代码实现

package com.hxzq.workflow.gateway;

import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;

/**
 * 排他网关
 * 
 * @author ZHEN.L
 * 
 *         select * from act_re_deployment;<br>
 *         select * from act_re_procdef;<br>
 * 
 *         select * from act_ru_execution;<br>
 *         select * from act_ru_task;<br>
 *         select * from act_ru_variable;<br>
 * 
 *         select * from act_hi_procinst;<br>
 *         select * from act_hi_taskinst;<br>
 *         select * from act_hi_varinst;<br>
 * 
 */
public class GateWay {

	ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

	/**
	 * 部署流程定义
	 */
	@Test
	public void deploymentProcessDefinition() {
		InputStream bpmn = this.getClass().getResourceAsStream("GateWay.bpmn");
		InputStream png = this.getClass().getResourceAsStream("GateWay.png");
		Deployment deployment = processEngine.getRepositoryService()
				.createDeployment().addInputStream("GateWay.bpmn", bpmn)
				.addInputStream("GateWay.png", png).name("排他网管").deploy();
		System.out.println(deployment.getId());
		System.out.println(deployment.getDeploymentTime());
	}

	/**
	 * 启动流程实例
	 */
	@Test
	public void startProcessInstance() {
		String processInstanceKey = "GateWay";
		ProcessInstance processInstance = processEngine.getRuntimeService()
				.startProcessInstanceByKey(processInstanceKey);
		System.out.println(processInstance.getId());
		System.out.println(processInstance.getProcessInstanceId());
		System.out.println(processInstance.getActivityId());

	}

	/**
	 * 查询个人任务
	 */
	@Test
	public void findTask() {
		String assignee = "李零";
		List<Task> tasks = processEngine.getTaskService().createTaskQuery()
				.taskAssignee(assignee).list();
		if (tasks != null && tasks.size() > 0) {
			for (Task t : tasks) {
				System.out.println(t.getId() + ", " + t.getAssignee() + ", "
						+ t.getName() + "," + t.getCreateTime());
			}
		}
	}

	/**
	 * 完成任务
	 */
	@Test
	public void completeTask() {
		String taskId = "1404";
		try {
			Map<String, Object> variables = new HashMap<String, Object>();
			variables.put("money", 400);
			processEngine.getTaskService().complete(taskId, variables);
			System.out.println("完成任务");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}




你可能感兴趣的:(activiti 排他网管(七))