|
@@ -1,26 +1,18 @@
|
|
package com.yomahub.liteflow.script.qlexpress;
|
|
package com.yomahub.liteflow.script.qlexpress;
|
|
|
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
|
import cn.hutool.core.util.ReflectUtil;
|
|
import cn.hutool.core.util.ReflectUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.ql.util.express.DefaultContext;
|
|
import com.ql.util.express.DefaultContext;
|
|
import com.ql.util.express.ExpressLoader;
|
|
import com.ql.util.express.ExpressLoader;
|
|
import com.ql.util.express.ExpressRunner;
|
|
import com.ql.util.express.ExpressRunner;
|
|
import com.ql.util.express.InstructionSet;
|
|
import com.ql.util.express.InstructionSet;
|
|
-import com.yomahub.liteflow.annotation.util.AnnoUtil;
|
|
|
|
-import com.yomahub.liteflow.context.ContextBean;
|
|
|
|
import com.yomahub.liteflow.enums.ScriptTypeEnum;
|
|
import com.yomahub.liteflow.enums.ScriptTypeEnum;
|
|
-import com.yomahub.liteflow.script.ScriptBeanManager;
|
|
|
|
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
|
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
|
-import com.yomahub.liteflow.slot.DataBus;
|
|
|
|
-import com.yomahub.liteflow.slot.Slot;
|
|
|
|
import com.yomahub.liteflow.script.ScriptExecutor;
|
|
import com.yomahub.liteflow.script.ScriptExecutor;
|
|
import com.yomahub.liteflow.script.exception.ScriptLoadException;
|
|
import com.yomahub.liteflow.script.exception.ScriptLoadException;
|
|
import com.yomahub.liteflow.util.CopyOnWriteHashMap;
|
|
import com.yomahub.liteflow.util.CopyOnWriteHashMap;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
-
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -31,7 +23,7 @@ import java.util.Map;
|
|
* @author Bryan.Zhang
|
|
* @author Bryan.Zhang
|
|
* @since 2.6.0
|
|
* @since 2.6.0
|
|
*/
|
|
*/
|
|
-public class QLExpressScriptExecutor implements ScriptExecutor {
|
|
|
|
|
|
+public class QLExpressScriptExecutor extends ScriptExecutor {
|
|
|
|
|
|
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
|
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
|
@@ -58,7 +50,7 @@ public class QLExpressScriptExecutor implements ScriptExecutor {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public Object execute(ScriptExecuteWrap wrap) throws Exception {
|
|
|
|
|
|
+ public Object executeScript(ScriptExecuteWrap wrap) throws Exception {
|
|
List<String> errorList = new ArrayList<>();
|
|
List<String> errorList = new ArrayList<>();
|
|
try {
|
|
try {
|
|
if (!compiledScriptMap.containsKey(wrap.getNodeId())) {
|
|
if (!compiledScriptMap.containsKey(wrap.getNodeId())) {
|
|
@@ -69,41 +61,7 @@ public class QLExpressScriptExecutor implements ScriptExecutor {
|
|
InstructionSet instructionSet = compiledScriptMap.get(wrap.getNodeId());
|
|
InstructionSet instructionSet = compiledScriptMap.get(wrap.getNodeId());
|
|
DefaultContext<String, Object> context = new DefaultContext<>();
|
|
DefaultContext<String, Object> context = new DefaultContext<>();
|
|
|
|
|
|
- // 往脚本语言绑定表里循环增加绑定上下文的key
|
|
|
|
- // key的规则为自定义上下文的simpleName
|
|
|
|
- // 比如你的自定义上下文为AbcContext,那么key就为:abcContext
|
|
|
|
- // 这里不统一放一个map的原因是考虑到有些用户会调用上下文里的方法,而不是参数,所以脚本语言的绑定表里也是放多个上下文
|
|
|
|
- DataBus.getContextBeanList(wrap.getSlotIndex()).forEach(o -> {
|
|
|
|
- ContextBean contextBean = AnnoUtil.getAnnotation(o.getClass(), ContextBean.class);
|
|
|
|
- String key;
|
|
|
|
- if (contextBean != null && contextBean.value().trim().length() > 0) {
|
|
|
|
- key = contextBean.value();
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- key = StrUtil.lowerFirst(o.getClass().getSimpleName());
|
|
|
|
- }
|
|
|
|
- context.put(key, o);
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- // 把wrap对象转换成元数据map
|
|
|
|
- Map<String, Object> metaMap = BeanUtil.beanToMap(wrap);
|
|
|
|
-
|
|
|
|
- // 在元数据里放入主Chain的流程参数
|
|
|
|
- Slot slot = DataBus.getSlot(wrap.getSlotIndex());
|
|
|
|
- metaMap.put("requestData", slot.getRequestData());
|
|
|
|
-
|
|
|
|
- // 如果有隐式流程,则放入隐式流程的流程参数
|
|
|
|
- Object subRequestData = slot.getChainReqData(wrap.getCurrChainName());
|
|
|
|
- if (ObjectUtil.isNotNull(subRequestData)) {
|
|
|
|
- metaMap.put("subRequestData", subRequestData);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 往脚本上下文里放入元数据
|
|
|
|
- context.put("_meta", metaMap);
|
|
|
|
-
|
|
|
|
- // 放入用户自己定义的bean
|
|
|
|
- // 放入用户自己定义的bean
|
|
|
|
- ScriptBeanManager.getScriptBeanMap().forEach(context::putIfAbsent);
|
|
|
|
|
|
+ bindParam(wrap, context::put, context::putIfAbsent);
|
|
|
|
|
|
return expressRunner.execute(instructionSet, context, errorList, true, false, null);
|
|
return expressRunner.execute(instructionSet, context, errorList, true, false, null);
|
|
}
|
|
}
|