Activiti的简单⼊门例⼦(经典的请假例⼦)经典的请假例⼦:
流程如下,⾸先需要部门经理审批,如果请假天数⼤于2天,则需要总经理审批,否则HR审批即可
⼀:创建maven项⽬,项⽬结构如下:
加⼊依赖
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>5.17.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-bpmn-layout</artifactId>
<version>5.17.0</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1103-jdbc41</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
</dependency>
l
数据库使⽤postgresql
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/schema/beans
/schema/beans/spring-beans.xsd">
<bean id="processEngineConfiguration" class="ine.impl.cfg.StandaloneProcessEngineConfiguration">        <property name="databaseSchemaUpdate" value="drop-create"/>
<property name="jdbcUrl" value="jdbc:postgresql://127.0.0.1/db_cloud"/>
<property name="jdbcDriver" value="org.postgresql.Driver"/>
<property name="jdbcUsername" value="admin"/>
<property name="jdbcPassword" value="root"/>
<property name="jobExecutorActivate" value="true"/>
</bean>
</beans>
流程⽂件l
createprocessa<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="/spec/BPMN/20100524/MODEL"
xmlns:activiti="/bpmn" targetNamespace="Examples"
xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/spec/BPMN/20100524/MODEL
/spec/BPMN/2.0/20100501/BPMN20.xsd">
<process id="leave_process" name="某公司请假流程">
<startEvent id="leave" name="请假申请"></startEvent>
<userTask id="dept_manager" name="部门经理审批"></userTask>
<userTask id="boss" name="总经理审批"></userTask>
<userTask id="hr" name="HR审批"></userTask>
<sequenceFlow id="flow1" sourceRef="leave" targetRef="dept_manager"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="dept_manager" targetRef="boss">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${day >= 3}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow3" sourceRef="boss" targetRef="hr"></sequenceFlow>
<sequenceFlow id="flow4" sourceRef="dept_manager" targetRef="hr">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${day < 3}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow5" sourceRef="hr" targetRef="end"></sequenceFlow>
<endEvent id="end" name="结束"></endEvent>
</process>
</definitions>
流程图如下:
⼆:代码演⽰
Leave.java
package com.lala.activiti;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import ine.ProcessEngine;
import ine.ProcessEngineConfiguration;
import ine.RepositoryService;
import ine.RuntimeService;
import ine.TaskService;
import ine.task.Task;
import ine.task.TaskQuery;
public class Leave
{
static void log(Object obj)
{
System.out.println(obj);
}
static void run(ProcessEngine processEngine) throws Exception
{
RepositoryService repositoryService = RepositoryService();
Map<String, Object> variables = new HashMap<>();
variables.put("userid", "10010");
variables.put("day", 3);
runtimeService.startProcessInstanceByKey("leave_process", variables);
TaskService taskService = TaskService();
TaskQuery query = ateTaskQuery();
List<Task> tasks = query.list();
for(Task task : tasks)
{
Id() + "," + Name());
Id(), variables);
}
log("--------------------");
tasks = query.list();
for(Task task : tasks)
{
Id() + "," + Name());
Id(), variables);
}
log("--------------------");
tasks = query.list();
for(Task task : tasks)
{
Id() + "," + Name());
Id(), variables);
}
}
public static void main(String[] args)
{
ProcessEngine processEngine = ateProcessEngineConfigurationFromResource("l").buildProcessEngine();
try {
run(processEngine);
} catch (Exception e) {
e.printStackTrace();
}
processEngine.close();
}
}
variables.put("day", 3);
⼤于等于3的时候,输出
9,部门经理审批
--------------------
11,总经理审批
--------------------
13,HR审批
否则,输出
9,部门经理审批
-
-------------------
11,HR审批

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。