feat:迁移plugin-core到iot-core

V0.5.x
xiwa 2024-02-09 00:12:27 +08:00
parent ef0de940f1
commit 1fcf5035dc
55 changed files with 126 additions and 1026 deletions

View File

@ -5,9 +5,9 @@
<parent> <parent>
<artifactId>iot-dao</artifactId> <artifactId>iot-dao</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>iot-data-model</artifactId> <artifactId>iot-data-model</artifactId>

View File

@ -5,10 +5,10 @@
<parent> <parent>
<artifactId>iot-dao</artifactId> <artifactId>iot-dao</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
<artifactId>iot-data-service</artifactId> <artifactId>iot-data-service</artifactId>
<dependencies> <dependencies>

View File

@ -5,10 +5,10 @@
<parent> <parent>
<artifactId>iot-dao</artifactId> <artifactId>iot-dao</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
<artifactId>iot-data-serviceImpl-cache</artifactId> <artifactId>iot-data-serviceImpl-cache</artifactId>
<dependencies> <dependencies>

View File

@ -5,9 +5,9 @@
<parent> <parent>
<artifactId>iot-dao</artifactId> <artifactId>iot-dao</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>iot-data-serviceImpl-rdb</artifactId> <artifactId>iot-data-serviceImpl-rdb</artifactId>
<description> <description>

View File

@ -5,10 +5,10 @@
<parent> <parent>
<artifactId>iot-dao</artifactId> <artifactId>iot-dao</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
<artifactId>iot-temporal-service</artifactId> <artifactId>iot-temporal-service</artifactId>
<dependencies> <dependencies>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-dao</artifactId> <artifactId>iot-dao</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-dao</artifactId> <artifactId>iot-dao</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,10 +5,10 @@
<parent> <parent>
<artifactId>iot-dao</artifactId> <artifactId>iot-dao</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
<artifactId>iot-temporal-serviceImpl-td</artifactId> <artifactId>iot-temporal-serviceImpl-td</artifactId>
<description> <description>

View File

@ -6,9 +6,9 @@
<parent> <parent>
<artifactId>iot-dao</artifactId> <artifactId>iot-dao</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
<artifactId>iot-temporal-serviceImpl-ts</artifactId> <artifactId>iot-temporal-serviceImpl-ts</artifactId>
<description> <description>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging> <packaging>pom</packaging>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-module</artifactId> <artifactId>iot-module</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -6,7 +6,6 @@ import cc.iotkit.common.enums.ErrCode;
import cc.iotkit.common.exception.BizException; import cc.iotkit.common.exception.BizException;
import cc.iotkit.common.utils.MapstructUtils; import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.common.utils.StringUtils; import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.common.utils.file.FileUtils;
import cc.iotkit.data.manager.IPluginInfoData; import cc.iotkit.data.manager.IPluginInfoData;
import cc.iotkit.manager.dto.bo.plugin.PluginInfoBo; import cc.iotkit.manager.dto.bo.plugin.PluginInfoBo;
import cc.iotkit.manager.dto.vo.plugin.PluginInfoVo; import cc.iotkit.manager.dto.vo.plugin.PluginInfoVo;
@ -20,14 +19,11 @@ import com.gitee.starblues.integration.operator.PluginOperator;
import com.gitee.starblues.integration.operator.upload.UploadParam; import com.gitee.starblues.integration.operator.upload.UploadParam;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.io.File;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.List;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
@ -53,11 +49,15 @@ public class PluginServiceImpl implements IPluginService {
public void upload(MultipartFile file, Long id) { public void upload(MultipartFile file, Long id) {
try { try {
PluginInfo plugin = pluginInfoData.findById(id); PluginInfo plugin = pluginInfoData.findById(id);
if (plugin == null) { if (file == null || plugin == null) {
throw new BizException(ErrCode.DATA_NOT_EXIST); throw new BizException(ErrCode.DATA_NOT_EXIST);
} }
String pluginId = plugin.getPluginId(); String pluginId = plugin.getPluginId();
if (!file.getName().contains(pluginId)) {
throw new BizException(ErrCode.PLUGIN_INSTALL_FAILED, "文件名与原插件id不匹配");
}
if (StringUtils.isNotBlank(pluginId)) { if (StringUtils.isNotBlank(pluginId)) {
//停止卸载旧的插件 //停止卸载旧的插件
com.gitee.starblues.core.PluginInfo pluginInfo = pluginOperator.getPluginInfo(pluginId); com.gitee.starblues.core.PluginInfo pluginInfo = pluginOperator.getPluginInfo(pluginId);
@ -78,26 +78,27 @@ public class PluginServiceImpl implements IPluginService {
throw new BizException(ErrCode.PLUGIN_INSTALL_FAILED); throw new BizException(ErrCode.PLUGIN_INSTALL_FAILED);
} }
JarFile jarFile = new JarFile(pluginInfo.getPluginPath());
// 获取config文件在jar包中的路径
String configFile = "classes/config.json";
JarEntry configEntry = jarFile.getJarEntry(configFile);
String configJson = ""; String configJson = "";
if (configEntry != null) {
//读取配置文件
configJson = IoUtil.read(jarFile.getInputStream(configEntry), Charset.defaultCharset());
log.info("configJson:{}", configJson);
}
//读取script.js脚本
String scriptFile = "classes/script.js";
JarEntry scriptEntity = jarFile.getJarEntry(scriptFile);
String script = ""; String script = "";
if (scriptEntity != null) { try (JarFile jarFile = new JarFile(pluginInfo.getPluginPath())) {
//读取脚本文件 // 获取config文件在jar包中的路径
script = IoUtil.read(jarFile.getInputStream(scriptEntity), Charset.defaultCharset()); String configFile = "classes/config.json";
log.info("script:{}", script); JarEntry configEntry = jarFile.getJarEntry(configFile);
if (configEntry != null) {
//读取配置文件
configJson = IoUtil.read(jarFile.getInputStream(configEntry), Charset.defaultCharset());
log.info("configJson:{}", configJson);
}
//读取script.js脚本
String scriptFile = "classes/script.js";
JarEntry scriptEntity = jarFile.getJarEntry(scriptFile);
if (scriptEntity != null) {
//读取脚本文件
script = IoUtil.read(jarFile.getInputStream(scriptEntity), Charset.defaultCharset());
log.info("script:{}", script);
}
} }
PluginState pluginState = pluginInfo.getPluginState(); PluginState pluginState = pluginInfo.getPluginState();
@ -113,6 +114,8 @@ public class PluginServiceImpl implements IPluginService {
plugin.setVersion(pluginDescriptor.getPluginVersion()); plugin.setVersion(pluginDescriptor.getPluginVersion());
plugin.setDescription(pluginDescriptor.getDescription()); plugin.setDescription(pluginDescriptor.getDescription());
pluginInfoData.save(plugin); pluginInfoData.save(plugin);
} catch (BizException e) {
throw e;
} catch (Exception e) { } catch (Exception e) {
throw new BizException(ErrCode.PLUGIN_INSTALL_FAILED, e); throw new BizException(ErrCode.PLUGIN_INSTALL_FAILED, e);
} }

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-module</artifactId> <artifactId>iot-module</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -19,6 +19,7 @@ import org.springframework.stereotype.Component;
@Slf4j @Slf4j
@Component @Component
public class DingTalkEventListener implements MessageEventListener { public class DingTalkEventListener implements MessageEventListener {
WebClient client = WebClient.create(VertxManager.INSTANCE.getVertx());
@Override @Override
@EventListener(classes = MessageEvent.class, condition = "#event.message.channel=='DingTalk'") @EventListener(classes = MessageEvent.class, condition = "#event.message.channel=='DingTalk'")
@ -27,13 +28,14 @@ public class DingTalkEventListener implements MessageEventListener {
String channelConfig = message.getChannelConfig(); String channelConfig = message.getChannelConfig();
DingTalkConfig dingTalkConfig = JsonUtils.parse(channelConfig, DingTalkConfig.class); DingTalkConfig dingTalkConfig = JsonUtils.parse(channelConfig, DingTalkConfig.class);
WebClient client = WebClient.create(VertxManager.INSTANCE.getVertx());
DingTalkMessage qyWechatMessage = DingTalkMessage.builder() DingTalkMessage qyWechatMessage = DingTalkMessage.builder()
.msgtype("text") .msgtype("text")
.text(DingTalkMessage.MessageContent.builder().content(message.getFormatContent()).build()) .text(DingTalkMessage.MessageContent.builder().content(message.getFormatContent()).build())
.build(); .build();
client.post(dingTalkConfig.getDingTalkWebhook()).sendJson(qyWechatMessage)
client.getAbs(dingTalkConfig.getDingTalkWebhook()).sendJson(qyWechatMessage)
.onSuccess(response -> log.info("Received response with status code" + response.statusCode())) .onSuccess(response -> log.info("Received response with status code" + response.statusCode()))
.onFailure(err -> log.error("Something went wrong " + err.getMessage())); .onFailure(err -> log.error("Something went wrong " + err.getMessage()));
} }
} }

View File

@ -19,6 +19,7 @@ import org.springframework.stereotype.Component;
@Slf4j @Slf4j
@Component @Component
public class QyWechatEventListener implements MessageEventListener { public class QyWechatEventListener implements MessageEventListener {
WebClient client = WebClient.create(VertxManager.INSTANCE.getVertx());
@Override @Override
@EventListener(classes = MessageEvent.class, condition = "#event.message.channel=='QyWechat'") @EventListener(classes = MessageEvent.class, condition = "#event.message.channel=='QyWechat'")
@ -27,12 +28,12 @@ public class QyWechatEventListener implements MessageEventListener {
String channelConfig = message.getChannelConfig(); String channelConfig = message.getChannelConfig();
QyWechatConfig qyWechatConfig = JsonUtils.parse(channelConfig, QyWechatConfig.class); QyWechatConfig qyWechatConfig = JsonUtils.parse(channelConfig, QyWechatConfig.class);
WebClient client = WebClient.create(VertxManager.INSTANCE.getVertx());
QyWechatMessage qyWechatMessage = QyWechatMessage.builder() QyWechatMessage qyWechatMessage = QyWechatMessage.builder()
.msgtype("text") .msgtype("text")
.text(QyWechatMessage.MessageContent.builder().content(message.getFormatContent()).build()) .text(QyWechatMessage.MessageContent.builder().content(message.getFormatContent()).build())
.build(); .build();
client.post(qyWechatConfig.getQyWechatWebhook()).sendJson(qyWechatMessage)
client.getAbs(qyWechatConfig.getQyWechatWebhook()).sendJson(qyWechatMessage)
.onSuccess(response -> log.info("Received response with status code" + response.statusCode())) .onSuccess(response -> log.info("Received response with status code" + response.statusCode()))
.onFailure(err -> log.error("Something went wrong " + err.getMessage())); .onFailure(err -> log.error("Something went wrong " + err.getMessage()));
} }

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-module</artifactId> <artifactId>iot-module</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -1,45 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>iot-plugin</artifactId>
<groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>iot-plugin-core</artifactId>
<dependencies>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-common-core</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-script-engine</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-message-core</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-data-service</artifactId>
</dependency>
<!--====================第三方库===================-->
<dependency>
<groupId>com.gitee.starblues</groupId>
<artifactId>spring-brick</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,22 +0,0 @@
package cc.iotkit.plugin.core;
import java.util.Map;
/**
*
*
* @author sjg
*/
public interface IPlugin {
/**
* mqttip
*
* @param pk key
* @param dn dn
* @return
*/
Map<String, Object> getLinkInfo(String pk, String dn);
}

View File

@ -1,21 +0,0 @@
package cc.iotkit.plugin.core;
import java.util.Map;
/**
*
*
* @author sjg
*/
public interface IPluginConfig {
/**
*
*
* @param pluginId id
* @return config
*/
Map<String, Object> getConfig(String pluginId);
}

View File

@ -1,27 +0,0 @@
package cc.iotkit.plugin.core;
import cc.iotkit.script.IScriptEngine;
/**
* 宿
*
* @author sjg
*/
public interface IPluginScript {
/**
*
*
* @param pluginId id
* @return IScriptEngine
*/
IScriptEngine getScriptEngine(String pluginId);
/**
*
*
* @param pluginId id
*/
void reloadScript(String pluginId);
}

View File

@ -1,18 +0,0 @@
package cc.iotkit.plugin.core;
import java.util.HashMap;
import java.util.Map;
/**
*
*
* @author sjg
*/
public class LocalPluginConfig implements IPluginConfig {
@Override
public Map<String, Object> getConfig(String pluginId) {
//本地的直接用程序中默认值
return new HashMap<>(0);
}
}

View File

@ -1,50 +0,0 @@
package cc.iotkit.plugin.core;
import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.common.utils.file.FileUtils;
import cc.iotkit.script.IScriptEngine;
import cc.iotkit.script.ScriptEngineFactory;
import java.net.URL;
import java.nio.charset.Charset;
/**
*
*
* @author sjg
*/
public class LocalPluginScript implements IPluginScript {
private IScriptEngine scriptEngine;
public LocalPluginScript(String scriptPath) {
if (StringUtils.isBlank(scriptPath)) {
return;
}
URL resource = LocalPluginScript.class.getClassLoader().getResource(scriptPath);
if (resource == null) {
return;
}
String script = FileUtils.readString(resource.getFile(), Charset.defaultCharset());
initScriptEngine(script);
}
public IScriptEngine initScriptEngine(String script) {
if (StringUtils.isBlank(script)) {
return null;
}
scriptEngine = ScriptEngineFactory.getJsEngine(script);
return scriptEngine;
}
@Override
public IScriptEngine getScriptEngine(String pluginId) {
return scriptEngine;
}
@Override
public void reloadScript(String pluginId) {
}
}

View File

@ -1,49 +0,0 @@
package cc.iotkit.plugin.core.thing;
import cc.iotkit.plugin.core.thing.actions.ActionResult;
import cc.iotkit.plugin.core.thing.actions.down.DeviceConfig;
import cc.iotkit.plugin.core.thing.actions.down.PropertyGet;
import cc.iotkit.plugin.core.thing.actions.down.PropertySet;
import cc.iotkit.plugin.core.thing.actions.down.ServiceInvoke;
/**
*
*
* @author sjg
*/
public interface IDevice {
/**
*
*
* @param action
* @return result
*/
ActionResult config(DeviceConfig action);
/**
*
*
* @param action
* @return result
*/
ActionResult propertyGet(PropertyGet action);
/**
*
*
* @param action
* @return result
*/
ActionResult propertySet(PropertySet action);
/**
*
*
* @param action
* @return result
*/
ActionResult serviceInvoke(ServiceInvoke action);
}

View File

@ -1,49 +0,0 @@
package cc.iotkit.plugin.core.thing;
import cc.iotkit.model.device.DeviceInfo;
import cc.iotkit.model.product.Product;
import cc.iotkit.plugin.core.thing.actions.ActionResult;
import cc.iotkit.plugin.core.thing.actions.IDeviceAction;
import java.util.Map;
/**
*
*
* @author sjg
*/
public interface IThingService {
/**
*
*
* @param action IDeviceAction
* @return result
*/
ActionResult post(String pluginId, IDeviceAction action);
/**
*
*
* @param pk key
* @return Product
*/
Product getProduct(String pk);
/**
*
*
* @param deviceName dn
* @return DeviceInfo
*/
DeviceInfo getDevice(String deviceName);
/**
*
*
* @param deviceName dn
* @return
*/
Map<String, ?> getProperty(String deviceName);
}

View File

@ -1,31 +0,0 @@
package cc.iotkit.plugin.core.thing.actions;
import lombok.Data;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
/**
* @author sjg
*/
@Data
@SuperBuilder
@ToString(callSuper = true)
public abstract class AbstractAction implements IDeviceAction {
protected String id;
protected ActionType type;
protected String productKey;
protected String deviceName;
protected Long time;
public AbstractAction() {
}
public AbstractAction(ActionType type) {
this.type = type;
}
}

View File

@ -1,29 +0,0 @@
package cc.iotkit.plugin.core.thing.actions;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
*
*
* @author sjg
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ActionResult {
/**
* 0:x:
*/
private int code;
/**
*
*/
private String reason;
}

View File

@ -1,39 +0,0 @@
package cc.iotkit.plugin.core.thing.actions;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
*
*
* @author sjg
*/
@Getter
@AllArgsConstructor
public enum ActionType {
//注册
REGISTER("register"),
//设备拓扑更新
TOPOLOGY("topology"),
//在离线状态变更
STATE_CHANGE("state_change"),
//属性上报
PROPERTY_REPORT("property_report"),
//事件上报
EVENT_REPORT("event_report"),
//服务回复
SERVICE_REPLY("service_reply"),
//属性设置
PROPERTY_SET("property_set"),
//属性获取
PROPERTY_GET("property_get"),
//服务调用
SERVICE_INVOKE("service_invoke"),
//配置
CONFIG("config");
private final String type;
}

View File

@ -1,21 +0,0 @@
package cc.iotkit.plugin.core.thing.actions;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
*
* @author sjg
*/
@Getter
@AllArgsConstructor
public enum DeviceState {
//在线
ONLINE("online"),
//离线
OFFLINE("offline");
private final String state;
}

View File

@ -1,24 +0,0 @@
package cc.iotkit.plugin.core.thing.actions;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
*
*
* @author sjg
*/
@Getter
@AllArgsConstructor
public enum EventLevel {
//信息
INFO("info"),
//告警
WARN("warn"),
//错误
ERROR("error");
private final String type;
}

View File

@ -1,79 +0,0 @@
package cc.iotkit.plugin.core.thing.actions;
/**
*
*
* @author sjg
*/
public interface IDeviceAction {
/**
* id
*
* @return id
*/
String getId();
/**
* id
*
* @param id id
*/
void setId(String id);
/**
*
*
* @return ActionType
*/
ActionType getType();
/**
*
*
* @param type type
*/
void setType(ActionType type);
/**
* key
*
* @return ProductKey
*/
String getProductKey();
/**
* key
*
* @param productKey pk
*/
void setProductKey(String productKey);
/**
* DN
*
* @return DN
*/
String getDeviceName();
/**
* DN
*
* @param deviceName dn
*/
void setDeviceName(String deviceName);
/**
*
*
* @return timespan
*/
Long getTime();
/**
*
*
* @param time timestamp
*/
void setTime(Long time);
}

View File

@ -1,40 +0,0 @@
package cc.iotkit.plugin.core.thing.actions.down;
import cc.iotkit.plugin.core.thing.actions.AbstractAction;
import cc.iotkit.plugin.core.thing.actions.ActionType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.Map;
/**
*
*
* @author sjg
*/
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
public class DeviceConfig extends AbstractAction {
/**
*
*/
private String module;
/**
*
*/
private Map<String, Object> config;
@Override
public ActionType getType() {
return ActionType.CONFIG;
}
}

View File

@ -1,35 +0,0 @@
package cc.iotkit.plugin.core.thing.actions.down;
import cc.iotkit.plugin.core.thing.actions.AbstractAction;
import cc.iotkit.plugin.core.thing.actions.ActionType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.List;
/**
*
*
* @author sjg
*/
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
public class PropertyGet extends AbstractAction {
/**
*
*/
private List<String> keys;
@Override
public ActionType getType() {
return ActionType.PROPERTY_GET;
}
}

View File

@ -1,35 +0,0 @@
package cc.iotkit.plugin.core.thing.actions.down;
import cc.iotkit.plugin.core.thing.actions.AbstractAction;
import cc.iotkit.plugin.core.thing.actions.ActionType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.Map;
/**
*
*
* @author sjg
*/
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
public class PropertySet extends AbstractAction {
/**
*
*/
private Map<String, ?> params;
@Override
public ActionType getType() {
return ActionType.PROPERTY_SET;
}
}

View File

@ -1,45 +0,0 @@
package cc.iotkit.plugin.core.thing.actions.down;
import cc.iotkit.plugin.core.thing.actions.AbstractAction;
import cc.iotkit.plugin.core.thing.actions.ActionType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.Map;
/**
*
*
* @author sjg
*/
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
public class ServiceInvoke extends AbstractAction {
/**
*
*/
private String name;
/**
*
*/
private Map<String, ?> params;
/**
*
*/
private Map<String, ?> config;
@Override
public ActionType getType() {
return ActionType.SERVICE_INVOKE;
}
}

View File

@ -1,36 +0,0 @@
package cc.iotkit.plugin.core.thing.actions.up;
import cc.iotkit.plugin.core.thing.actions.AbstractAction;
import cc.iotkit.plugin.core.thing.actions.ActionType;
import lombok.*;
import lombok.experimental.SuperBuilder;
/**
*
*
* @author sjg
*/
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@ToString(callSuper = true)
public class DeviceRegister extends AbstractAction {
/**
*
*/
private String model;
/**
*
*/
private String version;
@Override
public ActionType getType() {
return ActionType.REGISTER;
}
}

View File

@ -1,29 +0,0 @@
package cc.iotkit.plugin.core.thing.actions.up;
import cc.iotkit.plugin.core.thing.actions.AbstractAction;
import cc.iotkit.plugin.core.thing.actions.ActionType;
import cc.iotkit.plugin.core.thing.actions.DeviceState;
import lombok.*;
import lombok.experimental.SuperBuilder;
/**
* 线
*
* @author sjg
*/
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@ToString(callSuper = true)
public class DeviceStateChange extends AbstractAction {
private DeviceState state;
@Override
public ActionType getType() {
return ActionType.STATE_CHANGE;
}
}

View File

@ -1,33 +0,0 @@
package cc.iotkit.plugin.core.thing.actions.up;
import cc.iotkit.plugin.core.thing.actions.AbstractAction;
import cc.iotkit.plugin.core.thing.actions.ActionType;
import lombok.*;
import lombok.experimental.SuperBuilder;
import java.util.List;
/**
*
*
* @author sjg
*/
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@ToString(callSuper = true)
public class DeviceTopology extends AbstractAction {
/**
*
*/
private List<String> subDevices;
@Override
public ActionType getType() {
return ActionType.TOPOLOGY;
}
}

View File

@ -1,44 +0,0 @@
package cc.iotkit.plugin.core.thing.actions.up;
import cc.iotkit.plugin.core.thing.actions.AbstractAction;
import cc.iotkit.plugin.core.thing.actions.ActionType;
import cc.iotkit.plugin.core.thing.actions.EventLevel;
import lombok.*;
import lombok.experimental.SuperBuilder;
import java.util.Map;
/**
*
*
* @author sjg
*/
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@ToString(callSuper = true)
public class EventReport extends AbstractAction {
/**
*
*/
private String name;
/**
*
*/
private EventLevel level;
/**
*
*/
private Map<String, Object> params;
@Override
public ActionType getType() {
return ActionType.EVENT_REPORT;
}
}

View File

@ -1,33 +0,0 @@
package cc.iotkit.plugin.core.thing.actions.up;
import cc.iotkit.plugin.core.thing.actions.AbstractAction;
import cc.iotkit.plugin.core.thing.actions.ActionType;
import lombok.*;
import lombok.experimental.SuperBuilder;
import java.util.Map;
/**
*
*
* @author sjg
*/
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@ToString(callSuper = true)
public class PropertyReport extends AbstractAction {
/**
*
*/
private Map<String, Object> params;
@Override
public ActionType getType() {
return ActionType.PROPERTY_REPORT;
}
}

View File

@ -1,48 +0,0 @@
package cc.iotkit.plugin.core.thing.actions.up;
import cc.iotkit.plugin.core.thing.actions.AbstractAction;
import cc.iotkit.plugin.core.thing.actions.ActionType;
import lombok.*;
import lombok.experimental.SuperBuilder;
import java.util.Map;
/**
*
*
* @author sjg
*/
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@ToString(callSuper = true)
public class ServiceReply extends AbstractAction {
/**
*
*/
private String name;
/**
* id
*/
private String replyId;
/**
* ,0:,x:
*/
private int code;
/**
*
*/
private Map<String, Object> params;
@Override
public ActionType getType() {
return ActionType.SERVICE_REPLY;
}
}

View File

@ -1,34 +0,0 @@
package cc.iotkit.plugin.core.thing.model;
import lombok.Data;
/**
*
*
* @author sjg
*/
@Data
public class ThingDevice {
private String deviceId;
/**
* key
*/
private String productKey;
/**
* dn
*/
private String deviceName;
/**
*
*/
private String model;
/**
*
*/
private String secret;
}

View File

@ -1,23 +0,0 @@
package cc.iotkit.plugin.core.thing.model;
import lombok.Data;
/**
*
*
* @author sjg
*/
@Data
public class ThingProduct {
private String productKey;
private String productSecret;
private String name;
private String category;
private Integer nodeType;
}

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-plugin</artifactId> <artifactId>iot-plugin</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -13,11 +13,6 @@
<dependencies> <dependencies>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-common-thing</artifactId>
</dependency>
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-plugin-core</artifactId> <artifactId>iot-plugin-core</artifactId>
@ -28,6 +23,11 @@
<artifactId>iot-common-redis</artifactId> <artifactId>iot-common-redis</artifactId>
</dependency> </dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-data-service</artifactId>
</dependency>
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-temporal-service</artifactId> <artifactId>iot-temporal-service</artifactId>

View File

@ -13,7 +13,6 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**

View File

@ -29,7 +29,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;

View File

@ -16,6 +16,8 @@ import cc.iotkit.mq.MqProducer;
import cc.iotkit.plugin.core.thing.IThingService; import cc.iotkit.plugin.core.thing.IThingService;
import cc.iotkit.plugin.core.thing.actions.*; import cc.iotkit.plugin.core.thing.actions.*;
import cc.iotkit.plugin.core.thing.actions.up.*; import cc.iotkit.plugin.core.thing.actions.up.*;
import cc.iotkit.plugin.core.thing.model.ThingDevice;
import cc.iotkit.plugin.core.thing.model.ThingProduct;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -56,7 +58,7 @@ public class ThingServiceImpl implements IThingService {
//添加设备路由 //添加设备路由
deviceRouter.putRouter(deviceName, new PluginRouter(IPluginMain.MAIN_ID, pluginId)); deviceRouter.putRouter(deviceName, new PluginRouter(IPluginMain.MAIN_ID, pluginId));
DeviceInfo device = getDevice(deviceName); DeviceInfo device = getDeviceInfo(deviceName);
if (device == null) { if (device == null) {
log.warn("device:{} is not found.", deviceName); log.warn("device:{} is not found.", deviceName);
} }
@ -121,17 +123,26 @@ public class ThingServiceImpl implements IThingService {
} }
@Override @Override
public Product getProduct(String pk) { public ThingProduct getProduct(String pk) {
try { try {
return productData.findByProductKey(pk); Product product = productData.findByProductKey(pk);
if(product==null){
return null;
}
return ThingProduct.builder()
.category(product.getCategory())
.productKey(product.getProductKey())
.name(product.getName())
.nodeType(product.getNodeType())
.productSecret(product.getProductSecret())
.build();
} catch (Throwable e) { } catch (Throwable e) {
log.error("get product error", e); log.error("get product error", e);
return null; return null;
} }
} }
@Override public DeviceInfo getDeviceInfo(String dn) {
public DeviceInfo getDevice(String dn) {
try { try {
return deviceInfoData.findByDeviceName(dn); return deviceInfoData.findByDeviceName(dn);
} catch (Throwable e) { } catch (Throwable e) {
@ -140,9 +151,24 @@ public class ThingServiceImpl implements IThingService {
} }
} }
@Override
public ThingDevice getDevice(String dn) {
DeviceInfo deviceInfo = getDeviceInfo(dn);
if(deviceInfo==null){
return null;
}
return ThingDevice.builder()
.deviceId(deviceInfo.getDeviceId())
.deviceName(deviceInfo.getDeviceName())
.model(deviceInfo.getModel())
.productKey(deviceInfo.getProductKey())
.secret(deviceInfo.getSecret())
.build();
}
@Override @Override
public Map<String, ?> getProperty(String deviceName) { public Map<String, ?> getProperty(String deviceName) {
DeviceInfo device = getDevice(deviceName); DeviceInfo device = getDeviceInfo(deviceName);
if (device == null) { if (device == null) {
return new HashMap<>(0); return new HashMap<>(0);
} }
@ -153,7 +179,7 @@ public class ThingServiceImpl implements IThingService {
String productKey = register.getProductKey(); String productKey = register.getProductKey();
//指定了pk需验证 //指定了pk需验证
if (StringUtils.isNotBlank(productKey)) { if (StringUtils.isNotBlank(productKey)) {
Product product = getProduct(productKey); ThingProduct product = getProduct(productKey);
if (product == null) { if (product == null) {
throw new BizException(ErrCode.PRODUCT_NOT_FOUND); throw new BizException(ErrCode.PRODUCT_NOT_FOUND);
} }
@ -163,21 +189,21 @@ public class ThingServiceImpl implements IThingService {
log.info("device already registered"); log.info("device already registered");
} else { } else {
//不存在,注册新设备 //不存在,注册新设备
device = new DeviceInfo(); DeviceInfo deviceInfo = new DeviceInfo();
device.setId(DeviceUtil.newDeviceId(register.getDeviceName())); deviceInfo.setId(DeviceUtil.newDeviceId(register.getDeviceName()));
device.setDeviceId(device.getId()); deviceInfo.setDeviceId(deviceInfo.getId());
device.setProductKey(productKey); deviceInfo.setProductKey(productKey);
device.setDeviceName(register.getDeviceName()); deviceInfo.setDeviceName(register.getDeviceName());
device.setModel(register.getModel()); deviceInfo.setModel(register.getModel());
device.setSecret(RandomStringUtils.randomAlphabetic(16)); deviceInfo.setSecret(RandomStringUtils.randomAlphabetic(16));
//默认离线 //默认离线
device.setState(new DeviceInfo.State(false, null, null)); deviceInfo.setState(new DeviceInfo.State(false, null, null));
device.setCreateAt(System.currentTimeMillis()); deviceInfo.setCreateAt(System.currentTimeMillis());
deviceInfoData.save(device); deviceInfoData.save(deviceInfo);
log.info("device registered:{}", JsonUtils.toJsonString(device)); log.info("device registered:{}", JsonUtils.toJsonString(device));
publishMsg( publishMsg(
device, deviceInfo,
register, register,
ThingModelMessage.builder() ThingModelMessage.builder()
.type(ThingModelMessage.TYPE_LIFETIME) .type(ThingModelMessage.TYPE_LIFETIME)
@ -210,7 +236,7 @@ public class ThingServiceImpl implements IThingService {
private void deviceTopologyUpdate(DeviceInfo device, DeviceTopology topology) { private void deviceTopologyUpdate(DeviceInfo device, DeviceTopology topology) {
//设备拓扑关系更新 //设备拓扑关系更新
for (String deviceName : topology.getSubDevices()) { for (String deviceName : topology.getSubDevices()) {
DeviceInfo subDevice = getDevice(deviceName); DeviceInfo subDevice = getDeviceInfo(deviceName);
subDevice.setParentId(device.getDeviceId()); subDevice.setParentId(device.getDeviceId());
deviceInfoData.save(subDevice); deviceInfoData.save(subDevice);
} }

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-module</artifactId> <artifactId>iot-module</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -13,7 +13,6 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>
<module>iot-plugin-core</module>
<module>iot-plugin-main</module> <module>iot-plugin-main</module>
</modules> </modules>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-module</artifactId> <artifactId>iot-module</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-module</artifactId> <artifactId>iot-module</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-module</artifactId> <artifactId>iot-module</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -13,6 +13,16 @@
<packaging>jar</packaging> <packaging>jar</packaging>
<dependencies> <dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web-client</artifactId>
</dependency>
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-common-tenant</artifactId> <artifactId>iot-common-tenant</artifactId>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-test-tool</artifactId> <artifactId>iot-test-tool</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging> <packaging>pom</packaging>

View File

@ -12,7 +12,7 @@
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<version>0.5.1-SNAPSHOT</version> <version>0.5.2-SNAPSHOT</version>
<name>${project.artifactId}</name> <name>${project.artifactId}</name>
<description>奇特物联是一个开源的物联网基础开发平台,提供了物联网及相关业务开发的常见基础功能, <description>奇特物联是一个开源的物联网基础开发平台,提供了物联网及相关业务开发的常见基础功能,
能帮助你快速搭建自己的物联网相关业务平台。 能帮助你快速搭建自己的物联网相关业务平台。
@ -29,7 +29,7 @@
<properties> <properties>
<java.version>11</java.version> <java.version>11</java.version>
<iot-iita-core.version>1.0.1</iot-iita-core.version> <iot-iita-core.version>1.0.2</iot-iita-core.version>
<spring-boot.version>2.7.11</spring-boot.version> <spring-boot.version>2.7.11</spring-boot.version>
<vertx.version>4.2.2</vertx.version> <vertx.version>4.2.2</vertx.version>
<satoken.version>1.34.0</satoken.version> <satoken.version>1.34.0</satoken.version>
@ -37,7 +37,7 @@
<lang3.version>3.7</lang3.version> <lang3.version>3.7</lang3.version>
<hutool.version>5.8.18</hutool.version> <hutool.version>5.8.18</hutool.version>
<mapstruct-plus.version>1.3.1</mapstruct-plus.version> <mapstruct-plus.version>1.3.1</mapstruct-plus.version>
<spring-brick.version>3.1.3</spring-brick.version> <spring-brick.version>3.1.4</spring-brick.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
@ -391,7 +391,7 @@
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-plugin-core</artifactId> <artifactId>iot-plugin-core</artifactId>
<version>${project.version}</version> <version>${iot-iita-core.version}</version>
</dependency> </dependency>
<dependency> <dependency>