Commit 30ae986c1af58d77ce94be1f25884eff61115cdd
1 parent
4a251b19
【代码优化】IoT:整理 plugins 的依赖,以及对应 server 的启动逻辑
Showing
15 changed files
with
66 additions
and
80 deletions
plugins/yudao-module-iot-plugin-http-1.0.0.jar
No preview for this file type
yudao-module-iot/yudao-module-iot-api/pom.xml
| @@ -30,11 +30,17 @@ | @@ -30,11 +30,17 @@ | ||
| 30 | <scope>provided</scope> <!-- 设置为 provided,只有工具类需要使用到 --> | 30 | <scope>provided</scope> <!-- 设置为 provided,只有工具类需要使用到 --> |
| 31 | </dependency> | 31 | </dependency> |
| 32 | 32 | ||
| 33 | - <!-- PF4J --> | ||
| 34 | - <!-- TODO 芋艿:这个依赖,要不要放在 api 包 --> | 33 | + <!-- 工具类相关 --> |
| 34 | + <dependency> | ||
| 35 | + <groupId>com.fasterxml.jackson.core</groupId> | ||
| 36 | + <artifactId>jackson-databind</artifactId> | ||
| 37 | + <scope>provided</scope> <!-- 设置为 provided,只有工具类需要使用到 --> | ||
| 38 | + </dependency> | ||
| 39 | + | ||
| 35 | <dependency> | 40 | <dependency> |
| 36 | - <groupId>org.pf4j</groupId> | 41 | + <groupId>org.pf4j</groupId> <!-- PF4J:内置插件机制 --> |
| 37 | <artifactId>pf4j-spring</artifactId> | 42 | <artifactId>pf4j-spring</artifactId> |
| 43 | + <!-- TODO @芋艿:可以放到 bom 里配置 --> | ||
| 38 | <exclusions> | 44 | <exclusions> |
| 39 | <exclusion> | 45 | <exclusion> |
| 40 | <groupId>org.slf4j</groupId> | 46 | <groupId>org.slf4j</groupId> |
| @@ -43,13 +49,6 @@ | @@ -43,13 +49,6 @@ | ||
| 43 | </exclusions> | 49 | </exclusions> |
| 44 | </dependency> | 50 | </dependency> |
| 45 | 51 | ||
| 46 | - <!-- 工具类相关 --> | ||
| 47 | - <dependency> | ||
| 48 | - <groupId>com.fasterxml.jackson.core</groupId> | ||
| 49 | - <artifactId>jackson-databind</artifactId> | ||
| 50 | - <scope>provided</scope> <!-- 设置为 provided,只有工具类需要使用到 --> | ||
| 51 | - </dependency> | ||
| 52 | - | ||
| 53 | <!-- 参数校验 --> | 52 | <!-- 参数校验 --> |
| 54 | <dependency> | 53 | <dependency> |
| 55 | <groupId>org.springframework.boot</groupId> | 54 | <groupId>org.springframework.boot</groupId> |
yudao-module-iot/yudao-module-iot-biz/pom.xml
| @@ -64,25 +64,19 @@ | @@ -64,25 +64,19 @@ | ||
| 64 | <artifactId>yudao-spring-boot-starter-excel</artifactId> | 64 | <artifactId>yudao-spring-boot-starter-excel</artifactId> |
| 65 | </dependency> | 65 | </dependency> |
| 66 | 66 | ||
| 67 | - <!-- Vert.x 核心依赖 --> | ||
| 68 | - <dependency> | ||
| 69 | - <groupId>io.vertx</groupId> | ||
| 70 | - <artifactId>vertx-core</artifactId> | ||
| 71 | - </dependency> | ||
| 72 | - <!-- Vert.x Web 模块 --> | 67 | + <!-- 工具类相关 --> |
| 73 | <dependency> | 68 | <dependency> |
| 74 | <groupId>io.vertx</groupId> | 69 | <groupId>io.vertx</groupId> |
| 75 | <artifactId>vertx-web</artifactId> | 70 | <artifactId>vertx-web</artifactId> |
| 76 | </dependency> | 71 | </dependency> |
| 77 | - <!-- MQTT --> | 72 | + |
| 78 | <dependency> | 73 | <dependency> |
| 79 | - <groupId>org.eclipse.paho</groupId> | 74 | + <groupId>org.eclipse.paho</groupId> <!-- MQTT --> |
| 80 | <artifactId>org.eclipse.paho.client.mqttv3</artifactId> | 75 | <artifactId>org.eclipse.paho.client.mqttv3</artifactId> |
| 81 | </dependency> | 76 | </dependency> |
| 82 | 77 | ||
| 83 | - <!-- PF4J --> | ||
| 84 | <dependency> | 78 | <dependency> |
| 85 | - <groupId>org.pf4j</groupId> | 79 | + <groupId>org.pf4j</groupId> <!-- PF4J:内置插件机制 --> |
| 86 | <artifactId>pf4j-spring</artifactId> | 80 | <artifactId>pf4j-spring</artifactId> |
| 87 | <!-- TODO @芋艿:可以放到 bom 里配置 --> | 81 | <!-- TODO @芋艿:可以放到 bom 里配置 --> |
| 88 | <exclusions> | 82 | <exclusions> |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/UnifiedConfiguration.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/config/UnifiedConfiguration.java
| 1 | -package cn.iocoder.yudao.module.iot.framework.plugin; | 1 | +package cn.iocoder.yudao.module.iot.framework.plugin.config; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.iot.framework.plugin.listener.CustomPluginStateListener; | 3 | +import cn.iocoder.yudao.module.iot.framework.plugin.core.CustomPluginStateListener; |
| 4 | import lombok.extern.slf4j.Slf4j; | 4 | import lombok.extern.slf4j.Slf4j; |
| 5 | import org.pf4j.spring.SpringPluginManager; | 5 | import org.pf4j.spring.SpringPluginManager; |
| 6 | import org.springframework.beans.factory.annotation.Value; | 6 | import org.springframework.beans.factory.annotation.Value; |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/listener/CustomPluginStateListener.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/core/CustomPluginStateListener.java
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/PluginStart.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/core/PluginStart.java
| 1 | -package cn.iocoder.yudao.module.iot.framework.plugin; | 1 | +package cn.iocoder.yudao.module.iot.framework.plugin.core; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; | 4 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/aspect/TaosAspect.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/core/TaosAspect.java
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/pom.xml
| @@ -18,35 +18,24 @@ | @@ -18,35 +18,24 @@ | ||
| 18 | </description> | 18 | </description> |
| 19 | 19 | ||
| 20 | <dependencies> | 20 | <dependencies> |
| 21 | - <!-- TODO 芋艿:依赖整理 --> | ||
| 22 | <dependency> | 21 | <dependency> |
| 23 | - <groupId>cn.iocoder.boot</groupId> | ||
| 24 | - <artifactId>yudao-common</artifactId> | 22 | + <groupId>org.springframework.boot</groupId> |
| 23 | + <artifactId>spring-boot-starter</artifactId> | ||
| 25 | </dependency> | 24 | </dependency> |
| 26 | - <!-- 项目依赖 --> | 25 | + |
| 27 | <dependency> | 26 | <dependency> |
| 28 | <groupId>cn.iocoder.boot</groupId> | 27 | <groupId>cn.iocoder.boot</groupId> |
| 29 | <artifactId>yudao-module-iot-api</artifactId> | 28 | <artifactId>yudao-module-iot-api</artifactId> |
| 30 | <version>${revision}</version> | 29 | <version>${revision}</version> |
| 31 | </dependency> | 30 | </dependency> |
| 32 | 31 | ||
| 33 | - <dependency> | ||
| 34 | - <groupId>org.projectlombok</groupId> | ||
| 35 | - <artifactId>lombok</artifactId> | ||
| 36 | - </dependency> | ||
| 37 | - | 32 | + <!-- Web 相关 --> |
| 38 | <dependency> | 33 | <dependency> |
| 39 | <groupId>org.springframework</groupId> | 34 | <groupId>org.springframework</groupId> |
| 40 | <artifactId>spring-web</artifactId> | 35 | <artifactId>spring-web</artifactId> |
| 41 | </dependency> | 36 | </dependency> |
| 42 | 37 | ||
| 43 | - <!-- 其他依赖项 --> | ||
| 44 | - <dependency> | ||
| 45 | - <groupId>org.springframework.boot</groupId> | ||
| 46 | - <artifactId>spring-boot-starter</artifactId> | ||
| 47 | - </dependency> | ||
| 48 | - | ||
| 49 | - <!-- Vert.x Web --> | 38 | + <!-- 工具类相关 --> |
| 50 | <dependency> | 39 | <dependency> |
| 51 | <groupId>io.vertx</groupId> | 40 | <groupId>io.vertx</groupId> |
| 52 | <artifactId>vertx-web</artifactId> | 41 | <artifactId>vertx-web</artifactId> |
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/pom.xml
| @@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
| 16 | 16 | ||
| 17 | <name>${project.artifactId}</name> | 17 | <name>${project.artifactId}</name> |
| 18 | <description> | 18 | <description> |
| 19 | + <!-- TODO @芋艿:注释 --> | ||
| 19 | 物联网 插件模块 - http 插件 | 20 | 物联网 插件模块 - http 插件 |
| 20 | </description> | 21 | </description> |
| 21 | 22 | ||
| @@ -31,7 +32,7 @@ | @@ -31,7 +32,7 @@ | ||
| 31 | 32 | ||
| 32 | <build> | 33 | <build> |
| 33 | <plugins> | 34 | <plugins> |
| 34 | - <!-- 插件模式 zip --> | 35 | + <!-- 插件模式 zip --> |
| 35 | <plugin> | 36 | <plugin> |
| 36 | <groupId>org.apache.maven.plugins</groupId> | 37 | <groupId>org.apache.maven.plugins</groupId> |
| 37 | <artifactId>maven-antrun-plugin</artifactId> | 38 | <artifactId>maven-antrun-plugin</artifactId> |
| @@ -75,7 +76,7 @@ | @@ -75,7 +76,7 @@ | ||
| 75 | </executions> | 76 | </executions> |
| 76 | </plugin> | 77 | </plugin> |
| 77 | 78 | ||
| 78 | - <!-- 插件模式 jar --> | 79 | + <!-- 插件模式 jar --> |
| 79 | <plugin> | 80 | <plugin> |
| 80 | <groupId>org.apache.maven.plugins</groupId> | 81 | <groupId>org.apache.maven.plugins</groupId> |
| 81 | <artifactId>maven-jar-plugin</artifactId> | 82 | <artifactId>maven-jar-plugin</artifactId> |
| @@ -94,7 +95,7 @@ | @@ -94,7 +95,7 @@ | ||
| 94 | </configuration> | 95 | </configuration> |
| 95 | </plugin> | 96 | </plugin> |
| 96 | 97 | ||
| 97 | - <!-- 独立模式 --> | 98 | + <!-- 独立模式 --> |
| 98 | <plugin> | 99 | <plugin> |
| 99 | <groupId>org.springframework.boot</groupId> | 100 | <groupId>org.springframework.boot</groupId> |
| 100 | <artifactId>spring-boot-maven-plugin</artifactId> | 101 | <artifactId>spring-boot-maven-plugin</artifactId> |
| @@ -121,21 +122,13 @@ | @@ -121,21 +122,13 @@ | ||
| 121 | </build> | 122 | </build> |
| 122 | 123 | ||
| 123 | <dependencies> | 124 | <dependencies> |
| 124 | - <!-- TODO 芋艿:优化下 --> | ||
| 125 | - <!-- 项目依赖 --> | ||
| 126 | <dependency> | 125 | <dependency> |
| 127 | <groupId>cn.iocoder.boot</groupId> | 126 | <groupId>cn.iocoder.boot</groupId> |
| 128 | <artifactId>yudao-module-iot-plugin-common</artifactId> | 127 | <artifactId>yudao-module-iot-plugin-common</artifactId> |
| 129 | <version>${revision}</version> | 128 | <version>${revision}</version> |
| 130 | </dependency> | 129 | </dependency> |
| 131 | 130 | ||
| 132 | - <!-- 其他依赖项 --> | ||
| 133 | - <dependency> | ||
| 134 | - <groupId>org.springframework.boot</groupId> | ||
| 135 | - <artifactId>spring-boot-starter-web</artifactId> | ||
| 136 | - </dependency> | ||
| 137 | - | ||
| 138 | - <!-- Vert.x Web --> | 131 | + <!-- 工具类相关 --> |
| 139 | <dependency> | 132 | <dependency> |
| 140 | <groupId>io.vertx</groupId> | 133 | <groupId>io.vertx</groupId> |
| 141 | <artifactId>vertx-web</artifactId> | 134 | <artifactId>vertx-web</artifactId> |
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/HttpPluginSpringbootApplication.java
| 1 | package cn.iocoder.yudao.module.iot.plugin.http; | 1 | package cn.iocoder.yudao.module.iot.plugin.http; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.iot.plugin.http.upstream.IotDeviceUpstreamServer; | ||
| 4 | import lombok.extern.slf4j.Slf4j; | 3 | import lombok.extern.slf4j.Slf4j; |
| 5 | import org.springframework.boot.SpringApplication; | 4 | import org.springframework.boot.SpringApplication; |
| 6 | -import org.springframework.boot.WebApplicationType; | ||
| 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; | 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 8 | import org.springframework.context.ConfigurableApplicationContext; | 6 | import org.springframework.context.ConfigurableApplicationContext; |
| 9 | 7 | ||
| @@ -15,16 +13,15 @@ import org.springframework.context.ConfigurableApplicationContext; | @@ -15,16 +13,15 @@ import org.springframework.context.ConfigurableApplicationContext; | ||
| 15 | public class HttpPluginSpringbootApplication { | 13 | public class HttpPluginSpringbootApplication { |
| 16 | 14 | ||
| 17 | public static void main(String[] args) { | 15 | public static void main(String[] args) { |
| 18 | - SpringApplication application = new SpringApplication(HttpPluginSpringbootApplication.class); | ||
| 19 | - application.setWebApplicationType(WebApplicationType.NONE); | ||
| 20 | - ConfigurableApplicationContext context = application.run(args); | 16 | + ConfigurableApplicationContext context = SpringApplication.run(HttpPluginSpringbootApplication.class, args); |
| 21 | 17 | ||
| 22 | // 手动获取 VertxService 并启动 | 18 | // 手动获取 VertxService 并启动 |
| 23 | // TODO @haohao:可以放在 bean 的 init 里么?回复:会和插件模式冲突 @芋艿,测试下 | 19 | // TODO @haohao:可以放在 bean 的 init 里么?回复:会和插件模式冲突 @芋艿,测试下 |
| 24 | - IotDeviceUpstreamServer vertxService = context.getBean(IotDeviceUpstreamServer.class); | ||
| 25 | - vertxService.start(); | 20 | + // TODO @haohao:貌似去掉,没有问题额。。。 |
| 21 | +// IotDeviceUpstreamServer vertxService = context.getBean(IotDeviceUpstreamServer.class); | ||
| 22 | +// vertxService.start(); | ||
| 26 | 23 | ||
| 27 | - log.info("[HttpPluginSpringbootApplication] 独立模式启动完成"); | 24 | + log.info("[main][独立模式启动完成]"); |
| 28 | } | 25 | } |
| 29 | 26 | ||
| 30 | } | 27 | } |
| 31 | \ No newline at end of file | 28 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotHttpVertxPlugin.java
| @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.iot.plugin.http.config; | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.iot.plugin.http.config; | ||
| 3 | import cn.hutool.core.lang.Assert; | 3 | import cn.hutool.core.lang.Assert; |
| 4 | import cn.hutool.extra.spring.SpringUtil; | 4 | import cn.hutool.extra.spring.SpringUtil; |
| 5 | import cn.iocoder.yudao.module.iot.api.device.IotDeviceUpstreamApi; | 5 | import cn.iocoder.yudao.module.iot.api.device.IotDeviceUpstreamApi; |
| 6 | -import cn.iocoder.yudao.module.iot.plugin.http.upstream.IotDeviceUpstreamServer; | ||
| 7 | import lombok.extern.slf4j.Slf4j; | 6 | import lombok.extern.slf4j.Slf4j; |
| 8 | import org.pf4j.PluginWrapper; | 7 | import org.pf4j.PluginWrapper; |
| 9 | import org.pf4j.spring.SpringPlugin; | 8 | import org.pf4j.spring.SpringPlugin; |
| @@ -11,6 +10,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | @@ -11,6 +10,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | ||
| 11 | import org.springframework.context.ApplicationContext; | 10 | import org.springframework.context.ApplicationContext; |
| 12 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; | 11 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
| 13 | 12 | ||
| 13 | +// TODO @芋艿:完善注释 | ||
| 14 | /** | 14 | /** |
| 15 | * 负责插件的启动和停止,与 Vert.x 的生命周期管理 | 15 | * 负责插件的启动和停止,与 Vert.x 的生命周期管理 |
| 16 | */ | 16 | */ |
| @@ -30,8 +30,9 @@ public class IotHttpVertxPlugin extends SpringPlugin { | @@ -30,8 +30,9 @@ public class IotHttpVertxPlugin extends SpringPlugin { | ||
| 30 | Assert.notNull(pluginContext, "pluginContext 不能为空"); | 30 | Assert.notNull(pluginContext, "pluginContext 不能为空"); |
| 31 | 31 | ||
| 32 | // 2. 启动 Vert.x | 32 | // 2. 启动 Vert.x |
| 33 | - IotDeviceUpstreamServer vertxService = pluginContext.getBean(IotDeviceUpstreamServer.class); | ||
| 34 | - vertxService.start(); | 33 | + // TODO @haohao:貌似去掉,没有问题额。。。 |
| 34 | +// IotDeviceUpstreamServer vertxService = pluginContext.getBean(IotDeviceUpstreamServer.class); | ||
| 35 | +// vertxService.start(); | ||
| 35 | 36 | ||
| 36 | log.info("[HttpVertxPlugin][HttpVertxPlugin 插件启动成功...]"); | 37 | log.info("[HttpVertxPlugin][HttpVertxPlugin 插件启动成功...]"); |
| 37 | } catch (Exception e) { | 38 | } catch (Exception e) { |
| @@ -44,11 +45,11 @@ public class IotHttpVertxPlugin extends SpringPlugin { | @@ -44,11 +45,11 @@ public class IotHttpVertxPlugin extends SpringPlugin { | ||
| 44 | log.info("[HttpVertxPlugin][HttpVertxPlugin 插件停止开始...]"); | 45 | log.info("[HttpVertxPlugin][HttpVertxPlugin 插件停止开始...]"); |
| 45 | try { | 46 | try { |
| 46 | // 停止服务器 | 47 | // 停止服务器 |
| 47 | - ApplicationContext pluginContext = getApplicationContext(); | ||
| 48 | - if (pluginContext != null) { | ||
| 49 | - IotDeviceUpstreamServer vertxService = pluginContext.getBean(IotDeviceUpstreamServer.class); | ||
| 50 | - vertxService.stopServer(); | ||
| 51 | - } | 48 | +// ApplicationContext pluginContext = getApplicationContext(); |
| 49 | +// if (pluginContext != null) { | ||
| 50 | +// IotDeviceUpstreamServer vertxService = pluginContext.getBean(IotDeviceUpstreamServer.class); | ||
| 51 | +// vertxService.stop(); | ||
| 52 | +// } | ||
| 52 | 53 | ||
| 53 | log.info("[HttpVertxPlugin][HttpVertxPlugin 插件停止成功...]"); | 54 | log.info("[HttpVertxPlugin][HttpVertxPlugin 插件停止成功...]"); |
| 54 | } catch (Exception e) { | 55 | } catch (Exception e) { |
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotPluginHttpAutoConfiguration.java
| @@ -7,7 +7,9 @@ import org.springframework.context.annotation.Bean; | @@ -7,7 +7,9 @@ import org.springframework.context.annotation.Bean; | ||
| 7 | import org.springframework.context.annotation.Configuration; | 7 | import org.springframework.context.annotation.Configuration; |
| 8 | 8 | ||
| 9 | /** | 9 | /** |
| 10 | - * 插件与独立运行都可复用的配置类 | 10 | + * IoT 插件 HTTP 的专用自动配置类 |
| 11 | + * | ||
| 12 | + * @author haohao | ||
| 11 | */ | 13 | */ |
| 12 | @Configuration | 14 | @Configuration |
| 13 | public class IotPluginHttpAutoConfiguration { | 15 | public class IotPluginHttpAutoConfiguration { |
| @@ -19,8 +21,8 @@ public class IotPluginHttpAutoConfiguration { | @@ -19,8 +21,8 @@ public class IotPluginHttpAutoConfiguration { | ||
| 19 | @Value("${plugin.http.server.port:8092}") | 21 | @Value("${plugin.http.server.port:8092}") |
| 20 | private Integer port; | 22 | private Integer port; |
| 21 | 23 | ||
| 22 | - @Bean | ||
| 23 | - public IotDeviceUpstreamServer vertxService(IotDeviceUpstreamApi deviceUpstreamApi) { | 24 | + @Bean(initMethod = "start", destroyMethod = "stop") |
| 25 | + public IotDeviceUpstreamServer deviceUpstreamServer(IotDeviceUpstreamApi deviceUpstreamApi) { | ||
| 24 | return new IotDeviceUpstreamServer(port, deviceUpstreamApi); | 26 | return new IotDeviceUpstreamServer(port, deviceUpstreamApi); |
| 25 | } | 27 | } |
| 26 | 28 |
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/downstream/IotDeviceDownstreamHandlerImpl.java
| @@ -7,6 +7,14 @@ import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.IotDeviceSe | @@ -7,6 +7,14 @@ import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.IotDeviceSe | ||
| 7 | import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamHandler; | 7 | import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamHandler; |
| 8 | import org.springframework.stereotype.Component; | 8 | import org.springframework.stereotype.Component; |
| 9 | 9 | ||
| 10 | +/** | ||
| 11 | + * HTTP 插件的 {@link IotDeviceDownstreamHandler} 实现类 | ||
| 12 | + * | ||
| 13 | + * 但是:由于设备通过 HTTP 短链接接入,导致其实无法下行指导给 device 设备,所以基本都是直接返回失败!!! | ||
| 14 | + * 类似 MQTT、WebSocket、TCP 插件,是可以实现下行指令的。 | ||
| 15 | + * | ||
| 16 | + * @author 芋道源码 | ||
| 17 | + */ | ||
| 10 | @Component // TODO @芋艿:后续统一处理 | 18 | @Component // TODO @芋艿:后续统一处理 |
| 11 | public class IotDeviceDownstreamHandlerImpl implements IotDeviceDownstreamHandler { | 19 | public class IotDeviceDownstreamHandlerImpl implements IotDeviceDownstreamHandler { |
| 12 | 20 |
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/upstream/IotDeviceUpstreamServer.java
| @@ -51,7 +51,7 @@ public class IotDeviceUpstreamServer { | @@ -51,7 +51,7 @@ public class IotDeviceUpstreamServer { | ||
| 51 | /** | 51 | /** |
| 52 | * 停止所有 | 52 | * 停止所有 |
| 53 | */ | 53 | */ |
| 54 | - public void stopServer() { | 54 | + public void stop() { |
| 55 | log.info("[stop][开始关闭]"); | 55 | log.info("[stop][开始关闭]"); |
| 56 | try { | 56 | try { |
| 57 | // 关闭 HTTP 服务器 | 57 | // 关闭 HTTP 服务器 |
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/upstream/router/IotDevicePropertyReportVertxHandler.java
| @@ -10,21 +10,22 @@ import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStateEnum; | @@ -10,21 +10,22 @@ import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStateEnum; | ||
| 10 | import io.vertx.core.Handler; | 10 | import io.vertx.core.Handler; |
| 11 | import io.vertx.ext.web.RequestBody; | 11 | import io.vertx.ext.web.RequestBody; |
| 12 | import io.vertx.ext.web.RoutingContext; | 12 | import io.vertx.ext.web.RoutingContext; |
| 13 | +import lombok.RequiredArgsConstructor; | ||
| 13 | import lombok.extern.slf4j.Slf4j; | 14 | import lombok.extern.slf4j.Slf4j; |
| 14 | 15 | ||
| 15 | import java.time.LocalDateTime; | 16 | import java.time.LocalDateTime; |
| 16 | import java.util.Map; | 17 | import java.util.Map; |
| 17 | 18 | ||
| 19 | +/** | ||
| 20 | + * IoT 设备属性上报的 Vert.x Handler | ||
| 21 | + */ | ||
| 22 | +@RequiredArgsConstructor | ||
| 18 | @Slf4j | 23 | @Slf4j |
| 19 | public class IotDevicePropertyReportVertxHandler implements Handler<RoutingContext> { | 24 | public class IotDevicePropertyReportVertxHandler implements Handler<RoutingContext> { |
| 20 | 25 | ||
| 21 | public static final String PATH = "/sys/:productKey/:deviceName/thing/event/property/post"; | 26 | public static final String PATH = "/sys/:productKey/:deviceName/thing/event/property/post"; |
| 22 | 27 | ||
| 23 | - private final IotDeviceUpstreamApi deviceDataApi; | ||
| 24 | - | ||
| 25 | - public IotDevicePropertyReportVertxHandler(IotDeviceUpstreamApi deviceDataApi) { | ||
| 26 | - this.deviceDataApi = deviceDataApi; | ||
| 27 | - } | 28 | + private final IotDeviceUpstreamApi deviceUpstreamApi; |
| 28 | 29 | ||
| 29 | @Override | 30 | @Override |
| 30 | public void handle(RoutingContext ctx) { | 31 | public void handle(RoutingContext ctx) { |
| @@ -51,7 +52,7 @@ public class IotDevicePropertyReportVertxHandler implements Handler<RoutingConte | @@ -51,7 +52,7 @@ public class IotDevicePropertyReportVertxHandler implements Handler<RoutingConte | ||
| 51 | try { | 52 | try { |
| 52 | // TODO @haohao:pluginKey 需要设置 | 53 | // TODO @haohao:pluginKey 需要设置 |
| 53 | // 设备上线 | 54 | // 设备上线 |
| 54 | - deviceDataApi.updateDeviceState(((IotDeviceStateUpdateReqDTO) | 55 | + deviceUpstreamApi.updateDeviceState(((IotDeviceStateUpdateReqDTO) |
| 55 | new IotDeviceStateUpdateReqDTO().setRequestId(IdUtil.fastSimpleUUID()) | 56 | new IotDeviceStateUpdateReqDTO().setRequestId(IdUtil.fastSimpleUUID()) |
| 56 | .setPluginKey("http") | 57 | .setPluginKey("http") |
| 57 | .setReportTime(LocalDateTime.now()) | 58 | .setReportTime(LocalDateTime.now()) |
| @@ -59,7 +60,7 @@ public class IotDevicePropertyReportVertxHandler implements Handler<RoutingConte | @@ -59,7 +60,7 @@ public class IotDevicePropertyReportVertxHandler implements Handler<RoutingConte | ||
| 59 | .setState(IotDeviceStateEnum.ONLINE.getState())); | 60 | .setState(IotDeviceStateEnum.ONLINE.getState())); |
| 60 | 61 | ||
| 61 | // 属性上报 | 62 | // 属性上报 |
| 62 | - deviceDataApi.reportDeviceProperty(((IotDevicePropertyReportReqDTO) | 63 | + deviceUpstreamApi.reportDeviceProperty(((IotDevicePropertyReportReqDTO) |
| 63 | new IotDevicePropertyReportReqDTO().setRequestId(IdUtil.fastSimpleUUID()) | 64 | new IotDevicePropertyReportReqDTO().setRequestId(IdUtil.fastSimpleUUID()) |
| 64 | .setPluginKey("http").setReportTime(LocalDateTime.now()) | 65 | .setPluginKey("http").setReportTime(LocalDateTime.now()) |
| 65 | .setProductKey(productKey).setDeviceName(deviceName)) | 66 | .setProductKey(productKey).setDeviceName(deviceName)) |
| @@ -81,6 +82,7 @@ public class IotDevicePropertyReportVertxHandler implements Handler<RoutingConte | @@ -81,6 +82,7 @@ public class IotDevicePropertyReportVertxHandler implements Handler<RoutingConte | ||
| 81 | } | 82 | } |
| 82 | } | 83 | } |
| 83 | 84 | ||
| 85 | + // TODO @芋艿:抽一个 IotPluginCommonResult 出来?等 mqtt、websocket 出来后,再考虑优化! | ||
| 84 | private JSONObject createResponseJson(int code, JSONObject data, String id, | 86 | private JSONObject createResponseJson(int code, JSONObject data, String id, |
| 85 | String message, String method, String version) { | 87 | String message, String method, String version) { |
| 86 | JSONObject res = new JSONObject(); | 88 | JSONObject res = new JSONObject(); |
| @@ -92,4 +94,5 @@ public class IotDevicePropertyReportVertxHandler implements Handler<RoutingConte | @@ -92,4 +94,5 @@ public class IotDevicePropertyReportVertxHandler implements Handler<RoutingConte | ||
| 92 | res.set("version", version); | 94 | res.set("version", version); |
| 93 | return res; | 95 | return res; |
| 94 | } | 96 | } |
| 97 | + | ||
| 95 | } | 98 | } |