feat:1.0.1
parent
4d55ff956f
commit
0475f00826
|
@ -6,7 +6,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>iot-iita-core</artifactId>
|
<artifactId>iot-iita-core</artifactId>
|
||||||
<groupId>cc.iotkit</groupId>
|
<groupId>cc.iotkit</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>iot-common-core</artifactId>
|
<artifactId>iot-common-core</artifactId>
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package cc.iotkit.common.enums;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物模型数据类型
|
||||||
|
*
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum ThingDataType {
|
||||||
|
/**
|
||||||
|
* int 整数
|
||||||
|
*/
|
||||||
|
INT("int32", "整数"),
|
||||||
|
/**
|
||||||
|
* 小数
|
||||||
|
*/
|
||||||
|
FLOAT("float", "小数"),
|
||||||
|
/**
|
||||||
|
* 布尔
|
||||||
|
*/
|
||||||
|
BOOL("bool", "布尔"),
|
||||||
|
/**
|
||||||
|
* 枚举
|
||||||
|
*/
|
||||||
|
ENUM("enum", "枚举"),
|
||||||
|
/**
|
||||||
|
* 文本字符
|
||||||
|
*/
|
||||||
|
TEXT("text", "文本字符"),
|
||||||
|
/**
|
||||||
|
* 日期
|
||||||
|
*/
|
||||||
|
DATE("date", "时间戳"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String info;
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package cc.iotkit.common.utils;
|
package cc.iotkit.common.utils;
|
||||||
|
|
||||||
import cn.hutool.core.exceptions.UtilException;
|
|
||||||
import cn.hutool.core.lang.Dict;
|
import cn.hutool.core.lang.Dict;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.PrimitiveArrayUtil;
|
import cn.hutool.core.util.PrimitiveArrayUtil;
|
||||||
|
@ -28,7 +27,7 @@ public class JsonUtils {
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
OBJECT_MAPPER = SpringUtils.getBean(ObjectMapper.class);
|
OBJECT_MAPPER = SpringUtils.getBean(ObjectMapper.class);
|
||||||
} catch (UtilException e) {
|
} catch (Exception e) {
|
||||||
OBJECT_MAPPER = new ObjectMapper();
|
OBJECT_MAPPER = new ObjectMapper();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>iot-iita-core</artifactId>
|
<artifactId>iot-iita-core</artifactId>
|
||||||
<groupId>cc.iotkit</groupId>
|
<groupId>cc.iotkit</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>iot-iita-core</artifactId>
|
<artifactId>iot-iita-core</artifactId>
|
||||||
<groupId>cc.iotkit</groupId>
|
<groupId>cc.iotkit</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>iot-iita-core</artifactId>
|
<artifactId>iot-iita-core</artifactId>
|
||||||
<groupId>cc.iotkit</groupId>
|
<groupId>cc.iotkit</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>iot-iita-core</artifactId>
|
<artifactId>iot-iita-core</artifactId>
|
||||||
<groupId>cc.iotkit</groupId>
|
<groupId>cc.iotkit</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>iot-iita-core</artifactId>
|
<artifactId>iot-iita-core</artifactId>
|
||||||
<groupId>cc.iotkit</groupId>
|
<groupId>cc.iotkit</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>iot-iita-core</artifactId>
|
<artifactId>iot-iita-core</artifactId>
|
||||||
<groupId>cc.iotkit</groupId>
|
<groupId>cc.iotkit</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>iot-iita-core</artifactId>
|
<artifactId>iot-iita-core</artifactId>
|
||||||
<groupId>cc.iotkit</groupId>
|
<groupId>cc.iotkit</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>iot-iita-core</artifactId>
|
<artifactId>iot-iita-core</artifactId>
|
||||||
<groupId>cc.iotkit</groupId>
|
<groupId>cc.iotkit</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>iot-iita-core</artifactId>
|
<artifactId>iot-iita-core</artifactId>
|
||||||
<groupId>cc.iotkit</groupId>
|
<groupId>cc.iotkit</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>iot-iita-core</artifactId>
|
<artifactId>iot-iita-core</artifactId>
|
||||||
<groupId>cc.iotkit</groupId>
|
<groupId>cc.iotkit</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>iot-message-bus</artifactId>
|
<artifactId>iot-message-bus</artifactId>
|
||||||
<groupId>cc.iotkit</groupId>
|
<groupId>cc.iotkit</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>iot-message-bus</artifactId>
|
<artifactId>iot-message-bus</artifactId>
|
||||||
<groupId>cc.iotkit</groupId>
|
<groupId>cc.iotkit</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>iot-message-bus</artifactId>
|
<artifactId>iot-message-bus</artifactId>
|
||||||
<groupId>cc.iotkit</groupId>
|
<groupId>cc.iotkit</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>iot-iita-core</artifactId>
|
<artifactId>iot-iita-core</artifactId>
|
||||||
<groupId>cc.iotkit</groupId>
|
<groupId>cc.iotkit</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>iot-iita-core</artifactId>
|
<artifactId>iot-iita-core</artifactId>
|
||||||
<groupId>cc.iotkit</groupId>
|
<groupId>cc.iotkit</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>iot-script-engine</artifactId>
|
<artifactId>iot-script-engine</artifactId>
|
||||||
|
|
|
@ -12,4 +12,6 @@ public interface IScriptEngine {
|
||||||
|
|
||||||
<T> T invokeMethod(TypeReference<T> type, String methodName, Object... args);
|
<T> T invokeMethod(TypeReference<T> type, String methodName, Object... args);
|
||||||
|
|
||||||
|
String invokeMethod(String methodName, String args);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,12 +54,9 @@ public class JavaScriptEngine implements IScriptEngine {
|
||||||
@Override
|
@Override
|
||||||
public <T> T invokeMethod(TypeReference<T> type, String methodName, Object... args) {
|
public <T> T invokeMethod(TypeReference<T> type, String methodName, Object... args) {
|
||||||
Value member = jsScript.getMember("invoke");
|
Value member = jsScript.getMember("invoke");
|
||||||
|
|
||||||
StringBuilder sbArgs = formatArgs(args);
|
StringBuilder sbArgs = formatArgs(args);
|
||||||
|
|
||||||
//通过调用invoke方法将目标方法返回结果转成json
|
//通过调用invoke方法将目标方法返回结果转成json
|
||||||
Value rst = member.execute(methodName, args);
|
Value rst = member.execute(methodName, args);
|
||||||
|
|
||||||
String json = rst.asString();
|
String json = rst.asString();
|
||||||
log.info("invoke script={}, args={}, result={}", methodName, sbArgs, json);
|
log.info("invoke script={}, args={}, result={}", methodName, sbArgs, json);
|
||||||
|
|
||||||
|
@ -67,10 +64,23 @@ public class JavaScriptEngine implements IScriptEngine {
|
||||||
if (json == null || "null".equals(json)) {
|
if (json == null || "null".equals(json)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return JsonUtils.parseObject(json, type);
|
return JsonUtils.parseObject(json, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String invokeMethod(String methodName, String args) {
|
||||||
|
Value member = jsScript.getMember("invoke");
|
||||||
|
//通过调用invoke方法将目标方法返回结果转成json
|
||||||
|
Value rst = member.execute(methodName, JsonUtils.parseArray(args, Object.class));
|
||||||
|
String json = rst.asString();
|
||||||
|
log.info("invoke script={}, args={}, result={}", methodName, args, json);
|
||||||
|
//没有返回值
|
||||||
|
if (json == null || "null".equals(json)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
private static StringBuilder formatArgs(Object[] args) {
|
private static StringBuilder formatArgs(Object[] args) {
|
||||||
StringBuilder sbArgs = new StringBuilder("[");
|
StringBuilder sbArgs = new StringBuilder("[");
|
||||||
//将入参转成json
|
//将入参转成json
|
||||||
|
|
|
@ -36,6 +36,11 @@ public class ScriptEngineFactory {
|
||||||
public <T> T invokeMethod(TypeReference<T> type, String methodName, Object... args) {
|
public <T> T invokeMethod(TypeReference<T> type, String methodName, Object... args) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String invokeMethod(String methodName, String args) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
case "js":
|
case "js":
|
||||||
default:
|
default:
|
||||||
|
@ -43,4 +48,10 @@ public class ScriptEngineFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IScriptEngine getJsEngine(String script) {
|
||||||
|
JavaScriptEngine scriptEngine = new JavaScriptEngine();
|
||||||
|
scriptEngine.setScript(script);
|
||||||
|
return scriptEngine;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue