Commit 5110948db813ae41c466432b3c8064d4c1e7feb1
1 parent
911c8c74
【代码优化】IoT:设备下行实现前,相关代码的整理
Showing
25 changed files
with
44 additions
and
392 deletions
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/plugin/IotPluginDeployTypeEnum.java
| ... | ... | @@ -33,17 +33,13 @@ public enum IotPluginDeployTypeEnum implements ArrayValuable<Integer> { |
| 33 | 33 | this.name = name; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - public static IotPluginDeployTypeEnum fromDeployType(Integer deployType) { | |
| 36 | + public static IotPluginDeployTypeEnum valueOf(Integer deployType) { | |
| 37 | 37 | return Arrays.stream(values()) |
| 38 | 38 | .filter(value -> value.getDeployType().equals(deployType)) |
| 39 | 39 | .findFirst() |
| 40 | 40 | .orElse(null); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - public static boolean isValidDeployType(Integer deployType) { | |
| 44 | - return fromDeployType(deployType) != null; | |
| 45 | - } | |
| 46 | - | |
| 47 | 43 | @Override |
| 48 | 44 | public Integer[] array() { |
| 49 | 45 | return ARRAYS; | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/PluginInfoController.java
| ... | ... | @@ -3,11 +3,11 @@ package cn.iocoder.yudao.module.iot.controller.admin.plugin; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | -import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.PluginInfoImportReqVO; | |
| 7 | -import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.PluginInfoPageReqVO; | |
| 8 | -import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.PluginInfoRespVO; | |
| 9 | -import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.PluginInfoSaveReqVO; | |
| 10 | -import cn.iocoder.yudao.module.iot.dal.dataobject.plugininfo.PluginInfoDO; | |
| 6 | +import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.info.PluginInfoImportReqVO; | |
| 7 | +import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.info.PluginInfoPageReqVO; | |
| 8 | +import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.info.PluginInfoRespVO; | |
| 9 | +import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.info.PluginInfoSaveReqVO; | |
| 10 | +import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.PluginInfoDO; | |
| 11 | 11 | import cn.iocoder.yudao.module.iot.service.plugin.PluginInfoService; |
| 12 | 12 | import io.swagger.v3.oas.annotations.Operation; |
| 13 | 13 | import io.swagger.v3.oas.annotations.Parameter; | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/PluginInstanceSaveReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.controller.admin.plugin.vo; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.*; | |
| 5 | -import jakarta.validation.constraints.*; | |
| 6 | - | |
| 7 | -@Schema(description = "管理后台 - IoT 插件实例新增/修改 Request VO") | |
| 8 | -@Data | |
| 9 | -public class PluginInstanceSaveReqVO { | |
| 10 | - | |
| 11 | - @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "23864") | |
| 12 | - private Long id; | |
| 13 | - | |
| 14 | - @Schema(description = "插件主程序id", requiredMode = Schema.RequiredMode.REQUIRED, example = "23738") | |
| 15 | - @NotEmpty(message = "插件主程序id不能为空") | |
| 16 | - private String mainId; | |
| 17 | - | |
| 18 | - @Schema(description = "插件id", requiredMode = Schema.RequiredMode.REQUIRED, example = "26498") | |
| 19 | - @NotNull(message = "插件id不能为空") | |
| 20 | - private Long pluginId; | |
| 21 | - | |
| 22 | - @Schema(description = "插件主程序所在ip", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 23 | - @NotEmpty(message = "插件主程序所在ip不能为空") | |
| 24 | - private String ip; | |
| 25 | - | |
| 26 | - @Schema(description = "插件主程序端口", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 27 | - @NotNull(message = "插件主程序端口不能为空") | |
| 28 | - private Integer port; | |
| 29 | - | |
| 30 | - @Schema(description = "心跳时间,心路时间超过30秒需要剔除", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 31 | - @NotNull(message = "心跳时间,心路时间超过30秒需要剔除不能为空") | |
| 32 | - private Long heartbeatAt; | |
| 33 | - | |
| 34 | -} | |
| 35 | 0 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/PluginInfoImportReqVO.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/info/PluginInfoImportReqVO.java
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/PluginInfoPageReqVO.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/info/PluginInfoPageReqVO.java
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/PluginInfoRespVO.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/info/PluginInfoRespVO.java
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/PluginInfoSaveReqVO.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/info/PluginInfoSaveReqVO.java
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/PluginInstancePageReqVO.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/instance/PluginInstancePageReqVO.java
| 1 | -package cn.iocoder.yudao.module.iot.controller.admin.plugin.vo; | |
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.instance; | |
| 2 | 2 | |
| 3 | 3 | import lombok.*; |
| 4 | 4 | import io.swagger.v3.oas.annotations.media.Schema; |
| ... | ... | @@ -8,11 +8,8 @@ import java.time.LocalDateTime; |
| 8 | 8 | |
| 9 | 9 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
| 10 | 10 | |
| 11 | -// TODO @haohao:建议搞个 plugin,然后里面分 info 和 instance。另外,是不是 info => config 会好点,插件配置? | |
| 12 | 11 | @Schema(description = "管理后台 - IoT 插件实例分页 Request VO") |
| 13 | 12 | @Data |
| 14 | -@EqualsAndHashCode(callSuper = true) | |
| 15 | -@ToString(callSuper = true) | |
| 16 | 13 | public class PluginInstancePageReqVO extends PageParam { |
| 17 | 14 | |
| 18 | 15 | @Schema(description = "插件主程序id", example = "23738") | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/PluginInstanceRespVO.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/instance/PluginInstanceRespVO.java
| 1 | -package cn.iocoder.yudao.module.iot.controller.admin.plugin.vo; | |
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.instance; | |
| 2 | 2 | |
| 3 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | |
| 4 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 3 | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | -import lombok.*; | |
| 6 | +import lombok.Data; | |
| 7 | + | |
| 5 | 8 | import java.time.LocalDateTime; |
| 6 | -import com.alibaba.excel.annotation.*; | |
| 7 | 9 | |
| 8 | 10 | @Schema(description = "管理后台 - IoT 插件实例 Response VO") |
| 9 | 11 | @Data | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/plugininfo/PluginInfoDO.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/plugin/PluginInfoDO.java
| 1 | -package cn.iocoder.yudao.module.iot.dal.dataobject.plugininfo; | |
| 1 | +package cn.iocoder.yudao.module.iot.dal.dataobject.plugin; | |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | 4 | import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginDeployTypeEnum; |
| ... | ... | @@ -47,6 +47,7 @@ public class PluginInfoDO extends BaseDO { |
| 47 | 47 | * 枚举 {@link IotPluginDeployTypeEnum} |
| 48 | 48 | */ |
| 49 | 49 | private Integer deployType; |
| 50 | + // TODO @芋艿:如果是外置的插件,fileName 和 version 的选择~ | |
| 50 | 51 | /** |
| 51 | 52 | * 插件包文件名 |
| 52 | 53 | */ |
| ... | ... | @@ -55,6 +56,7 @@ public class PluginInfoDO extends BaseDO { |
| 55 | 56 | * 插件版本 |
| 56 | 57 | */ |
| 57 | 58 | private String version; |
| 59 | + // TODO @芋艿:type 字典的定义 | |
| 58 | 60 | /** |
| 59 | 61 | * 插件类型 |
| 60 | 62 | * <p> |
| ... | ... | @@ -64,6 +66,7 @@ public class PluginInfoDO extends BaseDO { |
| 64 | 66 | /** |
| 65 | 67 | * 设备插件协议类型 |
| 66 | 68 | */ |
| 69 | + // TODO @芋艿:枚举字段 | |
| 67 | 70 | private String protocol; |
| 68 | 71 | /** |
| 69 | 72 | * 状态 |
| ... | ... | @@ -71,6 +74,7 @@ public class PluginInfoDO extends BaseDO { |
| 71 | 74 | * 枚举 {@link IotPluginStatusEnum} |
| 72 | 75 | */ |
| 73 | 76 | private Integer status; |
| 77 | + // TODO @芋艿:configSchema、config 示例字段 | |
| 74 | 78 | /** |
| 75 | 79 | * 插件配置项描述信息 |
| 76 | 80 | */ |
| ... | ... | @@ -79,6 +83,7 @@ public class PluginInfoDO extends BaseDO { |
| 79 | 83 | * 插件配置信息 |
| 80 | 84 | */ |
| 81 | 85 | private String config; |
| 86 | + // TODO @芋艿:script 后续的使用 | |
| 82 | 87 | /** |
| 83 | 88 | * 插件脚本 |
| 84 | 89 | */ | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/plugininstance/PluginInstanceDO.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/plugin/PluginInstanceDO.java
| 1 | -package cn.iocoder.yudao.module.iot.dal.dataobject.plugininstance; | |
| 1 | +package cn.iocoder.yudao.module.iot.dal.dataobject.plugin; | |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | -import cn.iocoder.yudao.module.iot.dal.dataobject.plugininfo.PluginInfoDO; | |
| 5 | 4 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 6 | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
| 7 | 6 | import com.baomidou.mybatisplus.annotation.TableName; |
| ... | ... | @@ -28,6 +27,7 @@ public class PluginInstanceDO extends BaseDO { |
| 28 | 27 | */ |
| 29 | 28 | @TableId |
| 30 | 29 | private Long id; |
| 30 | + // TODO @芋艿:找一个更好的字段名 | |
| 31 | 31 | /** |
| 32 | 32 | * 插件主程序 ID |
| 33 | 33 | */ |
| ... | ... | @@ -43,10 +43,12 @@ public class PluginInstanceDO extends BaseDO { |
| 43 | 43 | * 插件主程序所在 IP |
| 44 | 44 | */ |
| 45 | 45 | private String ip; |
| 46 | + // TODO @芋艿:这个 port 是否有必要记录 | |
| 46 | 47 | /** |
| 47 | 48 | * 插件主程序端口 |
| 48 | 49 | */ |
| 49 | 50 | private Integer port; |
| 51 | + // TODO @芋艿:downstreamPort 增加,目的:用于下行 | |
| 50 | 52 | |
| 51 | 53 | // TODO @haohao:字段改成 heartbeatTime,LocalDateTime |
| 52 | 54 | /** | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/plugin/PluginInfoMapper.java
| ... | ... | @@ -3,12 +3,12 @@ package cn.iocoder.yudao.module.iot.dal.mysql.plugin; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 6 | -import cn.iocoder.yudao.module.iot.dal.dataobject.plugininfo.PluginInfoDO; | |
| 6 | +import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.info.PluginInfoPageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.PluginInfoDO; | |
| 7 | 8 | |
| 8 | 9 | import java.util.List; |
| 9 | 10 | |
| 10 | 11 | import org.apache.ibatis.annotations.Mapper; |
| 11 | -import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.*; | |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * IoT 插件信息 Mapper | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/plugin/PluginInstanceMapper.java
| ... | ... | @@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.iot.dal.mysql.plugin; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 6 | -import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.PluginInstancePageReqVO; | |
| 7 | -import cn.iocoder.yudao.module.iot.dal.dataobject.plugininstance.PluginInstanceDO; | |
| 6 | +import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.instance.PluginInstancePageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.PluginInstanceDO; | |
| 8 | 8 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 9 | |
| 10 | 10 | /** | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/emq/callback/EmqxCallback.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.emq.callback; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.module.iot.emq.client.EmqxClient; | |
| 4 | -import cn.iocoder.yudao.module.iot.emq.service.EmqxService; | |
| 5 | -import jakarta.annotation.Resource; | |
| 6 | -import lombok.extern.slf4j.Slf4j; | |
| 7 | -import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; | |
| 8 | -import org.eclipse.paho.client.mqttv3.MqttCallbackExtended; | |
| 9 | -import org.eclipse.paho.client.mqttv3.MqttMessage; | |
| 10 | -import org.springframework.context.annotation.Lazy; | |
| 11 | -import org.springframework.stereotype.Component; | |
| 12 | - | |
| 13 | -// TODO @芋艿:详细再瞅瞅 | |
| 14 | -/** | |
| 15 | - * 用于处理MQTT连接的回调,如连接断开、消息到达、消息发布完成、连接完成等事件。 | |
| 16 | - * | |
| 17 | - * @author ahh | |
| 18 | - */ | |
| 19 | -@Slf4j | |
| 20 | -//@Component | |
| 21 | -public class EmqxCallback implements MqttCallbackExtended { | |
| 22 | - | |
| 23 | - @Lazy | |
| 24 | - @Resource | |
| 25 | - private EmqxService emqxService; | |
| 26 | - | |
| 27 | - @Lazy | |
| 28 | - @Resource | |
| 29 | - private EmqxClient emqxClient; | |
| 30 | - | |
| 31 | - @Override | |
| 32 | - public void connectionLost(Throwable throwable) { | |
| 33 | - log.info("MQTT 连接断开", throwable); | |
| 34 | - } | |
| 35 | - | |
| 36 | - @Override | |
| 37 | - public void messageArrived(String topic, MqttMessage mqttMessage) { | |
| 38 | - emqxService.subscribeCallback(topic, mqttMessage); | |
| 39 | - } | |
| 40 | - | |
| 41 | - @Override | |
| 42 | - public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) { | |
| 43 | - log.info("消息发送成功: {}", iMqttDeliveryToken.getMessageId()); | |
| 44 | - } | |
| 45 | - | |
| 46 | - @Override | |
| 47 | - public void connectComplete(boolean reconnect, String serverURI) { | |
| 48 | - log.info("MQTT 已连接到服务器: {}", serverURI); | |
| 49 | - emqxService.subscribe(emqxClient.getMqttClient()); | |
| 50 | - } | |
| 51 | -} | |
| 52 | - | |
| 53 | - | |
| 54 | - |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/emq/client/EmqxClient.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.emq.client; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.module.iot.emq.callback.EmqxCallback; | |
| 4 | -import cn.iocoder.yudao.module.iot.emq.config.MqttConfig; | |
| 5 | -import jakarta.annotation.Resource; | |
| 6 | -import lombok.Data; | |
| 7 | -import lombok.extern.slf4j.Slf4j; | |
| 8 | -import org.eclipse.paho.client.mqttv3.MqttClient; | |
| 9 | -import org.eclipse.paho.client.mqttv3.MqttConnectOptions; | |
| 10 | -import org.eclipse.paho.client.mqttv3.MqttException; | |
| 11 | -import org.eclipse.paho.client.mqttv3.MqttMessage; | |
| 12 | -import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; | |
| 13 | -import org.springframework.stereotype.Component; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * MQTT客户端类,负责建立与MQTT服务器的连接,提供发布消息和订阅主题的功能 | |
| 17 | - * | |
| 18 | - * @author ahh | |
| 19 | - */ | |
| 20 | -@Slf4j | |
| 21 | -@Data | |
| 22 | -//@Component | |
| 23 | -public class EmqxClient { | |
| 24 | - | |
| 25 | - @Resource | |
| 26 | - private EmqxCallback emqxCallback; | |
| 27 | - @Resource | |
| 28 | - private MqttConfig mqttConfig; | |
| 29 | - | |
| 30 | - private MqttClient mqttClient; | |
| 31 | - | |
| 32 | - public void connect() { | |
| 33 | - if (mqttClient == null) { | |
| 34 | - createMqttClient(); | |
| 35 | - } | |
| 36 | - try { | |
| 37 | - mqttClient.connect(createMqttOptions()); | |
| 38 | - log.info("MQTT客户端连接成功"); | |
| 39 | - } catch (MqttException e) { | |
| 40 | - log.error("MQTT客户端连接失败", e); | |
| 41 | - } | |
| 42 | - } | |
| 43 | - | |
| 44 | - private void createMqttClient() { | |
| 45 | - try { | |
| 46 | - mqttClient = new MqttClient(mqttConfig.getHostUrl(), "yudao" + mqttConfig.getClientId(), new MemoryPersistence()); | |
| 47 | - mqttClient.setCallback(emqxCallback); | |
| 48 | - } catch (MqttException e) { | |
| 49 | - log.error("创建MQTT客户端失败", e); | |
| 50 | - } | |
| 51 | - } | |
| 52 | - | |
| 53 | - private MqttConnectOptions createMqttOptions() { | |
| 54 | - MqttConnectOptions options = new MqttConnectOptions(); | |
| 55 | - options.setUserName(mqttConfig.getUsername()); | |
| 56 | - options.setPassword(mqttConfig.getPassword().toCharArray()); | |
| 57 | - options.setConnectionTimeout(mqttConfig.getTimeout()); | |
| 58 | - options.setKeepAliveInterval(mqttConfig.getKeepalive()); | |
| 59 | - options.setCleanSession(mqttConfig.isClearSession()); | |
| 60 | - return options; | |
| 61 | - } | |
| 62 | - | |
| 63 | - public void publish(String topic, String message) { | |
| 64 | - try { | |
| 65 | - if (mqttClient == null || !mqttClient.isConnected()) { | |
| 66 | - connect(); | |
| 67 | - } | |
| 68 | - mqttClient.publish(topic, new MqttMessage(message.getBytes())); | |
| 69 | - log.info("消息已发布到主题: {}", topic); | |
| 70 | - } catch (MqttException e) { | |
| 71 | - log.error("消息发布失败", e); | |
| 72 | - } | |
| 73 | - } | |
| 74 | - | |
| 75 | - public void subscribe(String topic) { | |
| 76 | - try { | |
| 77 | - if (mqttClient == null || !mqttClient.isConnected()) { | |
| 78 | - connect(); | |
| 79 | - } | |
| 80 | - mqttClient.subscribe(topic); | |
| 81 | - log.info("订阅了主题: {}", topic); | |
| 82 | - } catch (MqttException e) { | |
| 83 | - log.error("订阅主题失败", e); | |
| 84 | - } | |
| 85 | - } | |
| 86 | -} | |
| 87 | 0 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/emq/config/MqttConfig.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.emq.config; | |
| 2 | - | |
| 3 | -import lombok.Data; | |
| 4 | -import org.springframework.boot.context.properties.ConfigurationProperties; | |
| 5 | -import org.springframework.stereotype.Component; | |
| 6 | - | |
| 7 | -// TODO @芋艿:详细再瞅瞅 | |
| 8 | - | |
| 9 | -/** | |
| 10 | - * 配置类,用于读取MQTT连接的配置信息,如用户名、密码、连接地址等 | |
| 11 | - * | |
| 12 | - * @author ahh | |
| 13 | - */ | |
| 14 | -@Data | |
| 15 | -//@Component | |
| 16 | -//@ConfigurationProperties("iot.emq") | |
| 17 | -public class MqttConfig { | |
| 18 | - | |
| 19 | - /** | |
| 20 | - * 用户名 | |
| 21 | - */ | |
| 22 | - private String username; | |
| 23 | - /** | |
| 24 | - * 密码 | |
| 25 | - */ | |
| 26 | - private String password; | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * 连接地址 | |
| 30 | - */ | |
| 31 | - private String hostUrl; | |
| 32 | - | |
| 33 | - /** | |
| 34 | - * 客户Id | |
| 35 | - */ | |
| 36 | - private String clientId; | |
| 37 | - | |
| 38 | - /** | |
| 39 | - * 默认连接话题 | |
| 40 | - */ | |
| 41 | - private String defaultTopic; | |
| 42 | - | |
| 43 | - /** | |
| 44 | - * 超时时间 | |
| 45 | - */ | |
| 46 | - private int timeout; | |
| 47 | - | |
| 48 | - /** | |
| 49 | - * 保持连接数 | |
| 50 | - */ | |
| 51 | - private int keepalive; | |
| 52 | - | |
| 53 | - /** | |
| 54 | - * 是否清除session | |
| 55 | - */ | |
| 56 | - private boolean clearSession; | |
| 57 | - | |
| 58 | - /** | |
| 59 | - * 是否共享订阅 | |
| 60 | - */ | |
| 61 | - private boolean isShared; | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * 分组共享订阅 | |
| 65 | - */ | |
| 66 | - private boolean isSharedGroup; | |
| 67 | - | |
| 68 | -} |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/emq/service/EmqxService.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.emq.service; | |
| 2 | - | |
| 3 | -import org.eclipse.paho.client.mqttv3.MqttClient; | |
| 4 | -import org.eclipse.paho.client.mqttv3.MqttMessage; | |
| 5 | - | |
| 6 | -// TODO @芋艿:在瞅瞅 | |
| 7 | -/** | |
| 8 | - * 用于处理MQTT消息的具体业务逻辑,如订阅回调 | |
| 9 | - * | |
| 10 | - * @author ahh | |
| 11 | - */ | |
| 12 | -public interface EmqxService { | |
| 13 | - | |
| 14 | - /** | |
| 15 | - * 订阅回调 | |
| 16 | - * | |
| 17 | - * @param topic 主题 | |
| 18 | - * @param mqttMessage 消息 | |
| 19 | - */ | |
| 20 | - void subscribeCallback(String topic, MqttMessage mqttMessage); | |
| 21 | - | |
| 22 | - /** | |
| 23 | - * 订阅主题 | |
| 24 | - * | |
| 25 | - * @param client MQTT 客户端 | |
| 26 | - */ | |
| 27 | - void subscribe(MqttClient client); | |
| 28 | -} |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/emq/service/EmqxServiceImpl.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.emq.service; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.module.iot.service.device.data.IotDevicePropertyService; | |
| 4 | -import jakarta.annotation.Resource; | |
| 5 | -import lombok.extern.slf4j.Slf4j; | |
| 6 | -import org.eclipse.paho.client.mqttv3.MqttClient; | |
| 7 | -import org.eclipse.paho.client.mqttv3.MqttMessage; | |
| 8 | -import org.springframework.scheduling.annotation.Async; | |
| 9 | - | |
| 10 | -// TODO @芋艿:在瞅瞅 | |
| 11 | - | |
| 12 | -/** | |
| 13 | - * 用于处理MQTT消息的具体业务逻辑,如订阅回调 | |
| 14 | - * | |
| 15 | - * @author ahh | |
| 16 | - */ | |
| 17 | -@Slf4j | |
| 18 | -// @Service | |
| 19 | -public class EmqxServiceImpl implements EmqxService { | |
| 20 | - | |
| 21 | - @Resource | |
| 22 | - private IotDevicePropertyService iotDeviceDataService; | |
| 23 | - | |
| 24 | - // TODO 多线程处理消息 | |
| 25 | - @Override | |
| 26 | - @Async | |
| 27 | - public void subscribeCallback(String topic, MqttMessage mqttMessage) { | |
| 28 | - log.info("收到消息,主题: {}, 内容: {}", topic, new String(mqttMessage.getPayload())); | |
| 29 | - // 根据不同的主题,处理不同的业务逻辑 | |
| 30 | - if (topic.contains("/property/post")) { | |
| 31 | - // 设备上报数据 topic /sys/f13f57c63e9/dianbiao1/thing/event/property/post | |
| 32 | - // TODO @hao:这块未来可能,搞个 IotTopicUrls 之类?把拼接和解析的逻辑,收敛 | |
| 33 | - String productKey = topic.split("/")[2]; | |
| 34 | - String deviceName = topic.split("/")[3]; | |
| 35 | - String message = new String(mqttMessage.getPayload()); | |
| 36 | -// IotDevicePropertyReportReqDTO createDTO = IotDevicePropertyReportReqDTO.builder() | |
| 37 | -// .productKey(productKey) | |
| 38 | -// .deviceName(deviceName) | |
| 39 | -// .properties(message) // TODO 芋艿:临时去掉,看看 | |
| 40 | -// .build(); | |
| 41 | -// iotDeviceDataService.saveDeviceProperty(createDTO); | |
| 42 | - } | |
| 43 | - } | |
| 44 | - | |
| 45 | - @Override | |
| 46 | - public void subscribe(MqttClient client) { | |
| 47 | - try { | |
| 48 | - // 订阅默认主题,可以根据需要修改 | |
| 49 | - client.subscribe("/sys/+/+/#", 1); | |
| 50 | - log.info("订阅默认主题成功"); | |
| 51 | - } catch (Exception e) { | |
| 52 | - log.error("订阅默认主题失败", e); | |
| 53 | - } | |
| 54 | - } | |
| 55 | - | |
| 56 | -} |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/emq/start/EmqxStart.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.emq.start; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.module.iot.emq.client.EmqxClient; | |
| 4 | -import jakarta.annotation.Resource; | |
| 5 | -import org.springframework.boot.ApplicationArguments; | |
| 6 | -import org.springframework.boot.ApplicationRunner; | |
| 7 | -import org.springframework.stereotype.Component; | |
| 8 | - | |
| 9 | -// TODO @芋艿:在瞅瞅 | |
| 10 | - | |
| 11 | -/** | |
| 12 | - * 用于在应用启动时自动连接MQTT服务器 | |
| 13 | - * | |
| 14 | - * @author ahh | |
| 15 | - */ | |
| 16 | -//@Component | |
| 17 | -public class EmqxStart implements ApplicationRunner { | |
| 18 | - | |
| 19 | - @Resource | |
| 20 | - private EmqxClient emqxClient; | |
| 21 | - | |
| 22 | - @Override | |
| 23 | - public void run(ApplicationArguments applicationArguments) { | |
| 24 | - emqxClient.connect(); | |
| 25 | - } | |
| 26 | -} |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/PluginStart.java
| ... | ... | @@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.iot.framework.plugin; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; |
| 5 | -import cn.iocoder.yudao.module.iot.dal.dataobject.plugininfo.PluginInfoDO; | |
| 5 | +import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.PluginInfoDO; | |
| 6 | 6 | import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginStatusEnum; |
| 7 | 7 | import cn.iocoder.yudao.module.iot.service.plugin.PluginInfoService; |
| 8 | 8 | import lombok.extern.slf4j.Slf4j; | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/UnifiedConfiguration.java
| ... | ... | @@ -18,7 +18,6 @@ public class UnifiedConfiguration { |
| 18 | 18 | private String pluginsDir; |
| 19 | 19 | |
| 20 | 20 | @Bean |
| 21 | -// @DependsOn("deviceDataApiImpl") | |
| 22 | 21 | public SpringPluginManager pluginManager() { |
| 23 | 22 | log.info("[init][实例化 SpringPluginManager]"); |
| 24 | 23 | SpringPluginManager springPluginManager = new SpringPluginManager(Paths.get(pluginsDir)) { | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/PluginInfoService.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.service.plugin; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.PluginInfoPageReqVO; | |
| 5 | -import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.PluginInfoSaveReqVO; | |
| 6 | -import cn.iocoder.yudao.module.iot.dal.dataobject.plugininfo.PluginInfoDO; | |
| 4 | +import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.info.PluginInfoPageReqVO; | |
| 5 | +import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.info.PluginInfoSaveReqVO; | |
| 6 | +import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.PluginInfoDO; | |
| 7 | 7 | import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginStatusEnum; |
| 8 | 8 | import jakarta.validation.Valid; |
| 9 | 9 | import org.springframework.web.multipart.MultipartFile; | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/PluginInfoServiceImpl.java
| ... | ... | @@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.iot.service.plugin; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | -import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.PluginInfoPageReqVO; | |
| 6 | -import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.PluginInfoSaveReqVO; | |
| 7 | -import cn.iocoder.yudao.module.iot.dal.dataobject.plugininfo.PluginInfoDO; | |
| 5 | +import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.info.PluginInfoPageReqVO; | |
| 6 | +import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.info.PluginInfoSaveReqVO; | |
| 7 | +import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.PluginInfoDO; | |
| 8 | 8 | import cn.iocoder.yudao.module.iot.dal.mysql.plugin.PluginInfoMapper; |
| 9 | 9 | import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginStatusEnum; |
| 10 | 10 | import jakarta.annotation.Resource; | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/PluginInstanceService.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.service.plugin; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.iot.dal.dataobject.plugininfo.PluginInfoDO; | |
| 3 | +import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.PluginInfoDO; | |
| 4 | 4 | import org.springframework.web.multipart.MultipartFile; |
| 5 | 5 | |
| 6 | 6 | /** |
| ... | ... | @@ -10,6 +10,7 @@ import org.springframework.web.multipart.MultipartFile; |
| 10 | 10 | */ |
| 11 | 11 | public interface PluginInstanceService { |
| 12 | 12 | |
| 13 | + // TODO @芋艿:这个是否应该放到 plugin 主动心跳,而是 server 自己心跳 | |
| 13 | 14 | /** |
| 14 | 15 | * 上报插件实例(心跳) |
| 15 | 16 | */ | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/PluginInstanceServiceImpl.java
| ... | ... | @@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.iot.service.plugin; |
| 3 | 3 | import cn.hutool.core.io.FileUtil; |
| 4 | 4 | import cn.hutool.core.net.NetUtil; |
| 5 | 5 | import cn.hutool.core.util.IdUtil; |
| 6 | -import cn.iocoder.yudao.module.iot.dal.dataobject.plugininfo.PluginInfoDO; | |
| 7 | -import cn.iocoder.yudao.module.iot.dal.dataobject.plugininstance.PluginInstanceDO; | |
| 6 | +import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.PluginInfoDO; | |
| 7 | +import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.PluginInstanceDO; | |
| 8 | 8 | import cn.iocoder.yudao.module.iot.dal.mysql.plugin.PluginInfoMapper; |
| 9 | 9 | import cn.iocoder.yudao.module.iot.dal.mysql.plugin.PluginInstanceMapper; |
| 10 | 10 | import cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants; |
| ... | ... | @@ -40,13 +40,15 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU |
| 40 | 40 | @Slf4j |
| 41 | 41 | public class PluginInstanceServiceImpl implements PluginInstanceService { |
| 42 | 42 | |
| 43 | - // TODO @haohao:mac@uuid | |
| 43 | + // TODO @haohao:mac@uuid | |
| 44 | 44 | public static final String MAIN_ID = IdUtil.fastSimpleUUID(); |
| 45 | 45 | |
| 46 | 46 | @Resource |
| 47 | 47 | private PluginInfoMapper pluginInfoMapper; |
| 48 | + | |
| 48 | 49 | @Resource |
| 49 | 50 | private PluginInstanceMapper pluginInstanceMapper; |
| 51 | + | |
| 50 | 52 | @Resource |
| 51 | 53 | private SpringPluginManager pluginManager; |
| 52 | 54 | ... | ... |