zoukankan      html  css  js  c++  java
  • Activiti学习笔记11 — 判断节点的使用

    一、 创建流程

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <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">
     3   <process id="确定旅游地点" name="确定旅游地点" isExecutable="true">
     4     <startEvent id="startevent1" name="Start"></startEvent>
     5     <receiveTask id="申请旅游经费" name="申请旅游经费"></receiveTask>
     6     <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="申请旅游经费"></sequenceFlow>
     7     <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway" default="缺省值"></exclusiveGateway>
     8     <sequenceFlow id="flow2" sourceRef="申请旅游经费" targetRef="exclusivegateway1"></sequenceFlow>
     9     <receiveTask id="国外游" name="国外游"></receiveTask>
    10     <receiveTask id="国内游" name="国内游"></receiveTask>
    11     <receiveTask id="省内游" name="省内游"></receiveTask>
    12     <sequenceFlow id="经费大于等于10000" name="经费大于等于10000" sourceRef="exclusivegateway1" targetRef="国外游">
    13       <conditionExpression xsi:type="tFormalExpression"><![CDATA[${money >= 10000}]]></conditionExpression>
    14     </sequenceFlow>
    15     <sequenceFlow id="经费大于1000小于10000" name="经费大于1000小于10000" sourceRef="exclusivegateway1" targetRef="国内游" skipExpression="经费大于1000小于10000">
    16       <conditionExpression xsi:type="tFormalExpression"><![CDATA[${money > 1000 && money < 10000}]]></conditionExpression>
    17     </sequenceFlow>
    18     <sequenceFlow id="缺省值" name="缺省值" sourceRef="exclusivegateway1" targetRef="省内游"></sequenceFlow>
    19     <endEvent id="endevent1" name="End"></endEvent>
    20     <sequenceFlow id="flow6" sourceRef="国外游" targetRef="endevent1"></sequenceFlow>
    21     <sequenceFlow id="flow7" sourceRef="国内游" targetRef="endevent1"></sequenceFlow>
    22     <sequenceFlow id="flow8" sourceRef="省内游" targetRef="endevent1"></sequenceFlow>
    23   </process>
    24   <bpmndi:BPMNDiagram id="BPMNDiagram_确定旅游地点">
    25     <bpmndi:BPMNPlane bpmnElement="确定旅游地点" id="BPMNPlane_确定旅游地点">
    26       <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
    27         <omgdc:Bounds height="35.0" width="35.0" x="350.0" y="50.0"></omgdc:Bounds>
    28       </bpmndi:BPMNShape>
    29       <bpmndi:BPMNShape bpmnElement="申请旅游经费" id="BPMNShape_申请旅游经费">
    30         <omgdc:Bounds height="55.0" width="105.0" x="315.0" y="150.0"></omgdc:Bounds>
    31       </bpmndi:BPMNShape>
    32       <bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
    33         <omgdc:Bounds height="40.0" width="40.0" x="347.0" y="260.0"></omgdc:Bounds>
    34       </bpmndi:BPMNShape>
    35       <bpmndi:BPMNShape bpmnElement="国外游" id="BPMNShape_国外游">
    36         <omgdc:Bounds height="55.0" width="105.0" x="120.0" y="360.0"></omgdc:Bounds>
    37       </bpmndi:BPMNShape>
    38       <bpmndi:BPMNShape bpmnElement="国内游" id="BPMNShape_国内游">
    39         <omgdc:Bounds height="55.0" width="105.0" x="315.0" y="360.0"></omgdc:Bounds>
    40       </bpmndi:BPMNShape>
    41       <bpmndi:BPMNShape bpmnElement="省内游" id="BPMNShape_省内游">
    42         <omgdc:Bounds height="55.0" width="105.0" x="530.0" y="360.0"></omgdc:Bounds>
    43       </bpmndi:BPMNShape>
    44       <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
    45         <omgdc:Bounds height="35.0" width="35.0" x="350.0" y="490.0"></omgdc:Bounds>
    46       </bpmndi:BPMNShape>
    47       <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
    48         <omgdi:waypoint x="367.0" y="85.0"></omgdi:waypoint>
    49         <omgdi:waypoint x="367.0" y="150.0"></omgdi:waypoint>
    50       </bpmndi:BPMNEdge>
    51       <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
    52         <omgdi:waypoint x="367.0" y="205.0"></omgdi:waypoint>
    53         <omgdi:waypoint x="367.0" y="260.0"></omgdi:waypoint>
    54       </bpmndi:BPMNEdge>
    55       <bpmndi:BPMNEdge bpmnElement="经费大于等于10000" id="BPMNEdge_经费大于等于10000">
    56         <omgdi:waypoint x="347.0" y="280.0"></omgdi:waypoint>
    57         <omgdi:waypoint x="173.0" y="280.0"></omgdi:waypoint>
    58         <omgdi:waypoint x="172.0" y="360.0"></omgdi:waypoint>
    59         <bpmndi:BPMNLabel>
    60           <omgdc:Bounds height="42.0" width="100.0" x="191.0" y="260.0"></omgdc:Bounds>
    61         </bpmndi:BPMNLabel>
    62       </bpmndi:BPMNEdge>
    63       <bpmndi:BPMNEdge bpmnElement="经费大于1000小于10000" id="BPMNEdge_经费大于1000小于10000">
    64         <omgdi:waypoint x="367.0" y="300.0"></omgdi:waypoint>
    65         <omgdi:waypoint x="367.0" y="360.0"></omgdi:waypoint>
    66         <bpmndi:BPMNLabel>
    67           <omgdc:Bounds height="42.0" width="100.0" x="380.0" y="309.0"></omgdc:Bounds>
    68         </bpmndi:BPMNLabel>
    69       </bpmndi:BPMNEdge>
    70       <bpmndi:BPMNEdge bpmnElement="缺省值" id="BPMNEdge_缺省值">
    71         <omgdi:waypoint x="387.0" y="280.0"></omgdi:waypoint>
    72         <omgdi:waypoint x="582.0" y="280.0"></omgdi:waypoint>
    73         <omgdi:waypoint x="582.0" y="360.0"></omgdi:waypoint>
    74         <bpmndi:BPMNLabel>
    75           <omgdc:Bounds height="14.0" width="36.0" x="519.0" y="260.0"></omgdc:Bounds>
    76         </bpmndi:BPMNLabel>
    77       </bpmndi:BPMNEdge>
    78       <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
    79         <omgdi:waypoint x="172.0" y="415.0"></omgdi:waypoint>
    80         <omgdi:waypoint x="367.0" y="490.0"></omgdi:waypoint>
    81       </bpmndi:BPMNEdge>
    82       <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
    83         <omgdi:waypoint x="367.0" y="415.0"></omgdi:waypoint>
    84         <omgdi:waypoint x="367.0" y="490.0"></omgdi:waypoint>
    85       </bpmndi:BPMNEdge>
    86       <bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
    87         <omgdi:waypoint x="582.0" y="415.0"></omgdi:waypoint>
    88         <omgdi:waypoint x="367.0" y="490.0"></omgdi:waypoint>
    89       </bpmndi:BPMNEdge>
    90     </bpmndi:BPMNPlane>
    91   </bpmndi:BPMNDiagram>
    92 </definitions>
    View Code

    二、发布流程

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

    三、运行、测试流程

     1     /**
     2      * 3、启动流程、执行任务,并查看状态
     3      */
     4     @Test
     5     public void testExcusiveGateway() {        
     6         // 获取服务对象的实例
     7         RuntimeService runtimeService = processEngine.getRuntimeService();
     8 
     9         String processDefinitionKey = "确定旅游地点";
    10         // 自动执行与Key相对应的流程的最高版本
    11         ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey);        
    12         
    13         String processInstanceId = processInstance.getId();        
    14         logger.info("processInstanceId:" + processInstance.getId());
    15         
    16         //获取当前流程下Execution对象
    17         Execution e1 = runtimeService
    18                                             .createExecutionQuery()
    19                                             .processInstanceId(processInstanceId) //每个流程的唯一标识
    20                                             .activityId("申请旅游经费")    //每个活动的唯一标识
    21                                             .singleResult();
    22         Assert.assertNotNull(e1);
    23         //执行逻辑,请领导批示旅游经费
    24         Double money =11500d;
    25         //把金额放入变量中
    26         runtimeService.setVariable(e1.getId(), "money", money);
    27         logger.info("领导批示的旅游经费是: " + money);
    28         
    29         //推动流程流转
    30         logger.info("executionId: " + e1.getId());
    31         runtimeService.signal(e1.getId());
    32         
    33         if (money >= 10000d) {
    34             Execution e2 = runtimeService
    35                                         .createExecutionQuery()
    36                                         .processInstanceId(processInstanceId) //每个流程的唯一标识
    37                                         .activityId("国外游")    //每个活动的唯一标识
    38                                         .singleResult();
    39             Assert.assertNotNull(e2);
    40             logger.info("由于领导指示的经费是:" + runtimeService.getVariable(e2.getId(), "money") + ",所以你可以国外游!" );
    41             
    42             //推动流程流转
    43             runtimeService.signal(e2.getId());
    44         } else if ( money > 1000d && money < 10000d ) {
    45             Execution e2 = runtimeService
    46                     .createExecutionQuery()
    47                     .processInstanceId(processInstanceId) //每个流程的唯一标识
    48                     .activityId("国内游")    //每个活动的唯一标识
    49                     .singleResult();
    50             Assert.assertNotNull(e2);
    51             logger.info("由于领导指示的经费是:" + runtimeService.getVariable(e2.getId(), "money") + ",所以你可以国内游!" );
    52             
    53             //推动流程流转
    54             runtimeService.signal(e2.getId());
    55         } else {
    56             Execution e2 = runtimeService
    57                     .createExecutionQuery()
    58                     .processInstanceId(processInstanceId) //每个流程的唯一标识
    59                     .activityId("省内游")    //每个活动的唯一标识
    60                     .singleResult();
    61             Assert.assertNotNull(e2);
    62             logger.info("由于领导指示的经费是:" + runtimeService.getVariable(e2.getId(), "money") + ",所以你可以省内游!" );
    63             
    64             //推动流程流转
    65             runtimeService.signal(e2.getId());
    66         }
    67         
    68         //检查结束状态
    69         ProcessInstance pInstance = runtimeService
    70                                                         .createProcessInstanceQuery()
    71                                                         .processInstanceId(processInstanceId)
    72                                                         .singleResult();
    73         Assert.assertNull(pInstance);
    74         logger.info("判断分支结点流程成功执行!");        
    75     }
    View Code

    四、运行结果

    [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]判断分支结点流程成功执行!

  • 相关阅读:
    AIX上Oracle安装10204补丁出现写文件错误
    Oracle自定义函数
    表中最大分区数
    查询RMAN资料库——RMAN用户手册
    查询访问同一表的两个以上索引(三)
    管理RMAN资料库——RMAN用户手册
    查询访问同一表的两个以上索引(一)
    DDL语句为什么不能回滚
    JDBC运行出现ORA17410错误
    MySQL数据库操作类(转)
  • 原文地址:https://www.cnblogs.com/maocs/p/5012977.html
Copyright © 2011-2022 走看看