Flowable_波哥_b站

boge-03-其他

会签 #

  • 流程图绘制 ly-20241212142115466

    • 注意上面几个参数

      • 多实例类型用来判断串行并行
      • 基数(有几个用户处理)
      • 元素变量
      • 集合(集合变量)
      • 完成条件–这里填的是 ${nrOfCompletedInstances > 1 }
    • 在任务监听器 ly-20241212142115672

      package org.flowable.listener;
      
      import org.flowable.engine.ProcessEngine;
      import org.flowable.engine.ProcessEngines;
      import org.flowable.engine.TaskService;
      import org.flowable.engine.delegate.TaskListener;
      import org.flowable.task.api.Task;
      import org.flowable.task.service.delegate.DelegateTask;
      
      public class MultiInstanceTaskListener implements TaskListener {
      
          @Override
          public void notify(DelegateTask delegateTask) {
              System.out.println("处理aaaa");
              if(delegateTask.getEventName().equals("create")) {
                  System.out.println("任务id" + delegateTask.getId());
                  System.out.println("哪些人需要会签" + delegateTask.getVariable("persons"));
                  System.out.println("任务处理人" + delegateTask.getVariable("person"));
                  ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
                  TaskService taskService = engine.getTaskService();
                  Task task = taskService.createTaskQuery().taskId(delegateTask.getId()).singleResult();
                  task.setAssignee(delegateTask.getVariable("person").toString());
                  taskService.saveTask(task);
              }
          }
      }
      

boge-02-flowable进阶_6

任务回退-串行回退 #

  • 流程图绘制 ly-20241212142114607

  • xml

    <?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:flowable="http://flowable.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.flowable.org/processdef" exporter="Flowable Open Source Modeler" exporterVersion="6.7.2">
      <process id="reback-key" name="回退处理" isExecutable="true">
        <documentation>reback-desc</documentation>
        <startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent>
        <userTask id="sid-D380E41A-48EE-4C08-AD01-1D509C512543" name="用户1" flowable:assignee="user1" flowable:formFieldValidation="true">
          <extensionElements>
            <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
          </extensionElements>
        </userTask>
        <sequenceFlow id="sid-E2423FC5-F954-43D3-B57C-8460057CB7D6" sourceRef="startEvent1" targetRef="sid-D380E41A-48EE-4C08-AD01-1D509C512543"></sequenceFlow>
        <userTask id="sid-AF50E3D0-2014-4308-A717-D76586837D70" name="用户2" flowable:assignee="user2" flowable:formFieldValidation="true">
          <extensionElements>
            <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
          </extensionElements>
        </userTask>
        <sequenceFlow id="sid-7C8750DC-E1C1-4AB2-B18C-2C103B61A5E5" sourceRef="sid-D380E41A-48EE-4C08-AD01-1D509C512543" targetRef="sid-AF50E3D0-2014-4308-A717-D76586837D70"></sequenceFlow>
        <userTask id="sid-F4CE7565-5977-4B9C-A603-AB3B817B8C8C" name="用户3" flowable:assignee="user3" flowable:formFieldValidation="true">
          <extensionElements>
            <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
          </extensionElements>
        </userTask>
        <sequenceFlow id="sid-F91582FE-D110-48C9-9407-605E503E42B2" sourceRef="sid-AF50E3D0-2014-4308-A717-D76586837D70" targetRef="sid-F4CE7565-5977-4B9C-A603-AB3B817B8C8C"></sequenceFlow>
        <userTask id="sid-727C1235-F9C1-4CC5-BC6C-E56ABCA105B0" name="用户4" flowable:assignee="user4" flowable:formFieldValidation="true">
          <extensionElements>
            <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
          </extensionElements>
        </userTask>
        <sequenceFlow id="sid-6D998C20-2A97-44B5-92D0-118E5CB05795" sourceRef="sid-F4CE7565-5977-4B9C-A603-AB3B817B8C8C" targetRef="sid-727C1235-F9C1-4CC5-BC6C-E56ABCA105B0"></sequenceFlow>
        <endEvent id="sid-6E5F5037-1979-4150-8408-D0BFD0315BCA"></endEvent>
        <sequenceFlow id="sid-3ECF3E34-6C07-4AE6-997B-583BF8868AC8" sourceRef="sid-727C1235-F9C1-4CC5-BC6C-E56ABCA105B0" targetRef="sid-6E5F5037-1979-4150-8408-D0BFD0315BCA"></sequenceFlow>
      </process>
      <bpmndi:BPMNDiagram id="BPMNDiagram_reback-key">
        <bpmndi:BPMNPlane bpmnElement="reback-key" id="BPMNPlane_reback-key">
          <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
            <omgdc:Bounds height="30.0" width="30.0" x="100.0" y="163.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="sid-D380E41A-48EE-4C08-AD01-1D509C512543" id="BPMNShape_sid-D380E41A-48EE-4C08-AD01-1D509C512543">
            <omgdc:Bounds height="80.0" width="100.0" x="165.0" y="135.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="sid-AF50E3D0-2014-4308-A717-D76586837D70" id="BPMNShape_sid-AF50E3D0-2014-4308-A717-D76586837D70">
            <omgdc:Bounds height="80.0" width="100.0" x="320.0" y="138.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="sid-F4CE7565-5977-4B9C-A603-AB3B817B8C8C" id="BPMNShape_sid-F4CE7565-5977-4B9C-A603-AB3B817B8C8C">
            <omgdc:Bounds height="80.0" width="100.0" x="465.0" y="138.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="sid-727C1235-F9C1-4CC5-BC6C-E56ABCA105B0" id="BPMNShape_sid-727C1235-F9C1-4CC5-BC6C-E56ABCA105B0">
            <omgdc:Bounds height="80.0" width="100.0" x="610.0" y="138.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="sid-6E5F5037-1979-4150-8408-D0BFD0315BCA" id="BPMNShape_sid-6E5F5037-1979-4150-8408-D0BFD0315BCA">
            <omgdc:Bounds height="28.0" width="28.0" x="755.0" y="164.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNEdge bpmnElement="sid-6D998C20-2A97-44B5-92D0-118E5CB05795" id="BPMNEdge_sid-6D998C20-2A97-44B5-92D0-118E5CB05795" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
            <omgdi:waypoint x="564.9499999999907" y="178.0"></omgdi:waypoint>
            <omgdi:waypoint x="609.9999999999807" y="178.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="sid-7C8750DC-E1C1-4AB2-B18C-2C103B61A5E5" id="BPMNEdge_sid-7C8750DC-E1C1-4AB2-B18C-2C103B61A5E5" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
            <omgdi:waypoint x="264.9499999999882" y="175.0"></omgdi:waypoint>
            <omgdi:waypoint x="292.5" y="175.0"></omgdi:waypoint>
            <omgdi:waypoint x="292.5" y="178.0"></omgdi:waypoint>
            <omgdi:waypoint x="319.9999999999603" y="178.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="sid-3ECF3E34-6C07-4AE6-997B-583BF8868AC8" id="BPMNEdge_sid-3ECF3E34-6C07-4AE6-997B-583BF8868AC8" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="14.0" flowable:targetDockerY="14.0">
            <omgdi:waypoint x="709.9499999999999" y="178.0"></omgdi:waypoint>
            <omgdi:waypoint x="755.0" y="178.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="sid-E2423FC5-F954-43D3-B57C-8460057CB7D6" id="BPMNEdge_sid-E2423FC5-F954-43D3-B57C-8460057CB7D6" flowable:sourceDockerX="15.0" flowable:sourceDockerY="15.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
            <omgdi:waypoint x="129.94340692927761" y="177.55019845363262"></omgdi:waypoint>
            <omgdi:waypoint x="164.99999999999906" y="176.4985"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="sid-F91582FE-D110-48C9-9407-605E503E42B2" id="BPMNEdge_sid-F91582FE-D110-48C9-9407-605E503E42B2" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
            <omgdi:waypoint x="419.94999999999067" y="178.0"></omgdi:waypoint>
            <omgdi:waypoint x="464.9999999999807" y="178.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
        </bpmndi:BPMNPlane>
      </bpmndi:BPMNDiagram>
    </definitions>
    
  • 部署并运行

    ...

boge-02-flowable进阶_5

网关 #

ly-20241212142112823

排他网关 #

会按照所有出口顺序流定义的顺序对它们进行计算,选择第一个条件计算为true的顺序流(当没有设置条件时,认为顺序流为true)继续流程

ly-20241212142113034

  • 排他网关的绘制 ly-20241212142113127 xml文件

    <?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:flowable="http://flowable.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.flowable.org/processdef" exporter="Flowable Open Source Modeler" exporterVersion="6.7.2">
      <process id="holiday-exclusive" name="请假流程-排他网关" isExecutable="true">
        <startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent>
        <userTask id="sid-3D5ED4D4-97F5-4FFD-B160-F00566ECC55E" name="创建请假单" flowable:assignee="zhangsan" flowable:formFieldValidation="true">
          <extensionElements>
            <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
          </extensionElements>
        </userTask>
        <sequenceFlow id="sid-33A73370-751D-413F-9306-39DEAA674DB6" sourceRef="startEvent1" targetRef="sid-3D5ED4D4-97F5-4FFD-B160-F00566ECC55E"></sequenceFlow>
        <exclusiveGateway id="sid-5B2117E6-D341-49F2-85B2-336CA836C7D8"></exclusiveGateway>
        <sequenceFlow id="sid-D1B1F6E0-EA7F-4FF7-AD0C-5D43DBCEBFD2" sourceRef="sid-3D5ED4D4-97F5-4FFD-B160-F00566ECC55E" targetRef="sid-5B2117E6-D341-49F2-85B2-336CA836C7D8"></sequenceFlow>
        <userTask id="sid-08A6CB64-C9BB-4342-852D-444A75315BDE" name="总经理审批" flowable:assignee="wangwu" flowable:formFieldValidation="true">
          <extensionElements>
            <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
          </extensionElements>
        </userTask>
        <userTask id="sid-EA98D0C3-E41D-4DEB-8933-91A1B7301ABE" name="部门经理审批" flowable:assignee="lisi" flowable:formFieldValidation="true">
          <extensionElements>
            <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
          </extensionElements>
        </userTask>
        <userTask id="sid-24F73F7F-EB61-484F-A494-686E194D0118" name="人事审批" flowable:assignee="zhaoliu" flowable:formFieldValidation="true">
          <extensionElements>
            <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
          </extensionElements>
        </userTask>
        <sequenceFlow id="sid-8BA0B88C-BA4F-446D-B5E7-6BF0830B1DC8" sourceRef="sid-EA98D0C3-E41D-4DEB-8933-91A1B7301ABE" targetRef="sid-24F73F7F-EB61-484F-A494-686E194D0118"></sequenceFlow>
        <sequenceFlow id="sid-E748F81F-B0B2-4C34-B993-FBAA2BCD0995" sourceRef="sid-08A6CB64-C9BB-4342-852D-444A75315BDE" targetRef="sid-24F73F7F-EB61-484F-A494-686E194D0118"></sequenceFlow>
        <sequenceFlow id="sid-928C6C6F-57F1-40F2-BE0F-1A9FF3E6E9E4" sourceRef="sid-5B2117E6-D341-49F2-85B2-336CA836C7D8" targetRef="sid-08A6CB64-C9BB-4342-852D-444A75315BDE">
          <conditionExpression xsi:type="tFormalExpression"><![CDATA[${num>3}]]></conditionExpression>
        </sequenceFlow>
        <sequenceFlow id="sid-4DB25720-11C8-401E-BB4C-83BB25510B2E" sourceRef="sid-5B2117E6-D341-49F2-85B2-336CA836C7D8" targetRef="sid-EA98D0C3-E41D-4DEB-8933-91A1B7301ABE">
          <conditionExpression xsi:type="tFormalExpression"><![CDATA[${num<3}]]></conditionExpression>
        </sequenceFlow>
      </process>
      <bpmndi:BPMNDiagram id="BPMNDiagram_holiday-exclusive">
        <bpmndi:BPMNPlane bpmnElement="holiday-exclusive" id="BPMNPlane_holiday-exclusive">
          <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
            <omgdc:Bounds height="30.0" width="30.0" x="30.0" y="163.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="sid-3D5ED4D4-97F5-4FFD-B160-F00566ECC55E" id="BPMNShape_sid-3D5ED4D4-97F5-4FFD-B160-F00566ECC55E">
            <omgdc:Bounds height="80.0" width="100.0" x="150.0" y="135.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="sid-5B2117E6-D341-49F2-85B2-336CA836C7D8" id="BPMNShape_sid-5B2117E6-D341-49F2-85B2-336CA836C7D8">
            <omgdc:Bounds height="40.0" width="40.0" x="315.0" y="155.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="sid-08A6CB64-C9BB-4342-852D-444A75315BDE" id="BPMNShape_sid-08A6CB64-C9BB-4342-852D-444A75315BDE">
            <omgdc:Bounds height="80.0" width="100.0" x="420.0" y="225.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="sid-EA98D0C3-E41D-4DEB-8933-91A1B7301ABE" id="BPMNShape_sid-EA98D0C3-E41D-4DEB-8933-91A1B7301ABE">
            <omgdc:Bounds height="80.0" width="100.0" x="405.0" y="30.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="sid-24F73F7F-EB61-484F-A494-686E194D0118" id="BPMNShape_sid-24F73F7F-EB61-484F-A494-686E194D0118">
            <omgdc:Bounds height="80.0" width="100.0" x="630.0" y="225.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNEdge bpmnElement="sid-8BA0B88C-BA4F-446D-B5E7-6BF0830B1DC8" id="BPMNEdge_sid-8BA0B88C-BA4F-446D-B5E7-6BF0830B1DC8" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
            <omgdi:waypoint x="504.95000000000005" y="70.0"></omgdi:waypoint>
            <omgdi:waypoint x="680.0" y="70.0"></omgdi:waypoint>
            <omgdi:waypoint x="680.0" y="225.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="sid-4DB25720-11C8-401E-BB4C-83BB25510B2E" id="BPMNEdge_sid-4DB25720-11C8-401E-BB4C-83BB25510B2E" flowable:sourceDockerX="20.5" flowable:sourceDockerY="20.5" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
            <omgdi:waypoint x="335.5" y="155.5"></omgdi:waypoint>
            <omgdi:waypoint x="335.5" y="70.0"></omgdi:waypoint>
            <omgdi:waypoint x="404.99999999996083" y="70.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="sid-33A73370-751D-413F-9306-39DEAA674DB6" id="BPMNEdge_sid-33A73370-751D-413F-9306-39DEAA674DB6" flowable:sourceDockerX="15.0" flowable:sourceDockerY="15.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
            <omgdi:waypoint x="59.94725673598754" y="177.70973069236373"></omgdi:waypoint>
            <omgdi:waypoint x="150.0" y="175.96677419354836"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="sid-D1B1F6E0-EA7F-4FF7-AD0C-5D43DBCEBFD2" id="BPMNEdge_sid-D1B1F6E0-EA7F-4FF7-AD0C-5D43DBCEBFD2" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="20.5" flowable:targetDockerY="20.5">
            <omgdi:waypoint x="249.95000000000002" y="175.18431734317343"></omgdi:waypoint>
            <omgdi:waypoint x="315.42592592592536" y="175.42592592592592"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="sid-E748F81F-B0B2-4C34-B993-FBAA2BCD0995" id="BPMNEdge_sid-E748F81F-B0B2-4C34-B993-FBAA2BCD0995" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
            <omgdi:waypoint x="519.95" y="265.0"></omgdi:waypoint>
            <omgdi:waypoint x="629.9999999998776" y="265.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="sid-928C6C6F-57F1-40F2-BE0F-1A9FF3E6E9E4" id="BPMNEdge_sid-928C6C6F-57F1-40F2-BE0F-1A9FF3E6E9E4" flowable:sourceDockerX="20.5" flowable:sourceDockerY="20.5" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
            <omgdi:waypoint x="335.5" y="194.43942522321433"></omgdi:waypoint>
            <omgdi:waypoint x="335.5" y="265.0"></omgdi:waypoint>
            <omgdi:waypoint x="420.0" y="265.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
        </bpmndi:BPMNPlane>
      </bpmndi:BPMNDiagram>
    </definitions>
    
  • 部署

    ...

boge-02-flowable进阶_4

候选人 #

  • 流程图设计

    • 总体 ly-20241212142111000
    • 具体 ly-20241212142111216
  • 部署并启动流程

    
        @Test
        public void deploy(){
            ProcessEngine processEngine= ProcessEngines.getDefaultProcessEngine();
            RepositoryService repositoryService = processEngine.getRepositoryService();
            Deployment deploy = repositoryService.createDeployment().name("ly画的请假流程-候选人")
                    .addClasspathResource("请假流程-候选人.bpmn20.xml")
                    .deploy();
    
        }
        @Test
        public void runProcess(){
            //设置候选人
            Map<String,Object> variables=new HashMap<>();
            variables.put("candidate1","张三");
            variables.put("candidate2","李四");
            variables.put("candidate3","王五");
            ProcessEngine engine=ProcessEngines.getDefaultProcessEngine();
            //获取流程运行服务
            RuntimeService runtimeService = engine.getRuntimeService();
            //运行流程
            ProcessInstance processInstance = runtimeService.startProcessInstanceById(
                    "holiday-candidate:1:4",variables);
            System.out.println("processInstance--"+processInstance);
        }
    
  • 查看数据库表数据

    • 处理人为空 ly-20241212142111312
    • 变量 ly-20241212142111408
    • 图解 ly-20241212142111504
  • 实际,作为登录用户如果是张三/李四或者王五,那它可以查看它自己是候选人的任务

    ...

boge-02-flowable进阶_3

任务分配-uel表达式 #

通过变量指定来进行分配

  • 首先绘制流程图(定义) ly-20241212142108250

    • 变量处理 ly-20241212142108471 ly-20241212142108572
  • 之后将xml文件导出

    <?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:flowable="http://flowable.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.flowable.org/processdef" exporter="Flowable Open Source Modeler" exporterVersion="6.7.2">
      <process id="holiday-new" name="新请假流程" isExecutable="true">
        <documentation>new-description</documentation>
        <startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent>
        <userTask id="sid-8D901410-5BD7-4EED-B988-5E40D12298C7" name="创建请假流程" flowable:assignee="${assignee0}" flowable:formFieldValidation="true">
          <extensionElements>
            <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
          </extensionElements>
        </userTask>
        <userTask id="sid-5EB8F68B-7876-42AF-98E1-FCA27F99D8CE" name="审批请假流程" flowable:assignee="${assignee1}" flowable:formFieldValidation="true">
          <extensionElements>
            <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
          </extensionElements>
        </userTask>
        <sequenceFlow id="sid-631EFFB0-795A-4777-B49E-CF7D015BFF15" sourceRef="sid-8D901410-5BD7-4EED-B988-5E40D12298C7" targetRef="sid-5EB8F68B-7876-42AF-98E1-FCA27F99D8CE"></sequenceFlow>
        <endEvent id="sid-15CAD0D3-7F8B-404C-9346-A8D2A456D47B"></endEvent>
        <sequenceFlow id="sid-001CA567-6169-4F8A-A0E5-010721D52508" sourceRef="sid-5EB8F68B-7876-42AF-98E1-FCA27F99D8CE" targetRef="sid-15CAD0D3-7F8B-404C-9346-A8D2A456D47B"></sequenceFlow>
        <sequenceFlow id="sid-0A4A52F2-ECF6-44B2-AA41-F926AA7F5932" sourceRef="startEvent1" targetRef="sid-8D901410-5BD7-4EED-B988-5E40D12298C7"></sequenceFlow>
      </process>
      <bpmndi:BPMNDiagram id="BPMNDiagram_holiday-new">
        <bpmndi:BPMNPlane bpmnElement="holiday-new" id="BPMNPlane_holiday-new">
          <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
            <omgdc:Bounds height="30.0" width="30.0" x="100.0" y="145.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="sid-8D901410-5BD7-4EED-B988-5E40D12298C7" id="BPMNShape_sid-8D901410-5BD7-4EED-B988-5E40D12298C7">
            <omgdc:Bounds height="80.0" width="100.0" x="225.0" y="120.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="sid-5EB8F68B-7876-42AF-98E1-FCA27F99D8CE" id="BPMNShape_sid-5EB8F68B-7876-42AF-98E1-FCA27F99D8CE">
            <omgdc:Bounds height="80.0" width="100.0" x="370.0" y="120.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="sid-15CAD0D3-7F8B-404C-9346-A8D2A456D47B" id="BPMNShape_sid-15CAD0D3-7F8B-404C-9346-A8D2A456D47B">
            <omgdc:Bounds height="28.0" width="28.0" x="555.0" y="146.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNEdge bpmnElement="sid-001CA567-6169-4F8A-A0E5-010721D52508" id="BPMNEdge_sid-001CA567-6169-4F8A-A0E5-010721D52508" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="14.0" flowable:targetDockerY="14.0">
            <omgdi:waypoint x="469.94999999997356" y="160.0"></omgdi:waypoint>
            <omgdi:waypoint x="555.0" y="160.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="sid-0A4A52F2-ECF6-44B2-AA41-F926AA7F5932" id="BPMNEdge_sid-0A4A52F2-ECF6-44B2-AA41-F926AA7F5932" flowable:sourceDockerX="15.0" flowable:sourceDockerY="15.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
            <omgdi:waypoint x="129.94999928606217" y="160.0"></omgdi:waypoint>
            <omgdi:waypoint x="224.99999999995185" y="160.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="sid-631EFFB0-795A-4777-B49E-CF7D015BFF15" id="BPMNEdge_sid-631EFFB0-795A-4777-B49E-CF7D015BFF15" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
            <omgdi:waypoint x="324.9499999999907" y="160.0"></omgdi:waypoint>
            <omgdi:waypoint x="369.9999999999807" y="160.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
        </bpmndi:BPMNPlane>
      </bpmndi:BPMNDiagram>
    </definitions>
    
  • 流程定义的部署

    ...

boge-02-flowable进阶_2

Service服务接口 #

ly-20241212142104630

  • 各个Service类 RepositoryService 资源管理类,流程定义、部署、文件 RuntimeService 流程运行管理类,运行过程中(执行) TaskService 任务管理类 HistoryService 历史管理类 ManagerService 引擎管理类

Flowable图标 #

BPMN2.0定义的一些图标

  • 时间

ly-20241212142104849

  • 活动 ly-20241212142104949
  • 网关 ly-20241212142105051

流程部署深入解析 #

  • 使用eclipse打包部署(没有eclipse环境,所以这里只有截图) 将两个流程,打包为bar文件,然后放到项目resources文件夹中 ly-20241212142105247 ly-20241212142105148

  • 这里是为了测试一次部署多个流程(定义,图) 代码如下 ly-20241212142105345

  • 部署完成后查看表结构

    • act_re_procdef

      部署id一样 ly-20241212142105443

    • act_re_deployment ly-20241212142105547

    • 结论:部署和定义是1对多的关系

  • 每次部署所涉及到的资源文件 ly-20241212142105649

  • 涉及到的三张表

    • act_ge_bytearray ly-20241212142105747

    • act_re_procdef category–>xml中的namespace name–>定义时起的名称 key_—>xml中定义的id resource_name—>xml文件名称 dgrm_resource_name–>生成图片名称 suspension_state –> 是否被挂起

      tenant_id – >谁部署的流程

    • act_re_deployment name_部署名

  • 代码 ly-20241212142105845

  • 主要源码 DeployCmd.class ly-20241212142105941

  • DeploymentEntityManagerImpl.java ly-20241212142106041

    ...

boge-02-flowable进阶_1

表结构 #

  • 尽量通过API动数据

  • ACT_RE:repository,包含流程定义和流程静态资源

  • ACT_RU: runtime,包含流程实例、任务、变量等,流程结束会删除

  • ACT_HI: history,包含历史数据,比如历史流程实例、变量、任务等

  • ACT_GE: general,通用数据

  • ACT_ID: identity,组织机构。包含标识的信息,如用户、用户组等等

  • 具体的

    • 流程历史记录

      ly-20241212142103886

    • 流程定义表 ly-20241212142104111

    • 运行实例表 ly-20241212142104209

    • 用户用户组表

      ly-20241212142104309

  • 源码中的体现 ly-20241212142104410

默认的配置文件加载 #

  • 对于

    ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
    //-->
    public static ProcessEngine getDefaultProcessEngine() {
            return getProcessEngine(NAME_DEFAULT); //NAME_DEFAULT = "default"
        }
    //-->
    public static ProcessEngine getProcessEngine(String processEngineName) {
            if (!isInitialized()) {
                init();
            }
            return processEngines.get(processEngineName);
        }
    //-->部分
    
        /**
         * Initializes all process engines that can be found on the classpath for resources <code>flowable.cfg.xml</code> (plain Flowable style configuration) and for resources
         * <code>flowable-context.xml</code> (Spring style configuration).
         */
        public static synchronized void init() {
            if (!isInitialized()) {
                if (processEngines == null) {
                    // Create new map to store process-engines if current map is null
                    processEngines = new HashMap<>();
                }
                ClassLoader classLoader = ReflectUtil.getClassLoader();
                Enumeration<URL> resources = null;
                try {
                    resources = classLoader.getResources("flowable.cfg.xml");
                } catch (IOException e) {
                    throw new FlowableIllegalArgumentException("problem retrieving flowable.cfg.xml resources on the classpath: " + System.getProperty("java.class.path"), e);
                }
              //后面还有,每帖出来
            }
        }
    
  • 注意这行classLoader.getResources("flowable.cfg.xml"); 需要在resources根目录下放这么一个文件

    ...

boge-01-flowable基础

Flowable介绍 #

  • flowable的历史

    ly-20241212142101999

  • flowable是BPNM的一个基于java的软件实现,不仅包括BPMN,还有DMN决策表和CMMNCase管理引擎,并且有自己的用户管理、微服务API等

获取Engine对象 #

  • maven依赖

    
        <dependencies>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>8.0.29</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.flowable/flowable-engine -->
            <dependency>
                <groupId>org.flowable</groupId>
                <artifactId>flowable-engine</artifactId>
                <version>6.7.2</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/junit/junit -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.13.2</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
  • 配置并获取ProcessEngine

    ProcessEngineConfiguration configuration=
                    new StandaloneProcessEngineConfiguration();
            //配置
            configuration.setJdbcDriver("com.mysql.cj.jdbc.Driver");
            configuration.setJdbcUsername("root");
            configuration.setJdbcPassword("123456");
            //nullCatalogMeansCurrent=true 设置为只查当前连接的schema库
            configuration.setJdbcUrl("jdbc:mysql://localhost:3306/flowable-learn?" +
                    "useUnicode=true&characterEncoding=utf-8" +
                    "&allowMultiQueries=true" +
                    "&nullCatalogMeansCurrent=true");
            //如果数据库中表结构不存在则新建
            configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
            //构建ProcessEngine
            ProcessEngine processEngine=configuration.buildProcessEngine();
    

日志和表结构介绍 #

  • 添加slf4j依赖

     <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-reload4j -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-reload4j</artifactId>
                <version>1.7.36</version>
                <scope>test</scope>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-api</artifactId>
                <version>2.17.2</version>
            </dependency>
    
  • 添加log配置文件

    ...