|
@@ -1,5 +1,6 @@
|
|
|
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.StrUtil;
|
|
@@ -8,6 +9,7 @@ import com.ql.util.express.ExpressLoader;
|
|
|
import com.ql.util.express.ExpressRunner;
|
|
|
import com.ql.util.express.InstructionSet;
|
|
|
import com.yomahub.liteflow.script.ScriptBeanManager;
|
|
|
+import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
|
|
import com.yomahub.liteflow.slot.DataBus;
|
|
|
import com.yomahub.liteflow.slot.Slot;
|
|
|
import com.yomahub.liteflow.script.ScriptExecutor;
|
|
@@ -52,36 +54,42 @@ public class QLExpressScriptExecutor implements ScriptExecutor {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Object execute(String currChainName, String nodeId, int slotIndex) {
|
|
|
+ public Object execute(ScriptExecuteWrap wrap) {
|
|
|
List<String> errorList = new ArrayList<>();
|
|
|
try{
|
|
|
- if (!compiledScriptMap.containsKey(nodeId)){
|
|
|
- String errorMsg = StrUtil.format("script for node[{}] is not loaded", nodeId);
|
|
|
+ if (!compiledScriptMap.containsKey(wrap.getNodeId())){
|
|
|
+ String errorMsg = StrUtil.format("script for node[{}] is not loaded", wrap.getNodeId());
|
|
|
throw new ScriptLoadException(errorMsg);
|
|
|
}
|
|
|
|
|
|
- InstructionSet instructionSet = compiledScriptMap.get(nodeId);
|
|
|
+ InstructionSet instructionSet = compiledScriptMap.get(wrap.getNodeId());
|
|
|
DefaultContext<String, Object> context = new DefaultContext<>();
|
|
|
|
|
|
//往脚本语言绑定表里循环增加绑定上下文的key
|
|
|
//key的规则为自定义上下文的simpleName
|
|
|
//比如你的自定义上下文为AbcContext,那么key就为:abcContext
|
|
|
//这里不统一放一个map的原因是考虑到有些用户会调用上下文里的方法,而不是参数,所以脚本语言的绑定表里也是放多个上下文
|
|
|
- DataBus.getContextBeanList(slotIndex).forEach(o -> {
|
|
|
+ DataBus.getContextBeanList(wrap.getSlotIndex()).forEach(o -> {
|
|
|
String key = StrUtil.lowerFirst(o.getClass().getSimpleName());
|
|
|
context.put(key, o);
|
|
|
});
|
|
|
|
|
|
- //放入主Chain的流程参数
|
|
|
- Slot slot = DataBus.getSlot(slotIndex);
|
|
|
- context.put("requestData", slot.getRequestData());
|
|
|
+ //把wrap对象转换成元数据map
|
|
|
+ Map<String, Object> metaMap = BeanUtil.beanToMap(wrap);
|
|
|
|
|
|
- //如果有隐试流程,则放入隐式流程的流程参数
|
|
|
- Object subRequestData = slot.getChainReqData(currChainName);
|
|
|
+ //在元数据里放入主Chain的流程参数
|
|
|
+ Slot slot = DataBus.getSlot(wrap.getSlotIndex());
|
|
|
+ metaMap.put("requestData", slot.getRequestData());
|
|
|
+
|
|
|
+ //如果有隐式流程,则放入隐式流程的流程参数
|
|
|
+ Object subRequestData = slot.getChainReqData(wrap.getCurrChainName());
|
|
|
if (ObjectUtil.isNotNull(subRequestData)){
|
|
|
- context.put("subRequestData", subRequestData);
|
|
|
+ metaMap.put("subRequestData", subRequestData);
|
|
|
}
|
|
|
|
|
|
+ //往脚本上下文里放入元数据
|
|
|
+ context.putAll(metaMap);
|
|
|
+
|
|
|
//放入用户自己定义的bean
|
|
|
context.putAll(ScriptBeanManager.getScriptBeanMap());
|
|
|
|
|
@@ -90,7 +98,7 @@ public class QLExpressScriptExecutor implements ScriptExecutor {
|
|
|
for (String scriptErrorMsg : errorList){
|
|
|
log.error("\n{}", scriptErrorMsg);
|
|
|
}
|
|
|
- String errorMsg = StrUtil.format("script execute error for node[{}]", nodeId);
|
|
|
+ String errorMsg = StrUtil.format("script execute error for node[{}]", wrap.getNodeId());
|
|
|
throw new ScriptExecuteException(errorMsg);
|
|
|
}
|
|
|
}
|