java实现flowable工作流(三)springboot驱动

2019-07-05  本文已影响0人  小吖么小一郎

加入依赖

        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter</artifactId>
            <version>6.4.1</version>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.2</version>
        </dependency>

数据库配置

在properties中加入:

server.port=8089
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/flowable?serverTimezone=Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC&autoReconnect=true
spring.datasource.username=root
spring.datasource.password=123456

新建一个名为FlowableConfig.java的文件

package com.example.demo.config.flowable;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.springframework.context.annotation.Configuration;
/**
 * ClassName:hehongqian
 * Description:
 */
@Configuration
public class FlowableConfig implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration> {
    @Override
    public void configure(SpringProcessEngineConfiguration engineConfiguration) {
        engineConfiguration.setActivityFontName("宋体");
        engineConfiguration.setLabelFontName("宋体");
        engineConfiguration.setAnnotationFontName("宋体");
    }

}

在resources目录下新建一个文件夹:processes,将画好的流程图的xml文件放到该目录下

微信图片_20190705110258.png

这里我们以InclusiveGateway.bpmn20.xml2为例,内容如下:

<?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">
  <process id="InclusiveGateway" name="InclusiveGateway" isExecutable="true">
    <documentation>InclusiveGateway</documentation>
    <startEvent id="startEvent1"></startEvent>
    <inclusiveGateway id="sid-0A90D258-BDAB-4604-B27A-443C81110DCE"></inclusiveGateway>
    <userTask id="sid-37330727-ED3A-4EF2-867C-EBD8BE153E87" name="选人" flowable:assignee="$INITIATOR" flowable:formKey="choicePeople">
      <extensionElements>
        <modeler:activiti-idm-initiator xmlns:modeler="http://flowable.org/modeler"><![CDATA[true]]></modeler:activiti-idm-initiator>
      </extensionElements>
    </userTask>
    <sequenceFlow id="sid-9F58D52B-93EE-4A5F-983E-FF2A7F2891CC" sourceRef="startEvent1" targetRef="sid-37330727-ED3A-4EF2-867C-EBD8BE153E87"></sequenceFlow>
    <sequenceFlow id="sid-D754B585-5210-4D9D-A35C-9D582A5965EF" sourceRef="sid-37330727-ED3A-4EF2-867C-EBD8BE153E87" targetRef="sid-0A90D258-BDAB-4604-B27A-443C81110DCE"></sequenceFlow>
    <userTask id="sid-C2D2F904-629F-4D88-8EEA-FF0D4CCA8436" name="第一个人" default="sid-1EB63304-43CF-4F64-B70D-80536766F39D" flowable:assignee="${theFirstPeople}" flowable:formKey="Test2">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
      </extensionElements>
    </userTask>
    <userTask id="sid-AFEE5BE3-48BD-4157-8AB9-8F33577E19AC" name="第二个人" default="sid-ED38F4B6-4657-48BF-94B9-49EC05A6D528" flowable:assignee="${theSecondPeople}" flowable:formKey="Test2">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
      </extensionElements>
    </userTask>
    <userTask id="sid-2752392D-4792-4793-8EB3-3EC90E20433F" name="第三个人" default="sid-045E4E4F-84C5-4557-A03E-F0CF686B29E8" flowable:assignee="${theThreePeople}" flowable:formKey="Test2">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
      </extensionElements>
    </userTask>
    <inclusiveGateway id="sid-394661B4-F5F2-46B7-B7B7-3B090D0FC03F"></inclusiveGateway>
    <exclusiveGateway id="sid-78140A62-6149-4B76-9EAB-6E52FFC2E613"></exclusiveGateway>
    <sequenceFlow id="sid-477D9E88-F2A9-4819-A204-AEEB920A4853" sourceRef="sid-394661B4-F5F2-46B7-B7B7-3B090D0FC03F" targetRef="sid-78140A62-6149-4B76-9EAB-6E52FFC2E613"></sequenceFlow>
    <endEvent id="sid-C55A8949-5F12-4DE0-99EE-8D9C234F02E0"></endEvent>
    <sequenceFlow id="sid-16C8753F-018A-45B2-8E6A-4394618FDF20" sourceRef="sid-78140A62-6149-4B76-9EAB-6E52FFC2E613" targetRef="sid-C55A8949-5F12-4DE0-99EE-8D9C234F02E0"></sequenceFlow>
    <exclusiveGateway id="sid-BCE3BAC4-B5E6-4FC6-BAE1-0278F5ECDE43"></exclusiveGateway>
    <sequenceFlow id="sid-4F8D325B-6F80-40B7-BF0B-35F7DBBEF1D7" sourceRef="sid-BCE3BAC4-B5E6-4FC6-BAE1-0278F5ECDE43" targetRef="sid-394661B4-F5F2-46B7-B7B7-3B090D0FC03F"></sequenceFlow>
    <exclusiveGateway id="sid-C256AD2A-75DC-4243-AFBD-3ED7DF4D4CCE"></exclusiveGateway>
    <sequenceFlow id="sid-DFAE8DDF-B497-4B8C-A701-01543992ABA7" sourceRef="sid-C256AD2A-75DC-4243-AFBD-3ED7DF4D4CCE" targetRef="sid-BCE3BAC4-B5E6-4FC6-BAE1-0278F5ECDE43"></sequenceFlow>
    <sequenceFlow id="sid-EA1BA091-9F95-496A-BDE3-E4BA5D9D6E6D" sourceRef="sid-C2D2F904-629F-4D88-8EEA-FF0D4CCA8436" targetRef="sid-C256AD2A-75DC-4243-AFBD-3ED7DF4D4CCE">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${test2=='aaa'}]]></conditionExpression>
    </sequenceFlow>
    <exclusiveGateway id="sid-FDBA3991-D053-4AF4-8C51-6E7904B6DB1B"></exclusiveGateway>
    <exclusiveGateway id="sid-0F87D41C-FB2A-4423-B0C7-5A39C4A32F64"></exclusiveGateway>
    <sequenceFlow id="sid-E4B18318-6B27-46AE-9AF1-A014EE397CF0" sourceRef="sid-0F87D41C-FB2A-4423-B0C7-5A39C4A32F64" targetRef="sid-394661B4-F5F2-46B7-B7B7-3B090D0FC03F"></sequenceFlow>
    <sequenceFlow id="sid-1620E41E-7711-437E-847C-5E4078827E8E" sourceRef="sid-FDBA3991-D053-4AF4-8C51-6E7904B6DB1B" targetRef="sid-0F87D41C-FB2A-4423-B0C7-5A39C4A32F64"></sequenceFlow>
    <sequenceFlow id="sid-FB26C185-4341-4828-89BF-9977A83770D8" sourceRef="sid-AFEE5BE3-48BD-4157-8AB9-8F33577E19AC" targetRef="sid-FDBA3991-D053-4AF4-8C51-6E7904B6DB1B">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${test2=='bbb'}]]></conditionExpression>
    </sequenceFlow>
    <exclusiveGateway id="sid-4AFD3B1A-B0DD-4A43-BF77-943B4AEF779C"></exclusiveGateway>
    <exclusiveGateway id="sid-A02A838A-1515-4BBC-AFB6-4406CFFC2688"></exclusiveGateway>
    <sequenceFlow id="sid-7C61B72D-DA55-425F-A72D-93D8FE4DEC52" sourceRef="sid-A02A838A-1515-4BBC-AFB6-4406CFFC2688" targetRef="sid-4AFD3B1A-B0DD-4A43-BF77-943B4AEF779C"></sequenceFlow>
    <sequenceFlow id="sid-201E50AF-5C51-4C4F-9CB0-1A41C1F5D76F" sourceRef="sid-4AFD3B1A-B0DD-4A43-BF77-943B4AEF779C" targetRef="sid-394661B4-F5F2-46B7-B7B7-3B090D0FC03F"></sequenceFlow>
    <sequenceFlow id="sid-FA66D27F-D877-45EB-BD87-E3274BB17577" sourceRef="sid-2752392D-4792-4793-8EB3-3EC90E20433F" targetRef="sid-A02A838A-1515-4BBC-AFB6-4406CFFC2688">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${test2=='ccc'}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="sid-045E4E4F-84C5-4557-A03E-F0CF686B29E8" sourceRef="sid-2752392D-4792-4793-8EB3-3EC90E20433F" targetRef="sid-4AFD3B1A-B0DD-4A43-BF77-943B4AEF779C"></sequenceFlow>
    <sequenceFlow id="sid-ED38F4B6-4657-48BF-94B9-49EC05A6D528" sourceRef="sid-AFEE5BE3-48BD-4157-8AB9-8F33577E19AC" targetRef="sid-0F87D41C-FB2A-4423-B0C7-5A39C4A32F64"></sequenceFlow>
    <sequenceFlow id="sid-1EB63304-43CF-4F64-B70D-80536766F39D" sourceRef="sid-C2D2F904-629F-4D88-8EEA-FF0D4CCA8436" targetRef="sid-BCE3BAC4-B5E6-4FC6-BAE1-0278F5ECDE43"></sequenceFlow>
    <sequenceFlow id="sid-C3E72217-2A81-41DB-9E47-B80D2E8B67A0" sourceRef="sid-0A90D258-BDAB-4604-B27A-443C81110DCE" targetRef="sid-C2D2F904-629F-4D88-8EEA-FF0D4CCA8436">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${theFirstPeople!=null}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="sid-E3FDD5E9-1184-4343-A287-9B478EFB124F" sourceRef="sid-0A90D258-BDAB-4604-B27A-443C81110DCE" targetRef="sid-AFEE5BE3-48BD-4157-8AB9-8F33577E19AC">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${theSecondPeople!=null}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="sid-13FCD0F9-5DDF-4583-A3D3-55CD452B6D28" sourceRef="sid-0A90D258-BDAB-4604-B27A-443C81110DCE" targetRef="sid-2752392D-4792-4793-8EB3-3EC90E20433F">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${theThreePeople!=null}]]></conditionExpression>
    </sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_InclusiveGateway">
    <bpmndi:BPMNPlane bpmnElement="InclusiveGateway" id="BPMNPlane_InclusiveGateway">
      <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
        <omgdc:Bounds height="30.0" width="30.0" x="0.0" y="260.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-0A90D258-BDAB-4604-B27A-443C81110DCE" id="BPMNShape_sid-0A90D258-BDAB-4604-B27A-443C81110DCE">
        <omgdc:Bounds height="40.0" width="40.0" x="270.0" y="255.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-37330727-ED3A-4EF2-867C-EBD8BE153E87" id="BPMNShape_sid-37330727-ED3A-4EF2-867C-EBD8BE153E87">
        <omgdc:Bounds height="80.0" width="100.0" x="60.0" y="235.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-C2D2F904-629F-4D88-8EEA-FF0D4CCA8436" id="BPMNShape_sid-C2D2F904-629F-4D88-8EEA-FF0D4CCA8436">
        <omgdc:Bounds height="80.0" width="100.0" x="360.0" y="45.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-AFEE5BE3-48BD-4157-8AB9-8F33577E19AC" id="BPMNShape_sid-AFEE5BE3-48BD-4157-8AB9-8F33577E19AC">
        <omgdc:Bounds height="80.0" width="100.0" x="360.0" y="235.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-2752392D-4792-4793-8EB3-3EC90E20433F" id="BPMNShape_sid-2752392D-4792-4793-8EB3-3EC90E20433F">
        <omgdc:Bounds height="80.0" width="100.0" x="360.0" y="430.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-394661B4-F5F2-46B7-B7B7-3B090D0FC03F" id="BPMNShape_sid-394661B4-F5F2-46B7-B7B7-3B090D0FC03F">
        <omgdc:Bounds height="40.0" width="40.0" x="645.0" y="255.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-78140A62-6149-4B76-9EAB-6E52FFC2E613" id="BPMNShape_sid-78140A62-6149-4B76-9EAB-6E52FFC2E613">
        <omgdc:Bounds height="40.0" width="40.0" x="750.0" y="255.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-C55A8949-5F12-4DE0-99EE-8D9C234F02E0" id="BPMNShape_sid-C55A8949-5F12-4DE0-99EE-8D9C234F02E0">
        <omgdc:Bounds height="28.0" width="28.0" x="835.0" y="261.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-BCE3BAC4-B5E6-4FC6-BAE1-0278F5ECDE43" id="BPMNShape_sid-BCE3BAC4-B5E6-4FC6-BAE1-0278F5ECDE43">
        <omgdc:Bounds height="40.0" width="40.0" x="600.0" y="65.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-C256AD2A-75DC-4243-AFBD-3ED7DF4D4CCE" id="BPMNShape_sid-C256AD2A-75DC-4243-AFBD-3ED7DF4D4CCE">
        <omgdc:Bounds height="40.0" width="40.0" x="525.0" y="65.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-FDBA3991-D053-4AF4-8C51-6E7904B6DB1B" id="BPMNShape_sid-FDBA3991-D053-4AF4-8C51-6E7904B6DB1B">
        <omgdc:Bounds height="40.0" width="40.0" x="525.0" y="255.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-0F87D41C-FB2A-4423-B0C7-5A39C4A32F64" id="BPMNShape_sid-0F87D41C-FB2A-4423-B0C7-5A39C4A32F64">
        <omgdc:Bounds height="40.0" width="40.0" x="585.0" y="255.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-4AFD3B1A-B0DD-4A43-BF77-943B4AEF779C" id="BPMNShape_sid-4AFD3B1A-B0DD-4A43-BF77-943B4AEF779C">
        <omgdc:Bounds height="40.0" width="40.0" x="600.0" y="450.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-A02A838A-1515-4BBC-AFB6-4406CFFC2688" id="BPMNShape_sid-A02A838A-1515-4BBC-AFB6-4406CFFC2688">
        <omgdc:Bounds height="40.0" width="40.0" x="525.0" y="450.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-7C61B72D-DA55-425F-A72D-93D8FE4DEC52" id="BPMNEdge_sid-7C61B72D-DA55-425F-A72D-93D8FE4DEC52">
        <omgdi:waypoint x="564.5650809716561" y="470.3716216216216"></omgdi:waypoint>
        <omgdi:waypoint x="600.1333333333259" y="470.1329999999999"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-1EB63304-43CF-4F64-B70D-80536766F39D" id="BPMNEdge_sid-1EB63304-43CF-4F64-B70D-80536766F39D">
        <omgdi:waypoint x="410.0" y="45.0"></omgdi:waypoint>
        <omgdi:waypoint x="410.0" y="14.0"></omgdi:waypoint>
        <omgdi:waypoint x="620.0" y="14.0"></omgdi:waypoint>
        <omgdi:waypoint x="620.0" y="65.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-DFAE8DDF-B497-4B8C-A701-01543992ABA7" id="BPMNEdge_sid-DFAE8DDF-B497-4B8C-A701-01543992ABA7">
        <omgdi:waypoint x="564.5650809716599" y="85.37162162162163"></omgdi:waypoint>
        <omgdi:waypoint x="600.1333333333323" y="85.13300000000001"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-9F58D52B-93EE-4A5F-983E-FF2A7F2891CC" id="BPMNEdge_sid-9F58D52B-93EE-4A5F-983E-FF2A7F2891CC">
        <omgdi:waypoint x="29.949997975751963" y="275.0"></omgdi:waypoint>
        <omgdi:waypoint x="59.99999999999278" y="275.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-E3FDD5E9-1184-4343-A287-9B478EFB124F" id="BPMNEdge_sid-E3FDD5E9-1184-4343-A287-9B478EFB124F">
        <omgdi:waypoint x="309.52159949622165" y="275.42016806722694"></omgdi:waypoint>
        <omgdi:waypoint x="359.99999999997846" y="275.2089958158996"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-477D9E88-F2A9-4819-A204-AEEB920A4853" id="BPMNEdge_sid-477D9E88-F2A9-4819-A204-AEEB920A4853">
        <omgdi:waypoint x="684.5319164264888" y="275.40865384615387"></omgdi:waypoint>
        <omgdi:waypoint x="750.0952380952381" y="275.095"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-1620E41E-7711-437E-847C-5E4078827E8E" id="BPMNEdge_sid-1620E41E-7711-437E-847C-5E4078827E8E">
        <omgdi:waypoint x="564.5942893401016" y="275.33898305084745"></omgdi:waypoint>
        <omgdi:waypoint x="585.1666666666645" y="275.16624999999993"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-045E4E4F-84C5-4557-A03E-F0CF686B29E8" id="BPMNEdge_sid-045E4E4F-84C5-4557-A03E-F0CF686B29E8">
        <omgdi:waypoint x="410.0" y="430.0"></omgdi:waypoint>
        <omgdi:waypoint x="410.0" y="376.0"></omgdi:waypoint>
        <omgdi:waypoint x="620.0" y="376.0"></omgdi:waypoint>
        <omgdi:waypoint x="620.0" y="450.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-C3E72217-2A81-41DB-9E47-B80D2E8B67A0" id="BPMNEdge_sid-C3E72217-2A81-41DB-9E47-B80D2E8B67A0">
        <omgdi:waypoint x="290.5" y="255.5"></omgdi:waypoint>
        <omgdi:waypoint x="290.5" y="85.0"></omgdi:waypoint>
        <omgdi:waypoint x="360.0" y="85.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-D754B585-5210-4D9D-A35C-9D582A5965EF" id="BPMNEdge_sid-D754B585-5210-4D9D-A35C-9D582A5965EF">
        <omgdi:waypoint x="159.94999999994312" y="275.0"></omgdi:waypoint>
        <omgdi:waypoint x="270.0" y="275.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-16C8753F-018A-45B2-8E6A-4394618FDF20" id="BPMNEdge_sid-16C8753F-018A-45B2-8E6A-4394618FDF20">
        <omgdi:waypoint x="789.5591869398207" y="275.37820512820514"></omgdi:waypoint>
        <omgdi:waypoint x="835.0002755524882" y="275.08885188426405"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-E4B18318-6B27-46AE-9AF1-A014EE397CF0" id="BPMNEdge_sid-E4B18318-6B27-46AE-9AF1-A014EE397CF0">
        <omgdi:waypoint x="624.5942893401016" y="275.33898305084745"></omgdi:waypoint>
        <omgdi:waypoint x="645.1666666666645" y="275.16624999999993"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-FA66D27F-D877-45EB-BD87-E3274BB17577" id="BPMNEdge_sid-FA66D27F-D877-45EB-BD87-E3274BB17577">
        <omgdi:waypoint x="459.95000000000005" y="470.0"></omgdi:waypoint>
        <omgdi:waypoint x="525.0" y="470.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-EA1BA091-9F95-496A-BDE3-E4BA5D9D6E6D" id="BPMNEdge_sid-EA1BA091-9F95-496A-BDE3-E4BA5D9D6E6D">
        <omgdi:waypoint x="459.94999999996685" y="85.0"></omgdi:waypoint>
        <omgdi:waypoint x="525.0" y="85.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-13FCD0F9-5DDF-4583-A3D3-55CD452B6D28" id="BPMNEdge_sid-13FCD0F9-5DDF-4583-A3D3-55CD452B6D28">
        <omgdi:waypoint x="290.5" y="294.4451310380267"></omgdi:waypoint>
        <omgdi:waypoint x="290.5" y="470.0"></omgdi:waypoint>
        <omgdi:waypoint x="360.0" y="470.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-ED38F4B6-4657-48BF-94B9-49EC05A6D528" id="BPMNEdge_sid-ED38F4B6-4657-48BF-94B9-49EC05A6D528">
        <omgdi:waypoint x="410.0" y="235.0"></omgdi:waypoint>
        <omgdi:waypoint x="410.0" y="190.0"></omgdi:waypoint>
        <omgdi:waypoint x="605.0" y="190.0"></omgdi:waypoint>
        <omgdi:waypoint x="605.0" y="255.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-4F8D325B-6F80-40B7-BF0B-35F7DBBEF1D7" id="BPMNEdge_sid-4F8D325B-6F80-40B7-BF0B-35F7DBBEF1D7">
        <omgdi:waypoint x="639.4287556053686" y="85.5"></omgdi:waypoint>
        <omgdi:waypoint x="665.0" y="85.5"></omgdi:waypoint>
        <omgdi:waypoint x="665.0" y="255.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-FB26C185-4341-4828-89BF-9977A83770D8" id="BPMNEdge_sid-FB26C185-4341-4828-89BF-9977A83770D8">
        <omgdi:waypoint x="459.9499999999993" y="275.18431734317346"></omgdi:waypoint>
        <omgdi:waypoint x="525.4259259259254" y="275.4259259259259"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-201E50AF-5C51-4C4F-9CB0-1A41C1F5D76F" id="BPMNEdge_sid-201E50AF-5C51-4C4F-9CB0-1A41C1F5D76F">
        <omgdi:waypoint x="639.4287556053811" y="470.5"></omgdi:waypoint>
        <omgdi:waypoint x="665.0" y="470.5"></omgdi:waypoint>
        <omgdi:waypoint x="665.0" y="294.9050793244627"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

驱动流程

package com.example.demo.config.flowable;

import com.example.demo.enums.ResultStatus;
import com.example.demo.model.ConditionalEventDefinition;
import com.example.demo.model.EscalationEventDefinition;
import com.example.demo.service.ActReProcdefService;
import com.example.demo.service.InfoMapper;
import com.example.demo.utils.JsonResponseEntity;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.collections.CollectionUtils;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;


import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.flowable.bpmn.model.*;
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
import org.flowable.engine.*;
import org.flowable.engine.history.HistoricActivityInstance;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.image.ProcessDiagramGenerator;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

/**
 * ClassName:InclusiveGateway
 * Description:
 */

@RestController
@RequestMapping("/InclusiveGateway")
public class InclusiveGateway {

    protected static final Logger logger = LogManager.getLogger(InclusiveGateway.class);

    @Autowired
    private ActReProcdefService actReProcdefService;
    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private RepositoryService repositoryService;
    @Autowired
    private ProcessEngine processEngine;
    @Autowired
    private ProcessEngineConfiguration processEngineConfiguration;
    @Autowired
    private IdentityService identityService;
    @Autowired
    private HistoryService historyService;
//    @Autowired
//    private FlowableProcessInstanceService processInstanceService;
    @Autowired
    private RedisTemplate redisTemplate;

    protected ObjectMapper objectMapper = new ObjectMapper();
    protected Map<String, InfoMapper> propertyMappers = new HashMap<>();
    protected List<String> eventElementTypes = new ArrayList<>();

    // 查询总共部署了多少流程
    // select key,max(version) from table group by key
    @GetMapping("/deploymentAmount")
    public JsonResponseEntity<Object> deploymentAmount() {
        return JsonResponseEntity.newJsonResult(ResultStatus.SUCCESS,actReProcdefService.getDeploymentAmount());
    }

    // 部署流程
    @PostMapping("/deployment")
    @ApiOperation(value = "根据上传的bpmn进行部署", notes = "code为200则成功,500部署失败,404文件有问题")
    @ApiImplicitParam(paramType = "form", name = "file", value = "bpmn文件", required = true, dataType = "file")
    public JsonResponseEntity<Object> deployment(@RequestParam("file") MultipartFile file) throws IOException {
        Deployment deployment = null;
        deployment = repositoryService.createDeployment()
                .addInputStream(file.getName(), file.getInputStream())
//                .addClasspathResource("flowable/uploadFile.bar")
                .deploy();
        if (deployment.getId() == null) return JsonResponseEntity.newJsonResult(ResultStatus.NO_STAFFNo,"您所要部署的流程,存在问题,请仔细检查后再部署");
        return JsonResponseEntity.newJsonResult(ResultStatus.SUCCESS,deployment.getId());
    }

    @PostMapping("/get/processDefinition/name/{deploymentId}")
    @ApiOperation(value = "根据deploymentId查询processDefinitionName", notes = "code为200则成功,500为失败")
    @ApiImplicitParam(paramType = "query", name = "deploymentId", value = "部署的流程id", required = true, dataType = "String")
    public JsonResponseEntity<Object> getProcessDefinitionName(@PathVariable String deploymentId) {
        List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery()
                .deploymentId(deploymentId)
                .list();
        if (list.size() == 0) return JsonResponseEntity.newJsonResult(ResultStatus.UNKNOWNERROR,"该部署id没有对应的数据");
        return JsonResponseEntity.newJsonResult(ResultStatus.SUCCESS,list);
    }

//    @ApiImplicitParams({
//            @ApiImplicitParam(paramType="path", name = "formKey", value = "表单key名称", required = true, dataType = "String"),
//            @ApiImplicitParam(paramType="path", name = "formData", value = "表单中填入的数据", required = true, dataType = "String")
//    })

    @PostMapping("/startUp/InclusiveGateway")
    @ApiOperation(value = "启动流程", notes = "code为200则成功,404为表单信息错误")
    public JsonResponseEntity<Object> startUp(@RequestParam(value = "username", required = true) String username,
                                              @RequestParam(value = "token",required = true) String token) {
        Map<String, Object> variables = new HashMap<String, Object>();
        identityService.setAuthenticatedUserId(username);
        ProcessInstance processInstance =
                runtimeService.startProcessInstanceByKey("InclusiveGateway", variables);
        String id = processInstance.getId();
        if (processInstance == null) return JsonResponseEntity.newJsonResult(ResultStatus.NO_STAFFNo,"表单信息填写有误");
        logger.info("processInstanceId == " + id);
        return JsonResponseEntity.newJsonResult(ResultStatus.SUCCESS,id);
    }

    // 查询任务
    @PostMapping("/task")
    public JsonResponseEntity<Object> checkTask(@RequestParam(value = "username", required = true) String username) {
        // $INITIATOR
        TaskService taskService = processEngine.getTaskService();
        List<Task> tasks = taskService.createTaskQuery().taskAssignee(username).list();
        System.out.println("You have " + tasks.size() + " tasks:");
        List list = new ArrayList<>();
        for (int i = 0; i < tasks.size(); i++) {
            logger.info((i + 1) + ") " + tasks.get(i).getName());
            list.add(tasks.get(i).getName());
        }
        return JsonResponseEntity.newJsonResult(ResultStatus.SUCCESS,list);
    }
    // 删除流程 :(data:删除原因)
    @DeleteMapping("/processInstanceId")
    public JsonResponseEntity<Object> deleteProcessInstanceId(@RequestParam("processInstanceId")String processInstanceId,@RequestParam("data")String data){
        runtimeService.deleteProcessInstance(processInstanceId,data);//删除流程
        return JsonResponseEntity.newJsonResult(ResultStatus.SUCCESS,null);
    }

    // 完成指定任务(选人)
    @PostMapping("/completeTask/choicePeople")
    public JsonResponseEntity<Object> completeTask(@RequestParam(value = "taskIndex") int taskIndex) {
        if(taskIndex < 1) return JsonResponseEntity.newJsonResult(ResultStatus.NO_STAFFNo,"请输入正确的角标");
        logger.info("taskIndex === " + taskIndex);
        TaskService taskService = processEngine.getTaskService();
        List<Task> tasks = taskService.createTaskQuery().taskAssignee("$INITIATOR").list();
        Task task = tasks.get(taskIndex - 1);
        if(task == null) return JsonResponseEntity.newJsonResult(ResultStatus.NO_STAFFNo,"请重新选择要完成的任务");
        logger.info("task  ======= " + task.toString());
        Map<String, Object> processVariables = taskService.getVariables(task.getId());
        // 任务完成之后
        Map variables = new HashMap<String, Object>();
        variables.put("theFirstPeople", "李四");
        variables.put("theSecondPeople", "王五");
        variables.put("theThreePeople", "赵六");
        taskService.complete(task.getId(), variables);
        return JsonResponseEntity.newJsonResult(ResultStatus.SUCCESS,task.getId());
    }

    // 获取流程图
    @GetMapping(value = "/runtime/process-instances/{processInstanceId}/diagram")
    public ResponseEntity<byte[]> getProcessInstanceDiagram(@ApiParam(name = "processInstanceId") @PathVariable String processInstanceId, HttpServletResponse response) {
        ProcessInstance processInstance =
                runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        ProcessDefinition pde = repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());

        if (pde != null && pde.hasGraphicalNotation()) {
            BpmnModel bpmnModel = repositoryService.getBpmnModel(pde.getId());
            ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
            InputStream resource = diagramGenerator.generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(processInstance.getId()), Collections.<String>emptyList(),
                    processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(),
                    processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader(), 1.0, processEngineConfiguration.isDrawSequenceFlowNameWithNoLabelDI());
            HttpHeaders responseHeaders = new HttpHeaders();
            responseHeaders.set("Content-Type", "image/png");
            try {
                return new ResponseEntity<>(IOUtils.toByteArray(resource), responseHeaders, HttpStatus.OK);
            } catch (Exception e) {
                throw new FlowableIllegalArgumentException("Error exporting diagram", e);
            }
        } else {
            throw new FlowableIllegalArgumentException("Process instance with id '" + processInstance.getId() + "' has no graphical notation defined.");
        }
    }

    @PostMapping("/completeTask/form")
    public void completeTaskForm(@RequestParam(value = "str", required = true) String str,
                                 @RequestParam(value = "taskIndex", required = true) int taskIndex,
                                 @RequestParam(value = "username", required = true) String username) {
        logger.info("taskIndex === " + taskIndex);
        TaskService taskService = processEngine.getTaskService();
        List<Task> tasks = taskService.createTaskQuery().taskAssignee(username).list();
        Task task = tasks.get(taskIndex - 1);
        System.out.println("task  ======= " + task.toString());
        Map<String, Object> processVariables = taskService.getVariables(task.getId());
        // 任务完成之后
        Map variables = new HashMap<String, Object>();
        variables.put("test2", str);
        taskService.complete(task.getId(), variables);
    }

    // 获取历史流程显示图 ===> 未完成
    @PostMapping("/history/diagram")
    public ResponseEntity<byte[]> historyDiagram(@RequestParam(value = "processInstanceId", required = true) String processInstanceId) {
        HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        String processDefinitionId = historicProcessInstance.getProcessDefinitionId();
        ProcessDefinition pde = repositoryService.getProcessDefinition(processDefinitionId);
        if (pde != null && pde.hasGraphicalNotation()) {
            BpmnModel bpmnModel = repositoryService.getBpmnModel(pde.getId());
            ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
            InputStream resource = diagramGenerator.generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(processDefinitionId), Collections.<String>emptyList(),
                    processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(),
                    processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader(), 1.0, processEngineConfiguration.isDrawSequenceFlowNameWithNoLabelDI());
            HttpHeaders responseHeaders = new HttpHeaders();
            responseHeaders.set("Content-Type", "image/png");
            try {
                return new ResponseEntity<>(IOUtils.toByteArray(resource), responseHeaders, HttpStatus.OK);
            } catch (Exception e) {
                throw new FlowableIllegalArgumentException("Error exporting diagram", e);
            }
        } else {
            throw new FlowableIllegalArgumentException("History Process instance with id '" + processDefinitionId + "' has no graphical notation defined.");
        }
    }
    // 获取流程历史显示图
    @RequestMapping(value = "/rest/process-instances/history/{processInstanceId}/model-json", method = RequestMethod.GET, produces = "application/json")
    public JsonNode getModelHistoryJSON(@PathVariable String processInstanceId) throws Exception {
        HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        if (processInstance == null) {
            throw new Exception("No process instance found with id " + processInstanceId);
        }
        BpmnModel pojoModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());
        if (pojoModel == null || pojoModel.getLocationMap().isEmpty()) {
            throw new Exception("Process definition could not be found with id " + processInstance.getProcessDefinitionId());
        }
        List<HistoricActivityInstance> activityInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).list();
        Set<String> completedActivityInstances = new HashSet<>();
        Set<String> currentActivityinstances = new HashSet<>();
        if (CollectionUtils.isNotEmpty(activityInstances)) {
            for (HistoricActivityInstance activityInstance : activityInstances) {
                if (activityInstance.getEndTime() != null) {
                    completedActivityInstances.add(activityInstance.getActivityId());
                } else {
                    currentActivityinstances.add(activityInstance.getActivityId());
                }
            }
        }
        ObjectNode displayNode = processProcessElements(pojoModel, completedActivityInstances, currentActivityinstances, Collections.EMPTY_LIST, processInstanceId);
        return displayNode;
    }

    protected ObjectNode processProcessElements(BpmnModel pojoModel, Set<String> completedElements, Set<String> currentElements, Collection<String> breakpoints, String processInstanceId) {
        ObjectNode displayNode = objectMapper.createObjectNode();
        GraphicInfo diagramInfo = new GraphicInfo();
        ArrayNode elementArray = objectMapper.createArrayNode();
        ArrayNode flowArray = objectMapper.createArrayNode();
        ArrayNode collapsedArray = objectMapper.createArrayNode();
        if (CollectionUtils.isNotEmpty(pojoModel.getPools())) {
            ArrayNode poolArray = objectMapper.createArrayNode();
            boolean firstElement = true;
            for (Pool pool : pojoModel.getPools()) {
                ObjectNode poolNode = objectMapper.createObjectNode();
                poolNode.put("id", pool.getId());
                poolNode.put("name", pool.getName());
                GraphicInfo poolInfo = pojoModel.getGraphicInfo(pool.getId());
                fillGraphicInfo(poolNode, poolInfo, true);
                org.flowable.bpmn.model.Process process = pojoModel.getProcess(pool.getId());
                if (process != null && CollectionUtils.isNotEmpty(process.getLanes())) {
                    ArrayNode laneArray = objectMapper.createArrayNode();
                    for (Lane lane : process.getLanes()) {
                        ObjectNode laneNode = objectMapper.createObjectNode();
                        laneNode.put("id", lane.getId());
                        laneNode.put("name", lane.getName());
                        fillGraphicInfo(laneNode, pojoModel.getGraphicInfo(lane.getId()), true);
                        laneArray.add(laneNode);
                    }
                    poolNode.set("lanes", laneArray);
                }
                poolArray.add(poolNode);
                double rightX = poolInfo.getX() + poolInfo.getWidth();
                double bottomY = poolInfo.getY() + poolInfo.getHeight();
                double middleX = poolInfo.getX() + (poolInfo.getWidth() / 2);
                if (firstElement || middleX < diagramInfo.getX()) {
                    diagramInfo.setX(middleX);
                }
                if (firstElement || poolInfo.getY() < diagramInfo.getY()) {
                    diagramInfo.setY(poolInfo.getY());
                }
                if (rightX > diagramInfo.getWidth()) {
                    diagramInfo.setWidth(rightX);
                }
                if (bottomY > diagramInfo.getHeight()) {
                    diagramInfo.setHeight(bottomY);
                }
                firstElement = false;
            }
            displayNode.set("pools", poolArray);
        } else {
            // in initialize with fake x and y to make sure the minimal
            // values are set
            diagramInfo.setX(9999);
            diagramInfo.setY(1000);
        }
        for (org.flowable.bpmn.model.Process process : pojoModel.getProcesses()) {
            processElements(process.getFlowElements(), pojoModel, elementArray, flowArray, collapsedArray,
                    diagramInfo, completedElements, currentElements, breakpoints, null, processInstanceId);
            processArtifacts(process.getArtifacts(), pojoModel, elementArray, flowArray, diagramInfo);
        }
        displayNode.set("elements", elementArray);
        displayNode.set("flows", flowArray);
        displayNode.set("collapsed", collapsedArray);

        displayNode.put("diagramBeginX", diagramInfo.getX());
        displayNode.put("diagramBeginY", diagramInfo.getY());
        displayNode.put("diagramWidth", diagramInfo.getWidth());
        displayNode.put("diagramHeight", diagramInfo.getHeight());
        return displayNode;
    }

    protected void fillGraphicInfo(ObjectNode elementNode, GraphicInfo graphicInfo, boolean includeWidthAndHeight) {
        commonFillGraphicInfo(elementNode, graphicInfo.getX(), graphicInfo.getY(), graphicInfo.getWidth(), graphicInfo.getHeight(), includeWidthAndHeight);
    }

    protected void commonFillGraphicInfo(ObjectNode elementNode, double x, double y, double width, double height, boolean includeWidthAndHeight) {
        elementNode.put("x", x);
        elementNode.put("y", y);
        if (includeWidthAndHeight) {
            elementNode.put("width", width);
            elementNode.put("height", height);
        }
    }

    protected void processElements(Collection<FlowElement> elementList, BpmnModel model, ArrayNode elementArray, ArrayNode flowArray,
                                   ArrayNode collapsedArray, GraphicInfo diagramInfo, Set<String> completedElements,
                                   Set<String> currentElements, Collection<String> breakpoints, ObjectNode collapsedNode, String processInstanceId) {
        for (FlowElement element : elementList) {
            ObjectNode elementNode = objectMapper.createObjectNode();
            if (completedElements != null) {
                elementNode.put("completed", completedElements.contains(element.getId()));
            }
            if (!breakpoints.isEmpty()) {
                elementNode.put("breakpoint", breakpoints.contains(element.getId()));
            }
            if (currentElements != null) {
                elementNode.put("current", currentElements.contains(element.getId()));
            }
            if (element instanceof SequenceFlow) {
                SequenceFlow flow = (SequenceFlow) element;
                elementNode.put("id", flow.getId());
                elementNode.put("type", "sequenceFlow");
                elementNode.put("sourceRef", flow.getSourceRef());
                elementNode.put("targetRef", flow.getTargetRef());
                elementNode.put("name", flow.getName());
                List<GraphicInfo> flowInfo = model.getFlowLocationGraphicInfo(flow.getId());
                if (CollectionUtils.isNotEmpty(flowInfo)) {
                    ArrayNode waypointArray = objectMapper.createArrayNode();
                    for (GraphicInfo graphicInfo : flowInfo) {
                        ObjectNode pointNode = objectMapper.createObjectNode();
                        fillGraphicInfo(pointNode, graphicInfo, false);
                        waypointArray.add(pointNode);
                        fillDiagramInfo(graphicInfo, diagramInfo);
                    }
                    elementNode.set("waypoints", waypointArray);
                    String className = element.getClass().getSimpleName();
                    if (propertyMappers.containsKey(className)) {
                        elementNode.set("properties", propertyMappers.get(className).map(element));
                    }
                    if (collapsedNode != null) {
                        ((ArrayNode) collapsedNode.get("flows")).add(elementNode);
                    } else {
                        flowArray.add(elementNode);
                    }
                }
            } else {
                elementNode.put("id", element.getId());
                elementNode.put("name", element.getName());
                GraphicInfo graphicInfo = model.getGraphicInfo(element.getId());
                if (graphicInfo != null) {
                    fillGraphicInfo(elementNode, graphicInfo, true);
                    fillDiagramInfo(graphicInfo, diagramInfo);
                }
                String className = element.getClass().getSimpleName();
                elementNode.put("type", className);
                fillEventTypes(className, element, elementNode);
                if (element instanceof ServiceTask) {
                    ServiceTask serviceTask = (ServiceTask) element;
                    if (ServiceTask.MAIL_TASK.equals(serviceTask.getType())) {
                        elementNode.put("taskType", "mail");
                    } else if ("camel".equals(serviceTask.getType())) {
                        elementNode.put("taskType", "camel");
                    } else if ("mule".equals(serviceTask.getType())) {
                        elementNode.put("taskType", "mule");
                    } else if (ServiceTask.HTTP_TASK.equals(serviceTask.getType())) {
                        elementNode.put("taskType", "http");
                    } else if (ServiceTask.SHELL_TASK.equals(serviceTask.getType())) {
                        elementNode.put("taskType", "shell");
                    }
                }
                if (propertyMappers.containsKey(className)) {
                    elementNode.set("properties", propertyMappers.get(className).map(element));
                }
                if (collapsedNode != null) {
                    ((ArrayNode) collapsedNode.get("elements")).add(elementNode);
                } else {
                    elementArray.add(elementNode);
                }
                if (element instanceof SubProcess) {
                    SubProcess subProcess = (SubProcess) element;
                    ObjectNode newCollapsedNode = collapsedNode;
                    // skip collapsed sub processes
                    if (graphicInfo != null && graphicInfo.getExpanded() != null && !graphicInfo.getExpanded()) {
                        elementNode.put("collapsed", "true");
                        newCollapsedNode = objectMapper.createObjectNode();
                        newCollapsedNode.put("id", subProcess.getId());
                        newCollapsedNode.putArray("elements");
                        newCollapsedNode.putArray("flows");
                        collapsedArray.add(newCollapsedNode);
                    }
                    processElements(subProcess.getFlowElements(), model, elementArray, flowArray, collapsedArray,
                            diagramInfo, completedElements, currentElements, breakpoints, newCollapsedNode, processInstanceId);
                    processArtifacts(subProcess.getArtifacts(), model, elementArray, flowArray, diagramInfo);
                }
            }
        }
    }

    protected void processArtifacts(Collection<Artifact> artifactList, BpmnModel model, ArrayNode elementArray, ArrayNode flowArray, GraphicInfo diagramInfo) {
        for (Artifact artifact : artifactList) {
            if (artifact instanceof Association) {
                ObjectNode elementNode = objectMapper.createObjectNode();
                Association flow = (Association) artifact;
                elementNode.put("id", flow.getId());
                elementNode.put("type", "association");
                elementNode.put("sourceRef", flow.getSourceRef());
                elementNode.put("targetRef", flow.getTargetRef());
                fillWaypoints(flow.getId(), model, elementNode, diagramInfo);
                flowArray.add(elementNode);
            } else {
                ObjectNode elementNode = objectMapper.createObjectNode();
                elementNode.put("id", artifact.getId());
                if (artifact instanceof TextAnnotation) {
                    TextAnnotation annotation = (TextAnnotation) artifact;
                    elementNode.put("text", annotation.getText());
                }
                GraphicInfo graphicInfo = model.getGraphicInfo(artifact.getId());
                if (graphicInfo != null) {
                    fillGraphicInfo(elementNode, graphicInfo, true);
                    fillDiagramInfo(graphicInfo, diagramInfo);
                }
                String className = artifact.getClass().getSimpleName();
                elementNode.put("type", className);
                elementArray.add(elementNode);
            }
        }
    }

    protected void fillDiagramInfo(GraphicInfo graphicInfo, GraphicInfo diagramInfo) {
        double rightX = graphicInfo.getX() + graphicInfo.getWidth();
        double bottomY = graphicInfo.getY() + graphicInfo.getHeight();
        double middleX = graphicInfo.getX() + (graphicInfo.getWidth() / 2);
        if (middleX < diagramInfo.getX()) {
            diagramInfo.setX(middleX);
        }
        if (graphicInfo.getY() < diagramInfo.getY()) {
            diagramInfo.setY(graphicInfo.getY());
        }
        if (rightX > diagramInfo.getWidth()) {
            diagramInfo.setWidth(rightX);
        }
        if (bottomY > diagramInfo.getHeight()) {
            diagramInfo.setHeight(bottomY);
        }
    }

    protected void fillEventTypes(String className, FlowElement element, ObjectNode elementNode) {
        if (eventElementTypes.contains(className)) {
            Event event = (Event) element;
            if (CollectionUtils.isNotEmpty(event.getEventDefinitions())) {
                EventDefinition eventDef = event.getEventDefinitions().get(0);
                ObjectNode eventNode = objectMapper.createObjectNode();
                if (eventDef instanceof TimerEventDefinition) {
                    TimerEventDefinition timerDef = (TimerEventDefinition) eventDef;
                    eventNode.put("type", "timer");
                    if (StringUtils.isNotEmpty(timerDef.getTimeCycle())) {
                        eventNode.put("timeCycle", timerDef.getTimeCycle());
                    }
                    if (StringUtils.isNotEmpty(timerDef.getTimeDate())) {
                        eventNode.put("timeDate", timerDef.getTimeDate());
                    }
                    if (StringUtils.isNotEmpty(timerDef.getTimeDuration())) {
                        eventNode.put("timeDuration", timerDef.getTimeDuration());
                    }

                } else if (eventDef instanceof ConditionalEventDefinition) {
                    ConditionalEventDefinition conditionalDef = (ConditionalEventDefinition) eventDef;
                    eventNode.put("type", "conditional");
                    if (StringUtils.isNotEmpty(conditionalDef.getConditionExpression())) {
                        eventNode.put("condition", conditionalDef.getConditionExpression());
                    }
                } else if (eventDef instanceof ErrorEventDefinition) {
                    ErrorEventDefinition errorDef = (ErrorEventDefinition) eventDef;
                    eventNode.put("type", "error");
                    if (StringUtils.isNotEmpty(errorDef.getErrorCode())) {
                        eventNode.put("errorCode", errorDef.getErrorCode());
                    }
                } else if (eventDef instanceof EscalationEventDefinition) {
                    EscalationEventDefinition escalationDef = (EscalationEventDefinition) eventDef;
                    eventNode.put("type", "escalation");
                    if (StringUtils.isNotEmpty(escalationDef.getEscalationCode())) {
                        eventNode.put("escalationCode", escalationDef.getEscalationCode());
                    }
                } else if (eventDef instanceof SignalEventDefinition) {
                    SignalEventDefinition signalDef = (SignalEventDefinition) eventDef;
                    eventNode.put("type", "signal");
                    if (StringUtils.isNotEmpty(signalDef.getSignalRef())) {
                        eventNode.put("signalRef", signalDef.getSignalRef());
                    }
                } else if (eventDef instanceof MessageEventDefinition) {
                    MessageEventDefinition messageDef = (MessageEventDefinition) eventDef;
                    eventNode.put("type", "message");
                    if (StringUtils.isNotEmpty(messageDef.getMessageRef())) {
                        eventNode.put("messageRef", messageDef.getMessageRef());
                    }
                }
                elementNode.set("eventDefinition", eventNode);
            }
        }
    }
    protected void fillWaypoints(String id, BpmnModel model, ObjectNode elementNode, GraphicInfo diagramInfo) {
        List<GraphicInfo> flowInfo = model.getFlowLocationGraphicInfo(id);
        ArrayNode waypointArray = objectMapper.createArrayNode();
        for (GraphicInfo graphicInfo : flowInfo) {
            ObjectNode pointNode = objectMapper.createObjectNode();
            fillGraphicInfo(pointNode, graphicInfo, false);
            waypointArray.add(pointNode);
            fillDiagramInfo(graphicInfo, diagramInfo);
        }
        elementNode.set("waypoints", waypointArray);
    }
}

上一篇 下一篇

猜你喜欢

热点阅读