activiti入门例子

package com.pingan.core;

import static org.junit.Assert.*;

import java.util.List;

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;
 
public class StudentLeaveTest {
	//获取默认流程引擎实例,会自动读取activiti.cfg.xml ,所以我们要严格定义配置文件的名称
	private ProcessEngine processEngine =ProcessEngines.getDefaultProcessEngine();
	
	/**
	 * 部署流程定义
	 */
	@Test
	public void deploy() {
		//获取部署相关service,这些都是activiti封装好的api接口,还有很多,下面也会用到很多
		Deployment deployment=processEngine.getRepositoryService()
		//创建部署
		.createDeployment()
		//加载流程图资源文件
		.addClasspathResource("activiti/StudentLeave.bpmn")
		//加载流程图片
		//.addClasspathResource("activiti/StudentLeave.png")
		//流程名称
		.name("学生请假流程")
		//部署流程
		.deploy();
		System.out.println("流程部署的ID: "+deployment.getId());
		System.out.println("流程部署的Name: "+deployment.getName());
	}
	
	/*
	 * 启动流程实例
	 */
	@Test
	public void start(){
		//运行启动流程的service
		ProcessInstance pi=processEngine.getRuntimeService()
		//定义流程表的KEY字段值,key值是我们前面定义好的key,可在act_re_procdef表中的key_字段中找到,
		.startProcessInstanceByKey("studentLeaveProcess");
		System.out.println(pi.getId());
		System.out.println(pi.getProcessDefinitionId());
	}
	
	/**
	 * 查看任务
	 */
	@Test
	public void findTaskList(){
		//获取任务列表的service
		List<Task> taskList=processEngine.getTaskService()
				//创建任务查询
				.createTaskQuery()
				//指定任务的执行人
				.taskAssignee("刘同学")
				.list();
		for(Task task:taskList){
			System.out.println("任务ID:"+task.getId());
			System.out.println("任务名称:"+task.getName());
			System.out.println("任务创建时间:"+task.getCreateTime());
			System.out.println("任务委派人:"+task.getAssignee());
			System.out.println("任务流程实例Id:"+task.getProcessInstanceId());
		}
	}
	
	/**
	 * 完成任务
	 */
	@Test
	public void completeTask(){
		processEngine.getTaskService().complete("2504");
	}
 
}
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="studentLeaveProcess" name="StudentLeaveProcess" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="usertask1" name="学生请假申请" activiti:assignee="刘同学"></userTask>
    <userTask id="usertask2" name="班主审批" activiti:assignee="刘班长"></userTask>
    <userTask id="usertask3" name="班主任审批" activiti:assignee="刘主任"></userTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="usertask2" targetRef="usertask3"></sequenceFlow>
    <sequenceFlow id="flow4" sourceRef="usertask3" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_studentLeaveProcess">
    <bpmndi:BPMNPlane bpmnElement="studentLeaveProcess" id="BPMNPlane_studentLeaveProcess">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="250.0" y="230.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55.0" width="105.0" x="480.0" y="220.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
        <omgdc:Bounds height="55.0" width="105.0" x="720.0" y="220.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
        <omgdc:Bounds height="55.0" width="105.0" x="980.0" y="220.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="1190.0" y="230.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="285.0" y="247.0"></omgdi:waypoint>
        <omgdi:waypoint x="480.0" y="247.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="585.0" y="247.0"></omgdi:waypoint>
        <omgdi:waypoint x="720.0" y="247.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="825.0" y="247.0"></omgdi:waypoint>
        <omgdi:waypoint x="980.0" y="247.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="1085.0" y="247.0"></omgdi:waypoint>
        <omgdi:waypoint x="1190.0" y="247.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

StudentLeave.bpmn

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值