仙术

  • 1、设置变量
    画图
    image.png

    xml文件:sequenceFlow 就代表了上方的双指向箭头
    双指向箭头在idea插件里面是没有的,需要用前面说的软件,点击指向线点击设置符号就会显示
    image_1.png

    <?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: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" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.activiti.org/processdef" exporter="activiti Modeler" exporterVersion="3.0.0">
        <process id="dd" name="testUpdate" isExecutable="true">
            <startEvent id="sid-f9290572-60fe-46c8-ba1a-6d49ab85d9c7" />
            <userTask id="_3" name="创建出差申请" activiti:assignee="${assignee0}">
                <extensionElements>
                    <activiti:formProperty id="Property 1" />
                    <activiti:formProperty id="Property 2" />
                </extensionElements>
            </userTask>
            <sequenceFlow id="sid-b30ee1df-6da8-4cfe-ac98-91f72c8494bc" sourceRef="sid-f9290572-60fe-46c8-ba1a-6d49ab85d9c7" targetRef="_3" />
            <userTask id="_4" name="部门经理审核" activiti:assignee="${assignee1}">
                <extensionElements>
                    <activiti:formProperty id="Property 1" />
                </extensionElements>
            </userTask>
            <sequenceFlow id="sid-9573370a-bf0b-4003-8d51-d51c463a282c" sourceRef="_3" targetRef="_4" />
            <userTask id="_5" name="总经理审批" activiti:assignee="${assignee2}">
                <extensionElements>
                    <activiti:formProperty id="Property 1" />
                </extensionElements>
            </userTask>
            <userTask id="_6" name="财务审批" activiti:assignee="${assignee3}" >
                <extensionElements>
                    <activiti:formProperty id="Property 1" />
                </extensionElements>
            </userTask>
    
            **<sequenceFlow id="_11" sourceRef="_4" targetRef="_5">
                <conditionExpression xsi:type="tFormalExpression">${evection.num>=3}</conditionExpression>
            </sequenceFlow>
            <sequenceFlow id="_10" sourceRef="_4" targetRef="_6">
                <conditionExpression xsi:type="tFormalExpression">${!(evection.num>=3)}</conditionExpression>
            </sequenceFlow>**
    
    
            <!--<sequenceFlow id="_11" sourceRef="_4" targetRef="_5">-->
            <!--    <conditionExpression xsi:type="tFormalExpression">${evection.num&gt;=3}</conditionExpression>-->
            <!--</sequenceFlow>-->
            <!--<sequenceFlow id="_10" sourceRef="_4" targetRef="_6">-->
            <!--    <conditionExpression xsi:type="tFormalExpression">${evection.num&lt;3}</conditionExpression>-->
            <!--</sequenceFlow>-->
    
    
    
            <sequenceFlow id="sid-5566d8ce-7ce5-49c1-9bb5-3b0430b874b1" sourceRef="_5" targetRef="_6" />
            <endEvent id="sid-a173a463-e580-4c50-8e37-1436c0a34950" />
            <sequenceFlow id="sid-5af69afe-a2f7-4259-b953-628840a60ee2" sourceRef="_6" targetRef="sid-a173a463-e580-4c50-8e37-1436c0a34950" />
        </process>
        <bpmndi:BPMNDiagram id="BPMNDiagram_testUpdate">
            <bpmndi:BPMNPlane id="BPMNPlane_testUpdate" bpmnElement="testUpdate">
                <bpmndi:BPMNShape id="shape-da9b2c9f-2cc1-4b6d-9564-0b64729aaf1f" bpmnElement="sid-f9290572-60fe-46c8-ba1a-6d49ab85d9c7">
                    <omgdc:Bounds x="261" y="81" width="30" height="30" />
                </bpmndi:BPMNShape>
                <bpmndi:BPMNShape id="shape-ab0f3ec4-3b5f-493f-9e9c-8e5c402af1db" bpmnElement="_3">
                    <omgdc:Bounds x="231" y="126" width="100" height="80" />
                </bpmndi:BPMNShape>
                <bpmndi:BPMNEdge id="edge-1d876cf9-3158-4b8c-b5b0-136f1d017ee7" bpmnElement="sid-b30ee1df-6da8-4cfe-ac98-91f72c8494bc">
                    <omgdi:waypoint x="283.5" y="111" />
                    <omgdi:waypoint x="281" y="126" />
                </bpmndi:BPMNEdge>
                <bpmndi:BPMNShape id="shape-05c6fa49-0531-48e8-84cd-36fe3f33d9c8" bpmnElement="_4">
                    <omgdc:Bounds x="231" y="221" width="100" height="80" />
                </bpmndi:BPMNShape>
                <bpmndi:BPMNEdge id="edge-69760489-b8bc-4419-a1fc-504694e219e9" bpmnElement="sid-9573370a-bf0b-4003-8d51-d51c463a282c">
                    <omgdi:waypoint x="281" y="206" />
                    <omgdi:waypoint x="281" y="221" />
                </bpmndi:BPMNEdge>
                <bpmndi:BPMNShape id="shape-b444c63b-fa51-4e0a-b103-25fea15de25e" bpmnElement="_5">
                    <omgdc:Bounds x="156" y="326" width="100" height="80" />
                </bpmndi:BPMNShape>
                <bpmndi:BPMNShape id="shape-bb3d593f-baaa-40fd-b233-6a21ec80239d" bpmnElement="_6">
                    <omgdc:Bounds x="316" y="326" width="100" height="80" />
                </bpmndi:BPMNShape>
                <bpmndi:BPMNEdge id="edge-15573ce2-e6a3-414c-b927-6d24214e5f6d" bpmnElement="_11">
                    <omgdi:waypoint x="256" y="301" />
                    <omgdi:waypoint x="231" y="326" />
                </bpmndi:BPMNEdge>
                <bpmndi:BPMNEdge id="edge-7a29c150-4f0e-48dc-8301-3fb34c3602cd" bpmnElement="_10">
                    <omgdi:waypoint x="306" y="301" />
                    <omgdi:waypoint x="341" y="326" />
                </bpmndi:BPMNEdge>
                <bpmndi:BPMNEdge id="edge-bb04d8dd-0c80-4dd1-82c2-d0a508f705c6" bpmnElement="sid-5566d8ce-7ce5-49c1-9bb5-3b0430b874b1">
                    <omgdi:waypoint x="256" y="366" />
                    <omgdi:waypoint x="316" y="366" />
                </bpmndi:BPMNEdge>
                <bpmndi:BPMNShape id="shape-0b537d4f-587d-4f06-b1d7-6b21374a8f49" bpmnElement="sid-a173a463-e580-4c50-8e37-1436c0a34950">
                    <omgdc:Bounds x="466" y="351" width="30" height="30" />
                </bpmndi:BPMNShape>
                <bpmndi:BPMNEdge id="edge-b166ebec-c69f-41ad-92b3-6b2ea2bb03ce" bpmnElement="sid-5af69afe-a2f7-4259-b953-628840a60ee2">
                    <omgdi:waypoint x="416" y="366" />
                    <omgdi:waypoint x="466" y="366.00002" />
                </bpmndi:BPMNEdge>
            </bpmndi:BPMNPlane>
        </bpmndi:BPMNDiagram>
    </definitions>

    然后正常流程启动:

    • 1、定义

          @Test
          public void Expression(){
              ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
              RepositoryService repositoryService = processEngine.getRepositoryService();
              Deployment deploy = repositoryService.createDeployment()
                      .name("出差申请流程-variables")
                      .addClasspathResource("bpmn1/testUpdate.bpmn20.xml")
                      .deploy();
          }
    • 2、启动

      //    启动
          @Test
          public void ExpressionStart(){
              ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
              RuntimeService runtimeService = processEngine.getRuntimeService();
      //流程变量的map
              Map<String,Object> variables = new HashMap();
      //设置流程变量
              Evection evection = new Evection();
      //设置出差日期
              evection.setNum(2d);
      //把流程变量的pojo放入map
              variables.put("evection",evection);
      //设定任务的负责人
              variables.put("assignee0","李四");
              variables.put("assignee1","王经理");
              variables.put("assignee2","杨总经理");
              variables.put("assignee3","张财务");
      //启动流程
              runtimeService.startProcessInstanceByKey("dd",variables);
          }
    • 3、提交任务

          @Test
          public void finshActivity1() {
              //获取引擎
              ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
              //获取操作任务的服务 TaskService
              TaskService taskService = processEngine.getTaskService();
              //完成任务,参数:任务id,
              
              先完成提交任务,在完成经理的初次审批任务,然后看效果会走向总经理还是直接走财务
              taskService.complete("35002");
          }
      
  • 2、网关

    • 1、排他网关
      所有分支都会判断条件是否为true,如果为true就执行该分支
      注意:只会选择一个true的分支执行,如果都满足条件,则走flowid最小的任务。
      与上述条件变量的区别:都不满足条件,则抛出异常。
      (一)创建bpmn文件
      image_2.png
      bug坑:

      1如果网关下面只有一条线,就不可以设置条件,因为他自己会把这个线当作默认,如果想只放一条线的话,就需要取消默认,目前我没有找到取消方法,所以只能先这样测试。
      ![image_3.png](/img/bVcYEIg)
      2这个地方必须是true,否则无法加载流程
      **(二)代码:**
      ```Java
          /**
           * 排他网关
           */
           **定义流程**
          @Test
          public void ExclusiveGetWay(){
              ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
              RepositoryService repositoryService = processEngine.getRepositoryService();
              Deployment deployment = repositoryService.createDeployment()
                      .addClasspathResource("bpmn1/getway1.bpmn20.xml")
                      .name("出差申请流程-排他网关")
                      .deploy();
          }
          **启动**
          @Test
          public void ExclusiveStart(){
              ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
              RuntimeService runtimeService = processEngine.getRuntimeService();
              Map<String, Object> map = new HashMap();
              Evection evection = new Evection();
              evection.setNum(3d);
              //定义流程变量,把出差pojo对象放入map
              map.put("evection",evection);
              //启动流程实例,并设置流程变量的值(把map传入)
              ProcessInstance processInstance = runtimeService
                      .startProcessInstanceByKey("定义的流程id", map);
                      如果不知道定义的流程id的可以会看前面的文章
      
      
          }
      **    完成任务**
          @Test
          public void finshActivity2() {
              //获取引擎
              ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
              //获取操作任务的服务 TaskService
              TaskService taskService = processEngine.getTaskService();
              //完成任务,参数:任务id,task表里面,如果不知道看前面文章
              taskService.complete("任务id");
          }
          
          完成任务后,在上方设置不同的天数进行测试看流程
      ​```


      • 2、并行网关
        可以把多条分支汇聚一起,会走所有的分支、还要等多个分支完成才可继续完成。
        注意:并行网关不会解析条件,即使定义了条件也会被忽略。
        图:
        image_4.png
        id和name自己填就行
        1和2这两条线表达式相反,判断不同结果
        image_5.png
        代码:

            /**
             * 并行网关
              */
        //    流程定义
            @Test
            public void ExclusiveGetWay1(){
                ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
                RepositoryService repositoryService = processEngine.getRepositoryService();
                Deployment deployment = repositoryService.createDeployment()
                        .addClasspathResource("bpmn1/getway2.bpmn20.xml")
                        .name("出差申请流程-并行网关")
                        .deploy();
            }
            @Test
            public void ExclusiveStart1(){
                ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
                RuntimeService runtimeService = processEngine.getRuntimeService();
                Map<String, Object> map = new HashMap();
                Evection evection = new Evection();
                evection.setNum(3d);
                //定义流程变量,把出差pojo对象放入map
                map.put("evection",evection);
                //启动流程实例,并设置流程变量的值(把map传入)
                ProcessInstance processInstance = runtimeService
                        .startProcessInstanceByKey("bingxing", map);
            }
            @Test
            public void finshActivity3() {
                //获取引擎
                ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
                //获取操作任务的服务 TaskService
                TaskService taskService = processEngine.getTaskService();
                //完成任务,参数:任务id
                taskService.complete("105008");
            }

        都在task任务表 定义之后:
        image_6.png
        完成任务后
        image_7.png
        将这两个任务都完成后:
        image_8.png
        总经理任务完成后记录删除;
        如果小于3天的话,不需要总经理审批,技术经理和项目经理任务完成后,记录直接删除。

      • 3、包含网关
        排他网关和并行网关的结合。都为ture的时候,都要执行任务,并且最后汇聚在一起才可以执行下去。
        bpmn文件图
        image_9.png
        id和name自己设置,这三条线增设条件
        2和3的条件一样,1的条件是<3
        image_10.png
        完成bpmn文件后,开始进行代码流程
          /**
           * 包含网关
           */
          @Test
          public void InclusiveGateway(){
              ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
              RepositoryService repositoryService = processEngine.getRepositoryService();
              Deployment deployment = repositoryService.createDeployment()
                      .addClasspathResource("bpmn1/getway3.bpmn20.xml")
                      .name("出差申请流程-包含网关")
                      .deploy();
          }
          //启动
          @Test
          public void InclusiveStart(){
              ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
              RuntimeService runtimeService = processEngine.getRuntimeService();
              //key可以见bpmn文件<process>标签id
              String key = "InclusiveGateway";
              Map<String, Object> map = new HashMap();
              Evection evection = new Evection();
              evection.setNum(2d);
              //定义流程变量,把出差pojo对象放入map
              map.put("evection",evection);
              //启动流程实例,并设置流程变量的值(把map传入)
              ProcessInstance processInstance = runtimeService
                      .startProcessInstanceByKey(key, map);
          }
      
          @Test
          public void finshActivity4() {
              //获取引擎
              ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
              //获取操作任务的服务 TaskService
              TaskService taskService = processEngine.getTaskService();
              //完成任务,参数:任务id
              taskService.complete("17508");

我个人喜欢看task表来观察流程效果,也可以看execution表和hi_tsakinst表、hi_actinst表看节点效果






到此关于idea2019以上版本的操作activiti7就暂时结束了,我也是刚开始学,尽量的将我遇见的问题都写出来,看了很多文章也没有看到讲的很细致的有时候都是一笔带过,我做的时候会一个地方卡很长时间,所以我就写的尽力的细致,大家看到我的文章时也不会太费力气,先入门。



橘子没有籽
1 声望0 粉丝