一、 创建流程

 <?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="确定旅游地点" name="确定旅游地点" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<receiveTask id="申请旅游经费" name="申请旅游经费"></receiveTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="申请旅游经费"></sequenceFlow>
<exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway" default="缺省值"></exclusiveGateway>
<sequenceFlow id="flow2" sourceRef="申请旅游经费" targetRef="exclusivegateway1"></sequenceFlow>
<receiveTask id="国外游" name="国外游"></receiveTask>
<receiveTask id="国内游" name="国内游"></receiveTask>
<receiveTask id="省内游" name="省内游"></receiveTask>
<sequenceFlow id="经费大于等于10000" name="经费大于等于10000" sourceRef="exclusivegateway1" targetRef="国外游">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${money >= }]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="经费大于1000小于10000" name="经费大于1000小于10000" sourceRef="exclusivegateway1" targetRef="国内游" skipExpression="经费大于1000小于10000">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${money > && money < }]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="缺省值" name="缺省值" sourceRef="exclusivegateway1" targetRef="省内游"></sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow6" sourceRef="国外游" targetRef="endevent1"></sequenceFlow>
<sequenceFlow id="flow7" sourceRef="国内游" targetRef="endevent1"></sequenceFlow>
<sequenceFlow id="flow8" sourceRef="省内游" targetRef="endevent1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_确定旅游地点">
<bpmndi:BPMNPlane bpmnElement="确定旅游地点" id="BPMNPlane_确定旅游地点">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="350.0" y="50.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="申请旅游经费" id="BPMNShape_申请旅游经费">
<omgdc:Bounds height="55.0" width="105.0" x="315.0" y="150.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
<omgdc:Bounds height="40.0" width="40.0" x="347.0" y="260.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="国外游" id="BPMNShape_国外游">
<omgdc:Bounds height="55.0" width="105.0" x="120.0" y="360.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="国内游" id="BPMNShape_国内游">
<omgdc:Bounds height="55.0" width="105.0" x="315.0" y="360.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="省内游" id="BPMNShape_省内游">
<omgdc:Bounds height="55.0" width="105.0" x="530.0" y="360.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="350.0" y="490.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="367.0" y="85.0"></omgdi:waypoint>
<omgdi:waypoint x="367.0" y="150.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="367.0" y="205.0"></omgdi:waypoint>
<omgdi:waypoint x="367.0" y="260.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="经费大于等于10000" id="BPMNEdge_经费大于等于10000">
<omgdi:waypoint x="347.0" y="280.0"></omgdi:waypoint>
<omgdi:waypoint x="173.0" y="280.0"></omgdi:waypoint>
<omgdi:waypoint x="172.0" y="360.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="42.0" width="100.0" x="191.0" y="260.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="经费大于1000小于10000" id="BPMNEdge_经费大于1000小于10000">
<omgdi:waypoint x="367.0" y="300.0"></omgdi:waypoint>
<omgdi:waypoint x="367.0" y="360.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="42.0" width="100.0" x="380.0" y="309.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="缺省值" id="BPMNEdge_缺省值">
<omgdi:waypoint x="387.0" y="280.0"></omgdi:waypoint>
<omgdi:waypoint x="582.0" y="280.0"></omgdi:waypoint>
<omgdi:waypoint x="582.0" y="360.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="36.0" x="519.0" y="260.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
<omgdi:waypoint x="172.0" y="415.0"></omgdi:waypoint>
<omgdi:waypoint x="367.0" y="490.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
<omgdi:waypoint x="367.0" y="415.0"></omgdi:waypoint>
<omgdi:waypoint x="367.0" y="490.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
<omgdi:waypoint x="582.0" y="415.0"></omgdi:waypoint>
<omgdi:waypoint x="367.0" y="490.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>

二、发布流程

 /**
* 2、发布一个流程
*/
@Test
public void testDeployProcess() {
RepositoryService repositoryService = processEngine.getRepositoryService();
DeploymentBuilder builder = repositoryService.createDeployment();
// 加载发布资源
builder.name("判断分支结点流程测试") // 设置流程显示别名
.addClasspathResource("travel.bpmn") // 设置流程规则文件
.addClasspathResource("travel.png"); // 设置流程规则的图片
// 发布流程
builder.deploy();
}

三、运行、测试流程

     /**
* 3、启动流程、执行任务,并查看状态
*/
@Test
public void testExcusiveGateway() {
// 获取服务对象的实例
RuntimeService runtimeService = processEngine.getRuntimeService(); String processDefinitionKey = "确定旅游地点";
// 自动执行与Key相对应的流程的最高版本
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey); String processInstanceId = processInstance.getId();
logger.info("processInstanceId:" + processInstance.getId()); //获取当前流程下Execution对象
Execution e1 = runtimeService
.createExecutionQuery()
.processInstanceId(processInstanceId) //每个流程的唯一标识
.activityId("申请旅游经费") //每个活动的唯一标识
.singleResult();
Assert.assertNotNull(e1);
//执行逻辑,请领导批示旅游经费
Double money =11500d;
//把金额放入变量中
runtimeService.setVariable(e1.getId(), "money", money);
logger.info("领导批示的旅游经费是: " + money); //推动流程流转
logger.info("executionId: " + e1.getId());
runtimeService.signal(e1.getId()); if (money >= 10000d) {
Execution e2 = runtimeService
.createExecutionQuery()
.processInstanceId(processInstanceId) //每个流程的唯一标识
.activityId("国外游") //每个活动的唯一标识
.singleResult();
Assert.assertNotNull(e2);
logger.info("由于领导指示的经费是:" + runtimeService.getVariable(e2.getId(), "money") + ",所以你可以国外游!" ); //推动流程流转
runtimeService.signal(e2.getId());
} else if ( money > 1000d && money < 10000d ) {
Execution e2 = runtimeService
.createExecutionQuery()
.processInstanceId(processInstanceId) //每个流程的唯一标识
.activityId("国内游") //每个活动的唯一标识
.singleResult();
Assert.assertNotNull(e2);
logger.info("由于领导指示的经费是:" + runtimeService.getVariable(e2.getId(), "money") + ",所以你可以国内游!" ); //推动流程流转
runtimeService.signal(e2.getId());
} else {
Execution e2 = runtimeService
.createExecutionQuery()
.processInstanceId(processInstanceId) //每个流程的唯一标识
.activityId("省内游") //每个活动的唯一标识
.singleResult();
Assert.assertNotNull(e2);
logger.info("由于领导指示的经费是:" + runtimeService.getVariable(e2.getId(), "money") + ",所以你可以省内游!" ); //推动流程流转
runtimeService.signal(e2.getId());
} //检查结束状态
ProcessInstance pInstance = runtimeService
.createProcessInstanceQuery()
.processInstanceId(processInstanceId)
.singleResult();
Assert.assertNull(pInstance);
logger.info("判断分支结点流程成功执行!");
}

四、运行结果

[INFO][2015-12-02 14:39:58,335][com.mcs.activiti.test.TestExclusiveGateway]processInstanceId:170001
[INFO][2015-12-02 14:39:58,641][com.mcs.activiti.test.TestExclusiveGateway]领导批示的旅游经费是: 11500.0
[INFO][2015-12-02 14:39:58,642][com.mcs.activiti.test.TestExclusiveGateway]executionId: 170001
[INFO][2015-12-02 14:39:58,816][com.mcs.activiti.test.TestExclusiveGateway]由于领导指示的经费是:11500.0,所以你可以国外游!
[INFO][2015-12-02 14:39:58,914][com.mcs.activiti.test.TestExclusiveGateway]判断分支结点流程成功执行!

Activiti学习笔记11 — 判断节点的使用的更多相关文章

  1. Activiti学习笔记目录

    1.Activiti学习笔记1 — 下载与开发环境的配置: 2.Activiti学习笔记2 — HelloWorld: 3.Activiti学习笔记3 — 流程定义: 4.Activiti学习笔记4 ...

  2. activiti学习笔记一

    activiti学习笔记 在讲activiti之前我们必须先了解一下什么是工作流,什么是工作流引擎. 在我们的日常工作中,我们会碰到很多流程化的东西,什么是流程化呢,其实通俗来讲就是有一系列固定的步骤 ...

  3. 并发编程学习笔记(11)----FutureTask的使用及实现

    1. Future的使用 Future模式解决的问题是.在实际的运用场景中,可能某一个任务执行起来非常耗时,如果我们线程一直等着该任务执行完成再去执行其他的代码,就会损耗很大的性能,而Future接口 ...

  4. Spring 源码学习笔记11——Spring事务

    Spring 源码学习笔记11--Spring事务 Spring事务是基于Spring Aop的扩展 AOP的知识参见<Spring 源码学习笔记10--Spring AOP> 图片参考了 ...

  5. Activiti 学习笔记记录(2016-8-31)

    上一篇:Activiti 学习笔记记录(二) 导读:上一篇学习了bpmn 画图的常用图形标记.那如何用它们组成一个可用文件呢? 我们知道 bpmn 其实是一个xml 文件

  6. Activiti 学习笔记记录(二)

    上一篇:Activiti 学习笔记记录 导读:对于工作流引擎的使用,我们都知道,需要一个业务事件,比如请假,它会去走一个流程(提交申请->领导审批---(批,不批)---->结束),Act ...

  7. Ext.Net学习笔记11:Ext.Net GridPanel的用法

    Ext.Net学习笔记11:Ext.Net GridPanel的用法 GridPanel是用来显示数据的表格,与ASP.NET中的GridView类似. GridPanel用法 直接看代码: < ...

  8. SQL反模式学习笔记11 限定列的有效值

    目标:限定列的有效值,将一列的有效字段值约束在一个固定的集合中.类似于数据字典. 反模式:在列定义上指定可选值 1. 对某一列定义一个检查约束项,这个约束不允许往列中插入或者更新任何会导致约束失败的值 ...

  9. golang学习笔记11 golang要用jetbrain的golang这个IDE工具开发才好

    golang学习笔记11   golang要用jetbrain的golang这个IDE工具开发才好  jetbrain家的全套ide都很好用,一定要dark背景风格才装B   从File-->s ...

随机推荐

  1. msf反弹shell

    今天回顾了一下msf反弹shell的操作,在这里做一下记录和分享.( ̄︶ ̄)↗ 反弹shell的两种方法 第一种Msfvenom实例: 1.msfconsole #启动msf 2.msfvenom - ...

  2. HTML中改变列表的序号类型

    HTML中,<ol>标签表示有序列表,每一个表项的编号默认从数字开始.比如 <html> <head> <title>test</title> ...

  3. pytest-文件名类名方法名执行部分用例

    pytest test_class_01.py 执行文件名 pytest -v -s test_class_01.py 执行文件名 pytest -v test_class_01.py::TestCl ...

  4. pyJWT

    现在用JWT 加密太火了,怎么能不跟上潮流?否则销售都不好意思出去吹牛逼! PyJWT是一个Python库,用来编码/解码JWT(JSON Web Token)的 1.定义:根据维基百科的定义,JSO ...

  5. Thread相关API

    参考书籍:<java多线程核心编程技术> Thread相关API,这些API可以改变线程对象的状态 新建一个线程对象,调用start方法后,系统会为该线程分配CPU资源,此时该线程处于可运 ...

  6. Linux下的Ngnix服务器部署静态页

    一.安装FTP vsftpd 的名字代表”very secure FTP daemon”, 安全是它的开发者 Chris Evans 考虑的首要问题之一.在这个 FTP 服务器设计开发的最开始的时候, ...

  7. final、finally和finalized的区别?

    (1)final:被final修饰的类,不被能继承:被final修饰的方法,不能被重写:被fianl修饰的量,为常量,只能被赋值一次: (2)finally:异常处理,和try.catch结合使用,可 ...

  8. 基于 CI 1.7.x 的 项目使用新版本CI的文件缓存类库

    维护的项目使用的是 codeigniter 1.7.x版本,但是我想使用文件缓存,但是旧版本是没有缓存类库的,并且autoload.php没有drivers这个配置项. 我复制的是 Codeignit ...

  9. 获取Delphi焦点所在的控件及通过控件名称访问控件

    方法一: Var I: Integer; Begin For I := To ComponentCount - Do //获取组件数量 Begin If Components[I] Is TWinCo ...

  10. Java——方法的重写(覆盖)

    2.2方法的重写(覆盖)(override,orverwrite) 2.2.1 什么时候方法要进行重写? 如果父类中的方法已经无法满足当前子类的业务需求,需要将父类中的方法进行重新写一遍.就是要改变父 ...