|
@@ -29,11 +29,10 @@ import org.eclipse.paho.client.mqttv3.MqttMessage;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
-import javax.script.Invocable;
|
|
|
|
|
-import javax.script.ScriptEngine;
|
|
|
|
|
-import javax.script.ScriptEngineManager;
|
|
|
|
|
-import javax.script.ScriptException;
|
|
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
|
|
|
|
+
|
|
|
|
|
+import org.mozilla.javascript.Context;
|
|
|
|
|
+import org.mozilla.javascript.Scriptable;
|
|
|
|
|
+import org.mozilla.javascript.ScriptableObject;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
@@ -248,12 +247,15 @@ public class MqttServiceImpl implements MqttService {
|
|
|
String value = bo.getValue();
|
|
String value = bo.getValue();
|
|
|
if(StringUtils.isNotBlank(i.getFormula())){
|
|
if(StringUtils.isNotBlank(i.getFormula())){
|
|
|
try {
|
|
try {
|
|
|
- ScriptEngineManager manager = new ScriptEngineManager();
|
|
|
|
|
- ScriptEngine se = manager.getEngineByName("javascript");
|
|
|
|
|
- String script = "function format(data) { return "+i.getFormula()+" ; }";
|
|
|
|
|
- se.eval(script);
|
|
|
|
|
- Invocable inv = (Invocable) se;
|
|
|
|
|
- value = (String) inv.invokeFunction("format", value );
|
|
|
|
|
|
|
+
|
|
|
|
|
+ Context context = Context.enter();
|
|
|
|
|
+ Scriptable scope = context.initStandardObjects();
|
|
|
|
|
+ String script = "function format(data) { return "+i.getFormula()+" ; } format("+value+");";
|
|
|
|
|
+ Object result = context.evaluateString(scope, script, "<cmd>", 1, null);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ value = (String) result;
|
|
|
System.out.println(value);
|
|
System.out.println(value);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
System.out.println("表达式runtime错误:" + e.getMessage());
|
|
System.out.println("表达式runtime错误:" + e.getMessage());
|
|
@@ -261,13 +263,16 @@ public class MqttServiceImpl implements MqttService {
|
|
|
}
|
|
}
|
|
|
Boolean isFilter = false;
|
|
Boolean isFilter = false;
|
|
|
if(StringUtils.isNotBlank(i.getFilterAlgorithm())){
|
|
if(StringUtils.isNotBlank(i.getFilterAlgorithm())){
|
|
|
- ScriptEngineManager manager = new ScriptEngineManager();
|
|
|
|
|
- ScriptEngine se = manager.getEngineByName("javascript");
|
|
|
|
|
|
|
+ Context context = Context.enter();
|
|
|
|
|
+ Scriptable scope = context.initStandardObjects();
|
|
|
|
|
+
|
|
|
String script = "function isFilter(data,up,down) { return "+i.getFilterAlgorithm()+" ; }";
|
|
String script = "function isFilter(data,up,down) { return "+i.getFilterAlgorithm()+" ; }";
|
|
|
try {
|
|
try {
|
|
|
- se.eval(script);
|
|
|
|
|
- Invocable inv = (Invocable) se;
|
|
|
|
|
- isFilter = (Boolean) inv.invokeFunction("isFilter", value,i.getUpperLimit(),i.getLowerLimit() );
|
|
|
|
|
|
|
+
|
|
|
|
|
+ script+="isFilter("+ value+","+i.getUpperLimit()+","+i.getLowerLimit()+")";
|
|
|
|
|
+ Object result = context.evaluateString(scope, script, "<cmd>", 1, null);
|
|
|
|
|
+ isFilter = (Boolean) result;
|
|
|
|
|
+// isFilter = (Boolean) inv.invokeFunction("isFilter", value,i.getUpperLimit(),i.getLowerLimit() );
|
|
|
System.out.println(isFilter);
|
|
System.out.println(isFilter);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
System.out.println("表达式runtime错误:" + e.getMessage());
|
|
System.out.println("表达式runtime错误:" + e.getMessage());
|