Merge branch 'feature/iot' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into origin/feature/iot
This commit is contained in:
commit
977ddcf02f
|
@ -1,2 +1 @@
|
|||
http-plugin
|
||||
http-plugin@0.0.1
|
||||
|
|
|
@ -4,6 +4,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.plugininfo.PluginInfoDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.*;
|
||||
|
||||
|
@ -22,4 +25,10 @@ public interface PluginInfoMapper extends BaseMapperX<PluginInfoDO> {
|
|||
.orderByDesc(PluginInfoDO::getId));
|
||||
}
|
||||
|
||||
default List<PluginInfoDO> selectListByStatus(Integer status) {
|
||||
return selectList(new LambdaQueryWrapperX<PluginInfoDO>()
|
||||
.eq(PluginInfoDO::getStatus, status)
|
||||
.orderByAsc(PluginInfoDO::getId));
|
||||
}
|
||||
|
||||
}
|
|
@ -17,7 +17,7 @@ import org.springframework.stereotype.Component;
|
|||
* @author ahh
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
//@Component
|
||||
public class EmqxCallback implements MqttCallbackExtended {
|
||||
|
||||
@Lazy
|
||||
|
|
|
@ -19,7 +19,7 @@ import org.springframework.stereotype.Component;
|
|||
*/
|
||||
@Slf4j
|
||||
@Data
|
||||
@Component
|
||||
//@Component
|
||||
public class EmqxClient {
|
||||
|
||||
@Resource
|
||||
|
|
|
@ -12,8 +12,8 @@ import org.springframework.stereotype.Component;
|
|||
* @author ahh
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties("iot.emq")
|
||||
//@Component
|
||||
//@ConfigurationProperties("iot.emq")
|
||||
public class MqttConfig {
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,7 @@ import org.springframework.stereotype.Service;
|
|||
* @author ahh
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
//@Service
|
||||
public class EmqxServiceImpl implements EmqxService {
|
||||
|
||||
@Resource
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.springframework.stereotype.Component;
|
|||
*
|
||||
* @author ahh
|
||||
*/
|
||||
@Component
|
||||
//@Component
|
||||
public class EmqxStart implements ApplicationRunner {
|
||||
|
||||
@Resource
|
||||
|
|
|
@ -76,4 +76,11 @@ public interface PluginInfoService {
|
|||
* @return 插件信息列表
|
||||
*/
|
||||
List<PluginInfoDO> getPluginInfoList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得运行状态的插件信息列表
|
||||
*
|
||||
* @return 运行状态的插件信息列表
|
||||
*/
|
||||
List<PluginInfoDO> getRunningPluginInfoList();
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
|
@ -186,20 +187,19 @@ public class PluginInfoServiceImpl implements PluginInfoService {
|
|||
if (pluginWrapper == null) {
|
||||
throw exception(PLUGIN_INSTALL_FAILED);
|
||||
}
|
||||
String pluginInfo = pluginKeyNew + "@" + pluginWrapper.getDescriptor().getVersion();
|
||||
List<String> targetLines = Files.exists(targetFilePath) ? Files.readAllLines(targetFilePath)
|
||||
: new ArrayList<>();
|
||||
List<String> oppositeLines = Files.exists(oppositeFilePath) ? Files.readAllLines(oppositeFilePath)
|
||||
: new ArrayList<>();
|
||||
|
||||
if (!targetLines.contains(pluginInfo)) {
|
||||
targetLines.add(pluginInfo);
|
||||
if (!targetLines.contains(pluginKeyNew)) {
|
||||
targetLines.add(pluginKeyNew);
|
||||
Files.write(targetFilePath, targetLines, StandardOpenOption.CREATE,
|
||||
StandardOpenOption.TRUNCATE_EXISTING);
|
||||
}
|
||||
|
||||
if (oppositeLines.contains(pluginInfo)) {
|
||||
oppositeLines.remove(pluginInfo);
|
||||
if (oppositeLines.contains(pluginKeyNew)) {
|
||||
oppositeLines.remove(pluginKeyNew);
|
||||
Files.write(oppositeFilePath, oppositeLines, StandardOpenOption.CREATE,
|
||||
StandardOpenOption.TRUNCATE_EXISTING);
|
||||
}
|
||||
|
@ -267,4 +267,8 @@ public class PluginInfoServiceImpl implements PluginInfoService {
|
|||
return pluginInfoMapper.selectList(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PluginInfoDO> getRunningPluginInfoList() {
|
||||
return pluginInfoMapper.selectListByStatus(IotPluginStatusEnum.RUNNING.getStatus());
|
||||
}
|
||||
}
|
|
@ -2,11 +2,6 @@
|
|||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<!-- <modelVersion>4.0.0</modelVersion>-->
|
||||
<!-- <groupId>cn.iocoder.boot</groupId>-->
|
||||
<!-- <artifactId>yudao-module-iot-plugin</artifactId>-->
|
||||
<!-- <version>0.0.1</version>-->
|
||||
<!-- <packaging>pom</packaging>-->
|
||||
<parent>
|
||||
<artifactId>yudao-module-iot</artifactId>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
|
@ -15,6 +10,7 @@
|
|||
<modules>
|
||||
<module>yudao-module-iot-demo-plugin</module>
|
||||
<module>yudao-module-iot-http-plugin</module>
|
||||
<module>yudao-module-iot-mqtt-plugin</module>
|
||||
</modules>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
plugin.id=mqtt-plugin
|
||||
plugin.class=cn.iocoder.yudao.module.iot.plugin.MqttPlugin
|
||||
plugin.version=0.0.1
|
||||
plugin.provider=ahh
|
||||
plugin.dependencies=
|
||||
plugin.description=mqtt-plugin-0.0.1
|
|
@ -0,0 +1,154 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="
|
||||
http://maven.apache.org/POM/4.0.0
|
||||
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>yudao-module-iot-plugin</artifactId>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<artifactId>yudao-module-iot-mqtt-plugin</artifactId>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
<description>
|
||||
物联网 插件模块 - mqtt 插件
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
<!-- 插件相关 -->
|
||||
<plugin.id>mqtt-plugin</plugin.id>
|
||||
<plugin.class>cn.iocoder.yudao.module.iot.plugin.MqttPlugin</plugin.class>
|
||||
<plugin.version>0.0.1</plugin.version>
|
||||
<plugin.provider>ahh</plugin.provider>
|
||||
<plugin.description>mqtt-plugin-0.0.1</plugin.description>
|
||||
<plugin.dependencies/>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- DOESN'T WORK WITH MAVEN 3 (I defined the plugin metadata in properties section)
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>properties-maven-plugin</artifactId>
|
||||
<version>1.0-alpha-2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>initialize</phase>
|
||||
<goals>
|
||||
<goal>read-project-properties</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<files>
|
||||
<file>plugin.properties</file>
|
||||
</files>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
-->
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>unzip jar file</id>
|
||||
<phase>package</phase>
|
||||
<configuration>
|
||||
<target>
|
||||
<unzip src="target/${project.artifactId}-${project.version}.${project.packaging}"
|
||||
dest="target/plugin-classes"/>
|
||||
</target>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>
|
||||
src/main/assembly/assembly.xml
|
||||
</descriptor>
|
||||
</descriptors>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>attached</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Plugin-Id>${plugin.id}</Plugin-Id>
|
||||
<Plugin-Class>${plugin.class}</Plugin-Class>
|
||||
<Plugin-Version>${plugin.version}</Plugin-Version>
|
||||
<Plugin-Provider>${plugin.provider}</Plugin-Provider>
|
||||
<Plugin-Description>${plugin.description}</Plugin-Description>
|
||||
<Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- 其他依赖项 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- PF4J Spring 集成 -->
|
||||
<dependency>
|
||||
<groupId>org.pf4j</groupId>
|
||||
<artifactId>pf4j-spring</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- 项目依赖 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<artifactId>yudao-module-iot-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.1.63.Final</version> <!-- 版本可根据需要调整 -->
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,31 @@
|
|||
<assembly>
|
||||
<id>plugin</id>
|
||||
<formats>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<dependencySets>
|
||||
<dependencySet>
|
||||
<useProjectArtifact>false</useProjectArtifact>
|
||||
<scope>runtime</scope>
|
||||
<outputDirectory>lib</outputDirectory>
|
||||
<includes>
|
||||
<include>*:jar:*</include>
|
||||
</includes>
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
<!--
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>target/classes</directory>
|
||||
<outputDirectory>classes</outputDirectory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
-->
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>target/plugin-classes</directory>
|
||||
<outputDirectory>classes</outputDirectory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
|
@ -0,0 +1,48 @@
|
|||
package cn.iocoder.yudao.module.iot.plugin;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi;
|
||||
import cn.iocoder.yudao.module.iot.api.ServiceRegistry;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.pf4j.PluginWrapper;
|
||||
import org.pf4j.Plugin;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@Slf4j
|
||||
public class MqttPlugin extends Plugin {
|
||||
|
||||
private ExecutorService executorService;
|
||||
private DeviceDataApi deviceDataApi;
|
||||
|
||||
public MqttPlugin(PluginWrapper wrapper) {
|
||||
super(wrapper);
|
||||
// 初始化线程池
|
||||
this.executorService = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
log.info("MqttPlugin.start()");
|
||||
|
||||
// 重新初始化线程池,确保它是活跃的
|
||||
if (executorService.isShutdown() || executorService.isTerminated()) {
|
||||
executorService = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
|
||||
// 从 ServiceRegistry 中获取主程序暴露的 DeviceDataApi 接口实例
|
||||
deviceDataApi = ServiceRegistry.getService(DeviceDataApi.class);
|
||||
if (deviceDataApi == null) {
|
||||
log.error("未能从 ServiceRegistry 获取 DeviceDataApi 实例,请确保主程序已正确注册!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
log.info("MqttPlugin.stop()");
|
||||
// 停止线程池
|
||||
executorService.shutdownNow();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue