feat:1.0.1

master
xiwa 2023-12-10 23:03:05 +08:00
parent 4d55ff956f
commit 0475f00826
22 changed files with 88 additions and 23 deletions

View File

@ -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>

View File

@ -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;
}

View File

@ -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();
} }
} }

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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);
} }

View File

@ -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

View File

@ -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;
}
} }

View File

@ -6,7 +6,7 @@
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-iita-core</artifactId> <artifactId>iot-iita-core</artifactId>
<version>1.0.0</version> <version>1.0.1</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>