Commit 7c7a8e0ce2b4865b46c3c6a52daa377b850b2228

Authored by 云中非
1 parent 92e8f8d5

refactor: 脚本引擎模板调整

1、输入参为:msg
2、输出参数为:out
... ... @@ -26,6 +26,7 @@ public class YtTcpDeviceProfileTransportConfiguration implements DeviceProfileTr
26 26 @NoXss
27 27 private TcpDataTypeEnum dataFormat = TcpDataTypeEnum.HEX;
28 28 private String scriptId;
  29 + private String scriptText;
29 30 private String pingText;
30 31
31 32 @Override
... ...
... ... @@ -21,11 +21,11 @@ public class YtTcpScriptFactory {
21 21
22 22 public static final String RULE_NODE_FUNCTION_NAME = "tcpTransportFunc";
23 23
24   - private static final String JS_WRAPPER_PREFIX_TEMPLATE = "function %s(msgStr) { " +
25   - " var msg = JSON.parse(msgStr); " +
  24 + private static final String JS_WRAPPER_PREFIX_TEMPLATE = "function %s(msg) { " +
  25 + " var out = new Object(); " +
26 26 " return JSON.stringify(%s(msg));" +
27 27 " function %s(%s) {";
28   - private static final String JS_WRAPPER_SUFFIX = "\n}" +
  28 + private static final String JS_WRAPPER_SUFFIX = "return out; \n }" +
29 29 "\n}";
30 30
31 31
... ...
... ... @@ -119,11 +119,11 @@ public class DeviceSessionCtx extends DeviceAwareSessionContext {
119 119 payloadType = TcpDataTypeEnum.HEX;
120 120 }
121 121 this.pingText = ByteUtils.getBytes(tcpConfiguration.getPingText(),ByteUtils.UTF_8);
122   - String jsBody="return {msg: msg, metadata: 456, msgType: 789};";
  122 + String scriptBody = tcpConfiguration.getScriptText();
123 123 try {
124   - this.scriptId = this.adaptor.getJsScriptEngineFunctionId(jsBody);
  124 + this.scriptId = this.adaptor.getJsScriptEngineFunctionId(scriptBody);
125 125 } catch (ExecutionException e) {
126   - log.warn("设备配置【{}】的脚本【{}】解析异常",deviceProfile.getSearchText(),jsBody);
  126 + log.warn("设备配置【{}】的脚本【{}】解析异常",deviceProfile.getSearchText(),scriptBody);
127 127 throw new RuntimeException(e);
128 128 } catch (InterruptedException e) {
129 129 throw new RuntimeException(e);
... ...