精华内容
下载资源
问答
  • camunda框架学习(零)-快速入门

    千次阅读 2021-02-20 11:28:06
    去官网下载快速入门项目 .../camunda-bpm-tomcat-7.14.0/server/apache-tomcat-9.0.36/conf/server.xml <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) u

    去官网下载快速入门项目 https://camunda.com/download/
    在这里插入图片描述

    然后本地运行,默认使用的h2嵌入式数据库,

        <Resource name="jdbc/ProcessEngine"
                  auth="Container"
                  type="javax.sql.DataSource" 
                  factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
                  uniqueResourceName="process-engine"
                  driverClassName="org.h2.Driver" 
                  url="jdbc:h2:./camunda-h2-dbs/process-engine;MVCC=TRUE;TRACE_LEVEL_FILE=0;DB_CLOSE_ON_EXIT=FALSE"
                  defaultTransactionIsolation="READ_COMMITTED"
                  username="sa"  
                  password="sa"
                  maxTotal="20"
                  minIdle="5"
                  maxIdle="20" />
    

    也可以改成自己的数据库,修改:
    /camunda-bpm-tomcat-7.14.0/server/apache-tomcat-9.0.36/conf/server.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!--
      Licensed to the Apache Software Foundation (ASF) under one or more
      contributor license agreements.  See the NOTICE file distributed with
      this work for additional information regarding copyright ownership.
      The ASF licenses this file to You under the Apache License, Version 2.0
      (the "License"); you may not use this file except in compliance with
      the License.  You may obtain a copy of the License at
    
          http://www.apache.org/licenses/LICENSE-2.0
    
      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    -->
    <!-- Note:  A "Server" is not itself a "Container", so you may not
         define subcomponents such as "Valves" at this level.
         Documentation at /docs/config/server.html
     -->
    <Server port="8005" shutdown="SHUTDOWN">
      <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
      <!-- Security listener. Documentation at /docs/config/listeners.html
      <Listener className="org.apache.catalina.security.SecurityListener" />
      -->
    
      <!--APR library loader. Documentation at /docs/apr.html -->
      <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
    
      <!-- Prevent memory leaks due to use of particular java/javax APIs-->
      <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
      
      <Listener className="org.camunda.bpm.container.impl.tomcat.TomcatBpmPlatformBootstrap" />
      
      <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
      <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
    
      <!-- Global JNDI resources
           Documentation at /docs/jndi-resources-howto.html
      -->
      <GlobalNamingResources>
        <!-- Editable user database that can also be used by
             UserDatabaseRealm to authenticate users
        -->
        <Resource name="UserDatabase" auth="Container"
                  type="org.apache.catalina.UserDatabase"
                  description="User database that can be updated and saved"
                  factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                  pathname="conf/tomcat-users.xml" />
    
        <!-- Additional properties can be set to avoid a common exception
             regarding connection timeout in the connection pool:
              testOnBorrow="true"
              validationQuery="SELECT 1"
        -->
    <!--     <Resource name="jdbc/ProcessEngine"
                  auth="Container"
                  type="javax.sql.DataSource" 
                  factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
                  uniqueResourceName="process-engine"
                  driverClassName="org.h2.Driver" 
                  url="jdbc:h2:./camunda-h2-dbs/process-engine;MVCC=TRUE;TRACE_LEVEL_FILE=0;DB_CLOSE_ON_EXIT=FALSE"
                  defaultTransactionIsolation="READ_COMMITTED"
                  username="sa"  
                  password="sa"
                  maxTotal="20"
                  minIdle="5"
                  maxIdle="20" /> -->
    
        <Resource name="jdbc/ProcessEngine"
                  auth="Container"
                  type="javax.sql.DataSource" 
                  factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
                  uniqueResourceName="process-engine"
                  driverClassName="com.mysql.jdbc.Driver" 
                  url="jdbc:mysql://127.0.0.1:3306/camunda"
                  defaultTransactionIsolation="READ_COMMITTED"
                  username="root"  
                  password="123456"
                  maxTotal="20"
                  minIdle="5"
                  maxIdle="20" />
    
        <Resource name="global/camunda-bpm-platform/process-engine/ProcessEngineService!org.camunda.bpm.ProcessEngineService" auth="Container"
                  type="org.camunda.bpm.ProcessEngineService"
                  description="camunda BPM platform Process Engine Service"
                  factory="org.camunda.bpm.container.impl.jndi.ProcessEngineServiceObjectFactory" />
                  
        <Resource name="global/camunda-bpm-platform/process-engine/ProcessApplicationService!org.camunda.bpm.ProcessApplicationService" auth="Container"
                  type="org.camunda.bpm.ProcessApplicationService"
                  description="camunda BPM platform Process Application Service"
                  factory="org.camunda.bpm.container.impl.jndi.ProcessApplicationServiceObjectFactory" />
    			  
      </GlobalNamingResources>
    
      <!-- A "Service" is a collection of one or more "Connectors" that share
           a single "Container" Note:  A "Service" is not itself a "Container",
           so you may not define subcomponents such as "Valves" at this level.
           Documentation at /docs/config/service.html
       -->
      <Service name="Catalina">
    
        <!--The connectors can use a shared executor, you can define one or more named thread pools-->
        <!--
        <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
            maxThreads="150" minSpareThreads="4"/>
        -->
    
    
        <!-- A "Connector" represents an endpoint by which requests are received
             and responses are returned. Documentation at :
             Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
             Java AJP  Connector: /docs/config/ajp.html
             APR (HTTP/AJP) Connector: /docs/apr.html
             Define a non-SSL HTTP/1.1 Connector on port 8080
        -->
        <Connector port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443" />
        <!-- A "Connector" using the shared thread pool-->
        <!--
        <Connector executor="tomcatThreadPool"
                   port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443" />
        -->
        <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443
             This connector uses the NIO implementation. The default
             SSLImplementation will depend on the presence of the APR/native
             library and the useOpenSSL attribute of the
             AprLifecycleListener.
             Either JSSE or OpenSSL style configuration may be used regardless of
             the SSLImplementation selected. JSSE style configuration is used below.
        -->
        <!--
        <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
                   maxThreads="150" SSLEnabled="true">
            <SSLHostConfig>
                <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                             type="RSA" />
            </SSLHostConfig>
        </Connector>
        -->
        <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
             This connector uses the APR/native implementation which always uses
             OpenSSL for TLS.
             Either JSSE or OpenSSL style configuration may be used. OpenSSL style
             configuration is used below.
        -->
        <!--
        <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
                   maxThreads="150" SSLEnabled="true" >
            <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
            <SSLHostConfig>
                <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
                             certificateFile="conf/localhost-rsa-cert.pem"
                             certificateChainFile="conf/localhost-rsa-chain.pem"
                             type="RSA" />
            </SSLHostConfig>
        </Connector>
        -->
    
        <!-- Define an AJP 1.3 Connector on port 8009 -->
        <!--
        <Connector protocol="AJP/1.3"
                   address="::1"
                   port="8009"
                   redirectPort="8443" />
        -->
    
        <!-- An Engine represents the entry point (within Catalina) that processes
             every request.  The Engine implementation for Tomcat stand alone
             analyzes the HTTP headers included with the request, and passes them
             on to the appropriate Host (virtual host).
             Documentation at /docs/config/engine.html -->
    
        <!-- You should set jvmRoute to support load-balancing via AJP ie :
        <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
        -->
        <Engine name="Catalina" defaultHost="localhost">
    
          <!--For clustering, please take a look at documentation at:
              /docs/cluster-howto.html  (simple how to)
              /docs/config/cluster.html (reference documentation) -->
          <!--
          <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
          -->
    
          <!-- Use the LockOutRealm to prevent attempts to guess user passwords
               via a brute-force attack -->
          <Realm className="org.apache.catalina.realm.LockOutRealm">
            <!-- This Realm uses the UserDatabase configured in the global JNDI
                 resources under the key "UserDatabase".  Any edits
                 that are performed against this UserDatabase are immediately
                 available for use by the Realm.  -->
            <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                   resourceName="UserDatabase"/>
          </Realm>
    
          <Host name="localhost"  appBase="webapps"
                unpackWARs="true" autoDeploy="true">
    
            <!-- SingleSignOn valve, share authentication between web applications
                 Documentation at: /docs/config/valve.html -->
            <!--
            <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
            -->
    
            <!-- Access log processes all example.
                 Documentation at: /docs/config/valve.html
                 Note: The pattern used is equivalent to using pattern="common" -->
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                   prefix="localhost_access_log" suffix=".txt"
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" />
    
          </Host>
        </Engine>
      </Service>
    </Server>
    
    

    然后放一个mysql的连接驱动jar包paiche.bpmn /Users/zhoupeng/Downloads/camunda-bpm-tomcat-7.14.0/server/apache-tomcat-9.0.36/lib/目录下(如mysql-connector-java-5.1.39.jar

    启动:

    sh /camunda-bpm-tomcat-7.14.0/start-camunda.sh
    

    停止:

    sh /camunda-bpm-tomcat-7.14.0/shutdown-camunda.sh
    
    展开全文
  • camunda框架学习(七)节点系列

    千次阅读 2021-03-05 17:34:26
    一、接收任务 接收任务不会再ACT_RUN_TASK表中插入数据 /** * insert into ACT_HI_ACTINST ( ID_, PARENT_ACT_INST_ID_, ... } 监听器类方式的使用: 添加类,与一个固定值,与一个变量值 服务任务" camunda:class=...

    一、接收任务

    在这里插入图片描述

    接收任务不会再ACT_RUN_TASK表中插入数据

        /**
         * insert into ACT_HI_ACTINST ( ID_, PARENT_ACT_INST_ID_, PROC_DEF_KEY_, PROC_DEF_ID_, ROOT_PROC_INST_ID_, PROC_INST_ID_, EXECUTION_ID_, ACT_ID_, TASK_ID_, CALL_PROC_INST_ID_, CALL_CASE_INST_ID_, ACT_NAME_, ACT_TYPE_, ASSIGNEE_, START_TIME_, END_TIME_, DURATION_, ACT_INST_STATE_, SEQUENCE_COUNTER_, TENANT_ID_, REMOVAL_TIME_ ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
         * update ACT_RU_EXECUTION set REV_ = ?, PROC_DEF_ID_ = ?, BUSINESS_KEY_ = ?, ACT_ID_ = ?, ACT_INST_ID_ = ?, IS_ACTIVE_ = ?, IS_CONCURRENT_ = ?, IS_SCOPE_ = ?, IS_EVENT_SCOPE_ = ?, PARENT_ID_ = ?, SUPER_EXEC_ = ?, SUSPENSION_STATE_ = ?, CACHED_ENT_STATE_ = ?, SEQUENCE_COUNTER_ = ?, TENANT_ID_ = ? where ID_ = ? and REV_ = ?
         * UPDATE ACT_HI_ACTINST SET EXECUTION_ID_ = ?, PROC_DEF_KEY_ = ?, PROC_DEF_ID_ = ?, ACT_ID_ = ?, ACT_NAME_ = ?, ACT_TYPE_ = ?, PARENT_ACT_INST_ID_ = ? , END_TIME_ = ? , DURATION_ = ? , ACT_INST_STATE_ = ? WHERE ID_ = ?
         */
        @Test
        public void signal() {
            //注意触发接收任务需要的参数 用的是执行实例ID,不是流程实例ID
            String executionId = "4801";
            //获取当日的销售额度,完成自己的一些业务,4501,触发实例继续往下流转
            runtimeService.signal(executionId);
        }
    
    根据活动查询执行实例
        /**
         * elect distinct RES.* from ACT_RU_EXECUTION RES
         * inner join ACT_RE_PROCDEF P on RES.PROC_DEF_ID_ = P.ID_ WHERE RES.ACT_ID_ = ? order by RES.ID_ asc LIMIT ? OFFSET ?
         */
        @Test
        public void createExecutionQuery() {
            //注意触发接收任务需要的参数 用的是执行实例ID,不是流程实例ID
            String activityId = "Activity_0sm44rv";
            //获取当日的销售额度,完成自己的一些业务,4501,触发实例继续往下流转
            Execution execution = runtimeService.createExecutionQuery().activityId(activityId).singleResult();
            System.out.println(execution);
        }
    

    二、接收任务与消息配合使用

    在这里插入图片描述

    实例执行到接受任务时,会向ACT_RU_EVENT_SUBSCR表中插入1条数据

    流程实例表ACT_RU_EXECUTION中会产生两条数据

    发射信号signal方法是执行实例,而不是流程实例

    实例执行完毕,则会删除ACT_RU_EVENT_SUBSCR中对应的数据

    附:

    新启动的流程,观察ACT_RU_EXECUTION表中:ROOT_PROC_INST_ID_字段有值为流程实例,执行实例为NULLPARENT_ID_字段有值为执行实例,流程实例为NULLACT_ID_字段有值为执行实例,流程实例为NULLIS_ACTIVE_字段为0为流程实例,为1为执行实例。

        /**
         * 带有消息的启动时会多插入一些表ACT_RU_EVENT_SUBSCR
         * insert into ACT_HI_PROCINST ( ID_, PROC_INST_ID_, BUSINESS_KEY_, PROC_DEF_KEY_, PROC_DEF_ID_, START_TIME_, END_TIME_, REMOVAL_TIME_, DURATION_, START_USER_ID_, START_ACT_ID_, END_ACT_ID_, SUPER_PROCESS_INSTANCE_ID_, ROOT_PROC_INST_ID_, SUPER_CASE_INSTANCE_ID_, CASE_INST_ID_, DELETE_REASON_, TENANT_ID_, STATE_ ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
         * insert into ACT_HI_ACTINST ( ID_, PARENT_ACT_INST_ID_, PROC_DEF_KEY_, PROC_DEF_ID_, ROOT_PROC_INST_ID_, PROC_INST_ID_, EXECUTION_ID_, ACT_ID_, TASK_ID_, CALL_PROC_INST_ID_, CALL_CASE_INST_ID_, ACT_NAME_, ACT_TYPE_, ASSIGNEE_, START_TIME_, END_TIME_, DURATION_, ACT_INST_STATE_, SEQUENCE_COUNTER_, TENANT_ID_, REMOVAL_TIME_ ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
         * insert into ACT_RU_EXECUTION ( ID_, ROOT_PROC_INST_ID_, PROC_INST_ID_, BUSINESS_KEY_, PROC_DEF_ID_, ACT_ID_, ACT_INST_ID_, IS_ACTIVE_, IS_CONCURRENT_, IS_SCOPE_, IS_EVENT_SCOPE_, PARENT_ID_, SUPER_EXEC_, SUPER_CASE_EXEC_, CASE_INST_ID_, SUSPENSION_STATE_, CACHED_ENT_STATE_, SEQUENCE_COUNTER_, TENANT_ID_, REV_ ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1 )
         * insert into ACT_RU_EVENT_SUBSCR ( ID_, EVENT_TYPE_, EVENT_NAME_, EXECUTION_ID_, PROC_INST_ID_, ACTIVITY_ID_, CONFIGURATION_, CREATED_, TENANT_ID_, REV_ ) values (?, ?, ?, ?, ?, ?, ?, ?, ?, 1 )
         */
        @Test
        public void startProcessInstanceByKey() {
            runtimeService.startProcessInstanceByKey("receiveTask");
        }
    
    
        /**
         * insert into ACT_HI_ACTINST ( ID_, PARENT_ACT_INST_ID_, PROC_DEF_KEY_, PROC_DEF_ID_, ROOT_PROC_INST_ID_, PROC_INST_ID_, EXECUTION_ID_, ACT_ID_, TASK_ID_, CALL_PROC_INST_ID_, CALL_CASE_INST_ID_, ACT_NAME_, ACT_TYPE_, ASSIGNEE_, START_TIME_, END_TIME_, DURATION_, ACT_INST_STATE_, SEQUENCE_COUNTER_, TENANT_ID_, REMOVAL_TIME_ ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
         * delete from ACT_RU_EVENT_SUBSCR where ID_ = ? and REV_ = ?
         * update ACT_RU_EXECUTION set REV_ = ?, PROC_DEF_ID_ = ?, BUSINESS_KEY_ = ?, ACT_ID_ = ?, ACT_INST_ID_ = ?, IS_ACTIVE_ = ?, IS_CONCURRENT_ = ?, IS_SCOPE_ = ?, IS_EVENT_SCOPE_ = ?, PARENT_ID_ = ?, SUPER_EXEC_ = ?, SUSPENSION_STATE_ = ?, CACHED_ENT_STATE_ = ?, SEQUENCE_COUNTER_ = ?, TENANT_ID_ = ? where ID_ = ? and REV_ = ?
         * delete from ACT_RU_EXECUTION where ID_ = ? and REV_ = ?
         * UPDATE ACT_HI_ACTINST SET EXECUTION_ID_ = ?, PROC_DEF_KEY_ = ?, PROC_DEF_ID_ = ?, ACT_ID_ = ?, ACT_NAME_ = ?, ACT_TYPE_ = ?, PARENT_ACT_INST_ID_ = ? , END_TIME_ = ? , DURATION_ = ? , ACT_INST_STATE_ = ? WHERE ID_ = ?
         */
        public void signalMsg() {
            String executionId = "5103";
            runtimeService.signal(executionId);
        }
    
    
    

    在这里插入图片描述

        @Test
        public void messageEventReceived() {
            String executionId = "5403";
            String messageName = "newInvoice";
            runtimeService.messageEventReceived(messageName, executionId);
        }
    

    也可以直接利用消息名称

        @Test
        public void correlateMessage() {
            String messageName = "newInvoice";
            runtimeService.correlateMessage(messageName);
        }
    
    

    事件(消息)订阅表查询

      /**
         * createEventSubscriptionQuery:select distinct RES.* from ACT_RU_EVENT_SUBSCR RES order by RES.ID_ asc LIMIT ? OFFSET ?
         */
        @Test
        public void correlateMessageAndcreateEventSubscriptionQuery() {
            String businessKey1 = "23";
            String businessKey2 = "42";
            runtimeService.startProcessInstanceByKey("receiveTask", businessKey1);
            runtimeService.startProcessInstanceByKey("receiveTask", businessKey2);
    
            //事件订阅表查询
            List<EventSubscription> list = runtimeService.createEventSubscriptionQuery().list();
            System.out.println("######EventSubscription:" + list.size());
    
            runtimeService.correlateMessage("newInvoice", "23");
            list = runtimeService.createEventSubscriptionQuery().list();
            System.out.println("######EventSubscription:" + list.size());
    
            runtimeService.correlateMessage("newInvoice", "42");
            list = runtimeService.createEventSubscriptionQuery().list();
            System.out.println("######EventSubscription:" + list.size());
        }
    
        /**
         * Cannot correlate a message with name 'newInvoice' to a single execution. 2 executions match the correlation keys
         */
        @Test
        public void correlateMessageAndcreateEventSubscriptionQuery2() {
            String businessKey1 = "23";
            String businessKey2 = "42";
            runtimeService.startProcessInstanceByKey("receiveTask", businessKey1);
            runtimeService.startProcessInstanceByKey("receiveTask", businessKey2);
    
            //事件订阅表查询
            List<EventSubscription> list = runtimeService.createEventSubscriptionQuery().list();
            System.out.println("######EventSubscription:" + list.size());
    
            runtimeService.correlateMessage("newInvoice");
            list = runtimeService.createEventSubscriptionQuery().list();
            System.out.println("######EventSubscription:" + list.size());
    
            runtimeService.correlateMessage("newInvoice");
            list = runtimeService.createEventSubscriptionQuery().list();
            System.out.println("######EventSubscription:" + list.size());
        }
    

    三、服务任务使用

    在这里插入图片描述
    在这里插入图片描述

    配置表达式使用:

    在这里插入图片描述
    启动实例的时候,必须传递Bean以及Value方法,定义类ValueBean

    public class ValueBean implements Serializable {
        
        private String value;
    
        public ValueBean(String value) {
            this.value = value;
        }
    
        public String getValue() {
            return value;
        }
    
        public void setValue(String value) {
            this.value = value;
        }
    }
    
    
        @Test
        public void startProcessInstanceByKey() {
            String key = "serviceTask";
            Map<String, Object> var = new HashMap<>();
            var.put("bean", new ValueBean("100"));
            runtimeService.startProcessInstanceByKey(key, var);
        }
    

    在这里插入图片描述

    监听器类方式的使用:

    添加类,与一个固定值,与一个变量值

        <bpmn:serviceTask id="Activity_1a0m850" name="服务任务" camunda:class="com.demo.ch11.PengJavaDelegate">
          <bpmn:extensionElements>
            <camunda:field name="fixed">
              <camunda:string>100</camunda:string>
            </camunda:field>
            <camunda:field name="expression">
              <camunda:expression>${var}</camunda:expression>
            </camunda:field>
          </bpmn:extensionElements>
          <bpmn:incoming>Flow_0mr15w0</bpmn:incoming>
          <bpmn:outgoing>Flow_16hmfzw</bpmn:outgoing>
        </bpmn:serviceTask>
    
    public class PengJavaDelegate implements JavaDelegate {
    
        private Expression expression;
        private Expression fixed;
    
        @Override
        public void execute(DelegateExecution delegateExecution) throws Exception {
            Object value = expression.getValue(delegateExecution);
            delegateExecution.setVariable("result", value);
    
            Object fixedValue = fixed.getValue(delegateExecution);
            delegateExecution.setVariable("fixedValue", fixedValue);
        }
    }
    
    
        @Test
        public void startProcessInstanceByKeyVar() {
            String key = "serviceTask";
            Map<String, Object> var = new HashMap<>();
            var.put("var", new ValueBean("200"));
            runtimeService.startProcessInstanceByKey(key, var);
        }
    

    以上启动流程,便会使得PengJavaDelegate触发

    四、发送任务使用

    在这里插入图片描述

    <bpmn:sendTask id="Activity_1a0m850" name="发送任务" camunda:class="com.demo.ch11.PengSendTaskJavaDelegate">
      <bpmn:incoming>Flow_0mr15w0</bpmn:incoming>
      <bpmn:outgoing>Flow_16hmfzw</bpmn:outgoing>
    </bpmn:sendTask>
    
    public class PengSendTaskJavaDelegate implements JavaDelegate {
    
        public static boolean wasExecuted = false;
    
        @Override
        public void execute(DelegateExecution delegateExecution) throws Exception {
    
            wasExecuted = true;
        }
    }
    
    
        @Test
        public void startProcessInstanceByKeyVar() {
            runtimeService.startProcessInstanceByKey("sendTask");
            System.out.println("是否执行:" + PengSendTaskJavaDelegate.wasExecuted);
        }
    

    五、脚本任务

    在这里插入图片描述
    在这里插入图片描述

      <!-- https://mvnrepository.com/artifact/org.python/jython -->
            <dependency>
                <groupId>org.python</groupId>
                <artifactId>jython</artifactId>
                <version>2.7.0</version>
            </dependency>
    
            <dependency>
                <groupId>org.jruby</groupId>
                <artifactId>jruby-complete</artifactId>
                <version>9.2.16.0</version>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all -->
            <dependency>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-all</artifactId>
                <version>3.0.7</version>
            </dependency>
    

    在这里插入图片描述

        <bpmn:scriptTask id="Activity_1a0m850" name="脚本任务" scriptFormat="javascript">
          <bpmn:incoming>Flow_0mr15w0</bpmn:incoming>
          <bpmn:outgoing>Flow_16hmfzw</bpmn:outgoing>
          <bpmn:script>var result=3;execution.setVariable('foo',result);</bpmn:script>
        </bpmn:scriptTask>
    

    执行后,ACT_HI_VARINST会产生foo=3的变量

    脚本还可以写成变量${val},启动流程时由variable参数传进去

        <bpmn:scriptTask id="Activity_1a0m850" name="脚本任务" scriptFormat="javascript">
          <bpmn:incoming>Flow_0mr15w0</bpmn:incoming>
          <bpmn:outgoing>Flow_16hmfzw</bpmn:outgoing>
          <bpmn:script>${val}</bpmn:script>
        </bpmn:scriptTask>
    
        @Test
        public void startProcessInstanceByKey() {
            Map<String, Object> var = new HashMap<>();
            var.put("val", "var sum=10;execution.setVariable('var-foo',sum);");
            runtimeService.startProcessInstanceByKey("scriptTask", var);
        }
    
    
    juel表达式脚本测试

    execution为其内置的流程变量,取其ID用resultVariable作为一个返回值变量

        <bpmn:scriptTask id="Activity_1a0m850" name="脚本任务" scriptFormat="juel" camunda:resultVariable="pengResult">
          <bpmn:incoming>Flow_0mr15w0</bpmn:incoming>
          <bpmn:outgoing>Flow_16hmfzw</bpmn:outgoing>
          <bpmn:script>#{execution.id}</bpmn:script>
        </bpmn:scriptTask>
    

    执行后,ACT_HI_VARINST会产生foo=3的变量,如果去掉resultVariableACT_HI_VARINST不会产生变量

    开启自动脚本变量开关:
        <bean id="processEngineConfiguration"
              class="org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
    
            <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1/camunda"/>
            <property name="jdbcDriver" value="com.mysql.jdbc.Driver"/>
            <property name="jdbcUsername" value="root"/>
            <property name="jdbcPassword" value="123456"/>
            <property name="databaseSchemaUpdate" value="false"/>
            <property name="dbHistoryUsed" value="true"/>
    
            <!--关闭租户校验-->
            <property name="tenantCheckEnabled" value="false"/>
            
            <!--开启自动保存脚本变量存储-->
            <property name="autoStoreScriptVariables" value="true"/>
        </bean>
    

    在这里插入图片描述
    在这里插入图片描述

    在这里插入图片描述

    外部脚本任务

    方式1:resource代表外部脚本路径

        <bpmn:scriptTask id="Activity_1a0m850" name="脚本任务" scriptFormat="javascript" camunda:resource="#{scriptPath}">
          <bpmn:incoming>Flow_0mr15w0</bpmn:incoming>
          <bpmn:outgoing>Flow_16hmfzw</bpmn:outgoing>
        </bpmn:scriptTask>
    
        @Test
        public void startProcessInstanceByKey4() {
            Map<String, Object> var = new HashMap<>();
            var.put("scriptPath", "com.demo/ch11/1.js");
            runtimeService.startProcessInstanceByKey("scriptTask", var);
        }
    

    方式2:也可以通过传递bean的属性,传过去
    在这里插入图片描述
    方式3:
    在这里插入图片描述

    代码参考:https://github.com/zhoupengwa/ProcessEngineDemo

    学习来源:腾讯课堂

    展开全文
  • 新建camunda.cfg.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...

    一、整体架构说明

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    二、demo

    新建camunda.cfg.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
        <bean id="processEngineConfiguration"
              class="org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
    
            <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1/camunda"/>
            <property name="jdbcDriver" value="com.mysql.jdbc.Driver"/>
            <property name="jdbcUsername" value="root"/>
            <property name="jdbcPassword" value="123456"/>
            <property name="databaseSchemaUpdate" value="true"/>
    
        </bean>
    </beans>
    
        public static void main(String[] args) {
            ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();//一直往下debug
            System.out.println("流程名称:" + processEngine.getName());
            System.out.println("配置类:" + processEngine.getProcessEngineConfiguration());
            System.out.println("鉴权:" + processEngine.getAuthorizationService());
            System.out.println("外部任务:" + processEngine.getExternalTaskService());
            System.out.println("过滤器:" + processEngine.getFilterService());
    
            System.out.println(processEngine.getFormService());
            System.out.println(processEngine.getHistoryService());
    
            System.out.println(processEngine.getIdentityService());
            System.out.println(processEngine.getManagementService());
            System.out.println(processEngine.getRepositoryService());
            System.out.println(processEngine.getRuntimeService());
            System.out.println(processEngine.getTaskService());
        }
    

    三、流程引擎类与配置类源码解析

    在这里插入图片描述
    ProcessEngines类中有4个集合

    在这里插入图片描述

    public static ProcessEngineConfiguration parseProcessEngineConfiguration(Resource springResource, String beanName) {
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
        xmlBeanDefinitionReader.setValidationMode(3);
        xmlBeanDefinitionReader.loadBeanDefinitions(springResource);
      //流程引擎配置类,初始化子类的时候,会实例化父类,父类中初始化了服务类
      ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl)beanFactory.getBean(beanName);
        if (processEngineConfiguration.getBeans() == null) {
            processEngineConfiguration.setBeans(new SpringBeanFactoryProxyMap(beanFactory));
        }
    
        return processEngineConfiguration;
    }
    
    public class SpringBeanFactoryProxyMap implements Map<Object, Object> {
        protected BeanFactory beanFactory;
    
        public SpringBeanFactoryProxyMap(BeanFactory beanFactory) {
            this.beanFactory = beanFactory;
        }
    
        public Object get(Object key) {
            return key != null && String.class.isAssignableFrom(key.getClass()) ? this.beanFactory.getBean((String)key) : null;
        }
    
        public boolean containsKey(Object key) {
            return key != null && String.class.isAssignableFrom(key.getClass()) ? this.beanFactory.containsBean((String)key) : false;
        }
    }
    

    从上面代码可以看出,可以通过获取流程引擎配置类获取SpringBeanFactoryProxyMap,再获取到在camunda.cfg.xml定义的spring的实例

    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
        <bean id="processEngineConfiguration"
              class="org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
    
            <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1/camunda"/>
            <property name="jdbcDriver" value="com.mysql.jdbc.Driver"/>
            <property name="jdbcUsername" value="root"/>
            <property name="jdbcPassword" value="123456"/>
            <property name="databaseSchemaUpdate" value="true"/>
            <!--<property name="databaseSchemaUpdate" value="false"/>-->
            <!--<property name="metricsEnabled" value="false"/>-->
            <property name="dbHistoryUsed" value="true"/>
            <!--<property name="historyLevel" value="HISTORY_LEVEL_FULL"/>-->
            <property name="processEnginePlugins">
                <list>
                    <bean id="myProcessEnginePlugin" class="com.demo.ch1.MyProcessEnginePlugin"/>
                </list>
            </property>
        </bean>
    
        <bean id="testUser" class="com.demo.ch1.TestUser">
            <property name="age" value="19"/>
            <property name="name" value="zhangsan"/>
        </bean>
    </beans>
    
    public static void main(String[] args) {
            ProcessEngine processEngine= ProcessEngines.getDefaultProcessEngine();
            StandaloneInMemProcessEngineConfiguration processEngineConfiguration = (StandaloneInMemProcessEngineConfiguration) processEngine.getProcessEngineConfiguration();
            Map<Object, Object> beans = processEngineConfiguration.getBeans();
            Object testUser = beans.get("testUser");
            System.out.println(testUser);
        }
    

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    四、流程引擎插件

    在这里插入图片描述

    	<property name="processEnginePlugins">
                <list>
                    <bean id="myProcessEnginePlugin" class="com.xylink.MyProcessEnginePlugin"/>
                </list>
    	</property>
    

    在这里插入图片描述

    五、手动编程创建流程引擎

        public static void main(String[] args) {
            ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
    
            processEngineConfiguration.setJdbcDriver("com.mysql.jdbc.Driver");
            processEngineConfiguration.setJdbcUrl("jdbc:mysql://127.0.0.1/camunda");
            processEngineConfiguration.setJdbcUsername("root");
            processEngineConfiguration.setJdbcPassword("123456");
    
            processEngineConfiguration.setHistoryLevel(HistoryLevel.HISTORY_LEVEL_FULL);
            ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
            System.out.println(processEngine);
        }
    }
    

    在这里插入图片描述

    六、流程引擎配置类源码扩展思路

    在这里插入图片描述

    七、Spring整合流程引擎

    在这里插入图片描述
    新建activiti-context.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
        <bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource">
            <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1/camunda"/>
            <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
            <property name="username" value="root"/>
            <property name="password" value="123456"/>
        </bean>
    
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource"/>
        </bean>
    
    
        <!--    <bean id="processEngineConfiguration" class="org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration">-->
        <bean id="processEngineConfiguration" class="com.demo.spring.MySpringProcessEngineConfiguration">
            <property name="dataSource" ref="dataSource"/>
            <property name="databaseSchemaUpdate" value="true"/>
            <property name="transactionManager" ref="transactionManager"/>
            <property name="deploymentResources" value="classpath:*.bpmn"/>
            <property name="databaseType" value="MYSQL"/>
            <property name="deploymentTenantId" value="A系统"/>
        </bean>
    
    
        <bean id="processEngine" class="org.camunda.bpm.engine.spring.ProcessEngineFactoryBean">
            <property name="processEngineConfiguration" ref="processEngineConfiguration"/>
        </bean>
    
    
    </beans>
    
    public class SpringProcessEngineTest {
    
        public static void main(String[] args) {
            //直接getDefaultProcessEngine会报错,Class<?> springConfigurationHelperClass = ReflectUtil.loadClass("org.camunda.bpm.engine.test.spring.SpringConfigurationHelper");
            // 没有test包
            //ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
            // System.out.println(defaultProcessEngine);
    
            ProcessEngineConfiguration processEngineConfigurationFromResource = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti-context.xml");
            ProcessEngine processEngine = processEngineConfigurationFromResource.buildProcessEngine();
            System.out.println(processEngine);
        }
    
    }
    
    

    在这里插入图片描述

    八、camunda启动数据源加载优化

    在这里插入图片描述
    可以手动设置MySpringProcessEngineConfiguration的属性databaseType,不用再走initDatabaseType

    代码参考:https://github.com/zhoupengwa/ProcessEngineDemo

    展开全文
  • camunda框架学习(四)流程定义系列

    千次阅读 热门讨论 2021-02-22 11:04:14
    表ACT_RE_PROCDEF中的CATEGORY_字段,对应*.bpmn中的definitions元素的targetNamespace属性,VERSION_TAG_对应process元素的camunda:versionTag属性 部署方式: 一、通过classpath部署流程 二、文本方式部署 @...

    总览

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    部署资源步骤

    在这里插入图片描述
    ACT_RE_PROCDEF中的CATEGORY_字段,对应*.bpmn中的definitions元素的targetNamespace属性,VERSION_TAG_对应process元素的camunda:versionTag属性

    部署方式:
    在这里插入图片描述

    一、通过classpath部署流程

    在这里插入图片描述
    在这里插入图片描述

    二、文本方式部署

    在这里插入图片描述

        @Test
        public void addString() {
            String resoueceName = "3.bpmn";
            String text = IOUtil.fileAsString("/Users/zhoupeng/IdeaProjects/activiti-demo/camunda/camunda-simple/src/main/resources/com.demo/ch8/diagram_1.bpmn");
            DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
            Deployment deployment = deploymentBuilder
                    .name("请求流程")
                    .source("本地测试")
                    .tenantId("a")
                    .addString(resoueceName, text)
                    .deploy();
    
            System.out.println(deploymentBuilder);
            System.out.println(deployment);
        }
    

    三、流与压缩流部署

     @Test
        public void addInputStream() {
            String resoueceName = "3.bpmn";
    
            InputStream inputStream = DeploymentTest.class.getClassLoader().getResourceAsStream("com.demo/ch8/diagram_1.bpmn");
    
            DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
            Deployment deployment = deploymentBuilder
                    .name("请求流程")
                    .source("本地测试")
                    .tenantId("a")
                    .addInputStream(resoueceName, inputStream)
                    .deploy();
    
            System.out.println(deploymentBuilder);
            System.out.println(deployment);
        }
    
    
        @Test
        public void addZipInputStream() {
    
            InputStream inputStream = DeploymentTest.class.getClassLoader().getResourceAsStream("com.demo/ch8/diagram_1.bpmn.zip");
    
            ZipInputStream zipInputStream = new ZipInputStream(inputStream);
    
            DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
            Deployment deployment = deploymentBuilder
                    .name("请求流程")
                    .source("本地测试")
                    .tenantId("a")
                    .addZipInputStream(zipInputStream)
                    .deploy();
    
            System.out.println(deploymentBuilder);
            System.out.println(deployment);
        }
    

    四、已部署资源再部署(仅camunda才有)

    ![

    
        @Test
        public void addDeploymentResourceById() {
            String deploymentId = "3801";
            String resourceId = "3802";
    
            DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
            Deployment deployment = deploymentBuilder
                    .name("请求流程")
                    .source("本地测试")
                    .tenantId("a")
                    .addDeploymentResourceById(deploymentId, resourceId)
                    .deploy();
    
            System.out.println(deploymentBuilder);
            System.out.println(deployment);
        }
    

    五、流程定义及资源批删除

      /**
         * delete from ACT_RU_IDENTITYLINK where PROC_DEF_ID_ = ?
         * delete from ACT_RE_PROCDEF where ID_ = ?
         * DELETE FROM ACT_RU_JOBDEF where PROC_DEF_ID_ = ?
         */
        @Test
        public void deleteProcessDefinition() {
            String processDefinationId = "leave:7:4003";
            repositoryService.deleteProcessDefinition(processDefinationId);
        }
    
    
        /**
         * delete from ACT_RU_IDENTITYLINK where PROC_DEF_ID_ = ?
         * delete B from ACT_GE_BYTEARRAY B inner join ACT_HI_JOB_LOG J on B.ID_ = J.JOB_EXCEPTION_STACK_ID_ and J.JOB_EXCEPTION_STACK_ID_ is not null and J.PROCESS_DEF_ID_ = ?
         * delete from ACT_RE_PROCDEF where ID_ = ?
         * delete from ACT_HI_INCIDENT where PROC_DEF_ID_ = ? and PROC_INST_ID_ is null
         * delete from ACT_HI_JOB_LOG where PROCESS_DEF_ID_ = ?
         * DELETE FROM ACT_RU_JOBDEF where PROC_DEF_ID_ = ?
         */
        @Test
        public void deleteProcessDefinitionCascade() {
            String processDefinationId = "leave:6:3903";
            boolean cascade = true;
            repositoryService.deleteProcessDefinition(processDefinationId, cascade);
        }
    
    
        @Test
        public void deleteProcessDefinitions() {
            String processDefinationId = "leave:6:3903";
            DeleteProcessDefinitionsSelectBuilder deleteProcessDefinitionsSelectBuilder = repositoryService.deleteProcessDefinitions();
            deleteProcessDefinitionsSelectBuilder.byIds(processDefinationId,processDefinationId).cascade().delete();
        }
    

    在这里插入图片描述
    删除部署:

    
        @Test
        public void deleteDeployment() {
            String deploymentId = "";
            repositoryService.deleteDeployment(deploymentId);
        }
    

    六、获取流程定义文档资源

        @Test
        public void getProcessModel() throws IOException {
            String processDefinitionId = "leave:5:3803";
            InputStream inputStream = repositoryService.getProcessModel(processDefinitionId);
            FileUtils.copyInputStreamToFile(inputStream, new File("/Users/zhoupeng/IdeaProjects/activiti-demo/camunda/camunda-simple/src/main/resources/com.demo/ch8/tmp.txt"));
        }
    
    
        @Test
        public void getProcessDiagram() throws IOException {
            String processDefinitionId = "leave:5:3803";
            InputStream inputStream = repositoryService.getProcessDiagram(processDefinitionId);
            FileUtils.copyInputStreamToFile(inputStream, new File("/Users/zhoupeng/IdeaProjects/activiti-demo/camunda/camunda-simple/src/main/resources/com.demo/ch8/tem.png"));
        }
    
    

    在这里插入图片描述

    七、流程定义文档、图片、坐标获取

    /**
         * select * from ACT_RE_PROCDEF where ID_ = ?   leave:5:3803(String)
         * select * from ACT_RE_DEPLOYMENT where ID_ = ?  3801(String)
         * select * from ACT_GE_BYTEARRAY where DEPLOYMENT_ID_ = ? and NAME_ = ?   3801(String), diagram_1.bpmn
         * select * from ACT_RE_PROCDEF where DEPLOYMENT_ID_ = ? and KEY_ = ?  3801(String), leave(String)
         * select * from ACT_RE_PROCDEF RES where KEY_ = ? and TENANT_ID_ = ? and VERSION_ = ( select max(VERSION_) from ACT_RE_PROCDEF where KEY_ = ? and TENANT_ID_ = ?)
         * leave(String), a(String), leave(String), a(String)
         */
        @Test
        public void getProcessModel() throws IOException {
            String processDefinitionId = "leave:5:3803";
            InputStream inputStream = repositoryService.getProcessModel(processDefinitionId);
            FileUtils.copyInputStreamToFile(inputStream, new File("/Users/zhoupeng/IdeaProjects/activiti-demo/camunda/camunda-simple/src/main/resources/com.demo/ch8/tmp.txt"));
        }
    
    
        @Test
        public void getProcessDiagram() throws IOException {
            String processDefinitionId = "leave:5:3803";
            InputStream inputStream = repositoryService.getProcessDiagram(processDefinitionId);
            FileUtils.copyInputStreamToFile(inputStream, new File("/Users/zhoupeng/IdeaProjects/activiti-demo/camunda/camunda-simple/src/main/resources/com.demo/ch8/tem.png"));
        }
    
    
        /**
         * select distinct RES.* from ACT_RE_DEPLOYMENT RES order by RES.ID_ asc LIMIT ? OFFSET ?
         */
        @Test
        public void createDeploymentQuery() throws IOException {
            DeploymentQuery deploymentQuery = repositoryService.createDeploymentQuery();
            List<Deployment> list = deploymentQuery.list();
            for (Deployment deployment : list) {
                System.out.println(deployment.toString());
            }
        }
    
    
        @Test
        public void getProcessDiagramLayout() throws IOException {
            String processDefinitionId = "paiche:1:503";
    
            DiagramLayout diagramLayout = repositoryService.getProcessDiagramLayout(processDefinitionId);
    
            Map<String, DiagramElement> elements = diagramLayout.getElements();
            Set<Map.Entry<String, DiagramElement>> entries = elements.entrySet();
    
            for (Map.Entry<String, DiagramElement> entry : entries) {
                String key = entry.getKey();
                DiagramElement value = entry.getValue();
    
                System.out.println(key + "," + value.getId());
            }
    
            DeploymentQuery deploymentQuery =
                    (DeploymentQuery) diagramLayout;
            List<Deployment> list = deploymentQuery.list();
            for (Deployment deployment : list) {
                System.out.println(deployment.toString());
            }
        }
    

    其他部署方式

    在这里插入图片描述

    八、自定义模型方式部署

    /**
         * insert into ACT_RE_DEPLOYMENT(ID_, NAME_, DEPLOY_TIME_, SOURCE_, TENANT_ID_) values(?, ?, ?, ?, ?)
         * insert into ACT_GE_BYTEARRAY( ID_, NAME_, BYTES_, DEPLOYMENT_ID_, GENERATED_, TENANT_ID_, TYPE_, CREATE_TIME_, REV_) values ( ?, ?, ?, ?, ?, ?, ?, ?, 1)
         * insert into ACT_RE_PROCDEF(ID_, CATEGORY_, NAME_, KEY_, VERSION_, DEPLOYMENT_ID_, RESOURCE_NAME_, DGRM_RESOURCE_NAME_, HAS_START_FORM_KEY_, SUSPENSION_STATE_, TENANT_ID_, VERSION_TAG_, HISTORY_TTL_, STARTABLE_, REV_) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1 )
         */
        @Test
        public void createExecutableProcess() throws IOException {
            BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess("leave")
                    .startEvent().name("开始节点")
                    .userTask("申请人").camundaCandidateUsers("张三")
                    .exclusiveGateway().name("排他网关").condition("小于三天", "${day<3}")
                    .userTask().name("组长审批").camundaCandidateUsers("张三")
                    .endEvent()
    
                    .findLastGateway()
                    .builder().condition("大于等于三天", "${day>=3}")
                    .userTask().name("组长审批").camundaCandidateUsers("李四")
                    .userTask().name("项目经理审批").camundaCandidateUsers("王五")
                    .endEvent()
    
                    .done();
    
            repositoryService.createDeployment()
                    .addModelInstance("customer.bpmn", bpmnModelInstance)
                    .deploy();
    
        }
    

    获取模型,编辑 再部署

        @Test
        public void getBpmnModelInstance() throws IOException {
            String processDefinitionId = "leave:8:4303";
    
            BpmnModelInstance bpmnModelInstance = repositoryService.getBpmnModelInstance(processDefinitionId);
            Collection<UserTask> modelElementsByType = bpmnModelInstance.getModelElementsByType(UserTask.class);
    
            System.out.println("###########" + modelElementsByType);
    
    
            DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
            deploymentBuilder
                    .addModelInstance("customer.bpmn", bpmnModelInstance).deploy();
        }
    
    

    总结

    在这里插入图片描述
    关于流程图:前端可以利用“有向图算法”根据后台返回的节点出入关系自行渲染,我们这边前端人员自行渲染的,看着效果还可以:
    在这里插入图片描述

    代码参考:https://github.com/zhoupengwa/ProcessEngineDemo

    学习来源:腾讯课堂

    展开全文
  • camunda框架学习(十六)中国式流程系列

    千次阅读 热门讨论 2021-03-11 18:09:12
    } camunda框架有bug,这里没有成功执行。 我们可以手动执行ACT_RU_JOB,执行后ACT_RU_JOB会产生3个任务,将其完成即可。先完成``instance-migration,最后完成batch-monitor-job`,监听到迁移完了,会删除批次。 @...
  • 已发流程、已办任务、待办事项等,引擎都只支持物理删除。有时候需要查看历史数据,又要满足查询要求,我们根据(十六)中可以通过手动改造查询逻辑来自定义分页,定义查询参数等。那么支持逻辑删除就呼之欲出:查询...
  • camunda框架学习(五)流程实例系列

    千次阅读 2021-02-27 11:09:49
    RuntimeService类 启动流程方式 一、执行实例流程三个经典案例 流程定义: 流程实例: 流程实例不会运转,执行实例才会运转 ... * insert into ACT_HI_TASKINST ( ID_, PROC_DEF_KEY_, PROC_DEF_ID_, ROOT_PROC_...
  • 过滤器仅camunda系列有 过滤器的继承 过滤器查询对象使用 过滤器删除 一、过滤器各种场景下的使用 创建Filter: /** * insert into ACT_RU_FILTER (ID_, RESOURCE_TYPE_, NAME_, OWNER_, QUERY_, PROPERTIES_, ...
  • package org.camunda.bpm.engine.authorization; public enum Resources implements Resource { APPLICATION("Application", 0), USER("User", 1), GROUP("Group", 2), GROUP_MEMBERSHIP("Group membership", 3...
  • camunda框架学习(十四)表单系列

    千次阅读 2021-03-10 20:06:23
    一、表单生命周期、定义...bpmn:startEvent id="StartEvent_1" camunda:formKey="start.html"> <bpmn:outgoing>Flow_0ycrxbl</bpmn:outgoing> </bpmn:startEvent> <bpmn:sequenceFlow id=
  • 首先查看引擎的执行逻辑,在:包org.camunda.bpm.engine.impl.mapping.entity下的Task.xml(绝对路径:/org/camunda/bpm/engine/impl/mapping/entity/Task.xml) 可以看到返回结果是mybatis的resultMap <...
  • 一、单消息与多消息启动事件 <bpmn:startEvent id="StartEvent_1"> <bpmn:outgoing>Flow_0wpbzu5</bpmn:outgoing> <bpmn:messageEventDefinition id="MessageEventDefinition_0c1wtew" ...
  • camunda框架学习(九)网关系列

    千次阅读 2021-03-08 11:39:17
    一、排他网关的使用及原理 @Test public void ... } 排他网关多条件设置:https://www.cnblogs.com/zz22–/p/11226248.html 代码参考:https://github.com/zhoupengwa/ProcessEngineDemo 学习来源:腾讯课堂
  • camunda框架学习(十五)定时器系列

    千次阅读 2021-03-11 15:03:49
    一、双异步机制任务节点部署 全局的优先级定义为50 <...bpmn:userTask id="Activity_1nicj02" name="【总经理】审批" camunda:asyncBefore="true" camunda:asyncAfter="true" camunda:priorit
  • 目前,外部任务仅camunda框架才有。 一、外部任务抓取锁定使用 <bpmn:serviceTask id="Activity_05ut8e6" name="外部任务1" camunda:type="external" camunda:topic="topic1" camunda:taskPriority="50"> ...
  • 一、变量设置以及涉及三张表说明 启动流程设置变量: /** * ------------------------------------------------------------------------------------------------------------------------ ...
  • camunda框架学习(六)任务节点系列

    千次阅读 2021-02-27 17:00:10
    节点:开始节点、结束节点、活动节点、等待活动节点、不等待活动... } 三、使用监听器 监听器分为任务监听器与执行监听器 请假申请" camunda:priority="50"> <bpmn:extensionElements> <camunda:taskListener class=...
  • @Before public void init() { ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("com.demo.ch6/camunda.cfg.xml");...
  • 一、抛出信号与信号启动 启动信号事件: <bpmn:startEvent id="StartEvent_1"> <bpmn:outgoing>Flow_...第二个实例开始运转到”任务1“ 代码参考:https://github.com/zhoupengwa/ProcessEngineDemo 学习来源:腾讯课堂

空空如也

空空如也

1 2 3 4 5 ... 17
收藏数 337
精华内容 134
关键字:

camunda框架学习