为您推荐:
精华内容
最热下载
问答
  • 61.71MB weixin_42164931 2021-05-27 18:05:43
  • 631KB weixin_42138408 2021-05-27 20:00:45
  • 475KB samxx8 2017-08-23 13:34:18
  • 4星
    448KB u014414161 2018-01-30 18:38:29
  • 1.31MB aketoit 2019-04-13 20:52:24
  • 7.04MB chainsky 2014-06-24 07:53:17
  • 936KB qq_58157133 2021-10-04 00:42:33
  • 按我自己的理解,规则流(bpmn2)里应该画一些“比较条件”,这些条件可能会变化,图像的形式更容易让人理解。 规则(drl)里写一些固定的结果,比如说当某种情况下,执行某些行为 判断情况写在bpmn里 执行结果写在...

    最近项目用到了规则流踩了一些小坑,特以记录。
    代码写好了再放到规则文件中,规则流最好一步一步画,因为错了就给你抛看不懂没意义的异常。
    所有的包包括List这种都得引。
    我自己也一知半解,本文都是一些小细节,如有错漏,欢迎指正。
    1.文档
    官网:https://www.drools.org/
    官方文档:https://nheron.gitbooks.io/droolsonboarding/content/gettingStarted/drools.html <-- lesson 4
    GitHub:https://github.com/kiegroup/droolscourse
    参考了很多人的博客 ,记不全了
    https://blog.csdn.net/tian6318/article/details/78569388
    https://blog.csdn.net/wo541075754/article/category/6397798
    以前规则流是用Drools自己的.rf文件,现在用bpmn2 参考以下回答。
    https://stackoverflow.com/questions/16698617/difference-between-rf-and-bpmn2
    2.Intellj idea
    如果使用Intellj idea来使用drools到没有什么问题,bpmn打开很别扭啊,劝退劝退
    (1)官方视频 https://screencast-o-matic.com/watch/cbfFXsX1gX
    过程就是安装jboss jpmn
    在这里插入图片描述
    然后改打开方式
    在这里插入图片描述
    可是这样 全都堆在一起,看官方视频可能mac支持的好?
    在这里插入图片描述
    (2)如果用actiBPM ,倒是可以正常用,但是这查看xml和生成png的方式也是绝了。
    可以看这个 https://blog.csdn.net/qq_35463719/article/details/82967287
    生成png: https://blog.csdn.net/wk52525/article/details/79362904

    下面开始正文
    一. 安装
    可以参考https://blog.csdn.net/shenhaiwen/article/details/70230103
    我用的是eclipse mars,安装以下插件
    https://download.jboss.org/drools/release/7.5.0.Final/org.drools.updatesite/
    在这里插入图片描述
    二. 使用
    最简单的方式,建一个drool project 选带例子的 先了解一下大概的结构,就是有点旧。
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    三. 规则和规则流搭配使用
    按我自己的理解,规则流(bpmn2)里应该画一些“比较条件”,这些条件可能会变化,图像的形式更容易让人理解。
    规则(drl)里写一些固定的结果,比如说当某种情况下,执行某些行为 判断情况写在bpmn里 执行结果写在drl里
    (以下springboot工程)
    pom 添加

    		<dependency>
    			<groupId>org.drools</groupId>
    			<artifactId>drools-core</artifactId>
    			<version>7.0.0.Final</version>
    		</dependency>
    		<dependency>
    			<groupId>org.drools</groupId>
    			<artifactId>drools-compiler</artifactId>
    			<version>7.0.0.Final</version>
    		</dependency>
    		<dependency>
    			<groupId>org.drools</groupId>
    			<artifactId>drools-decisiontables</artifactId>
    			<version>7.0.0.Final</version>
    		</dependency>
    		<dependency>
    			<groupId>org.drools</groupId>
    			<artifactId>drools-templates</artifactId>
    			<version>7.0.0.Final</version>
    		</dependency>
    
    		<dependency>
    			<groupId>org.kie</groupId>
    			<artifactId>kie-api</artifactId>
    			<version>7.0.0.Final</version>
    		</dependency>
    		<dependency>
    			<groupId>org.jbpm</groupId>
    			<artifactId>jbpm-bpmn2</artifactId>
    			<version>7.0.0.Final</version>
    		</dependency>
    

    目录机构
    在这里插入图片描述
    建议先画一个只有开始结束的规则流,验证一下好不好使,再添加步骤。

    (1) 新建drl
    新建规则
    在这里插入图片描述
    注意包的引用 !!!

    package process
    import java.util.Calendar;
    import java.util.Date;
    import com.summer.my.droolsproject.Fact.PersonFact;
    
    rule "age-rule"
    	ruleflow-group "age-check-group"
        lock-on-active true
        when
            p:PersonFact()
        then
            System.out.println("hello"+p.getName());
            if(p.getBirthday()!=null){
        		int age =0;
        		Calendar now = Calendar.getInstance();
                now.setTime(new Date());
    
                Calendar birth = Calendar.getInstance();
                birth.setTime(p.getBirthday());
    
                if (birth.after(now)) {
                    age = 0;
                } else {
                    age = now.get(Calendar.YEAR) - birth.get(Calendar.YEAR);
                    if (now.get(Calendar.DAY_OF_YEAR) > birth.get(Calendar.DAY_OF_YEAR)) {
                        age += 1;
                    }
                }
               
                p.setAge(age);
        	}
    
    end
    
    rule "teenager-rule"
    	ruleflow-group "teenager"
        lock-on-active true
        when
            p:PersonFact()
        then
            System.out.println(p.getName()+"是一名青少年");
    end
    
    rule "adult-rule"
    	ruleflow-group "adult"
        lock-on-active true
        when
            p:PersonFact()
        then
            System.out.println(p.getName()+"是一名成年");
    end
    

    (2) META-INF 文件夹 新建kmodule.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
        <kbase name="process" packages="process">
            <ksession name="ksession-process"/>
        </kbase>
    </kmodule>
    

    (3) 新建bpmn2 ??用bpmn2建也行?标签不一样
    新建规则流
    在这里插入图片描述
    bpmn中的内容 有start 经过task

    在这里插入图片描述
    箭头所指的部分要对应规则(drl)中的 ruleflow-group 指定执行的规则组
    在这里插入图片描述
    在这里插入图片描述
    注意箭头选项,优先级,和condition的语言
    在规则流里用的类需要import
    在这里插入图片描述
    AppTest 规则和流都放在process下,如果分开放是不是得指定上级的包啊,要不kSession的package定义多个包?

    package com.summer.my.droolsproject;
    
    import org.apache.commons.lang3.time.DateUtils;
    import org.junit.Test;
    import org.kie.api.KieServices;
    import org.kie.api.runtime.KieContainer;
    import org.kie.api.runtime.KieSession;
    
    import com.summer.my.droolsproject.Fact.PersonFact;
    
    /**
     * Unit test for simple App.
     */
    public class AppTest{
    	@Test
    	public void testOne(){
    		try {
    	        KieServices ks = KieServices.Factory.get();
    	        KieContainer kContainer = ks.getKieClasspathContainer();
    	        KieSession kSession = kContainer.newKieSession("ksession-process");
    	        PersonFact person = new PersonFact();
    	        person.setName("李某某");
    	        person.setBirthday(DateUtils.parseDate("1999-01-01","yyyy-MM-dd"));
    	      
    	        kSession.insert(person);
    	        kSession.startProcess("process.myProcess");
    	        kSession.fireAllRules();  
    	        kSession.dispose();
    	        System.out.println(person.getName()+"的年龄是:"+person.getAge());
    	    } catch (Throwable t) {
    	        t.printStackTrace();
    	    }
    	}
    	
    }
    
    

    输出结果
    在这里插入图片描述
    以xml形式查看规则流

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- origin at X=0.0 Y=0.0 -->
    <bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:java="http://www.java.com/javaTypes" xmlns:tns="http://www.jboss.org/drools" xmlns="http://www.jboss.org/drools" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd http://www.jboss.org/drools drools.xsd http://www.bpsim.org/schemas/1.0 bpsim.xsd" id="Definition" exporter="org.eclipse.bpmn2.modeler.core" exporterVersion="1.2.5.Final-v20160831-1132-B114" expressionLanguage="http://www.mvel.org/2.0" targetNamespace="http://www.jboss.org/drools" typeLanguage="http://www.java.com/javaTypes">
      <bpmn2:itemDefinition id="ItemDefinition_2" isCollection="false" structureRef="com.summer.my.droolsproject.Fact.PersonFact"/>
      <bpmn2:process id="process.myProcess" tns:packageName="process" name="myProcess" isExecutable="true" processType="Private">
        <bpmn2:extensionElements>
          <tns:import name="com.summer.my.droolsproject.Fact.PersonFact"/>
        </bpmn2:extensionElements>
        <bpmn2:startEvent id="StartEvent_1" name="StartProcess">
          <bpmn2:extensionElements>
            <tns:metaData name="elementname">
              <tns:metaValue><![CDATA[StartProcess]]></tns:metaValue>
            </tns:metaData>
          </bpmn2:extensionElements>
          <bpmn2:outgoing>SequenceFlow_5</bpmn2:outgoing>
        </bpmn2:startEvent>
        <bpmn2:businessRuleTask id="BusinessRuleTask_2" tns:ruleFlowGroup="age-check-group" name="年龄校验">
          <bpmn2:extensionElements>
            <tns:metaData name="elementname">
              <tns:metaValue><![CDATA[年龄校验]]></tns:metaValue>
            </tns:metaData>
          </bpmn2:extensionElements>
          <bpmn2:incoming>SequenceFlow_5</bpmn2:incoming>
          <bpmn2:outgoing>SequenceFlow_8</bpmn2:outgoing>
        </bpmn2:businessRuleTask>
        <bpmn2:sequenceFlow id="SequenceFlow_5" tns:priority="1" sourceRef="StartEvent_1" targetRef="BusinessRuleTask_2"/>
        <bpmn2:exclusiveGateway id="ExclusiveGateway_2" name="Exclusive Gateway 2" gatewayDirection="Diverging">
          <bpmn2:incoming>SequenceFlow_8</bpmn2:incoming>
          <bpmn2:outgoing>SequenceFlow_9</bpmn2:outgoing>
          <bpmn2:outgoing>SequenceFlow_10</bpmn2:outgoing>
        </bpmn2:exclusiveGateway>
        <bpmn2:sequenceFlow id="SequenceFlow_8" tns:priority="1" sourceRef="BusinessRuleTask_2" targetRef="ExclusiveGateway_2"/>
        <bpmn2:businessRuleTask id="BusinessRuleTask_3" tns:ruleFlowGroup="teenager" name="child">
          <bpmn2:extensionElements>
            <tns:metaData name="elementname">
              <tns:metaValue><![CDATA[child]]></tns:metaValue>
            </tns:metaData>
          </bpmn2:extensionElements>
          <bpmn2:incoming>SequenceFlow_9</bpmn2:incoming>
          <bpmn2:outgoing>SequenceFlow_11</bpmn2:outgoing>
        </bpmn2:businessRuleTask>
        <bpmn2:sequenceFlow id="SequenceFlow_9" tns:priority="1" sourceRef="ExclusiveGateway_2" targetRef="BusinessRuleTask_3">
          <bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression" id="FormalExpression_1" language="http://www.jboss.org/drools/rule">p:PersonFact(age&lt;=18)</bpmn2:conditionExpression>
        </bpmn2:sequenceFlow>
        <bpmn2:businessRuleTask id="BusinessRuleTask_4" tns:ruleFlowGroup="adult" name="adult">
          <bpmn2:extensionElements>
            <tns:metaData name="elementname">
              <tns:metaValue><![CDATA[adult]]></tns:metaValue>
            </tns:metaData>
          </bpmn2:extensionElements>
          <bpmn2:incoming>SequenceFlow_10</bpmn2:incoming>
          <bpmn2:outgoing>SequenceFlow_12</bpmn2:outgoing>
        </bpmn2:businessRuleTask>
        <bpmn2:sequenceFlow id="SequenceFlow_10" tns:priority="2" sourceRef="ExclusiveGateway_2" targetRef="BusinessRuleTask_4">
          <bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression" id="FormalExpression_2" language="http://www.jboss.org/drools/rule">eval(true)</bpmn2:conditionExpression>
        </bpmn2:sequenceFlow>
        <bpmn2:endEvent id="EndEvent_3" name="End Event 3">
          <bpmn2:extensionElements>
            <tns:metaData name="elementname">
              <tns:metaValue><![CDATA[End Event 3]]></tns:metaValue>
            </tns:metaData>
          </bpmn2:extensionElements>
          <bpmn2:incoming>SequenceFlow_11</bpmn2:incoming>
        </bpmn2:endEvent>
        <bpmn2:sequenceFlow id="SequenceFlow_11" tns:priority="1" sourceRef="BusinessRuleTask_3" targetRef="EndEvent_3"/>
        <bpmn2:endEvent id="EndEvent_4" name="End Event 4">
          <bpmn2:extensionElements>
            <tns:metaData name="elementname">
              <tns:metaValue><![CDATA[End Event 4]]></tns:metaValue>
            </tns:metaData>
          </bpmn2:extensionElements>
          <bpmn2:incoming>SequenceFlow_12</bpmn2:incoming>
        </bpmn2:endEvent>
        <bpmn2:sequenceFlow id="SequenceFlow_12" tns:priority="1" sourceRef="BusinessRuleTask_4" targetRef="EndEvent_4"/>
      </bpmn2:process>
      <bpmndi:BPMNDiagram id="BPMNDiagram_1">
        <bpmndi:BPMNPlane id="BPMNPlane_Process_1" bpmnElement="process.myProcess">
          <bpmndi:BPMNShape id="BPMNShape_StartEvent_1" bpmnElement="StartEvent_1">
            <dc:Bounds height="0.0" width="0.0" x="45.0" y="45.0"/>
            <bpmndi:BPMNLabel>
              <dc:Bounds height="15.0" width="71.0" x="28.0" y="81.0"/>
            </bpmndi:BPMNLabel>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape id="BPMNShape_BusinessRuleTask_2" bpmnElement="BusinessRuleTask_2">
            <dc:Bounds height="50.0" width="110.0" x="186.0" y="38.0"/>
            <bpmndi:BPMNLabel>
              <dc:Bounds height="15.0" width="48.0" x="217.0" y="55.0"/>
            </bpmndi:BPMNLabel>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape id="BPMNShape_ExclusiveGateway_2" bpmnElement="ExclusiveGateway_2" isMarkerVisible="true">
            <dc:Bounds height="50.0" width="50.0" x="371.0" y="38.0"/>
            <bpmndi:BPMNLabel>
              <dc:Bounds height="30.0" width="57.0" x="368.0" y="88.0"/>
            </bpmndi:BPMNLabel>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape id="BPMNShape_BusinessRuleTask_3" bpmnElement="BusinessRuleTask_3">
            <dc:Bounds height="50.0" width="110.0" x="526.0" y="38.0"/>
            <bpmndi:BPMNLabel>
              <dc:Bounds height="15.0" width="26.0" x="568.0" y="55.0"/>
            </bpmndi:BPMNLabel>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape id="BPMNShape_BusinessRuleTask_4" bpmnElement="BusinessRuleTask_4">
            <dc:Bounds height="50.0" width="110.0" x="526.0" y="138.0"/>
            <bpmndi:BPMNLabel>
              <dc:Bounds height="15.0" width="27.0" x="567.0" y="155.0"/>
            </bpmndi:BPMNLabel>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape id="BPMNShape_EndEvent_3" bpmnElement="EndEvent_3">
            <dc:Bounds height="36.0" width="36.0" x="704.0" y="45.0"/>
            <bpmndi:BPMNLabel>
              <dc:Bounds height="15.0" width="65.0" x="690.0" y="81.0"/>
            </bpmndi:BPMNLabel>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape id="BPMNShape_EndEvent_4" bpmnElement="EndEvent_4">
            <dc:Bounds height="36.0" width="36.0" x="704.0" y="145.0"/>
            <bpmndi:BPMNLabel>
              <dc:Bounds height="15.0" width="65.0" x="690.0" y="181.0"/>
            </bpmndi:BPMNLabel>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_5" bpmnElement="SequenceFlow_5" sourceElement="BPMNShape_StartEvent_1" targetElement="BPMNShape_BusinessRuleTask_2">
            <di:waypoint xsi:type="dc:Point" x="81.0" y="63.0"/>
            <di:waypoint xsi:type="dc:Point" x="133.0" y="63.0"/>
            <di:waypoint xsi:type="dc:Point" x="186.0" y="63.0"/>
            <bpmndi:BPMNLabel/>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_8" bpmnElement="SequenceFlow_8" sourceElement="BPMNShape_BusinessRuleTask_2" targetElement="BPMNShape_ExclusiveGateway_2">
            <di:waypoint xsi:type="dc:Point" x="296.0" y="63.0"/>
            <di:waypoint xsi:type="dc:Point" x="333.0" y="63.0"/>
            <di:waypoint xsi:type="dc:Point" x="371.0" y="63.0"/>
            <bpmndi:BPMNLabel/>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_9" bpmnElement="SequenceFlow_9" sourceElement="BPMNShape_ExclusiveGateway_2" targetElement="BPMNShape_BusinessRuleTask_3">
            <di:waypoint xsi:type="dc:Point" x="421.0" y="63.0"/>
            <di:waypoint xsi:type="dc:Point" x="473.0" y="63.0"/>
            <di:waypoint xsi:type="dc:Point" x="526.0" y="63.0"/>
            <bpmndi:BPMNLabel/>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_10" bpmnElement="SequenceFlow_10" sourceElement="BPMNShape_ExclusiveGateway_2" targetElement="BPMNShape_BusinessRuleTask_4">
            <di:waypoint xsi:type="dc:Point" x="396.0" y="88.0"/>
            <di:waypoint xsi:type="dc:Point" x="396.0" y="163.0"/>
            <di:waypoint xsi:type="dc:Point" x="526.0" y="163.0"/>
            <bpmndi:BPMNLabel/>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_11" bpmnElement="SequenceFlow_11" sourceElement="BPMNShape_BusinessRuleTask_3" targetElement="BPMNShape_EndEvent_3">
            <di:waypoint xsi:type="dc:Point" x="636.0" y="63.0"/>
            <di:waypoint xsi:type="dc:Point" x="670.0" y="63.0"/>
            <di:waypoint xsi:type="dc:Point" x="704.0" y="63.0"/>
            <bpmndi:BPMNLabel/>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_12" bpmnElement="SequenceFlow_12" sourceElement="BPMNShape_BusinessRuleTask_4" targetElement="BPMNShape_EndEvent_4">
            <di:waypoint xsi:type="dc:Point" x="636.0" y="163.0"/>
            <di:waypoint xsi:type="dc:Point" x="670.0" y="163.0"/>
            <di:waypoint xsi:type="dc:Point" x="704.0" y="163.0"/>
            <bpmndi:BPMNLabel/>
          </bpmndi:BPMNEdge>
        </bpmndi:BPMNPlane>
      </bpmndi:BPMNDiagram>
    </bpmn2:definitions>
    

    PersonFact

    package com.summer.my.droolsproject.Fact;
    
    import java.util.Date;
    
    public class PersonFact {
    	
    	private String name;
    	
    	private Integer age;
    	
    	private Date birthday;
    
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    
    	public Integer getAge() {
    		return age;
    	}
    
    	public void setAge(Integer age) {
    		this.age = age;
    	}
    
    	public Date getBirthday() {
    		return birthday;
    	}
    
    	public void setBirthday(Date birthday) {
    		this.birthday = birthday;
    	}
        
    	
    
    }
    
    
    展开全文
    fengqingyuebai19 2019-07-17 11:36:24
  • Flowable 一款流行的bpmn2流程引擎,里面包含了绘制bpmn2的流程图工具。本次flowable 版本为 6.4.2 , 6.5开始flowable走商用路线了。6.4.2基本上满足了常用流程引擎的功能。 在绘制用户任务流程图的时候,除.

    记录一下对flowable流程引擎创建自定义下拉框属性步骤方法

    说明

    Flowable 一款流行的bpmn2流程引擎,里面包含了绘制bpmn2的流程图工具。本次flowable 版本为 6.4.2 , 6.5开始flowable走商用路线了。6.4.2基本上满足了常用流程引擎的功能。

    在绘制用户任务流程图的时候,除了bpmn2规定的一些规范属性值外,我们希望对流程属性有一些自定义的属性信息,例如这个流程是专门用于提交表单的还是用于审批的,这个流程是否可以被终止等等,虽然客户采用各种排他网关或并行网关解决,但流程图必会很复杂。

    例如下图中的 【任务类型】 【可被撤销】【可终止流程】属性,就是自定义属性。
    在这里插入图片描述

    可以想象一些,如果没有自定义属性,所有的步骤都可能具备 终止,撤销操作,那么如果全部用网关来画,这个图一定成了蛛网形状了。

    添加自定义属性

    思路

    可能你会不断百度或者其他搜索引擎查询相关博客
    可能你会自告奋勇阅读源码
    可能你会…

    以上不管你怎么弄,其实都需要你花费一定的精力和毅力去做,中国的博客目前为止,至少关于flowable 的系统的、完整的、流畅的解决你的困扰,还很少。
    因此,最后还得靠自己的思维方法解决自己的业务场景!

    步骤

    要在flowable 原有的画图网页上,添加自定义页面,

    找到 flowable的静态画图页面文件

    首先你的找到 flowable的静态画图页面, 下载源码,找画bpmn2的工程文件。。。 总之最后的工程文件路径是如下面截图所示:
    在这里插入图片描述
    如果你觉得很烦,或者你不想自己再搞一个画图工程,从flowable源码中copy页面文件,copy一系列springBoot 的依赖工程 等等,你可以下载下面的已经处理过的,免登录flowable-modeler工程:

    https://gitee.com/banana6/flowable-bpmn2-modeler

    当然其他人分享的,都大同小异,毕竟都是copy源代码修改的。

    找到bpmnjson的数据文件

    找到 stencilset_bpmn_*.json 文件,
    我的这里有中英文国际化,因此有两个,并且放在了resources目录下,通过代码自定义访问加载。
    不管什么加载方式,文件名称叫什么,文件的内容都一样,前端请求你给它一样的内容即可。
    在这里插入图片描述

    修改找到bpmnjson的数据

    修改位置在开头json节点属性 propertyPackages中:

    
    {
      "title" : "Process editor",
      "namespace" : "http://b3mn.org/stencilset/bpmn2.0#",
      "description" : "BPMN process editor",
      "propertyPackages" : [ {
        "name" : "process_idpackage",
        "properties" : [ {
          "id" : "process_id",
          "type" : "String",
          "title" : "流程标识",
          "value" : "process",
          "description" : "定义流程的唯一标识符.",
          "popular" : true
        } ]
      },
    
      ....  这里面添加  .....
    
    

    里面添加属性内容:

    {
        "name" : "revokeflagpackage",
        "properties" : [ {
          "id" : "revokeflag",
          "type" : "Boolean",
          "title" : "可被撤销",
          "value" : "false",
          "description" : "定义该步骤提交后是否可以撤销.",
          "popular" : true
        } ]
      },{
        "name" : "endflagpackage",
        "properties" : [ {
          "id" : "endflag",
          "type" : "Boolean",
          "title" : "可终止流程",
          "value" : "false",
          "description" : "定义该步骤提交后是否可以撤销.",
          "popular" : true
        } ]
      }, {
        "name" : "nodetypepackage",
        "properties" : [ {
          "id" : "nodetype",
          "type" : "nodetype",
          "title" : "任务类型",
          "value" : "commit",
          "description" : "节点分为普通节点和审核节点.",
          "popular" : true
        } ]
      }
    

    关联到 userTask 节点, 就在刚才配置文件的底端 id = “UserTask” 节点,修改propertyPackages 属性值,将上面的3个自定义的属性id加入其中:

    
     {
        "type" : "node",
        "id" : "UserTask",
        "title" : "用户任务",
         ......
        "propertyPackages" : [...... , "nodetypepackage", "revokeflagpackage","endflagpackage", ...... ],
         ......
      }
    
    

    英文配置文件同步修改,当然如果你没有英文环境,则可以不修改。

    添加自定义下拉框属性类型

    目前flowable 画图页面上属性中,有各种数据类型,文本类型,布尔类型、还有其他复合类型, 可以说每一个属性除了 文本、布尔、数字等基础类型外其他的每一个属性都对应一个数据类型(一系列 html、js文件)。
    在这里插入图片描述

    以上的这些内置的属性类型配置信息,可查看 配置文件 properties.js 得知:
    在这里插入图片描述
    我们上面的 自定义【任务类型】属性类型就是下拉框,里面包含两个值“commit” 和 “audit” ,这里找了很久,通过比对 【多实例类型】 属性相关配置文件,进行添加修改相应文件,步骤如下:

    1. 在 properties.js 中添加如下属性:
        "nodetype" : {
            "readModeTemplateUrl": "editor-app/configuration/properties/default-value-display-template.html",
            "writeModeTemplateUrl": "editor-app/configuration/properties/nodetype-property-write-template.html"
        },
    

    看到 上面的 “nodetype” 了吗,和 之前在 bpmnjson 添加的内容中的 “type” : “nodetype” 对应上,名称保持一致。
    在这里插入图片描述

    1. 创建对应的html 和 js文件

    就是上面 添加的 nodetype-property-write-template.html 文件,路径在
    static/modeler/editor-app/configuration/properties/

    内容如下:

    <div ng-controller="FlowableNodeTypeCtrl">
        <select ng-model="property.value" ng-change="nodeTypeChanged()">
        	<option>commit</option>
        	<option>audit</option>
        </select>
    </div>
    

    然后继续创建 js 文件:properties-nodetype-controller.js ,路径在
    static/modeler/editor-app/configuration/

    angular.module('flowableModeler').controller('FlowableNodeTypeCtrl', [ '$scope', function($scope) {
    
        if ($scope.property.value === undefined)
        {
        	$scope.property.value = 'commit';
        }
    
        $scope.nodeTypeChanged = function() {
            $scope.updatePropertyInModel($scope.property);
        };
    }]);
    
    

    其中 html中的 <div ng-controller=“FlowableNodeTypeCtrl”> 和 js 中的 .controller(‘FlowableNodeTypeCtrl’, 对应上即可,这里都是 angularJS语法,没学过也无妨,照抄多实例应用里面的属性文件即可。

    1. 最后在首页 index.html中加载js文件
    <script src="editor-app/configuration/properties-nodetype-controller.js" type="text/javascript"></script>
    

    在这里插入图片描述

    添加自定义属性转换器

    到目前为止,静态页面上的工作处理完毕,接下来就是后端java代码处理,

    指导思想:

    • 页面上的属性 -----导出--------》 bpmn2 XML 文件
    • bpmn2 XML 文件 ------导入-------》 页面上的属性
    • 页面上的属性 -----保存--------》 Flowable java 对象 -----持久化—》 数据库表
    • 数据库表 -----查询--------》 Flowable java 对象 -----转换—》 页面上的属性

    对于flowable 这种流程引擎架构,上面所列出的一系列数据格式的转换必定会有一个转换器角色的功能类来实现 !

    而且 转换器角色的功能类 肯定不止一个, 必定都实现或者由哪一个控制类统一管控, flowable用的最多的应该是 用户任务,UserTask,转换器的名称一般编程中都喜欢用 Converter 来表示, 因此:

    使用IDEA 强大的搜索功能来找一找: UserTaskConverter , 还真有!

    org.flowable.editor.language.json.converter.UserTaskJsonConverter
    

    在这里插入图片描述
    当然一般 你可能是 根据前端 F12 查看,到底调用哪一个接口,然在顺藤摸瓜进行一番debug查找,最后一定能找到 UserTaskJsonConverter。

    创建自定义属性转换器:
    这里省略了一系列 debug的痛苦过程,直接说结果:

    继承 UserTaskJsonConverter 创建名称为 CustomizeUserTaskJsonConverter 的转换器类。

    package com.xxx.bbb.aaa.convert;
    
    import com.fasterxml.jackson.databind.JsonNode;
    import com.fasterxml.jackson.databind.node.ArrayNode;
    import com.fasterxml.jackson.databind.node.BooleanNode;
    import com.fasterxml.jackson.databind.node.ObjectNode;
    import com.fasterxml.jackson.databind.node.TextNode;
    import com.middol.flowable.modeler.utils.ExtensionAttributeUtils;
    import org.flowable.bpmn.model.*;
    import org.flowable.editor.language.json.converter.ActivityProcessor;
    import org.flowable.editor.language.json.converter.BaseBpmnJsonConverter;
    import org.flowable.editor.language.json.converter.UserTaskJsonConverter;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.util.StringUtils;
    
    import java.util.Collections;
    import java.util.List;
    import java.util.Map;
    
    /**
     * 新建自定义userTaskjson解析器CustomizeUserTaskJsonConverter
     *
     * @author guzt
     */
    public class CustomizeUserTaskJsonConverter extends UserTaskJsonConverter {
        private static final Logger LOGGER = LoggerFactory.getLogger(CustomizeUserTaskJsonConverter.class);
    
        private static final String NODE_TYPE_KEY = "nodetype";
        private static final String REVOKE_FLAG_KEY = "revokeflag";
        private static final String END_FLAG_KEY = "endflag";
    
        /**
         * 覆盖原 UserTaskJsonConverter 中的 fillTypes 方法
         *
         * @param convertersToBpmnMap map
         * @param convertersToJsonMap map
         * @see org.flowable.editor.language.json.converter.BpmnJsonConverter  中的静态代码块
         */
        public static void fillTypes(Map<String, Class<? extends BaseBpmnJsonConverter>> convertersToBpmnMap,
                                     Map<Class<? extends BaseElement>, Class<? extends BaseBpmnJsonConverter>> convertersToJsonMap) {
    
            fillJsonTypes(convertersToBpmnMap);
            fillBpmnTypes(convertersToJsonMap);
        }
    
        /**
         * 覆盖原 UserTaskJsonConverter 中的 fillBpmnTypes 方法
         *
         * @param convertersToJsonMap map
         * @see org.flowable.editor.language.json.converter.BpmnJsonConverter  中的静态代码块
         */
        public static void fillBpmnTypes(
                Map<Class<? extends BaseElement>, Class<? extends BaseBpmnJsonConverter>> convertersToJsonMap) {
            convertersToJsonMap.put(UserTask.class, CustomizeUserTaskJsonConverter.class);
        }
    
        /**
         * 覆盖原 UserTaskJsonConverter 中的 fillJsonTypes 方法
         *
         * @param convertersToBpmnMap map
         * @see org.flowable.editor.language.json.converter.BpmnJsonConverter  中的静态代码块
         */
        public static void fillJsonTypes(Map<String, Class<? extends BaseBpmnJsonConverter>> convertersToBpmnMap) {
            convertersToBpmnMap.put(STENCIL_TASK_USER, CustomizeUserTaskJsonConverter.class);
        }
    
    	// 主要用于 外部 xml 导入到 flowable画图页面中
        @Override
        public void convertToJson(BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {
            super.convertToJson(baseElement, processor, model, container, shapesArrayNode, subProcessX, subProcessY);
            if (baseElement instanceof UserTask) {
                LOGGER.debug("userTaskId = {} 扩展属性 = {}", baseElement.getId(), baseElement.getAttributes());
                Map<String, List<ExtensionAttribute>> stringListMap = baseElement.getAttributes();
    
                String nodetype = stringListMap.get(NODE_TYPE_KEY).get(0).getValue();
                String revokeflag = stringListMap.get(REVOKE_FLAG_KEY).get(0).getValue();
                String endflag = stringListMap.get(END_FLAG_KEY).get(0).getValue();
    
                shapesArrayNode.forEach(node -> {
                    if (baseElement.getId().equals(node.get("resourceId").textValue())) {
                        ObjectNode properties = (ObjectNode) node.get("properties");
                        properties.set(NODE_TYPE_KEY, new TextNode(nodetype));
                        properties.set(REVOKE_FLAG_KEY, BooleanNode.valueOf(Boolean.parseBoolean(revokeflag)));
                        properties.set(END_FLAG_KEY, BooleanNode.valueOf(Boolean.parseBoolean(endflag)));
                    }
                });
            }
        }
    
        // 主要用于 页面属性加载和导出 xml使用
        @Override
        protected FlowElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode,
                                                   Map<String, JsonNode> shapeMap) {
            FlowElement flowElement = super.convertJsonToElement(elementNode, modelNode, shapeMap);
    
            if (flowElement instanceof UserTask) {
                LOGGER.debug("进入自定义属性解析CustomizeUserTaskJsonConverter...");
                Map<String, List<ExtensionAttribute>> attributes = flowElement.getAttributes();
                String nodetype = getPropertyValueAsString(NODE_TYPE_KEY, elementNode);
                if (StringUtils.isEmpty(nodetype)) {
                    LOGGER.debug("nodetype 属性为空,设置为默认值");
                    nodetype = "commit";
                }
                attributes.put(NODE_TYPE_KEY, Collections.singletonList(
                        ExtensionAttributeUtils.generate(NODE_TYPE_KEY, nodetype)));
    
                String revokeflag = getPropertyValueAsString(REVOKE_FLAG_KEY, elementNode);
                if (StringUtils.isEmpty(revokeflag)) {
                    LOGGER.debug("revokeflag 属性为空,设置为默认值");
                    revokeflag = "false";
                }
                attributes.put(REVOKE_FLAG_KEY, Collections.singletonList(
                        ExtensionAttributeUtils.generate(REVOKE_FLAG_KEY, revokeflag)));
    
                String endflag = getPropertyValueAsString(END_FLAG_KEY, elementNode);
                if (StringUtils.isEmpty(endflag)) {
                    LOGGER.debug("endflag 属性为空,设置为默认值");
                    endflag = "false";
                }
                attributes.put(END_FLAG_KEY, Collections.singletonList(
                        ExtensionAttributeUtils.generate(END_FLAG_KEY, endflag)));
                LOGGER.debug("自定义属性解析CustomizeUserTaskJsonConverter 完成");
                LOGGER.debug("当前 attributes 为 {}", attributes);
            }
    
            return flowElement;
        }
    
    
    }
    
    

    看到里面的 三个属性了吗,就是一开始我们在js文件中添加的3个自定义属性的 id值

        private static final String NODE_TYPE_KEY = "nodetype";
        private static final String REVOKE_FLAG_KEY = "revokeflag";
        private static final String END_FLAG_KEY = "endflag";
    

    生效自定义属性转换器:
    让 CustomizeUserTaskJsonConverter 在运行期间替换 UserTaskJsonConverter 还需要做如下事情:

    创建一个 spring Bean 名称叫什么无所谓,暂且为 CustomBpmnJsonConverter ,必须 继承 BpmnJsonConverter,
    为什么要继承 BpmnJsonConverter ? 因为没办法,convertersToBpmnMap convertersToJsonMap 是 protected 类型,而正是这两个Map 来存储当解析用户任务节点时用哪一个转换器。

    
    package com.xxx.bbb.aaa.convert;
    
    import org.flowable.editor.language.json.converter.BpmnJsonConverter;
    import org.springframework.stereotype.Component;
    
    /**
    * 目的是将BpmnJsonConverter中的 UserTaskJsonConverter 设置替换成 CustomizeUserTaskJsonConverter。
    * 为什么要继承 BpmnJsonConverter ? 因为没办法,convertersToBpmnMap  convertersToJsonMap 是 protected 类型
    *
    * @author guzt
    * @see org.flowable.editor.language.json.converter.BpmnJsonConverter  中的静态代码块
    */
    @Component
    public class CustomBpmnJsonConverter extends BpmnJsonConverter {
    
      static {
          CustomizeUserTaskJsonConverter.fillTypes(convertersToBpmnMap, convertersToJsonMap);
      }
    }
    
    

    上面用到的工具类 ExtensionAttributeUtils 代码如下:

    package com.xxx.bbb.aaa.convert;
    
    import org.flowable.bpmn.model.ExtensionAttribute;
    import org.flowable.editor.language.json.converter.BpmnJsonConverter;
    
    /**
     * @author guzt
     */
    public class ExtensionAttributeUtils {
    
        public static ExtensionAttribute generate(String key, String val) {
            ExtensionAttribute ea = new ExtensionAttribute();
            ea.setNamespace(BpmnJsonConverter.MODELER_NAMESPACE);
            ea.setName(key);
            ea.setNamespacePrefix("custom");
            ea.setValue(val);
            return ea;
        }
    
    }
    
    

    自此,准备工作全部结束,然后编译项目,重新启动看看,是否有3个自定义属性,而且可以导入,而且可以将外部的xml 文件导入进去也能解析出自定义属性值。

    获取自定义属性值

    我们调用 flowable 中查询 userTask 接口获得 用户任务列表时 或者 查询流程定义的属性信息时,总之是 org.flowable.bpmn.model.UserTask 类或其子类。

    UserTask 可以 通过调用 getAttributes(); 方法获得自定义属性值。

        protected static final String NODE_TYPE_KEY = "nodetype";
        protected static final String REVOKE_FLAG_KEY = "revokeflag";
        protected static final String END_FLAG_KEY = "endflag";
    
      Map<String, List<ExtensionAttribute>> attributes = task.getAttributes();
    
            List<ExtensionAttribute> att1 = attributes.get(NODE_TYPE_KEY);
            if (CollectionUtil.isNotEmpty(att1)) {
               System.out.println("nodetype 的值为:" + att1.get(0).getValue()); 
            }
    
            List<ExtensionAttribute> att2 = attributes.get(REVOKE_FLAG_KEY);
            if (CollectionUtil.isNotEmpty(att1)) {
               System.out.println("revokeflag的值为:" + att1.get(0).getValue()); 
            }
    
            List<ExtensionAttribute> att3 = attributes.get(END_FLAG_KEY);
            if (CollectionUtil.isNotEmpty(att1)) {
               System.out.println("endflag的值为:" + att1.get(0).getValue()); 
            }
    

    Over , Thanks 如有不对地方请指正

    展开全文
    gzt19881123 2021-09-20 10:19:51
  • 460KB weixin_38744902 2021-03-02 12:48:45
  • 文章目录一、因为bpmn自带的camunda,所以需要适配activiti.json二、完成后的xml三、调整初始位置,避免图片在弹框难回显四、显示流程图4.1、这里就是为了这个代理人,才适配的`activiti`五、适配前后 一、因为bpmn...

    一、因为bpmn自带的camunda,所以需要适配activiti.json

      import BpmnModeler from 'bpmn-js/lib/Modeler'
      import PropertiesPanelModule from 'bpmn-js-properties-panel'
      //上面两个是bpmn的
      import PropertiesProviderModule from './properties-panel/provider/activiti' // bpmn的camunda配置提供改成了ActivitiPropertiesProvider
      
      import ActivitiModdleDescriptor from './activiti' // 适配的json
      import CustomControls from './customControls/' //CustomContextPad、CustomPalette、index
      import CustomTranslate from './CustomTranslate' //翻译
    
    
    mounted () {
          const canvas = this.$refs.canvas
    
          const CustomTranslateModule = {
            translate: ['value', CustomTranslate]
          };
    
          this.bpmnModeler = new BpmnModeler({
            container: canvas,
            propertiesPanel: {
              parent: '#properties'
            },
            additionalModules: [
              PropertiesProviderModule,
              PropertiesPanelModule,
              CustomTranslateModule,
              CustomControls
            ],
            moddleExtensions: {
              activiti: ActivitiModdleDescriptor
            }
          });
        }
    

    activiti.json

    {
      "name": "Activiti",
      "uri": "http://activiti.org/bpmn",
      "prefix": "activiti",
      "xml": {
        "tagAlias": "lowerCase"
      },
      "associations": [],
      "types": [
        {
          "name": "Definitions",
          "isAbstract": true,
          "extends": [
            "bpmn:Definitions"
          ],
          "properties": [
            {
              "name": "diagramRelationId",
              "isAttr": true,
              "type": "String"
            }
          ]
        }
    ......
    ],
        
      "emumerations": [ ]
    }
    
    

    二、完成后的xml

    <?xml version="1.0" encoding="UTF-8"?>
    <bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:activiti="http://activiti.org/bpmn" id="sample-diagram" targetNamespace="http://activiti.org/bpmn" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
    <bpmn2:process id="model_audit" name="model_audit" isExecutable="true">
    <bpmn2:startEvent id="StartEvent_1" name="开始">
    <bpmn2:outgoing>Flow_1p8y3br</bpmn2:outgoing>
    </bpmn2:startEvent>
    <bpmn2:userTask id="Activity_0q6zet6" name="编辑" activiti:assignee="${assignee}">
    <bpmn2:incoming>Flow_1p8y3br</bpmn2:incoming>
    <bpmn2:incoming>Flow_1ir809z</bpmn2:incoming>
    <bpmn2:outgoing>Flow_1rs9lec</bpmn2:outgoing>
    </bpmn2:userTask>
    <bpmn2:userTask id="Activity_0tgvyfk" name="审批" activiti:assignee="${assignee}">
    <bpmn2:incoming>Flow_1rs9lec</bpmn2:incoming>
    <bpmn2:outgoing>Flow_0oatdru</bpmn2:outgoing>
    </bpmn2:userTask>
    <bpmn2:exclusiveGateway id="Gateway_0cv9egj" name="判断">
    <bpmn2:incoming>Flow_0oatdru</bpmn2:incoming>
    <bpmn2:outgoing>Flow_09y0fvg</bpmn2:outgoing>
    <bpmn2:outgoing>Flow_1ir809z</bpmn2:outgoing>
    </bpmn2:exclusiveGateway>
    <bpmn2:endEvent id="Event_1oqrik5" name="结束">
    <bpmn2:incoming>Flow_09y0fvg</bpmn2:incoming>
    </bpmn2:endEvent>
    <bpmn2:sequenceFlow id="Flow_1p8y3br" sourceRef="StartEvent_1" targetRef="Activity_0q6zet6" />
    <bpmn2:sequenceFlow id="Flow_1rs9lec" sourceRef="Activity_0q6zet6" targetRef="Activity_0tgvyfk" />
    <bpmn2:sequenceFlow id="Flow_0oatdru" sourceRef="Activity_0tgvyfk" targetRef="Gateway_0cv9egj" />
    <bpmn2:sequenceFlow id="Flow_09y0fvg" name="通过" sourceRef="Gateway_0cv9egj" targetRef="Event_1oqrik5">
    <bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${check==1}</bpmn2:conditionExpression>
    </bpmn2:sequenceFlow>
    <bpmn2:sequenceFlow id="Flow_1ir809z" name="驳回" sourceRef="Gateway_0cv9egj" targetRef="Activity_0q6zet6" />
    </bpmn2:process>
    <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="model_audit">
    <bpmndi:BPMNEdge id="Flow_1p8y3br_di" bpmnElement="Flow_1p8y3br">
    <di:waypoint x="186" y="168" />
    <di:waypoint x="230" y="168" />
    </bpmndi:BPMNEdge>
    <bpmndi:BPMNEdge id="Flow_1rs9lec_di" bpmnElement="Flow_1rs9lec">
    <di:waypoint x="330" y="168" />
    <di:waypoint x="370" y="168" />
    </bpmndi:BPMNEdge>
    <bpmndi:BPMNEdge id="Flow_0oatdru_di" bpmnElement="Flow_0oatdru">
    <di:waypoint x="470" y="168" />
    <di:waypoint x="515" y="168" />
    </bpmndi:BPMNEdge>
    <bpmndi:BPMNEdge id="Flow_09y0fvg_di" bpmnElement="Flow_09y0fvg">
    <di:waypoint x="565" y="168" />
    <di:waypoint x="652" y="168" />
    <bpmndi:BPMNLabel>
    <dc:Bounds x="597" y="150" width="23" height="14" />
    </bpmndi:BPMNLabel>
    </bpmndi:BPMNEdge>
    <bpmndi:BPMNEdge id="Flow_1ir809z_di" bpmnElement="Flow_1ir809z">
    <di:waypoint x="540" y="143" />
    <di:waypoint x="540" y="60" />
    <di:waypoint x="280" y="60" />
    <di:waypoint x="280" y="128" />
    <bpmndi:BPMNLabel>
    <dc:Bounds x="399" y="42" width="22" height="14" />
    </bpmndi:BPMNLabel>
    </bpmndi:BPMNEdge>
    <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
    <dc:Bounds x="150" y="150" width="36" height="36" />
    <bpmndi:BPMNLabel>
    <dc:Bounds x="157" y="193" width="23" height="14" />
    </bpmndi:BPMNLabel>
    </bpmndi:BPMNShape>
    <bpmndi:BPMNShape id="Activity_0q6zet6_di" bpmnElement="Activity_0q6zet6">
    <dc:Bounds x="230" y="128" width="100" height="80" />
    </bpmndi:BPMNShape>
    <bpmndi:BPMNShape id="Activity_0tgvyfk_di" bpmnElement="Activity_0tgvyfk">
    <dc:Bounds x="370" y="128" width="100" height="80" />
    </bpmndi:BPMNShape>
    <bpmndi:BPMNShape id="Gateway_0cv9egj_di" bpmnElement="Gateway_0cv9egj" isMarkerVisible="true">
    <dc:Bounds x="515" y="143" width="50" height="50" />
    <bpmndi:BPMNLabel>
    <dc:Bounds x="529" y="200" width="23" height="14" />
    </bpmndi:BPMNLabel>
    </bpmndi:BPMNShape>
    <bpmndi:BPMNShape id="Event_1oqrik5_di" bpmnElement="Event_1oqrik5">
    <dc:Bounds x="652" y="150" width="36" height="36" />
    <bpmndi:BPMNLabel>
    <dc:Bounds x="659" y="193" width="23" height="14" />
    </bpmndi:BPMNLabel>
    </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
    </bpmndi:BPMNDiagram>
    </bpmn2:definitions>
    

    三、调整初始位置,避免图片在弹框难回显

    StartEvent_1是我这里给的开始点x="150" y="150"坐标

    <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
    <dc:Bounds x="150" y="150" width="36" height="36" />
    

    四、显示流程图

    4.1、这里就是为了这个代理人,才适配的activiti

    在这里插入图片描述

    五、适配前后

    camunda:assignee="${assignee}" 
    
    //适配前后的代理人这里的差异
    activiti:assignee="${assignee}"
    
    展开全文
    weixin_46037781 2021-08-02 17:58:43
  • BPMN流程文件可以使用eclipse bpmn2插件开发比如eclipse bpmn2 modeler或者idea activiti插件。 <?xml version="1.0" encoding="UTF-8"?> <!-- origin at X=0.0 Y=0.0 --> <bpmn2:de...

    统一的BPMN标准,对工作流的流程定义采用BPMN统一格式。BPMN流程文件可以使用eclipse bpmn2插件开发比如eclipse bpmn2 modeler或者idea activiti插件。

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- origin at X=0.0 Y=0.0 -->
    <bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:java="http://www.java.com/javaTypes" xmlns:tns="http://www.jboss.org/drools" xmlns="http://www.jboss.org/drools" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd http://www.jboss.org/drools drools.xsd http://www.bpsim.org/schemas/1.0 bpsim.xsd" id="Definition" exporter="org.eclipse.bpmn2.modeler.core" exporterVersion="1.1.6.Final-v20160330-1631-B1306" expressionLanguage="http://www.mvel.org/2.0" targetNamespace="http://www.jboss.org/drools" typeLanguage="http://www.java.com/javaTypes">
      <bpmn2:itemDefinition id="ItemDefinition_1" isCollection="false" structureRef="String"/>
      <bpmn2:itemDefinition id="ItemDefinition_2" isCollection="false" structureRef="Integer"/>
      <bpmn2:itemDefinition id="ItemDefinition_3" isCollection="false" structureRef="Boolean"/>
      <bpmn2:process id="net.hs.cw.bpme.ta.flow_index_mainflow" tns:packageName="net.hs.cw.bpme.ta" name="flow_index_mainflow" isExecutable="true" processType="Private">
        <bpmn2:startEvent id="StartEvent_1" name="StartProcess">
          <bpmn2:extensionElements>
            <tns:metaData name="elementname">
              <tns:metaValue><![CDATA[StartProcess]]></tns:metaValue>
            </tns:metaData>
          </bpmn2:extensionElements>
          <bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
        </bpmn2:startEvent>
        <bpmn2:userTask id="UserTask_1" name="指数行情导入">
          <bpmn2:extensionElements>
            <tns:metaData name="elementname">
              <tns:metaValue><![CDATA[指数行情导入]]></tns:metaValue>
            </tns:metaData>
          </bpmn2:extensionElements>
          <bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
          <bpmn2:outgoing>SequenceFlow_2</bpmn2:outgoing>
          <bpmn2:ioSpecification id="InputOutputSpecification_2">
            <bpmn2:dataInput id="DataInput_8" itemSubjectRef="ItemDefinition_1" name="TaskName"/>
            <bpmn2:dataInput id="DataInput_9" itemSubjectRef="ItemDefinition_2" name="Priority"/>
            <bpmn2:dataInput id="DataInput_10" itemSubjectRef="ItemDefinition_1" name="Comment"/>
            <bpmn2:dataInput id="DataInput_11" itemSubjectRef="ItemDefinition_1" name="GroupId"/>
            <bpmn2:dataInput id="DataInput_12" itemSubjectRef="ItemDefinition_3" name="Skippable"/>
            <bpmn2:dataInput id="DataInput_13" itemSubjectRef="ItemDefinition_1" name="Content"/>
            <bpmn2:dataInput id="DataInput_14" itemSubjectRef="ItemDefinition_1" name="Locale"/>
            <bpmn2:inputSet id="_InputSet_209">
              <bpmn2:dataInputRefs>DataInput_8</bpmn2:dataInputRefs>
              <bpmn2:dataInputRefs>DataInput_9</bpmn2:dataInputRefs>
              <bpmn2:dataInputRefs>DataInput_10</bpmn2:dataInputRefs>
              <bpmn2:dataInputRefs>DataInput_11</bpmn2:dataInputRefs>
              <bpmn2:dataInputRefs>DataInput_12</bpmn2:dataInputRefs>
              <bpmn2:dataInputRefs>DataInput_13</bpmn2:dataInputRefs>
              <bpmn2:dataInputRefs>DataInput_14</bpmn2:dataInputRefs>
            </bpmn2:inputSet>
            <bpmn2:outputSet id="OutputSet_2" name="Output Set"/>
          </bpmn2:ioSpecification>
          <bpmn2:dataInputAssociation id="DataInputAssociation_8">
            <bpmn2:targetRef>DataInput_8</bpmn2:targetRef>
            <bpmn2:assignment id="Assignment_8">
              <bpmn2:from xsi:type="bpmn2:tFormalExpression" id="FormalExpression_15">ImpIndexFile</bpmn2:from>
              <bpmn2:to xsi:type="bpmn2:tFormalExpression" id="FormalExpression_16">DataInput_8</bpmn2:to>
            </bpmn2:assignment>
          </bpmn2:dataInputAssociation>
          <bpmn2:dataInputAssociation id="DataInputAssociation_9">
            <bpmn2:targetRef>DataInput_9</bpmn2:targetRef>
            <bpmn2:assignment id="Assignment_9">
              <bpmn2:from xsi:type="bpmn2:tFormalExpression" id="FormalExpression_17">1</bpmn2:from>
              <bpmn2:to xsi:type="bpmn2:tFormalExpression" id="FormalExpression_18">DataInput_9</bpmn2:to>
            </bpmn2:assignment>
          </bpmn2:dataInputAssociation>
          <bpmn2:dataInputAssociation id="DataInputAssociation_10">
            <bpmn2:targetRef>DataInput_10</bpmn2:targetRef>
          </bpmn2:dataInputAssociation>
          <bpmn2:dataInputAssociation id="DataInputAssociation_11">
            <bpmn2:targetRef>DataInput_11</bpmn2:targetRef>
          </bpmn2:dataInputAssociation>
          <bpmn2:dataInputAssociation id="DataInputAssociation_12">
            <bpmn2:targetRef>DataInput_12</bpmn2:targetRef>
            <bpmn2:assignment id="Assignment_12">
              <bpmn2:from xsi:type="bpmn2:tFormalExpression" id="FormalExpression_23">true</bpmn2:from>
              <bpmn2:to xsi:type="bpmn2:tFormalExpression" id="FormalExpression_24">DataInput_12</bpmn2:to>
            </bpmn2:assignment>
          </bpmn2:dataInputAssociation>
          <bpmn2:dataInputAssociation id="DataInputAssociation_13">
            <bpmn2:targetRef>DataInput_13</bpmn2:targetRef>
            <bpmn2:assignment id="Assignment_13">
              <bpmn2:from xsi:type="bpmn2:tFormalExpression" id="FormalExpression_25">{&quot;executeMode&quot;:&quot;manual&quot;}</bpmn2:from>
              <bpmn2:to xsi:type="bpmn2:tFormalExpression" id="FormalExpression_26">DataInput_13</bpmn2:to>
            </bpmn2:assignment>
          </bpmn2:dataInputAssociation>
          <bpmn2:dataInputAssociation id="DataInputAssociation_14">
            <bpmn2:targetRef>DataInput_14</bpmn2:targetRef>
            <bpmn2:assignment id="Assignment_14">
              <bpmn2:from xsi:type="bpmn2:tFormalExpression" id="FormalExpression_27">en-UK</bpmn2:from>
              <bpmn2:to xsi:type="bpmn2:tFormalExpression" id="FormalExpression_28">DataInput_14</bpmn2:to>
            </bpmn2:assignment>
          </bpmn2:dataInputAssociation>
        </bpmn2:userTask>
        <bpmn2:sequenceFlow id="SequenceFlow_1" tns:priority="1" sourceRef="StartEvent_1" targetRef="UserTask_1"/>
        <bpmn2:endEvent id="EndEvent_1" name="End Event 1">
          <bpmn2:extensionElements>
            <tns:metaData name="elementname">
              <tns:metaValue><![CDATA[End Event 1]]></tns:metaValue>
            </tns:metaData>
          </bpmn2:extensionElements>
          <bpmn2:incoming>SequenceFlow_2</bpmn2:incoming>
        </bpmn2:endEvent>
        <bpmn2:sequenceFlow id="SequenceFlow_2" tns:priority="1" sourceRef="UserTask_1" targetRef="EndEvent_1"/>
      </bpmn2:process>
      <bpmndi:BPMNDiagram id="BPMNDiagram_1">
        <bpmndi:BPMNPlane id="BPMNPlane_Process_1" bpmnElement="net.hs.cw.bpme.ta.flow_index_mainflow">
          <bpmndi:BPMNShape id="BPMNShape_StartEvent_1" bpmnElement="StartEvent_1">
            <dc:Bounds height="36.0" width="36.0" x="377.0" y="30.0"/>
            <bpmndi:BPMNLabel id="BPMNLabel_1">
              <dc:Bounds height="15.0" width="71.0" x="360.0" y="66.0"/>
            </bpmndi:BPMNLabel>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape id="BPMNShape_UserTask_1" bpmnElement="UserTask_1">
            <dc:Bounds height="47.0" width="231.0" x="280.0" y="119.0"/>
            <bpmndi:BPMNLabel id="BPMNLabel_2">
              <dc:Bounds height="15.0" width="72.0" x="359.0" y="135.0"/>
            </bpmndi:BPMNLabel>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape id="BPMNShape_EndEvent_1" bpmnElement="EndEvent_1">
            <dc:Bounds height="36.0" width="36.0" x="377.0" y="217.0"/>
            <bpmndi:BPMNLabel id="BPMNLabel_3">
              <dc:Bounds height="15.0" width="65.0" x="363.0" y="253.0"/>
            </bpmndi:BPMNLabel>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_1" bpmnElement="SequenceFlow_1" sourceElement="BPMNShape_StartEvent_1" targetElement="BPMNShape_UserTask_1">
            <di:waypoint xsi:type="dc:Point" x="395.0" y="66.0"/>
            <di:waypoint xsi:type="dc:Point" x="395.0" y="85.0"/>
            <di:waypoint xsi:type="dc:Point" x="395.0" y="119.0"/>
            <bpmndi:BPMNLabel id="BPMNLabel_4"/>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_2" bpmnElement="SequenceFlow_2" sourceElement="BPMNShape_UserTask_1" targetElement="BPMNShape_EndEvent_1">
            <di:waypoint xsi:type="dc:Point" x="395.0" y="166.0"/>
            <di:waypoint xsi:type="dc:Point" x="395.0" y="191.0"/>
            <di:waypoint xsi:type="dc:Point" x="395.0" y="191.0"/>
            <di:waypoint xsi:type="dc:Point" x="395.0" y="217.0"/>
            <bpmndi:BPMNLabel id="BPMNLabel_5"/>
          </bpmndi:BPMNEdge>
        </bpmndi:BPMNPlane>
      </bpmndi:BPMNDiagram>
    </bpmn2:definitions>

    如下是对该类型文件的解析工具类和方法。

        public void init() throws XMLStreamException, IOException {
            for (int i = 0; i < bpmnLocation.length; i++) {
                InputStream is = bpmnLocation[i].getInputStream();
                byte[] encoded = IOUtils.toByteArray(is);
                String bpmnResource = new String(encoded, Charset.forName("UTF-8"));
                BpmnXMLConverter converter = new BpmnXMLConverter();
                XMLInputFactory factory = XMLInputFactory.newInstance();
                @Cleanup XMLStreamReader reader = factory.createXMLStreamReader(bpmnLocation[i].getInputStream());
                BpmnModel bpmnModel = converter.convertToBpmnModel(reader);
                Process process = bpmnModel.getProcesses().get(0);
                ProcessDefinition processDefinition = new ProcessDefinition();
                processDefinition.setProcessSource(bpmnResource);
                processDefinition.setProcessId(process.getId());
                processDefinition.setProcessName(process.getName());
                List<FlowElement> flowElementList = (List<FlowElement>) process.getFlowElements();
                Map<String,FlowElement> flowElementMap = new HashMap();
                for (FlowElement flowElement : flowElementList) {
                    flowElementMap.put(flowElement.getId(),flowElement);
                }
                processDefinition.setFlowElementMap(flowElementMap);
                ProcessDataUtil.processDefinitionMap.put(process.getId(), processDefinition);
            }
        }

     

    转载于:https://www.cnblogs.com/zhjh256/p/10021208.html

    展开全文
    weixin_30243533 2018-11-26 16:39:00
  • 4星
    71B u014742035 2014-04-16 10:59:27
  • 228KB weixin_42097208 2021-02-06 14:28:44
  • zhangjs712 2016-03-26 17:18:31
  • 476KB qqq104 2021-05-04 18:44:33
  • workhd 2021-10-18 15:10:56
  • 5星
    2.78MB weixin_52265084 2020-12-29 17:54:10
  • 4星
    15.11MB qml99199 2020-10-20 17:12:18
  • 286KB madianding 2019-12-24 14:22:36
  • 166KB Feng_wwf 2021-09-18 15:31:04
  • 627KB weixin_42111465 2021-02-19 16:34:27
  • 867B Feng_wwf 2021-09-18 15:31:04
  • 101KB weixin_42117032 2021-04-09 01:25:10
  • weixin_34072637 2017-04-21 11:00:00
  • Leezh0808 2018-05-16 16:44:51
  • 3星
    1.17MB weixin_42127937 2021-03-20 04:07:17
  • 7.1MB weixin_42113754 2021-05-11 13:14:41

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 16,630
精华内容 6,652
关键字:

bpmn2

友情链接: NVMeGeneric.kext.zip