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
项目结构:
maven依赖:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>compileflow</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>compileflow</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba.compileflow</groupId>
<artifactId>compileflow</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
代码使用:
package com.example.compileflow.service;
import com.alibaba.compileflow.engine.ProcessEngine;
import com.alibaba.compileflow.engine.ProcessEngineFactory;
import com.alibaba.compileflow.engine.definition.tbbpm.TbbpmModel;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.TbbpmModelConverter;
import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import org.springframework.stereotype.Component;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 参考:https://www.jianshu.com/p/a3ff29cf579d
* 参考:https://www.jianshu.com/p/9bb2f01ad816
*/
@Component
public class RunCase {
public void run() {
//code在bpm文件中定义
String code = "bpm.ktvExample";
//执行流程的入参
Map<String, Object> context = new HashMap<>(1);
List<String> pList = new ArrayList<>();
pList.add("wuxiang");
pList.add("yusu");
pList.add("xugong");
pList.add("fandu");
context.put("pList", pList);
try {
ProcessEngine processEngine = ProcessEngineFactory.getProcessEngine();
Map<String, Object> result = processEngine.execute(code, context);
System.out.println(result.get("price"));
} catch (Exception e) {
e.printStackTrace();
}
}
public void run2() {
//code在bpm文件中定义
String code = "bpm.sqrt";
//执行流程的入参
Map<String, Object> context = new HashMap<>(1);
context.put("num", 4);
try {
ProcessEngine processEngine = ProcessEngineFactory.getProcessEngine();
Map<String, Object> result = processEngine.execute(code, context);
System.out.println(result.get("numSqrt"));
} catch (Exception e) {
e.printStackTrace();
}
}
public void getProcessEngine() {
final String code = "bpm.ktv.ktvExample";
final Map<String, Object> context = new HashMap<>(1);
final List<String> pList = new ArrayList<>();
pList.add("wuxiang");
pList.add("xuan");
pList.add("yusu");
context.put("pList", pList);
final ProcessEngine<TbbpmModel> processEngine = ProcessEngineFactory.getProcessEngine();
final TbbpmModel tbbpmModel = processEngine.load(code);
final OutputStream outputStream = TbbpmModelConverter.getInstance().convertToStream(tbbpmModel);
System.out.println(outputStream);
System.out.println(processEngine.getTestCode(code));
processEngine.preCompile(code);
System.out.println(processEngine.execute(code, context));
}
public void run3() {
//code在bpm文件中定义
String code = "bpm.ktvExample";
//执行流程的入参
Map<String, Object> context = new HashMap<>(1);
List<String> pList = new ArrayList<>();
pList.add("a1");
pList.add("a2");
pList.add("a3");
pList.add("a4");
pList.add("a5");
pList.add("a6");
pList.add("a7");
pList.add("a8");
pList.add("a9");
pList.add("a10");
pList.add("a11");
context.put("pList", pList);
try {
ProcessEngine processEngine = ProcessEngineFactory.getProcessEngine();
Map<String, Object> result = processEngine.execute(code, context);
System.out.println(result.get("price"));
} catch (Exception e) {
e.printStackTrace();
}
}
public void quick_start() throws Exception {
ExpressRunner runner = new ExpressRunner();
DefaultContext<String, Object> context = new DefaultContext<>();
context.put("a", 1);
context.put("b", 2);
context.put("c", 3);
//下面五个参数意义分别是 表达式,上下文,errorList,是否缓存,是否输出日志
Object result = runner.execute("a+b+c", context, null, true, false);
System.out.println("a+b+c=" + result);
}
}
创建文件流程:
查看流程:
其他操作方法:
@Test
public void testProcessEngine() {
final String code = "bpm.ktv.ktvExample";
final Map<String, Object> context = new HashMap<>();
List<String> pList = new ArrayList<>();
pList.add("wuxiang");
pList.add("yusu");
context.put("pList", pList);
final ProcessEngine processEngine = ProcessEngineFactory.getProcessEngine();
System.out.println(processEngine.getTestCode(code));
System.out.println(processEngine.execute(code, context));
}
@Test
public void testProcessEngineBpmn20() {
final String code = "bpmn20.ktv.ktvExample";
final Map<String, Object> context = new HashMap<>();
List<String> pList = new ArrayList<>();
pList.add("wuxiang");
pList.add("yusu");
context.put("pList", pList);
final ProcessEngine processEngine = ProcessEngineFactory.getStatelessProcessEngine(FlowModelType.BPMN);
System.out.println(processEngine.start(code, context));
}
@Test
public void testTbbpmModelConvert() {
// final String code = "bpm.ktv.ktvExample";
String code = "bpm.om.waitpaySuccessflow";
final ProcessEngine<TbbpmModel> processEngine = ProcessEngineFactory.getProcessEngine();
final TbbpmModel tbbpmModel = processEngine.load(code);
final OutputStream outputStream = TbbpmModelConverter.getInstance().convertToStream(tbbpmModel);
System.out.println(outputStream.toString());
final String srcCode = processEngine.getJavaCode(code);
System.out.println(srcCode);
}
@Test
public void testWaitPayProcess(){
String code = "bpm.om.waitpaySuccessflow";
System.out.println(ProcessEngineFactory.getProcessEngine().getJavaCode(code));
Map<String, Object> context = new HashMap<>();
context.put("num", 100d);
ProcessEngineFactory.getProcessEngine().execute(code,context);
}
@Test
public void testTiggerWaitPayProcess() {
String code = "bpm.om.waitpaySuccessflow";
Map<String, Object> context = new HashMap<>();
context.put("num", 100d);
StatefulProcessEngine processEngine = ProcessEngineFactory.getStatefulProcessEngine();
try {
System.out.println(processEngine.getJavaCode(code));
System.out.println("------receiver not real event------");
System.out.println(processEngine.trigger(code, "randomEvent", context));
System.out.println("------receiver real event------");
context.put("eventName","PaymentPendingCallback");
System.out.println(processEngine.trigger(code, "PaymentPendingCallback", context));
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
@Test
public void testStatefulProcessEngine() {
String code = "bpm.om.generalOrderFulfillmentFlow";
//String code = "bpm.route.uopOrderFullLinkRouteDecide";
StatefulProcessEngine processEngine = ProcessEngineFactory.getStatefulProcessEngine();
System.out.println(ProcessEngineFactory.getProcessEngine().getJavaCode(code));
Map<String, Object> context = new HashMap<>();
List<String> pList = new ArrayList<>();
pList.add("wuxiang");
pList.add("yusu");
context.put("pList", pList);
try {
System.out.println(processEngine.getJavaCode(code));
System.out.println(processEngine.trigger(code, "PaymentPendingCallback", context));
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
/**
* 测试代码中的异常
*
*/
@Test(expected=IllegalArgumentException.class)
public void test_process_runtime() {
TbbpmModel model = Mockito.mock(TbbpmModel.class);
TbbpmStatelessProcessRuntime runtime = TbbpmStatelessProcessRuntime.of(model);
when(runtime.generateTestCode()).thenReturn("hello world");
System.out.println(runtime.generateTestCode());
runtime.registerNodeGenerator(null);
}
如何启动web界面:将所以前端放到static文件目录下即可