compileflow-idea-designer是一款Idea插件。能够让你轻松完成compileflow引擎的流程的编码设计和属性编辑。

    compileflow引擎开源地址:https://github.com/alibaba/compileflow

    插件最新安装包下载,下载地址: https://github.com/compileflow/compileflow-designer-upgrade
    web界面:https://github.com/compileflow/compileflow-web-designer
    项目结构:
    image.png
    maven依赖:

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    4. <modelVersion>4.0.0</modelVersion>
    5. <parent>
    6. <groupId>org.springframework.boot</groupId>
    7. <artifactId>spring-boot-starter-parent</artifactId>
    8. <version>2.5.2</version>
    9. <relativePath/> <!-- lookup parent from repository -->
    10. </parent>
    11. <groupId>com.example</groupId>
    12. <artifactId>compileflow</artifactId>
    13. <version>0.0.1-SNAPSHOT</version>
    14. <name>compileflow</name>
    15. <description>Demo project for Spring Boot</description>
    16. <properties>
    17. <java.version>11</java.version>
    18. </properties>
    19. <dependencies>
    20. <dependency>
    21. <groupId>org.springframework.boot</groupId>
    22. <artifactId>spring-boot-starter-web</artifactId>
    23. </dependency>
    24. <dependency>
    25. <groupId>org.projectlombok</groupId>
    26. <artifactId>lombok</artifactId>
    27. <optional>true</optional>
    28. </dependency>
    29. <dependency>
    30. <groupId>org.springframework.boot</groupId>
    31. <artifactId>spring-boot-starter-test</artifactId>
    32. <scope>test</scope>
    33. </dependency>
    34. <dependency>
    35. <groupId>com.alibaba.compileflow</groupId>
    36. <artifactId>compileflow</artifactId>
    37. <version>1.0.0</version>
    38. </dependency>
    39. </dependencies>
    40. <build>
    41. <plugins>
    42. <plugin>
    43. <groupId>org.springframework.boot</groupId>
    44. <artifactId>spring-boot-maven-plugin</artifactId>
    45. <configuration>
    46. <excludes>
    47. <exclude>
    48. <groupId>org.projectlombok</groupId>
    49. <artifactId>lombok</artifactId>
    50. </exclude>
    51. </excludes>
    52. </configuration>
    53. </plugin>
    54. </plugins>
    55. </build>
    56. </project>

    代码使用:

    1. package com.example.compileflow.service;
    2. import com.alibaba.compileflow.engine.ProcessEngine;
    3. import com.alibaba.compileflow.engine.ProcessEngineFactory;
    4. import com.alibaba.compileflow.engine.definition.tbbpm.TbbpmModel;
    5. import com.alibaba.compileflow.engine.process.preruntime.converter.impl.TbbpmModelConverter;
    6. import com.ql.util.express.DefaultContext;
    7. import com.ql.util.express.ExpressRunner;
    8. import org.springframework.stereotype.Component;
    9. import java.io.OutputStream;
    10. import java.util.ArrayList;
    11. import java.util.HashMap;
    12. import java.util.List;
    13. import java.util.Map;
    14. /**
    15. * 参考:https://www.jianshu.com/p/a3ff29cf579d
    16. * 参考:https://www.jianshu.com/p/9bb2f01ad816
    17. */
    18. @Component
    19. public class RunCase {
    20. public void run() {
    21. //code在bpm文件中定义
    22. String code = "bpm.ktvExample";
    23. //执行流程的入参
    24. Map<String, Object> context = new HashMap<>(1);
    25. List<String> pList = new ArrayList<>();
    26. pList.add("wuxiang");
    27. pList.add("yusu");
    28. pList.add("xugong");
    29. pList.add("fandu");
    30. context.put("pList", pList);
    31. try {
    32. ProcessEngine processEngine = ProcessEngineFactory.getProcessEngine();
    33. Map<String, Object> result = processEngine.execute(code, context);
    34. System.out.println(result.get("price"));
    35. } catch (Exception e) {
    36. e.printStackTrace();
    37. }
    38. }
    39. public void run2() {
    40. //code在bpm文件中定义
    41. String code = "bpm.sqrt";
    42. //执行流程的入参
    43. Map<String, Object> context = new HashMap<>(1);
    44. context.put("num", 4);
    45. try {
    46. ProcessEngine processEngine = ProcessEngineFactory.getProcessEngine();
    47. Map<String, Object> result = processEngine.execute(code, context);
    48. System.out.println(result.get("numSqrt"));
    49. } catch (Exception e) {
    50. e.printStackTrace();
    51. }
    52. }
    53. public void getProcessEngine() {
    54. final String code = "bpm.ktv.ktvExample";
    55. final Map<String, Object> context = new HashMap<>(1);
    56. final List<String> pList = new ArrayList<>();
    57. pList.add("wuxiang");
    58. pList.add("xuan");
    59. pList.add("yusu");
    60. context.put("pList", pList);
    61. final ProcessEngine<TbbpmModel> processEngine = ProcessEngineFactory.getProcessEngine();
    62. final TbbpmModel tbbpmModel = processEngine.load(code);
    63. final OutputStream outputStream = TbbpmModelConverter.getInstance().convertToStream(tbbpmModel);
    64. System.out.println(outputStream);
    65. System.out.println(processEngine.getTestCode(code));
    66. processEngine.preCompile(code);
    67. System.out.println(processEngine.execute(code, context));
    68. }
    69. public void run3() {
    70. //code在bpm文件中定义
    71. String code = "bpm.ktvExample";
    72. //执行流程的入参
    73. Map<String, Object> context = new HashMap<>(1);
    74. List<String> pList = new ArrayList<>();
    75. pList.add("a1");
    76. pList.add("a2");
    77. pList.add("a3");
    78. pList.add("a4");
    79. pList.add("a5");
    80. pList.add("a6");
    81. pList.add("a7");
    82. pList.add("a8");
    83. pList.add("a9");
    84. pList.add("a10");
    85. pList.add("a11");
    86. context.put("pList", pList);
    87. try {
    88. ProcessEngine processEngine = ProcessEngineFactory.getProcessEngine();
    89. Map<String, Object> result = processEngine.execute(code, context);
    90. System.out.println(result.get("price"));
    91. } catch (Exception e) {
    92. e.printStackTrace();
    93. }
    94. }
    95. public void quick_start() throws Exception {
    96. ExpressRunner runner = new ExpressRunner();
    97. DefaultContext<String, Object> context = new DefaultContext<>();
    98. context.put("a", 1);
    99. context.put("b", 2);
    100. context.put("c", 3);
    101. //下面五个参数意义分别是 表达式,上下文,errorList,是否缓存,是否输出日志
    102. Object result = runner.execute("a+b+c", context, null, true, false);
    103. System.out.println("a+b+c=" + result);
    104. }
    105. }

    创建文件流程:
    image.png
    查看流程:
    image.png
    image.png
    其他操作方法:

    1. @Test
    2. public void testProcessEngine() {
    3. final String code = "bpm.ktv.ktvExample";
    4. final Map<String, Object> context = new HashMap<>();
    5. List<String> pList = new ArrayList<>();
    6. pList.add("wuxiang");
    7. pList.add("yusu");
    8. context.put("pList", pList);
    9. final ProcessEngine processEngine = ProcessEngineFactory.getProcessEngine();
    10. System.out.println(processEngine.getTestCode(code));
    11. System.out.println(processEngine.execute(code, context));
    12. }
    13. @Test
    14. public void testProcessEngineBpmn20() {
    15. final String code = "bpmn20.ktv.ktvExample";
    16. final Map<String, Object> context = new HashMap<>();
    17. List<String> pList = new ArrayList<>();
    18. pList.add("wuxiang");
    19. pList.add("yusu");
    20. context.put("pList", pList);
    21. final ProcessEngine processEngine = ProcessEngineFactory.getStatelessProcessEngine(FlowModelType.BPMN);
    22. System.out.println(processEngine.start(code, context));
    23. }
    24. @Test
    25. public void testTbbpmModelConvert() {
    26. // final String code = "bpm.ktv.ktvExample";
    27. String code = "bpm.om.waitpaySuccessflow";
    28. final ProcessEngine<TbbpmModel> processEngine = ProcessEngineFactory.getProcessEngine();
    29. final TbbpmModel tbbpmModel = processEngine.load(code);
    30. final OutputStream outputStream = TbbpmModelConverter.getInstance().convertToStream(tbbpmModel);
    31. System.out.println(outputStream.toString());
    32. final String srcCode = processEngine.getJavaCode(code);
    33. System.out.println(srcCode);
    34. }
    35. @Test
    36. public void testWaitPayProcess(){
    37. String code = "bpm.om.waitpaySuccessflow";
    38. System.out.println(ProcessEngineFactory.getProcessEngine().getJavaCode(code));
    39. Map<String, Object> context = new HashMap<>();
    40. context.put("num", 100d);
    41. ProcessEngineFactory.getProcessEngine().execute(code,context);
    42. }
    43. @Test
    44. public void testTiggerWaitPayProcess() {
    45. String code = "bpm.om.waitpaySuccessflow";
    46. Map<String, Object> context = new HashMap<>();
    47. context.put("num", 100d);
    48. StatefulProcessEngine processEngine = ProcessEngineFactory.getStatefulProcessEngine();
    49. try {
    50. System.out.println(processEngine.getJavaCode(code));
    51. System.out.println("------receiver not real event------");
    52. System.out.println(processEngine.trigger(code, "randomEvent", context));
    53. System.out.println("------receiver real event------");
    54. context.put("eventName","PaymentPendingCallback");
    55. System.out.println(processEngine.trigger(code, "PaymentPendingCallback", context));
    56. } catch (Exception e) {
    57. e.printStackTrace();
    58. Assert.fail(e.getMessage());
    59. }
    60. }
    61. @Test
    62. public void testStatefulProcessEngine() {
    63. String code = "bpm.om.generalOrderFulfillmentFlow";
    64. //String code = "bpm.route.uopOrderFullLinkRouteDecide";
    65. StatefulProcessEngine processEngine = ProcessEngineFactory.getStatefulProcessEngine();
    66. System.out.println(ProcessEngineFactory.getProcessEngine().getJavaCode(code));
    67. Map<String, Object> context = new HashMap<>();
    68. List<String> pList = new ArrayList<>();
    69. pList.add("wuxiang");
    70. pList.add("yusu");
    71. context.put("pList", pList);
    72. try {
    73. System.out.println(processEngine.getJavaCode(code));
    74. System.out.println(processEngine.trigger(code, "PaymentPendingCallback", context));
    75. } catch (Exception e) {
    76. e.printStackTrace();
    77. Assert.fail(e.getMessage());
    78. }
    79. }
    80. /**
    81. * 测试代码中的异常
    82. *
    83. */
    84. @Test(expected=IllegalArgumentException.class)
    85. public void test_process_runtime() {
    86. TbbpmModel model = Mockito.mock(TbbpmModel.class);
    87. TbbpmStatelessProcessRuntime runtime = TbbpmStatelessProcessRuntime.of(model);
    88. when(runtime.generateTestCode()).thenReturn("hello world");
    89. System.out.println(runtime.generateTestCode());
    90. runtime.registerNodeGenerator(null);
    91. }

    如何启动web界面:将所以前端放到static文件目录下即可
    image.png
    image.png