【功能完善】IoT: 添加 MQTT 插件支持,重构插件管理,新增获取运行状态插件信息接口,优化插件信息存储逻辑,移除不必要的 Spring 注解。
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user