在使用 flowable框架的时候,首先需要引入 flowable的jar包,flowable maven仓库地址为:

  1. <!-- https://mvnrepository.com/artifact/org.flowable/flowable-engine -->
  2. <dependency>
  3. <groupId>org.flowable</groupId>
  4. <artifactId>flowable-engine</artifactId>
  5. <version>6.0.0.RC1</version>
  6. </dependency>

新建flowable.cfg.xml文件,如下图所示:
flowable - 图1
flowable.cfg.xml文件内容如下所示:

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://www.springframework.org/schema/beans
  4. http://www.springframework.org/schema/beans/spring-beans.xsd">
  5. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
  6. <property name="driverClassName">
  7. <value>com.mysql.jdbc.Driver</value>
  8. </property>
  9. <property name="url">
  10. <value>jdbc:mysql://127.0.0.1:3306/shareniuflowable?useUnicode=true&characterEncoding=UTF-8
  11. </value>
  12. </property>
  13. <property name="username">
  14. <value>root</value>
  15. </property>
  16. <property name="password" value="" />
  17. <!-- -->
  18. </bean>
  19. <bean id="processEngineConfiguration"
  20. class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration" >
  21. <property name="dataSource" ref="dataSource" />
  22. <property name="databaseSchemaUpdate" value="true" />
  23. </bean>
  24. </beans>

新建测试类如下所示:

  1. package com.shareniu.flowables.ch1;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import org.flowable.engine.IdentityService;
  5. import org.flowable.engine.ProcessEngine;
  6. import org.flowable.engine.ProcessEngineConfiguration;
  7. import org.flowable.engine.RepositoryService;
  8. import org.flowable.engine.RuntimeService;
  9. import org.flowable.engine.TaskService;
  10. import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
  11. import org.flowable.engine.repository.Deployment;
  12. import org.flowable.engine.repository.DeploymentBuilder;
  13. import org.junit.Before;
  14. import org.junit.Test;
  15. /**
  16. * 分享牛http://www.shareniu.com/
  17. *
  18. */
  19. public class App
  20. {
  21. // 获取到Activiti ProcessEngine
  22. ProcessEngine processEngine = null;
  23. // 获取RepositoryService 实例对象
  24. RepositoryService repositoryService = null;
  25. // 资源名称
  26. String resourceName = "shareniu_addInputStream.bpmn";
  27. IdentityService identityService;
  28. RuntimeService runtimeService;
  29. TaskService taskService;
  30. @Before
  31. public void init() {
  32. InputStream in = App.class.getClassLoader().getResourceAsStream(
  33. "com/shareniu/flowables/ch1/flowable.cfg.xml");
  34. ProcessEngineConfiguration pcf = ProcessEngineConfiguration
  35. .createProcessEngineConfigurationFromInputStream(in);
  36. processEngine = pcf.buildProcessEngine();
  37. repositoryService = processEngine.getRepositoryService();
  38. identityService = processEngine.getIdentityService();
  39. runtimeService = processEngine.getRuntimeService();
  40. taskService = processEngine.getTaskService();
  41. ProcessEngineConfigurationImpl pc = (ProcessEngineConfigurationImpl) processEngine
  42. .getProcessEngineConfiguration();
  43. }
  44. @Test
  45. public void addInputStreamTest() throws IOException {
  46. // 定义的文件信息的流读取 分享牛http://www.shareniu.com/
  47. InputStream inputStream = App.class
  48. .getClassLoader().getResource("com/shareniu/flowables/ch1/common.bpmn").openStream();
  49. // 流程定义的分类 分享牛http://www.shareniu.com/
  50. String category = "shareniu_addInputStream";
  51. // 构造DeploymentBuilder对象
  52. DeploymentBuilder deploymentBuilder = repositoryService
  53. .createDeployment().category(category)
  54. .addInputStream(resourceName, inputStream);
  55. // 部署
  56. Deployment deploy = deploymentBuilder.deploy();
  57. System.out.println(deploy);
  58. }
  59. }

多数据源

可以自己手写一份,也可以在xml中进行多数据的配置,当然了我们也可以将数据库信息初始化到表中,项目启动的时候进行数据的加载,这个环节跟配置是差不多的。
优点:可以灵活加同一种类型的数据库,比如mysql的写好了,也可以继续加下去。
缺点:过于繁琐
本质上和配置的形式类似,这里以项目数据库的形式进行说明,首先建表,如下:
1、人大金仓数据库写法

DROP TABLE IF EXISTS sysdata_source;
CREATE TABLE sys_data_source (
id
varchar(255) NOT NULL ,
key varchar(255) DEFAULT NULL ,
name
varchar(255) DEFAULT NULL ,
desc varchar(255) DEFAULT NULL ,
db_type
varchar(64) DEFAULT NULL ,
classpath varchar(64) DEFAULT NULL ,
attributesjson bytea ,
DELETED boolean DEFAULT ‘0’ ,
PRIMARY KEY (id)
) ;
2、mysql数据库写法
— ——————————————
— Table structure for sys_data_source
— ——————————————
DROP TABLE IF EXISTS sys_data_source;
CREATE TABLE sys_data_source (
`id
varchar(255) COLLATE utf8_bin NOT NULL COMMENT '主键',<br />keyvarchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '别名',<br />namevarchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '名称',<br />descvarchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '描述',<br />db_typevarchar(64) COLLATE utf8_bin DEFAULT NULL COMMENT '类型',<br />classpathvarchar(64) COLLATE utf8_bin DEFAULT NULL COMMENT '路径',<br />attributesjsonlongblob COMMENT '配置',<br />DELETEDtinyint(1) DEFAULT '0' COMMENT '是否是系统的',<br /> PRIMARY KEY (id_`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT=’连接池’;

— ——————————————
— Records of sys_data_source
— ——————————————
BEGIN;
INSERT INTO sys_data_source VALUES (‘1’, ‘dataSourceDefault’, ‘本地数据源 ‘, ‘本地数据源 ‘, ‘MYSQL’, NULL, 0x5B7B22636F6D6D656E74223A22757365726E616D65222C226E616D65223A22757365726E616D65222C227265717569726564223A66616C73652C2274797065223A226A6176612E6C616E672E537472696E67222C2276616C7565223A22726F6F74227D2C7B22636F6D6D656E74223A2270617373776F7264222C226E616D65223A2270617373776F7264222C227265717569726564223A66616C73652C2274797065223A226A6176612E6C616E672E537472696E67222C2276616C7565223A22726F6F74227D2C7B22636F6D6D656E74223A22696E697469616C53697A65222C226E616D65223A22696E697469616C53697A65222C227265717569726564223A66616C73652C2274797065223A22696E74222C2276616C7565223A223130227D2C7B22636F6D6D656E74223A226D6178416374697665222C226E616D65223A226D6178416374697665222C227265717569726564223A66616C73652C2274797065223A22696E74222C2276616C7565223A22313030227D2C7B22636F6D6D656E74223A226D696E49646C65222C226E616D65223A226D696E49646C65222C227265717569726564223A66616C73652C2274797065223A22696E74222C2276616C7565223A223130227D2C7B22636F6D6D656E74223A226D617857616974222C226E616D65223A226D617857616974222C227265717569726564223A66616C73652C2274797065223A226C6F6E67222C2276616C7565223A223630303030227D2C7B22636F6D6D656E74223A2276616C69646174696F6E5175657279222C226E616D65223A2276616C69646174696F6E5175657279222C227265717569726564223A66616C73652C2274797065223A226A6176612E6C616E672E537472696E67222C2276616C7565223A2273656C656374202A2066726F6D204143545F47455F50524F5045525459227D2C7B22636F6D6D656E74223A22746573744F6E426F72726F77222C226E616D65223A22746573744F6E426F72726F77222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2266616C7365227D2C7B22636F6D6D656E74223A22746573744F6E52657475726E222C226E616D65223A22746573744F6E52657475726E222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2266616C7365227D2C7B22636F6D6D656E74223A22746573745768696C6549646C65222C226E616D65223A22746573745768696C6549646C65222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D2C7B22636F6D6D656E74223A22706F6F6C507265706172656453746174656D656E7473222C226E616D65223A22706F6F6C507265706172656453746174656D656E7473222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D2C7B22636F6D6D656E74223A226D6178506F6F6C507265706172656453746174656D656E74506572436F6E6E656374696F6E53697A65222C226E616D65223A226D6178506F6F6C507265706172656453746174656D656E74506572436F6E6E656374696F6E53697A65222C227265717569726564223A66616C73652C2274797065223A22696E74222C2276616C7565223A223230227D2C7B22636F6D6D656E74223A2266696C74657273222C226E616D65223A2266696C74657273222C227265717569726564223A66616C73652C2274797065223A226A6176612E7574696C2E4C697374222C2276616C7565223A2273746174227D2C7B22636F6D6D656E74223A2274696D654265747765656E4576696374696F6E52756E734D696C6C6973222C226E616D65223A2274696D654265747765656E4576696374696F6E52756E734D696C6C6973222C227265717569726564223A66616C73652C2274797065223A226C6F6E67222C2276616C7565223A223630303030227D2C7B22636F6D6D656E74223A226D696E457669637461626C6549646C6554696D654D696C6C6973222C226E616D65223A226D696E457669637461626C6549646C6554696D654D696C6C6973222C227265717569726564223A66616C73652C2274797065223A226C6F6E67222C2276616C7565223A22333030303030227D2C7B22636F6D6D656E74223A2272656D6F76654162616E646F6E6564222C226E616D65223A2272656D6F76654162616E646F6E6564222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D2C7B22636F6D6D656E74223A2272656D6F76654162616E646F6E656454696D656F75744D696C6C6973222C226E616D65223A2272656D6F76654162616E646F6E656454696D656F75744D696C6C6973222C227265717569726564223A66616C73652C2274797065223A226C6F6E67222C2276616C7565223A223630303030227D2C7B22636F6D6D656E74223A226C6F674162616E646F6E6564222C226E616D65223A226C6F674162616E646F6E6564222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D2C7B22636F6D6D656E74223A2275726C222C226E616D65223A2275726C222C227265717569726564223A66616C73652C2274797065223A226A6176612E6C616E672E537472696E67222C2276616C7565223A226A6462633A6D7973716C3A2F2FE4B8BBE69CBA3A333330362FE695B0E68DAEE5BA93E5908D3F757365556E69636F64653D7472756526636861726163746572456E636F64696E673D7574662D383B227D2C7B22636F6D6D656E74223A22627265616B4166746572416371756972654661696C757265222C226E616D65223A22627265616B4166746572416371756972654661696C757265222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D5D, 0);
INSERT INTO sys_data_source VALUES (‘683048477462102016’, ‘22’, ‘11’, ‘33’, ‘ORACLE’, NULL, 0x5B7B22636F6D6D656E74223A22757365726E616D65222C226E616D65223A22757365726E616D65222C227265717569726564223A66616C73652C2274797065223A226A6176612E6C616E672E537472696E67222C2276616C7565223A22726F6F74227D2C7B22636F6D6D656E74223A2270617373776F7264222C226E616D65223A2270617373776F7264222C227265717569726564223A66616C73652C2274797065223A226A6176612E6C616E672E537472696E67222C2276616C7565223A22726F6F74227D2C7B22636F6D6D656E74223A22696E697469616C53697A65222C226E616D65223A22696E697469616C53697A65222C227265717569726564223A66616C73652C2274797065223A22696E74222C2276616C7565223A223130227D2C7B22636F6D6D656E74223A226D6178416374697665222C226E616D65223A226D6178416374697665222C227265717569726564223A66616C73652C2274797065223A22696E74222C2276616C7565223A22313030227D2C7B22636F6D6D656E74223A226D696E49646C65222C226E616D65223A226D696E49646C65222C227265717569726564223A66616C73652C2274797065223A22696E74222C2276616C7565223A223130227D2C7B22636F6D6D656E74223A226D617857616974222C226E616D65223A226D617857616974222C227265717569726564223A66616C73652C2274797065223A226C6F6E67222C2276616C7565223A223630303030227D2C7B22636F6D6D656E74223A2276616C69646174696F6E5175657279222C226E616D65223A2276616C69646174696F6E5175657279222C227265717569726564223A66616C73652C2274797065223A226A6176612E6C616E672E537472696E67222C2276616C7565223A2273656C656374202A2066726F6D204143545F47455F50524F5045525459227D2C7B22636F6D6D656E74223A22746573744F6E426F72726F77222C226E616D65223A22746573744F6E426F72726F77222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2266616C7365227D2C7B22636F6D6D656E74223A22746573744F6E52657475726E222C226E616D65223A22746573744F6E52657475726E222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2266616C7365227D2C7B22636F6D6D656E74223A22746573745768696C6549646C65222C226E616D65223A22746573745768696C6549646C65222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D2C7B22636F6D6D656E74223A22706F6F6C507265706172656453746174656D656E7473222C226E616D65223A22706F6F6C507265706172656453746174656D656E7473222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D2C7B22636F6D6D656E74223A226D6178506F6F6C507265706172656453746174656D656E74506572436F6E6E656374696F6E53697A65222C226E616D65223A226D6178506F6F6C507265706172656453746174656D656E74506572436F6E6E656374696F6E53697A65222C227265717569726564223A66616C73652C2274797065223A22696E74222C2276616C7565223A223230227D2C7B22636F6D6D656E74223A2266696C74657273222C226E616D65223A2266696C74657273222C227265717569726564223A66616C73652C2274797065223A226A6176612E7574696C2E4C697374222C2276616C7565223A2273746174227D2C7B22636F6D6D656E74223A2274696D654265747765656E4576696374696F6E52756E734D696C6C6973222C226E616D65223A2274696D654265747765656E4576696374696F6E52756E734D696C6C6973222C227265717569726564223A66616C73652C2274797065223A226C6F6E67222C2276616C7565223A223630303030227D2C7B22636F6D6D656E74223A226D696E457669637461626C6549646C6554696D654D696C6C6973222C226E616D65223A226D696E457669637461626C6549646C6554696D654D696C6C6973222C227265717569726564223A66616C73652C2274797065223A226C6F6E67222C2276616C7565223A22333030303030227D2C7B22636F6D6D656E74223A2272656D6F76654162616E646F6E6564222C226E616D65223A2272656D6F76654162616E646F6E6564222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D2C7B22636F6D6D656E74223A2272656D6F76654162616E646F6E656454696D656F75744D696C6C6973222C226E616D65223A2272656D6F76654162616E646F6E656454696D656F75744D696C6C6973222C227265717569726564223A66616C73652C2274797065223A226C6F6E67222C2276616C7565223A223630303030227D2C7B22636F6D6D656E74223A226C6F674162616E646F6E6564222C226E616D65223A226C6F674162616E646F6E6564222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D2C7B22636F6D6D656E74223A2275726C222C226E616D65223A2275726C222C227265717569726564223A66616C73652C2274797065223A226A6176612E6C616E672E537472696E67222C2276616C7565223A22206A6462633A6F7261636C653A7468696E3A40E4B8BBE69CBA3A313532313AE695B0E68DAEE5BA93E5AE9EE4BE8B3B227D2C7B22636F6D6D656E74223A22627265616B4166746572416371756972654661696C757265222C226E616D65223A22627265616B4166746572416371756972654661696C757265222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D5D, 1);
INSERT INTO sys_data_source VALUES (‘683081265699618816’, ‘2323’, ‘232’, ‘’, ‘MYSQL’, NULL, 0x5B7B22636F6D6D656E74223A22757365726E616D65222C226E616D65223A22757365726E616D65222C227265717569726564223A66616C73652C2274797065223A226A6176612E6C616E672E537472696E67222C2276616C7565223A22227D2C7B22636F6D6D656E74223A2270617373776F7264222C226E616D65223A2270617373776F7264222C227265717569726564223A66616C73652C2274797065223A226A6176612E6C616E672E537472696E67222C2276616C7565223A223132313231227D2C7B22636F6D6D656E74223A22696E697469616C53697A65222C226E616D65223A22696E697469616C53697A65222C227265717569726564223A66616C73652C2274797065223A22696E74222C2276616C7565223A22227D2C7B22636F6D6D656E74223A226D6178416374697665222C226E616D65223A226D6178416374697665222C227265717569726564223A66616C73652C2274797065223A22696E74222C2276616C7565223A22313030227D2C7B22636F6D6D656E74223A226D696E49646C65222C226E616D65223A226D696E49646C65222C227265717569726564223A66616C73652C2274797065223A22696E74222C2276616C7565223A223130227D2C7B22636F6D6D656E74223A226D617857616974222C226E616D65223A226D617857616974222C227265717569726564223A66616C73652C2274797065223A226C6F6E67222C2276616C7565223A223630303030227D2C7B22636F6D6D656E74223A2276616C69646174696F6E5175657279222C226E616D65223A2276616C69646174696F6E5175657279222C227265717569726564223A66616C73652C2274797065223A226A6176612E6C616E672E537472696E67222C2276616C7565223A2273656C656374202A2066726F6D204143545F47455F50524F5045525459227D2C7B22636F6D6D656E74223A22746573744F6E426F72726F77222C226E616D65223A22746573744F6E426F72726F77222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2266616C7365227D2C7B22636F6D6D656E74223A22746573744F6E52657475726E222C226E616D65223A22746573744F6E52657475726E222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2266616C7365227D2C7B22636F6D6D656E74223A22746573745768696C6549646C65222C226E616D65223A22746573745768696C6549646C65222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D2C7B22636F6D6D656E74223A22706F6F6C507265706172656453746174656D656E7473222C226E616D65223A22706F6F6C507265706172656453746174656D656E7473222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D2C7B22636F6D6D656E74223A226D6178506F6F6C507265706172656453746174656D656E74506572436F6E6E656374696F6E53697A65222C226E616D65223A226D6178506F6F6C507265706172656453746174656D656E74506572436F6E6E656374696F6E53697A65222C227265717569726564223A66616C73652C2274797065223A22696E74222C2276616C7565223A223230227D2C7B22636F6D6D656E74223A2266696C74657273222C226E616D65223A2266696C74657273222C227265717569726564223A66616C73652C2274797065223A226A6176612E7574696C2E4C697374222C2276616C7565223A2273746174227D2C7B22636F6D6D656E74223A2274696D654265747765656E4576696374696F6E52756E734D696C6C6973222C226E616D65223A2274696D654265747765656E4576696374696F6E52756E734D696C6C6973222C227265717569726564223A66616C73652C2274797065223A226C6F6E67222C2276616C7565223A223630303030227D2C7B22636F6D6D656E74223A226D696E457669637461626C6549646C6554696D654D696C6C6973222C226E616D65223A226D696E457669637461626C6549646C6554696D654D696C6C6973222C227265717569726564223A66616C73652C2274797065223A226C6F6E67222C2276616C7565223A22333030303030227D2C7B22636F6D6D656E74223A2272656D6F76654162616E646F6E6564222C226E616D65223A2272656D6F76654162616E646F6E6564222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D2C7B22636F6D6D656E74223A2272656D6F76654162616E646F6E656454696D656F75744D696C6C6973222C226E616D65223A2272656D6F76654162616E646F6E656454696D656F75744D696C6C6973222C227265717569726564223A66616C73652C2274797065223A226C6F6E67222C2276616C7565223A223630303030227D2C7B22636F6D6D656E74223A226C6F674162616E646F6E6564222C226E616D65223A226C6F674162616E646F6E6564222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D2C7B22636F6D6D656E74223A2275726C222C226E616D65223A2275726C222C227265717569726564223A66616C73652C2274797065223A226A6176612E6C616E672E537472696E67222C2276616C7565223A2231323132227D2C7B22636F6D6D656E74223A22627265616B4166746572416371756972654661696C757265222C226E616D65223A22627265616B4166746572416371756972654661696C757265222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D5D, 1);
INSERT INTO sys_data_source VALUES (‘683084205604732928’, ‘1’, ‘1’, ‘’, ‘MYSQL’, NULL, 0x5B7B22636F6D6D656E74223A22757365726E616D65222C226E616D65223A22757365726E616D65222C227265717569726564223A66616C73652C2274797065223A226A6176612E6C616E672E537472696E67222C2276616C7565223A22323332726F6F74227D2C7B22636F6D6D656E74223A2270617373776F7264222C226E616D65223A2270617373776F7264222C227265717569726564223A66616C73652C2274797065223A226A6176612E6C616E672E537472696E67222C2276616C7565223A22726F6F74227D2C7B22636F6D6D656E74223A22696E697469616C53697A65222C226E616D65223A22696E697469616C53697A65222C227265717569726564223A66616C73652C2274797065223A22696E74222C2276616C7565223A223130227D2C7B22636F6D6D656E74223A226D6178416374697665222C226E616D65223A226D6178416374697665222C227265717569726564223A66616C73652C2274797065223A22696E74222C2276616C7565223A22313030227D2C7B22636F6D6D656E74223A226D696E49646C65222C226E616D65223A226D696E49646C65222C227265717569726564223A66616C73652C2274797065223A22696E74222C2276616C7565223A223130227D2C7B22636F6D6D656E74223A226D617857616974222C226E616D65223A226D617857616974222C227265717569726564223A66616C73652C2274797065223A226C6F6E67222C2276616C7565223A223630303030227D2C7B22636F6D6D656E74223A2276616C69646174696F6E5175657279222C226E616D65223A2276616C69646174696F6E5175657279222C227265717569726564223A66616C73652C2274797065223A226A6176612E6C616E672E537472696E67222C2276616C7565223A2273656C656374202A2066726F6D204143545F47455F50524F5045525459227D2C7B22636F6D6D656E74223A22746573744F6E426F72726F77222C226E616D65223A22746573744F6E426F72726F77222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2266616C7365227D2C7B22636F6D6D656E74223A22746573744F6E52657475726E222C226E616D65223A22746573744F6E52657475726E222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2266616C7365227D2C7B22636F6D6D656E74223A22746573745768696C6549646C65222C226E616D65223A22746573745768696C6549646C65222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D2C7B22636F6D6D656E74223A22706F6F6C507265706172656453746174656D656E7473222C226E616D65223A22706F6F6C507265706172656453746174656D656E7473222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D2C7B22636F6D6D656E74223A226D6178506F6F6C507265706172656453746174656D656E74506572436F6E6E656374696F6E53697A65222C226E616D65223A226D6178506F6F6C507265706172656453746174656D656E74506572436F6E6E656374696F6E53697A65222C227265717569726564223A66616C73652C2274797065223A22696E74222C2276616C7565223A223230227D2C7B22636F6D6D656E74223A2266696C74657273222C226E616D65223A2266696C74657273222C227265717569726564223A66616C73652C2274797065223A226A6176612E7574696C2E4C697374222C2276616C7565223A2273746174227D2C7B22636F6D6D656E74223A2274696D654265747765656E4576696374696F6E52756E734D696C6C6973222C226E616D65223A2274696D654265747765656E4576696374696F6E52756E734D696C6C6973222C227265717569726564223A66616C73652C2274797065223A226C6F6E67222C2276616C7565223A223630303030227D2C7B22636F6D6D656E74223A226D696E457669637461626C6549646C6554696D654D696C6C6973222C226E616D65223A226D696E457669637461626C6549646C6554696D654D696C6C6973222C227265717569726564223A66616C73652C2274797065223A226C6F6E67222C2276616C7565223A22333030303030227D2C7B22636F6D6D656E74223A2272656D6F76654162616E646F6E6564222C226E616D65223A2272656D6F76654162616E646F6E6564222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D2C7B22636F6D6D656E74223A2272656D6F76654162616E646F6E656454696D656F75744D696C6C6973222C226E616D65223A2272656D6F76654162616E646F6E656454696D656F75744D696C6C6973222C227265717569726564223A66616C73652C2274797065223A226C6F6E67222C2276616C7565223A223630303030227D2C7B22636F6D6D656E74223A226C6F674162616E646F6E6564222C226E616D65223A226C6F674162616E646F6E6564222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D2C7B22636F6D6D656E74223A2275726C222C226E616D65223A2275726C222C227265717569726564223A66616C73652C2274797065223A226A6176612E6C616E672E537472696E67222C2276616C7565223A2231323132227D2C7B22636F6D6D656E74223A22627265616B4166746572416371756972654661696C757265222C226E616D65223A22627265616B4166746572416371756972654661696C757265222C227265717569726564223A66616C73652C2274797065223A22626F6F6C65616E222C2276616C7565223A2274727565227D5D, 1);
COMMIT;

— ——————————————
— Table structure for sysdata_source_def
— ——————————————
DROP TABLE IF EXISTS sys_data_source_def;
CREATE TABLE sys_data_source_def (
`id
varchar(255) COLLATE utf8_bin NOT NULL COMMENT '主键',<br />namevarchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '名称',<br />class_pathvarchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '类路径',<br />attributesjsonlongblob COMMENT '属性',<br />DELETEDtinyint(1) DEFAULT NULL COMMENT '是否已删,1已删除,0未删除',<br />systemtinyint(1) DEFAULT NULL COMMENT '是否是系统的',<br /> PRIMARY KEY (id_`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT=’连接池’;

— ——————————————
— Records of sys_data_source_def
— ——————————————
BEGIN;
INSERT INTO sys_data_source_def VALUES (‘1’, ‘DURID数据源 ‘, ‘com.alibaba.druid.pool.DruidDataSource’, 0x5B7B226E616D65223A22757365726E616D65222C22636F6D6D656E74223A22757365726E616D65222C2274797065223A226A6176612E6C616E672E537472696E67222C226261736541747472223A2231222C2264656661756C74223A22726F6F74227D2C7B226E616D65223A2270617373776F7264222C22636F6D6D656E74223A2270617373776F7264222C2274797065223A226A6176612E6C616E672E537472696E67222C226261736541747472223A2231222C2264656661756C74223A22726F6F74227D2C7B226E616D65223A22696E697469616C53697A65222C22636F6D6D656E74223A22696E697469616C53697A65222C2274797065223A22696E74222C226261736541747472223A2231222C2264656661756C74223A223130227D2C7B226E616D65223A226D6178416374697665222C22636F6D6D656E74223A226D6178416374697665222C2274797065223A22696E74222C226261736541747472223A2231222C2264656661756C74223A22313030227D2C7B226E616D65223A226D696E49646C65222C22636F6D6D656E74223A226D696E49646C65222C2274797065223A22696E74222C226261736541747472223A2231222C2264656661756C74223A223130227D2C7B226E616D65223A226D617857616974222C22636F6D6D656E74223A226D617857616974222C2274797065223A226C6F6E67222C226261736541747472223A2231222C2264656661756C74223A223630303030227D2C7B226E616D65223A2276616C69646174696F6E5175657279222C22636F6D6D656E74223A2276616C69646174696F6E5175657279222C2274797065223A226A6176612E6C616E672E537472696E67222C226261736541747472223A2231222C2264656661756C74223A2273656C656374202A2066726F6D204143545F47455F50524F5045525459227D2C7B226E616D65223A22746573744F6E426F72726F77222C22636F6D6D656E74223A22746573744F6E426F72726F77222C2274797065223A22626F6F6C65616E222C226261736541747472223A2231222C2264656661756C74223A2266616C7365227D2C7B226E616D65223A22746573744F6E52657475726E222C22636F6D6D656E74223A22746573744F6E52657475726E222C2274797065223A22626F6F6C65616E222C226261736541747472223A2231222C2264656661756C74223A2266616C7365227D2C7B226E616D65223A22746573745768696C6549646C65222C22636F6D6D656E74223A22746573745768696C6549646C65222C2274797065223A22626F6F6C65616E222C226261736541747472223A2231222C2264656661756C74223A2274727565227D2C7B226E616D65223A22706F6F6C507265706172656453746174656D656E7473222C22636F6D6D656E74223A22706F6F6C507265706172656453746174656D656E7473222C2274797065223A22626F6F6C65616E222C226261736541747472223A2231222C2264656661756C74223A2274727565227D2C7B226E616D65223A226D6178506F6F6C507265706172656453746174656D656E74506572436F6E6E656374696F6E53697A65222C22636F6D6D656E74223A226D6178506F6F6C507265706172656453746174656D656E74506572436F6E6E656374696F6E53697A65222C2274797065223A22696E74222C226261736541747472223A2231222C2264656661756C74223A223230227D2C7B226E616D65223A2266696C74657273222C22636F6D6D656E74223A2266696C74657273222C2274797065223A226A6176612E7574696C2E4C697374222C226261736541747472223A2231222C2264656661756C74223A2273746174227D2C7B226E616D65223A2274696D654265747765656E4576696374696F6E52756E734D696C6C6973222C22636F6D6D656E74223A2274696D654265747765656E4576696374696F6E52756E734D696C6C6973222C2274797065223A226C6F6E67222C226261736541747472223A2231222C2264656661756C74223A223630303030227D2C7B226E616D65223A226D696E457669637461626C6549646C6554696D654D696C6C6973222C22636F6D6D656E74223A226D696E457669637461626C6549646C6554696D654D696C6C6973222C2274797065223A226C6F6E67222C226261736541747472223A2231222C2264656661756C74223A22333030303030227D2C7B226E616D65223A2272656D6F76654162616E646F6E6564222C22636F6D6D656E74223A2272656D6F76654162616E646F6E6564222C2274797065223A22626F6F6C65616E222C226261736541747472223A2231222C2264656661756C74223A2274727565227D2C7B226E616D65223A2272656D6F76654162616E646F6E656454696D656F75744D696C6C6973222C22636F6D6D656E74223A2272656D6F76654162616E646F6E656454696D656F75744D696C6C6973222C2274797065223A226C6F6E67222C226261736541747472223A2231222C2264656661756C74223A223630303030227D2C7B226E616D65223A226C6F674162616E646F6E6564222C22636F6D6D656E74223A226C6F674162616E646F6E6564222C2274797065223A22626F6F6C65616E222C226261736541747472223A2231222C2264656661756C74223A2274727565227D2C7B226973416464223A747275652C226E616D65223A2275726C222C22636F6D6D656E74223A2275726C222C2274797065223A226A6176612E6C616E672E537472696E67222C226261736541747472223A2231222C2264656661756C74223A22227D2C7B226973416464223A747275652C226E616D65223A22627265616B4166746572416371756972654661696C757265222C22636F6D6D656E74223A22627265616B4166746572416371756972654661696C757265222C2274797065223A22626F6F6C65616E222C226261736541747472223A2231222C2264656661756C74223A2274727565227D5D, 0, 1);
COMMIT;
————————————————
image.png
在flowable6.3以后的版本中,支持了MULTI_INSTANCE_ACTIVITY_COMPLETED_WITH_CONDITION事件,这个事件顾名思义就是在多实例节点完成的时候,flowable引擎去发布这个完成事件信号。该事件同其他的事件一样,定义在FlowableEngineEventType.java类中。
关于多实例所支持的事件类型如下所示:

MULTI_INSTANCE_ACTIVITY_COMPLETED(多实例完成),
MULTI_INSTANCE_ACTIVITY_COMPLETED_WITH_CONDITION(多实例正常完成),
MULTI_INSTANCE_ACTIVITY_CANCELLED(多实例取消),

不管是什么事件,我们在开发的过程中往往只会关心事件的类型以及事件所产生的数据而已。现在既然我们知道了新增的事件类型是

MULTI_INSTANCE_ACTIVITY_COMPLETED,
MULTI_INSTANCE_ACTIVITY_COMPLETED_WITH_CONDITION,
MULTI_INSTANCE_ACTIVITY_CANCELLED,

三个,那接下来,我们看一下这些事件所对应的事件处理类,具体细节在AbstractFlowableEngineEventListener类中如下所示:

  1. case MULTI_INSTANCE_ACTIVITY_COMPLETED:
  2. multiInstanceActivityCompleted((FlowableMultiInstanceActivityCompletedEvent) flowableEngineEvent);
  3. break;
  4. case MULTI_INSTANCE_ACTIVITY_COMPLETED_WITH_CONDITION:
  5. multiInstanceActivityCompletedWithCondition((FlowableMultiInstanceActivityCompletedEvent) flowableEngineEvent);
  6. break;
  7. case MULTI_INSTANCE_ACTIVITY_CANCELLED:
  8. multiInstanceActivityCancelled((FlowableMultiInstanceActivityCancelledEvent) flowableEngineEvent)
  9. protected void multiInstanceActivityCompleted(FlowableMultiInstanceActivityEvent event) {}
  10. protected void multiInstanceActivityCompleted(FlowableMultiInstanceActivityCompletedEvent event) {}
  11. protected void multiInstanceActivityCompletedWithCondition(FlowableMultiInstanceActivityCompletedEvent event) {}
  12. protected void multiInstanceActivityCancelled(FlowableMultiInstanceActivityCancelledEvent event) {}

MULTI_INSTANCE_ACTIVITY_COMPLETED事件对应的事件类为:
FlowableMultiInstanceActivityCompletedEvent

MULTI_INSTANCE_ACTIVITY_COMPLETED_WITH_CONDITION事件对应的事件类为:FlowableMultiInstanceActivityCompletedEvent。

MULTI_INSTANCE_ACTIVITY_CANCELLED事件对应的事件类为:
FlowableMultiInstanceActivityCancelledEvent。

由上面的源码可以知道 MULTI_INSTANCE_ACTIVITY_COMPLETED与MULTI_INSTANCE_ACTIVITY_COMPLETED_WITH_CONDITION事件对应的事件类是相同的,都是FlowableMultiInstanceActivityCompletedEvent。

MULTI_INSTANCE_ACTIVITY_CANCELLED事件对应的事件类为:
FlowableMultiInstanceActivityCancelledEvent。

通过FlowableMultiInstanceActivityCompletedEvent类我们可以获取到的属性信息如下:

numberOfInstances(多实例的个数)
numberOfActiveInstances(多实例活动的个数)
numberOfCompletedInstances(多实例已经完成的活动个数)

Flowable数据表清单:

Flowable的所有数据库表都以ACT开头。第二部分是说明表用途的两字符标示符。服务API的命名也大略符合这个规则。
ACT_RE
: ‘RE’代表 repository 。带有这个前缀的表包含“静态”信息,例如流程定义与流程资源(图片、规则等)。
ACTRU
: ‘RU’代表 runtime 。这些表存储运行时信息,例如流程实例(process instance)、用户任务(user task)、变量
(variable)、作业(job)等。Activiti只在流程实例运行中保存运行时数据,并在流程实例结束时删除记录。这样保证运行时表小和
快。
ACTID: ‘ID’代表 identity 。这些表包含身份信息,例如用户、组等。
ACTHI
: ‘HI’代表 history 。这些表存储历史数据,例如已完成的流程实例、变量、任务等。
ACTGE*: 通用数据。用于不同场景下。

ACTEVT*:事件表。主要存放事件信息和事件日志等。

ACTPROCDEF*:流程定义表,流程定义历史更新数据。

flowable camunda activiti对比

flowable camunda activiti 三个框架都是从jbpm框架诞生出来的,先是有jbpm4,然后出来了一个activiti5,activiti5发展一段时间,又出来了一个Camunda。activiti5发展了4年,紧接着出来了一个flowable。本文重点对flowable camunda两个框架的功能对比。对比的camunda版本是7.10.0,flowable框架的版本是6.4.1.

设计器对比
camunda有一个eclipse插件设计器,还有一个独立的modler设计器,有基于BS的,也有基于CS的。用于绘制BPMN/CMMN/DMN引擎需要的流程文档。

flowable只有个eclipse插件设计器,目前只能绘制5版本的流程,6版本新增加的节点以及属性无法绘制。本质上就是activiti5 eclipse插件,只是换了一个图标;在线web设计器基于angularjs1.x版本开发的。
camunda设计器如下:
image.png

flowable设计器如下:
image.png
小结
camunda设计器既可以面向业务人员,又可以面向开发人员。

flowable设计器仅面向专业开发人员。

支持的数据库对比
camunda支持的数据库
MySQL 5.6 / 5.7
MariaDB 10.0 / 10.2 / 10.3
Oracle 10g / 11g / 12c
IBM DB2 9.7 /10.1 / 10.5 / 11.1 (excluding IBM z/OS for all versions)
PostgreSQL 9.1 / 9.3 / 9.4 / 9.6 / 10.4
Microsoft SQL Server 2008 R2/2012/2014/2016 (see Configuration Note)
H2 1.4 (not recommended for Cluster Mode - see Deployment Note)
Flowable支持的数据库
MySQL 5.6 / 5.7
Oracle 10g / 11g / 12c
IBM DB2 9.7 /10.1 / 10.5 / 11.1 (excluding IBM z/OS for all versions)
PostgreSQL 9.1 / 9.3 / 9.4 / 9.6 / 10.4
Microsoft SQL Server 2008 R2/2012/2014/2016 (see Configuration Note)
H2 1.4 (not recommended for Cluster Mode - see Deployment Note)
小结
flowable暂时不支持MariaDB。

运行容器对比
camunda支持的运行容器
Apache Tomcat 7.0 / 8.0 / 9.0
JBoss Application Server 7.2 and JBoss EAP 6.1 / 6.2 / 6.3 / 6.4 / 7.0 / 7.1
Wildfly Application Server 8.2 / 10.1 / 11.0 / 12.0 / 13.0 / 14.0
IBM WebSphere Application Server 8.5 / 9.0 (Enterprise Edition only)
Oracle WebLogic Server 12c (12R1,12R2) (Enterprise Edition only)
Spring Boot application with embedded Tomcat (see Supported versions and Deployment scenarios)
flowable支持的运行容器
Apache Tomcat 7.0 / 8.0 / 9.0
Oracle WebLogic Server 12c (12R1,12R2) (Enterprise Edition only)
小结
flowable框架不支持运行在JBoss、Wildfly之类的容器之上。官方目前也没有开发计划。

框架兼容其他workflow情况
camunda兼容其他workflow情况
Active BPEL
Alfresco Activiti
Appian BPM
Bonitasoft
JBoss jBPM
IBM WPS / IBM BPM / IBM MQ Workflow / IBM Lotus Notes
Oracle BPM
Software AG Webmethods
Pega BPM
flowable兼容其他workflow情况
Alfresco Activiti5
Flowable5
小结
因为flowable去除了PVM,目前只有兼容activiti5的程序包,关于其他基于pvm开发的流程引擎统统不兼容。

功能对比
由于Flowable与Camunda好多功能都是类似的,因此在这里重点罗列差异化的功能

camunda支持流程实例的迁移,比如同一个流程有多个实例,多个流程版本,不同流程实例运行在不同的版本中,camunda支持任意版本的实例迁移到指定的流程版本中,并可以在迁移的过程中支持从哪个节点开始。
camunda基于PVM技术,所以用户从Activii5迁移到camunda基本上毫无差异。flowable没有pvm了,所以迁移工作量更大(实例的迁移,流程定义的迁移、定时器的迁移都非常麻烦)。
camunda对于每一个CMD命令类都提供了权限校验机制,flowable没有。
camunda继续每一个API都有批处理的影子,flowable几乎没有。比如批量挂起流程、激活流程等,使用camunda可以直接使用API操作,使用Flowable则只能自己去查询集合,然后循环遍历集合并操作。
camunda很多API均支持批处理,在批量处理的时候可以指定是异步方式操作或者是同步方式操作。异步的话定时器会去执行。Flowable没有异步批处理的机制。比如批量异步删除所有的历史数据。
camunda启动实例的时候支持从哪个节点开始,而不是仅仅只能从开始节点运转实例。Flowable仅仅只能从开始节点运转实例。
camunda支持任意节点的跳转,可以跳转到连线也可以跳转到节点,并且在跳转的过程中支持是否触发目标节点的监听器。flowable没有改原生API需用户去扩展。
camunda支持链式生成流程,比如

  1. Bpmn.createExecutableProcess(PROCESS_KEY)
  2. .camundaHistoryTimeToLive(5)
  3. .startEvent()
  4. .userTask()
  5. .endEvent().done(); flowable不支持。

camunda支持双异步机制,第一个异步即节点可以异步执行,第二个异步方式是:完成异步任务后,还可以继续异步去执行任务后面的连线。所以称之为双异步机制,flowable只有第一种异步方式。
camunda支持多种脚本语言,这些脚本语言可以在连线上进行条件表达式的配置,开箱即用。比如python、ruby、groovy、JUEL。flowable仅仅支持JUEL、groovy。开箱即用的意思就是如果想用python直接引入jython包就可以用了,不需要额外配置。
camunda支持外部任务,比如我们有时候想在一个节点中执行调用第三方的API或者完成一些特定的逻辑操作,就可以使用外部任务,外部任务有两种表,并支持第三方系统定期来抓取并锁定外部任务,然后执行业务完毕之后,完成外部任务,流程实例继续往下执行。外部任务的好处就是解决了分布式事物的问题。在flowable中我们可以使用httpTask任务,我个人更倾向于camunda外部任务,因为这个外部任务有外部系统决定什么时候完成,httpTask是不等待任务,实例走到这个节点之后,调用一个api就直接往下跑了,外部任务不会继续往下跑,有外部系统去决定啥时候往下跑。
camunda支持为用户定制一些个性化的偏好查找API,比如张三每次查询任务的时候,一般固定点击某某三个查询条件过滤数据,使用camunda就可以将这三个查询条件进行持久化,下次张三来了,就可以直接根据他的偏好进行数据的过滤,类似机器学习。
camunda支持历史数据的批量删除或者批量迁移到其他介质,比如批量迁移到es,flowable没有该机制。
camunda支持在高并发部署流程的时候,是否使用锁机制,flowable没有该机制。
camunda支持单引擎多组合、多引擎多库。flowable仅仅支持单引擎多组合。
camunda支持流程实例跨流程定义跳转,flowable没有该机制。
camunda支持分布式定时器,flowable没有该机制。
flowable支持nosql,camunda只有nosql的解决方案。
camunda支持优化流程,以及了解流程引擎的瓶颈所在和每个环节的耗时,flowable没有该机制。
camunda修改了流程模板xml解析方式,相比flowable性能更好。
camunda在解析流程模板xml的时候,去除了activiti5的双解析机制,相对而言耗时时间更短。flowable没有了pvm所以规避了双解析机制。关于双解析机制可以参考《Activiti权威指南》一书。
camunda可以在任意节点添加任意的属性,flowable原生API没有,需要自己扩展。
camunda框架没有为流程生成图片的API(所有流程图展示以及高亮均在前端动态计算),activiti5/6/flowable5/flowable6有图片生成以及高亮的API.
camunda可以在节点中定义定时作业的优先级,也可以在流程中进行全局优先级的定义。当节点没有定义优先级的时候可以使用全局的优先级字段。activiti5/6/flowable5/flowable6没有改功能。
camunda可以再流程中定义流程的tag标记,activiti5/6/flowable5/flowable6没有改功能。
camunda/activiti5/6/flowable5/flowable6 均不支持国产数据库,比如人大金仓 和 达梦。
flowable6支持LDAP,openLDAP,camunda不支持。activiti5不支持。

Activiti增加的子流程

flowable和Activiti6新增了ad-hoc子流程(adHocSubProcess),即adHocSubProcess流程。该类型的子流程无需再子流程中为节点配置任何的出线:
runtimeService.getEnabledActivitiesFromAdhocSubProcess(executionId);
runtimeService.executeActivityInAdhocSubProcess(executionId, id);
runtimeService.completeAdhocSubProcess(executionId);

Activiti加Redis

  1. import org.activiti.engine.impl.persistence.deploy.DeploymentCache;
  2. import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.data.redis.core.StringRedisTemplate;
  5. import java.io.*;
  6. public class ShareniuProcessDefinitionCache implements DeploymentCache<ProcessDefinitionEntity> {
  7. @Autowired
  8. private StringRedisTemplate stringRedisTemplate;
  9. public ProcessDefinitionEntity get(String id) {
  10. String bs = stringRedisTemplate.opsForValue().get(id);
  11. if (bs == null) return null;
  12. //将二进制数据转换为ProcessDefinitionEntity对象
  13. Object object = toObject(bs);
  14. if (object == null) return null;
  15. return (ProcessDefinitionEntity) object;
  16. }
  17. public void add(String id, ProcessDefinitionEntity object) {
  18. //添加到缓存,因为value为object对象,所以需要将该对象转化为二进制进行存储
  19. stringRedisTemplate.opsForValue().set(id, toByteArray(object));
  20. }
  21. public void remove(String id) {
  22. //删除制定的key
  23. stringRedisTemplate.delete(id);
  24. }
  25. public void clear() {
  26. //清除所有的数据,在这里默认不提供实现,避免误操作
  27. }
  28. public static byte[] toByteArray(Object obj) {
  29. byte[] bytes = null;
  30. try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos)) {
  31. oos.writeObject(obj);
  32. oos.flush();
  33. bytes = bos.toByteArray();
  34. } catch (IOException ex) {
  35. }
  36. return bytes;
  37. }
  38. public static Object toObject(byte[] bytes) {
  39. Object obj = null;
  40. try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bis);){
  41. obj = ois.readObject();
  42. } catch (Exception e) {
  43. }
  44. return obj;
  45. }
  46. }

ProcessDefinitionInfoCache.java

  1. protected Map<String, ProcessDefinitionInfoCacheObject> cache;
  2. protected CommandExecutor commandExecutor;
  3. public ProcessDefinitionInfoCache(CommandExecutor commandExecutor) {
  4. this.commandExecutor = commandExecutor;
  5. this.cache = new HashMap<String, ProcessDefinitionInfoCacheObject>();
  6. }
  7. public ProcessDefinitionInfoCache(CommandExecutor commandExecutor, final int limit) {
  8. this.commandExecutor = commandExecutor;
  9. this.cache = Collections.synchronizedMap(new LinkedHashMap<String, ProcessDefinitionInfoCacheObject>(limit + 1, 0.75f, true) {
  10. private static final long serialVersionUID = 1L;
  11. protected boolean removeEldestEntry(Map.Entry<String, ProcessDefinitionInfoCacheObject> eldest) {
  12. boolean removeEldest = size() > limit;
  13. return removeEldest;
  14. }
  15. });
  16. }
  17. public ProcessDefinitionInfoCacheObject get(final String processDefinitionId) {
  18. ProcessDefinitionInfoCacheObject infoCacheObject = null;
  19. if (cache.containsKey(processDefinitionId)) {
  20. infoCacheObject = commandExecutor.execute(new Command<ProcessDefinitionInfoCacheObject>() {
  21. public ProcessDefinitionInfoCacheObject execute(CommandContext commandContext) {
  22. ProcessDefinitionInfoEntityManager infoEntityManager = commandContext.getProcessDefinitionInfoEntityManager();
  23. ObjectMapper objectMapper = commandContext.getProcessEngineConfiguration().getObjectMapper();
  24. ProcessDefinitionInfoCacheObject cacheObject = cache.get(processDefinitionId);
  25. ProcessDefinitionInfoEntityinfoEntity=infoEntityManager.findProcessDefinitionInfoByProcessDefinitionId(processDefinitionId);
  26. if (infoEntity != null && infoEntity.getRevision() != cacheObject.getRevision()) {
  27. cacheObject.setRevision(infoEntity.getRevision());
  28. if (infoEntity.getInfoJsonId() != null) {
  29. byte[] infoBytes = infoEntityManager.findInfoJsonById(infoEntity.getInfoJsonId());
  30. try {
  31. ObjectNode infoNode = (ObjectNode) objectMapper.readTree(infoBytes);
  32. cacheObject.setInfoNode(infoNode);
  33. } catch (Exception e) {}
  34. }
  35. } else if (infoEntity == null) { #-9
  36. cacheObject.setRevision(0);
  37. cacheObject.setInfoNode(objectMapper.createObjectNode());
  38. }
  39. return cacheObject;
  40. }
  41. });
  42. }
  43. return infoCacheObject;
  44. }

activiti跳转

  1. import java.util.Iterator;
  2. import java.util.Map;
  3. import org.activiti.engine.impl.context.Context;
  4. import org.activiti.engine.impl.interceptor.Command;
  5. import org.activiti.engine.impl.interceptor.CommandContext;
  6. import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
  7. import org.activiti.engine.impl.persistence.entity.ExecutionEntityManager;
  8. import org.activiti.engine.impl.persistence.entity.TaskEntity;
  9. import org.activiti.engine.impl.pvm.process.ActivityImpl;
  10. /**
  11. * JD节点的跳转
  12. * 分享牛原创(尊重原创 转载对的时候第一行请注明,转载出处来自分享牛http://blog.csdn.net/qq_30739519)
  13. */
  14. public class JumpTaskCmd implements Command<Void> {
  15. protected String executionId;
  16. protected ActivityImpl desActivity;
  17. protected Map<String, Object> objectMap;
  18. protected ActivityImpl currentActivity;
  19. /**
  20. * http://blog.csdn.net/qq_30739519
  21. */
  22. public Void execute(CommandContext commandContext) {
  23. ExecutionEntityManager executionEntityManager = Context
  24. .getCommandContext().getExecutionEntityManager();
  25. // 获取当前流程的executionId,因为在并发的情况下executionId是唯一的。
  26. ExecutionEntity executionEntity = executionEntityManager
  27. .findExecutionById(executionId);
  28. executionEntity.setVariables(objectMap);
  29. executionEntity.setEventSource(this.currentActivity);
  30. executionEntity.setActivity(this.currentActivity);
  31. // 根据executionId 获取Task
  32. Iterator<TaskEntity> localIterator = Context.getCommandContext()
  33. .getTaskEntityManager()
  34. .findTasksByExecutionId(this.executionId).iterator();
  35. while (localIterator.hasNext()) {
  36. TaskEntity taskEntity = localIterator.next();
  37. // 触发任务监听
  38. taskEntity.fireEvent("complete");
  39. // 删除任务的原因
  40. Context.getCommandContext().getTaskEntityManager()
  41. .deleteTask(taskEntity, "completed", false);
  42. }
  43. executionEntity.executeActivity(this.desActivity);
  44. return null;
  45. }
  46. /**
  47. * 构造参数 可以根据自己的业务需要添加更多的字段
  48. * 分享牛原创(尊重原创 转载对的时候第一行请注明,转载出处来自分享牛http://blog.csdn.net/qq_30739519)
  49. *
  50. * @param executionId
  51. * @param desActivity
  52. * @param objectMap
  53. * @param currentActivity
  54. */
  55. public JumpTaskCmd(String executionId, ActivityImpl desActivity,
  56. Map<String, Object> objectMap, ActivityImpl currentActivity) {
  57. this.executionId = executionId;
  58. this.desActivity = desActivity;
  59. this.objectMap = objectMap;
  60. this.currentActivity = currentActivity;
  61. }
  62. }
  63. import org.activiti.engine.ManagementService;
  64. import org.activiti.engine.ProcessEngine;
  65. import org.activiti.engine.RepositoryService;
  66. import org.activiti.engine.TaskService;
  67. import org.activiti.engine.impl.pvm.ReadOnlyProcessDefinition;
  68. import org.activiti.engine.impl.pvm.process.ActivityImpl;
  69. import org.springframework.beans.factory.annotation.Autowired;
  70. import org.springframework.stereotype.Service;
  71. import java.util.Collections;
  72. import java.util.HashMap;
  73. import java.util.Map;
  74. @Service
  75. public class JumpService {
  76. @Autowired
  77. private TaskService taskService;
  78. @Autowired
  79. private ProcessEngine processEngine;
  80. /**
  81. * 任务id
  82. * @param processDefinitionId
  83. * @param staffCode 跳转执行人
  84. * @param executionId 执行id
  85. * @param toActivityId 目标节点
  86. * @param fromActivityId 当前节点
  87. */
  88. public void Jump(String processDefinitionId, String staffCode, String executionId, String toActivityId, String fromActivityId) {
  89. ManagementService managementService = processEngine.getManagementService();
  90. Map<String, Object> vars = new HashMap<>();
  91. vars.put("assigneeList", Collections.singletonList("U_" + staffCode));
  92. RepositoryService repositoryService = processEngine.getRepositoryService();
  93. ReadOnlyProcessDefinition processDefinitionEntity = (ReadOnlyProcessDefinition) repositoryService.getProcessDefinition(processDefinitionId);
  94. // 目标节点
  95. ActivityImpl destinationActivity = (ActivityImpl) processDefinitionEntity.findActivity(toActivityId);
  96. // 当前节点
  97. ActivityImpl currentActivity = (ActivityImpl) processDefinitionEntity.findActivity(fromActivityId);
  98. managementService.executeCommand(new JumpTaskCmd(executionId, destinationActivity, vars, currentActivity));
  99. }
  100. }

DMN开源框架

  1. 盘古BPM工作流平台(DMN)是国内首款开源的互联网决策引擎系统,可以无缝对接Activiti/Flowable/Zeebe/Drools等多种工作流系统。拥有独立的DMN1.3标准设计器、解析器、决策引擎、支持决策表(decision table)、DRDDRG。目标是打造一款集成主流工作流且轻量易用的DMN决策引擎系统,满足互联网业务系统以及工作流系统打通决策管理等功能。<br />码云地址:[https://gitee.com/pangu-dm/pangubpm-dmn](https://gitee.com/pangu-dm/pangubpm-dmn)<br />主要特点:

轻量级,通用;

无缝对接Activiti/Flowable/Zeebe等多种工作流系统,满足大部分企业业务系统的决策需求;
独立的决策引擎系统,为下游商业务平台提供统一决策接入接口,轻松实现统一决策接入;
项目代码免费开源且定期更新维护,扩展自由、使用无忧;
配套完善的系统使用文档、部署文档、视频教程,学习使用更轻松;
拥有活跃的产品技术学习交流社群,学习交流更高效;
由专业的BPM/DMN/CMMN系统产品技术团队提供服务支持,专业性及持续性有保障;
项目结构

├── feel-api //feel-api接口定义板块
├── feel-juel //feel-api接口定义实现板块
├── logging //日志板块
├── pangu-dmn-examples //demo使用
├── pangu-dmn-modeler //设计器
├── pangu-xml-model //DMN1.3 对应的实体包
├── typed-values //变量相关工具包
└── utils //通用工具包
盘古DMN开源框架与市面上DMN框架区别1(DMN标准实现情况)

框架 决策表(Decision table) DRD DRG DMN1.3标准 inputData knowledgeSource businessKnowledgeModel literalExpression
盘古DMN ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Activiti5 ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
Activiti6 ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
Activiti7 ✅ ❌ ❌ ❌ ❌ ❌ ❌ ❌
Flowable ✅ ❌ ❌ ✅ ❌ ❌ ❌ ❌
Zeebe ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
Drools ✅ ✅ ✅ ❌ ❌ ✅ ❌ ✅
盘古DMN开源框架与市面上DMN框架区别2(支持的脚本语言)

框架 JavaScript JRuby Groovy Python FEEL UEL
盘古DMN ✅ ✅ ✅ ✅ ✅ ✅
Activiti5 ✅ ✅ ✅ ✅ ❌ ✅
Activiti6 ✅ ✅ ✅ ✅ ❌ ✅
Activiti7 ✅ ✅ ✅ ✅ ❌ ✅
Flowable ✅ ✅ ✅ ✅ ❌ ✅
Zeebe ❌ ❌ ❌ ❌ ❌ ❌
Drools ✅ ✅ ✅ ✅ ✅ ✅

盘古DMN开源框架与市面上DMN框架区别3(计算策略)

框架 UNIQUE FIRST PRIORITY ANY COLLECT RULE ORDER OUTPUT ORDER
盘古DMN ✅ ✅ ✅ ✅ ✅ ✅ ✅
Activiti5 ❌ ❌ ❌ ❌ ❌ ❌ ❌
Activiti6 ✅ ✅ ✅ ✅ ✅ ❌ ❌
Activiti7 ✅ ✅ ✅ ✅ ✅ ❌ ❌
Flowable ✅ ✅ ✅ ✅ ✅ ✅ ❌
Zeebe ❌ ❌ ❌ ❌ ❌ ❌ ❌
Drools ✅ ✅ ✅ ✅ ✅ ✅扩展形式) ✅(扩展形式)
盘古DMN开源框架与市面上DMN框架区别4(可扩展性)

框架 是否可以独立运行
盘古DMN ✅
Activiti5 ❌(没有实现DMN)
Activiti6 ❌(绑定在modler后台,cmmn/bmn/dmn捆绑在一起使用)
Activiti7 ❌(暂时没有实现)
Flowable ❌(绑定在modler后台,cmmn/bmn/dmn捆绑在一起使用)
Zeebe ❌
Drools ❌(需要绑定CEP平台)

盘古DMN开源框架与市面上DMN框架区别5(设计器支持的前端语言)

框架 原生html+js vue
AngularJS

盘古DMN ✅ ✅ ✅
Activiti5 ❌ ❌ ❌
Activiti6 ❌ ❌ ✅
Activiti7 ❌ ❌ ✅
Flowable ❌ ❌ ✅
Zeebe ❌ ❌ ❌
Drools ❌ ❌ ✅
盘古DMN开源框架与市面上DMN框架区别6(组合其他标准,涵盖CMMN和BPM)

框架 CMMN BPM
盘古DMN ✅ ✅
Activiti5 ❌ ❌
Activiti6 ❌ ✅
Activiti7 ✅ ✅
Flowable ✅ ✅
Zeebe ❌ ❌
Drools ✅ ✅