mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
feature #I44FT8 支持脚本语言的组件,并支持动态刷新脚本(版本特性)
This commit is contained in:
31
liteflow-script-qlexpress/pom.xml
Normal file
31
liteflow-script-qlexpress/pom.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>liteflow</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>2.5.11</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>liteflow-script-qlexpress</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-script-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>QLExpress</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.yomahub.liteflow.script.qlexpress;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ql.util.express.DefaultContext;
|
||||
import com.ql.util.express.ExpressRunner;
|
||||
import com.yomahub.liteflow.entity.data.DataBus;
|
||||
import com.yomahub.liteflow.entity.data.Slot;
|
||||
import com.yomahub.liteflow.script.ScriptExecutor;
|
||||
import com.yomahub.liteflow.script.exception.ScriptExecuteException;
|
||||
import com.yomahub.liteflow.script.exception.ScriptLoadException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class QLExpressScriptExecutor implements ScriptExecutor {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private ExpressRunner expressRunner;
|
||||
|
||||
@Override
|
||||
public ScriptExecutor init() {
|
||||
expressRunner = new ExpressRunner();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(String nodeId, String script) {
|
||||
try{
|
||||
expressRunner.loadMutilExpress(nodeId, script);
|
||||
}catch (Exception e){
|
||||
String errorMsg = StrUtil.format("script loading error for node[{}]", nodeId);
|
||||
throw new ScriptLoadException(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String nodeId, int slotIndex) {
|
||||
List<String> errorList = new ArrayList<>();
|
||||
try{
|
||||
Slot slot = DataBus.getSlot(slotIndex);
|
||||
DefaultContext<String, Object> context = new DefaultContext<String, Object>();
|
||||
context.put("slot", slot);
|
||||
expressRunner.executeByExpressName(nodeId, context, errorList, true, false, null);
|
||||
}catch (Exception e){
|
||||
for (String scriptErrorMsg : errorList){
|
||||
log.error("\n{}", scriptErrorMsg);
|
||||
}
|
||||
String errorMsg = StrUtil.format("script execute error for node[{}]", nodeId);
|
||||
throw new ScriptExecuteException(errorMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user