Commit b1d3b73b6d73d99808a24797831a5cab58213844

Authored by puhui999
1 parent ff9267ad

【代码优化】IoT: 数据桥梁 config 优化

Showing 18 changed files with 325 additions and 259 deletions
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/DictTypeConstants.java
... ... @@ -15,5 +15,8 @@ public class DictTypeConstants {
15 15 public static final String VALIDATE_TYPE = "iot_validate_type";
16 16  
17 17 public static final String DEVICE_STATE = "iot_device_state";
  18 + public static final String IOT_DATA_BRIDGE_DIRECTION_ENUM = "iot_data_bridge_direction_enum";
  19 + public static final String IOT_DATA_BRIDGE_TYPE_ENUM = "iot_data_bridge_type_enum";
  20 +
18 21  
19 22 }
... ...
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotDataBridgDirectionEnum.java renamed to yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotDataBridgeDirectionEnum.java
... ... @@ -13,14 +13,14 @@ import java.util.Arrays;
13 13 */
14 14 @RequiredArgsConstructor
15 15 @Getter
16   -public enum IotDataBridgDirectionEnum implements ArrayValuable<Integer> {
  16 +public enum IotDataBridgeDirectionEnum implements ArrayValuable<Integer> {
17 17  
18 18 INPUT(1), // 输入
19 19 OUTPUT(2); // 输出
20 20  
21 21 private final Integer type;
22 22  
23   - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotDataBridgDirectionEnum::getType).toArray(Integer[]::new);
  23 + public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotDataBridgeDirectionEnum::getType).toArray(Integer[]::new);
24 24  
25 25 @Override
26 26 public Integer[] array() {
... ...
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotDataBridgTypeEnum.java renamed to yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotDataBridgeTypeEnum.java
... ... @@ -13,25 +13,26 @@ import java.util.Arrays;
13 13 */
14 14 @RequiredArgsConstructor
15 15 @Getter
16   -public enum IotDataBridgTypeEnum implements ArrayValuable<Integer> {
  16 +public enum IotDataBridgeTypeEnum implements ArrayValuable<Integer> {
17 17  
18   - HTTP(1),
19   - TCP(2),
20   - WEBSOCKET(3),
  18 + HTTP(1, "HTTP"),
  19 + TCP(2, "TCP"),
  20 + WEBSOCKET(3, "WEBSOCKET"),
21 21  
22   - MQTT(10),
  22 + MQTT(10, "MQTT"),
23 23  
24   - DATABASE(20),
25   - REDIS_STREAM(21),
  24 + DATABASE(20, "DATABASE"),
  25 + REDIS_STREAM(21, "REDIS_STREAM"),
26 26  
27   - ROCKETMQ(30),
28   - RABBITMQ(31),
29   - KAFKA(32)
30   - ;
  27 + ROCKETMQ(30, "ROCKETMQ"),
  28 + RABBITMQ(31, "RABBITMQ"),
  29 + KAFKA(32, "KAFKA");
31 30  
32 31 private final Integer type;
33 32  
34   - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotDataBridgTypeEnum::getType).toArray(Integer[]::new);
  33 + private final String name;
  34 +
  35 + public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotDataBridgeTypeEnum::getType).toArray(Integer[]::new);
35 36  
36 37 @Override
37 38 public Integer[] array() {
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/IotDataBridgeRespVO.java
... ... @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge;
2 2  
3 3 import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
4 4 import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
  5 +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeConfig;
5 6 import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
6 7 import com.alibaba.excel.annotation.ExcelProperty;
7 8 import io.swagger.v3.oas.annotations.media.Schema;
... ... @@ -9,6 +10,10 @@ import lombok.Data;
9 10  
10 11 import java.time.LocalDateTime;
11 12  
  13 +import static cn.iocoder.yudao.module.iot.enums.DictTypeConstants.IOT_DATA_BRIDGE_DIRECTION_ENUM;
  14 +import static cn.iocoder.yudao.module.iot.enums.DictTypeConstants.IOT_DATA_BRIDGE_TYPE_ENUM;
  15 +import static cn.iocoder.yudao.module.system.enums.DictTypeConstants.COMMON_STATUS;
  16 +
12 17 @Schema(description = "管理后台 - IoT 数据桥梁 Response VO")
13 18 @Data
14 19 @ExcelIgnoreUnannotated
... ... @@ -28,22 +33,22 @@ public class IotDataBridgeRespVO {
28 33  
29 34 @Schema(description = "桥梁状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
30 35 @ExcelProperty(value = "桥梁状态", converter = DictConvert.class)
31   - @DictFormat("common_status") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
  36 + @DictFormat(COMMON_STATUS)
32 37 private Integer status;
33 38  
34 39 @Schema(description = "桥梁方向", requiredMode = Schema.RequiredMode.REQUIRED)
35 40 @ExcelProperty(value = "桥梁方向", converter = DictConvert.class)
36   - @DictFormat("iot_data_bridg_direction_enum") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
  41 + @DictFormat(IOT_DATA_BRIDGE_DIRECTION_ENUM)
37 42 private Integer direction;
38 43  
39 44 @Schema(description = "桥梁类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
40 45 @ExcelProperty(value = "桥梁类型", converter = DictConvert.class)
41   - @DictFormat("iot_data_bridg_type_enum") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
  46 + @DictFormat(IOT_DATA_BRIDGE_TYPE_ENUM)
42 47 private Integer type;
43 48  
44 49 @Schema(description = "桥梁配置")
45 50 @ExcelProperty("桥梁配置")
46   - private String config;
  51 + private IotDataBridgeConfig config;
47 52  
48 53 @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
49 54 @ExcelProperty("创建时间")
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/IotDataBridgeSaveReqVO.java
1 1 package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge;
2 2  
  3 +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeConfig;
3 4 import io.swagger.v3.oas.annotations.media.Schema;
4 5 import jakarta.validation.constraints.NotEmpty;
5 6 import jakarta.validation.constraints.NotNull;
... ... @@ -32,6 +33,7 @@ public class IotDataBridgeSaveReqVO {
32 33 private Integer type;
33 34  
34 35 @Schema(description = "桥梁配置")
35   - private String config;
  36 + @NotNull(message = "桥梁配置不能为空")
  37 + private IotDataBridgeConfig config;
36 38  
37 39 }
38 40 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeConfig.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonSubTypes;
  4 +import com.fasterxml.jackson.annotation.JsonTypeInfo;
  5 +import lombok.Data;
  6 +
  7 +/**
  8 + * 抽象类 IotDataBridgeConfig
  9 + *
  10 + * 用于表示数据桥梁配置数据的通用类型,根据具体的 "type" 字段动态映射到对应的子类。
  11 + * 提供多态支持,适用于不同类型的数据结构序列化和反序列化场景。
  12 + *
  13 + * @author HUIHUI
  14 + */
  15 +@Data
  16 +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", visible = true)
  17 +@JsonSubTypes({
  18 + @JsonSubTypes.Type(value = IotDataBridgeHttpConfig.class, name = "HTTP"),
  19 + @JsonSubTypes.Type(value = IotDataBridgeKafkaMQConfig.class, name = "KAFKA"),
  20 + @JsonSubTypes.Type(value = IotDataBridgeMqttConfig.class, name = "MQTT"),
  21 + @JsonSubTypes.Type(value = IotDataBridgeRabbitMQConfig.class, name = "RABBITMQ"),
  22 + @JsonSubTypes.Type(value = IotDataBridgeRedisStreamMQConfig.class, name = "REDIS_STREAM"),
  23 + @JsonSubTypes.Type(value = IotDataBridgeRocketMQConfig.class, name = "ROCKETMQ"),
  24 +})
  25 +public abstract class IotDataBridgeConfig {
  26 +
  27 + /**
  28 + * 配置类型
  29 + */
  30 + private String type;
  31 +
  32 +}
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeHttpConfig.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import java.util.Map;
  6 +
  7 +/**
  8 + * HTTP 配置
  9 + *
  10 + * @author HUIHUI
  11 + */
  12 +@Data
  13 +public class IotDataBridgeHttpConfig extends IotDataBridgeConfig {
  14 +
  15 + /**
  16 + * 请求 URL
  17 + */
  18 + private String url;
  19 + /**
  20 + * 请求方法
  21 + */
  22 + private String method;
  23 + /**
  24 + * 请求头
  25 + */
  26 + private Map<String, String> headers;
  27 + /**
  28 + * 请求参数
  29 + */
  30 + private Map<String, String> query;
  31 + /**
  32 + * 请求体
  33 + */
  34 + private String body;
  35 +
  36 +}
0 37 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeKafkaMQConfig.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config;
  2 +
  3 +import lombok.Data;
  4 +
  5 +/**
  6 + * Kafka 配置
  7 + *
  8 + * @author HUIHUI
  9 + */
  10 +@Data
  11 +public class IotDataBridgeKafkaMQConfig extends IotDataBridgeConfig {
  12 +
  13 + /**
  14 + * Kafka 服务器地址
  15 + */
  16 + private String bootstrapServers;
  17 + /**
  18 + * 用户名
  19 + */
  20 + private String username;
  21 + /**
  22 + * 密码
  23 + */
  24 + private String password;
  25 + /**
  26 + * 是否启用 SSL
  27 + */
  28 + private Boolean ssl;
  29 +
  30 + /**
  31 + * 主题
  32 + */
  33 + private String topic;
  34 +
  35 +}
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeMqttConfig.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config;
  2 +
  3 +import lombok.Data;
  4 +
  5 +/**
  6 + * MQTT 配置
  7 + *
  8 + * @author HUIHUI
  9 + */
  10 +@Data
  11 +public class IotDataBridgeMqttConfig extends IotDataBridgeConfig {
  12 +
  13 + /**
  14 + * MQTT 服务器地址
  15 + */
  16 + private String url;
  17 + /**
  18 + * 用户名
  19 + */
  20 + private String username;
  21 + /**
  22 + * 密码
  23 + */
  24 + private String password;
  25 + /**
  26 + * 客户端编号
  27 + */
  28 + private String clientId;
  29 + /**
  30 + * 主题
  31 + */
  32 + private String topic;
  33 +
  34 +}
0 35 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeRabbitMQConfig.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config;
  2 +
  3 +import lombok.Data;
  4 +
  5 +/**
  6 + * RabbitMQ 配置
  7 + *
  8 + * @author HUIHUI
  9 + */
  10 +@Data
  11 +public class IotDataBridgeRabbitMQConfig extends IotDataBridgeConfig {
  12 +
  13 + /**
  14 + * RabbitMQ 服务器地址
  15 + */
  16 + private String host;
  17 + /**
  18 + * 端口
  19 + */
  20 + private Integer port;
  21 + /**
  22 + * 虚拟主机
  23 + */
  24 + private String virtualHost;
  25 + /**
  26 + * 用户名
  27 + */
  28 + private String username;
  29 + /**
  30 + * 密码
  31 + */
  32 + private String password;
  33 +
  34 + /**
  35 + * 交换机名称
  36 + */
  37 + private String exchange;
  38 + /**
  39 + * 路由键
  40 + */
  41 + private String routingKey;
  42 + /**
  43 + * 队列名称
  44 + */
  45 + private String queue;
  46 +}
0 47 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeRedisStreamMQConfig.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config;
  2 +
  3 +import lombok.Data;
  4 +
  5 +/**
  6 + * Redis Stream MQ 配置
  7 + *
  8 + * @author HUIHUI
  9 + */
  10 +@Data
  11 +public class IotDataBridgeRedisStreamMQConfig extends IotDataBridgeConfig {
  12 +
  13 + /**
  14 + * Redis 服务器地址
  15 + */
  16 + private String host;
  17 + /**
  18 + * 端口
  19 + */
  20 + private Integer port;
  21 + /**
  22 + * 密码
  23 + */
  24 + private String password;
  25 + /**
  26 + * 数据库索引
  27 + */
  28 + private Integer database;
  29 +
  30 + /**
  31 + * 主题
  32 + */
  33 + private String topic;
  34 +}
0 35 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeRocketMQConfig.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config;
  2 +
  3 +import lombok.Data;
  4 +
  5 +/**
  6 + * RocketMQ 配置
  7 + *
  8 + * @author HUIHUI
  9 + */
  10 +@Data
  11 +public class IotDataBridgeRocketMQConfig extends IotDataBridgeConfig {
  12 +
  13 + /**
  14 + * RocketMQ 名称服务器地址
  15 + */
  16 + private String nameServer;
  17 + /**
  18 + * 访问密钥
  19 + */
  20 + private String accessKey;
  21 + /**
  22 + * 秘密钥匙
  23 + */
  24 + private String secretKey;
  25 +
  26 + /**
  27 + * 生产者组
  28 + */
  29 + private String group;
  30 + /**
  31 + * 主题
  32 + */
  33 + private String topic;
  34 + /**
  35 + * 标签
  36 + */
  37 + private String tags;
  38 +
  39 +}
0 40 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotDataBridgeDO.java
1 1 package cn.iocoder.yudao.module.iot.dal.dataobject.rule;
2 2  
3 3 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeConfig;
  5 +import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeDirectionEnum;
  6 +import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum;
4 7 import com.baomidou.mybatisplus.annotation.KeySequence;
5 8 import com.baomidou.mybatisplus.annotation.TableField;
6 9 import com.baomidou.mybatisplus.annotation.TableId;
7 10 import com.baomidou.mybatisplus.annotation.TableName;
8 11 import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
9   -import com.fasterxml.jackson.annotation.JsonTypeInfo;
10 12 import lombok.*;
11 13  
12   -import java.util.Map;
13   -
14 14 /**
15 15 * IoT 数据桥梁 DO
16 16 *
... ... @@ -48,14 +48,14 @@ public class IotDataBridgeDO extends BaseDO {
48 48 /**
49 49 * 桥梁方向
50 50 *
51   - * 枚举 {@link cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgDirectionEnum}
  51 + * 枚举 {@link IotDataBridgeDirectionEnum}
52 52 */
53 53 private Integer direction;
54 54  
55 55 /**
56 56 * 桥梁类型
57 57 *
58   - * 枚举 {@link cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgTypeEnum}
  58 + * 枚举 {@link IotDataBridgeTypeEnum}
59 59 */
60 60 private Integer type;
61 61  
... ... @@ -63,211 +63,6 @@ public class IotDataBridgeDO extends BaseDO {
63 63 * 桥梁配置
64 64 */
65 65 @TableField(typeHandler = JacksonTypeHandler.class)
66   - private Config config;
67   -
68   - /**
69   - * 文件客户端的配置
70   - * 不同实现的客户端,需要不同的配置,通过子类来定义
71   - *
72   - * @author 芋道源码
73   - */
74   - @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
75   - // @JsonTypeInfo 注解的作用,Jackson 多态
76   - // 1. 序列化到时数据库时,增加 @class 属性。
77   - // 2. 反序列化到内存对象时,通过 @class 属性,可以创建出正确的类型
78   - public interface Config {
79   - }
80   -
81   - /**
82   - * HTTP 配置
83   - */
84   - @Data
85   - public static class HttpConfig implements Config {
86   -
87   - /**
88   - * 请求 URL
89   - */
90   - private String url;
91   - /**
92   - * 请求方法
93   - */
94   - private String method;
95   - /**
96   - * 请求头
97   - */
98   - private Map<String, String> headers;
99   - /**
100   - * 请求参数
101   - */
102   - private Map<String, String> query;
103   - /**
104   - * 请求体
105   - */
106   - private String body;
107   -
108   - }
109   -
110   - /**
111   - * MQTT 配置
112   - */
113   - @Data
114   - public static class MqttConfig implements Config {
115   -
116   - /**
117   - * MQTT 服务器地址
118   - */
119   - private String url;
120   - /**
121   - * 用户名
122   - */
123   - private String username;
124   - /**
125   - * 密码
126   - */
127   - private String password;
128   - /**
129   - * 客户端编号
130   - */
131   - private String clientId;
132   - /**
133   - * 主题
134   - */
135   - private String topic;
136   -
137   - }
138   -
139   - /**
140   - * RocketMQ 配置
141   - */
142   - @Data
143   - public static class RocketMQConfig implements Config {
144   -
145   - /**
146   - * RocketMQ 名称服务器地址
147   - */
148   - private String nameServer;
149   - /**
150   - * 访问密钥
151   - */
152   - private String accessKey;
153   - /**
154   - * 秘密钥匙
155   - */
156   - private String secretKey;
157   -
158   - /**
159   - * 生产者组
160   - */
161   - private String group;
162   - /**
163   - * 主题
164   - */
165   - private String topic;
166   - /**
167   - * 标签
168   - */
169   - private String tags;
170   -
171   - }
172   -
173   - /**
174   - * Kafka 配置
175   - */
176   - @Data
177   - public static class KafkaMQConfig implements Config {
178   -
179   - /**
180   - * Kafka 服务器地址
181   - */
182   - private String bootstrapServers;
183   - /**
184   - * 用户名
185   - */
186   - private String username;
187   - /**
188   - * 密码
189   - */
190   - private String password;
191   - /**
192   - * 是否启用 SSL
193   - */
194   - private Boolean ssl;
195   -
196   - /**
197   - * 主题
198   - */
199   - private String topic;
200   -
201   - }
202   -
203   - /**
204   - * RabbitMQ 配置
205   - */
206   - @Data
207   - public static class RabbitMQConfig implements Config {
208   -
209   - /**
210   - * RabbitMQ 服务器地址
211   - */
212   - private String host;
213   - /**
214   - * 端口
215   - */
216   - private Integer port;
217   - /**
218   - * 虚拟主机
219   - */
220   - private String virtualHost;
221   - /**
222   - * 用户名
223   - */
224   - private String username;
225   - /**
226   - * 密码
227   - */
228   - private String password;
229   -
230   - /**
231   - * 交换机名称
232   - */
233   - private String exchange;
234   - /**
235   - * 路由键
236   - */
237   - private String routingKey;
238   - /**
239   - * 队列名称
240   - */
241   - private String queue;
242   - }
243   -
244   - /**
245   - * Redis Stream MQ 配置
246   - */
247   - @Data
248   - public static class RedisStreamMQConfig implements Config {
249   -
250   - /**
251   - * Redis 服务器地址
252   - */
253   - private String host;
254   - /**
255   - * 端口
256   - */
257   - private Integer port;
258   - /**
259   - * 密码
260   - */
261   - private String password;
262   - /**
263   - * 数据库索引
264   - */
265   - private Integer database;
266   -
267   - /**
268   - * 主题
269   - */
270   - private String topic;
271   - }
  66 + private IotDataBridgeConfig config;
272 67  
273 68 }
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotHttpDataBridgeExecute.java
... ... @@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.iot.service.rule.action.databridge;
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
5 5 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
6   -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO;
7   -import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgTypeEnum;
  6 +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeHttpConfig;
  7 +import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum;
8 8 import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage;
9 9 import jakarta.annotation.Resource;
10 10 import lombok.extern.slf4j.Slf4j;
... ... @@ -25,19 +25,19 @@ import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_
25 25 */
26 26 @Component
27 27 @Slf4j
28   -public class IotHttpDataBridgeExecute implements IotDataBridgeExecute<IotDataBridgeDO.HttpConfig> {
  28 +public class IotHttpDataBridgeExecute implements IotDataBridgeExecute<IotDataBridgeHttpConfig> {
29 29  
30 30 @Resource
31 31 private RestTemplate restTemplate;
32 32  
33 33 @Override
34 34 public Integer getType() {
35   - return IotDataBridgTypeEnum.HTTP.getType();
  35 + return IotDataBridgeTypeEnum.HTTP.getType();
36 36 }
37 37  
38 38 @Override
39 39 @SuppressWarnings({"unchecked", "deprecation"})
40   - public void execute0(IotDeviceMessage message, IotDataBridgeDO.HttpConfig config) {
  40 + public void execute0(IotDeviceMessage message, IotDataBridgeHttpConfig config) {
41 41 String url = null;
42 42 HttpMethod method = HttpMethod.valueOf(config.getMethod().toUpperCase());
43 43 HttpEntity<String> requestEntity = null;
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotKafkaMQDataBridgeExecute.java
1 1 package cn.iocoder.yudao.module.iot.service.rule.action.databridge;
2 2  
  3 +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeKafkaMQConfig;
3 4 import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO;
4   -import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgTypeEnum;
  5 +import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum;
5 6 import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage;
6 7 import lombok.extern.slf4j.Slf4j;
7 8 import org.apache.kafka.clients.producer.ProducerConfig;
... ... @@ -26,17 +27,17 @@ import java.util.concurrent.TimeUnit;
26 27 @Component
27 28 @Slf4j
28 29 public class IotKafkaMQDataBridgeExecute extends
29   - AbstractCacheableDataBridgeExecute<IotDataBridgeDO.KafkaMQConfig, KafkaTemplate<String, String>> {
  30 + AbstractCacheableDataBridgeExecute<IotDataBridgeKafkaMQConfig, KafkaTemplate<String, String>> {
30 31  
31 32 private static final Duration SEND_TIMEOUT = Duration.ofMillis(10000); // 10 秒超时时间
32 33  
33 34 @Override
34 35 public Integer getType() {
35   - return IotDataBridgTypeEnum.KAFKA.getType();
  36 + return IotDataBridgeTypeEnum.KAFKA.getType();
36 37 }
37 38  
38 39 @Override
39   - public void execute0(IotDeviceMessage message, IotDataBridgeDO.KafkaMQConfig config) throws Exception {
  40 + public void execute0(IotDeviceMessage message, IotDataBridgeKafkaMQConfig config) throws Exception {
40 41 // 1. 获取或创建 KafkaTemplate
41 42 KafkaTemplate<String, String> kafkaTemplate = getProducer(config);
42 43  
... ... @@ -47,7 +48,7 @@ public class IotKafkaMQDataBridgeExecute extends
47 48 }
48 49  
49 50 @Override
50   - protected KafkaTemplate<String, String> initProducer(IotDataBridgeDO.KafkaMQConfig config) {
  51 + protected KafkaTemplate<String, String> initProducer(IotDataBridgeKafkaMQConfig config) {
51 52 // 1.1 构建生产者配置
52 53 Map<String, Object> props = new HashMap<>();
53 54 props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, config.getBootstrapServers());
... ... @@ -82,7 +83,7 @@ public class IotKafkaMQDataBridgeExecute extends
82 83 IotKafkaMQDataBridgeExecute action = new IotKafkaMQDataBridgeExecute();
83 84  
84 85 // 2. 创建共享的配置
85   - IotDataBridgeDO.KafkaMQConfig config = new IotDataBridgeDO.KafkaMQConfig();
  86 + IotDataBridgeKafkaMQConfig config = new IotDataBridgeKafkaMQConfig();
86 87 config.setBootstrapServers("127.0.0.1:9092");
87 88 config.setTopic("test-topic");
88 89 config.setSsl(false);
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRabbitMQDataBridgeExecute.java
1 1 package cn.iocoder.yudao.module.iot.service.rule.action.databridge;
2 2  
  3 +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeRabbitMQConfig;
3 4 import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO;
4   -import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgTypeEnum;
  5 +import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum;
5 6 import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage;
6 7 import com.rabbitmq.client.Channel;
7 8 import com.rabbitmq.client.Connection;
... ... @@ -22,16 +23,16 @@ import java.time.LocalDateTime;
22 23 @Component
23 24 @Slf4j
24 25 public class IotRabbitMQDataBridgeExecute extends
25   - AbstractCacheableDataBridgeExecute<IotDataBridgeDO.RabbitMQConfig, Channel> {
  26 + AbstractCacheableDataBridgeExecute<IotDataBridgeRabbitMQConfig, Channel> {
26 27  
27 28  
28 29 @Override
29 30 public Integer getType() {
30   - return IotDataBridgTypeEnum.RABBITMQ.getType();
  31 + return IotDataBridgeTypeEnum.RABBITMQ.getType();
31 32 }
32 33  
33 34 @Override
34   - public void execute0(IotDeviceMessage message, IotDataBridgeDO.RabbitMQConfig config) throws Exception {
  35 + public void execute0(IotDeviceMessage message, IotDataBridgeRabbitMQConfig config) throws Exception {
35 36 // 1. 获取或创建 Channel
36 37 Channel channel = getProducer(config);
37 38  
... ... @@ -48,7 +49,7 @@ public class IotRabbitMQDataBridgeExecute extends
48 49  
49 50 @Override
50 51 @SuppressWarnings("resource")
51   - protected Channel initProducer(IotDataBridgeDO.RabbitMQConfig config) throws Exception {
  52 + protected Channel initProducer(IotDataBridgeRabbitMQConfig config) throws Exception {
52 53 // 1. 创建连接工厂
53 54 ConnectionFactory factory = new ConnectionFactory();
54 55 factory.setHost(config.getHost());
... ... @@ -81,7 +82,7 @@ public class IotRabbitMQDataBridgeExecute extends
81 82 IotRabbitMQDataBridgeExecute action = new IotRabbitMQDataBridgeExecute();
82 83  
83 84 // 2. 创建共享的配置
84   - IotDataBridgeDO.RabbitMQConfig config = new IotDataBridgeDO.RabbitMQConfig();
  85 + IotDataBridgeRabbitMQConfig config = new IotDataBridgeRabbitMQConfig();
85 86 config.setHost("localhost");
86 87 config.setPort(5672);
87 88 config.setVirtualHost("/");
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRedisStreamMQDataBridgeExecute.java
... ... @@ -2,8 +2,9 @@ package cn.iocoder.yudao.module.iot.service.rule.action.databridge;
2 2  
3 3 import cn.hutool.core.util.ReflectUtil;
4 4 import cn.hutool.core.util.StrUtil;
  5 +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeRedisStreamMQConfig;
5 6 import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO;
6   -import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgTypeEnum;
  7 +import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum;
7 8 import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage;
8 9 import com.fasterxml.jackson.databind.ObjectMapper;
9 10 import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
... ... @@ -30,15 +31,15 @@ import java.time.LocalDateTime;
30 31 @Component
31 32 @Slf4j
32 33 public class IotRedisStreamMQDataBridgeExecute extends
33   - AbstractCacheableDataBridgeExecute<IotDataBridgeDO.RedisStreamMQConfig, RedisTemplate<String, Object>> {
  34 + AbstractCacheableDataBridgeExecute<IotDataBridgeRedisStreamMQConfig, RedisTemplate<String, Object>> {
34 35  
35 36 @Override
36 37 public Integer getType() {
37   - return IotDataBridgTypeEnum.REDIS_STREAM.getType();
  38 + return IotDataBridgeTypeEnum.REDIS_STREAM.getType();
38 39 }
39 40  
40 41 @Override
41   - public void execute0(IotDeviceMessage message, IotDataBridgeDO.RedisStreamMQConfig config) throws Exception {
  42 + public void execute0(IotDeviceMessage message, IotDataBridgeRedisStreamMQConfig config) throws Exception {
42 43 // 1. 获取 RedisTemplate
43 44 RedisTemplate<String, Object> redisTemplate = getProducer(config);
44 45  
... ... @@ -50,7 +51,7 @@ public class IotRedisStreamMQDataBridgeExecute extends
50 51 }
51 52  
52 53 @Override
53   - protected RedisTemplate<String, Object> initProducer(IotDataBridgeDO.RedisStreamMQConfig config) {
  54 + protected RedisTemplate<String, Object> initProducer(IotDataBridgeRedisStreamMQConfig config) {
54 55 // 1.1 创建 Redisson 配置
55 56 Config redissonConfig = new Config();
56 57 SingleServerConfig serverConfig = redissonConfig.useSingleServer()
... ... @@ -101,7 +102,7 @@ public class IotRedisStreamMQDataBridgeExecute extends
101 102 IotRedisStreamMQDataBridgeExecute action = new IotRedisStreamMQDataBridgeExecute();
102 103  
103 104 // 2. 创建共享的配置
104   - IotDataBridgeDO.RedisStreamMQConfig config = new IotDataBridgeDO.RedisStreamMQConfig();
  105 + IotDataBridgeRedisStreamMQConfig config = new IotDataBridgeRedisStreamMQConfig();
105 106 config.setHost("127.0.0.1");
106 107 config.setPort(6379);
107 108 config.setDatabase(0);
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRocketMQDataBridgeExecute.java
1 1 package cn.iocoder.yudao.module.iot.service.rule.action.databridge;
2 2  
  3 +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeRocketMQConfig;
3 4 import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO;
4   -import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgTypeEnum;
  5 +import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum;
5 6 import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage;
6 7 import lombok.extern.slf4j.Slf4j;
7 8 import org.apache.rocketmq.client.producer.DefaultMQProducer;
... ... @@ -23,15 +24,15 @@ import java.time.LocalDateTime;
23 24 @Component
24 25 @Slf4j
25 26 public class IotRocketMQDataBridgeExecute extends
26   - AbstractCacheableDataBridgeExecute<IotDataBridgeDO.RocketMQConfig, DefaultMQProducer> {
  27 + AbstractCacheableDataBridgeExecute<IotDataBridgeRocketMQConfig, DefaultMQProducer> {
27 28  
28 29 @Override
29 30 public Integer getType() {
30   - return IotDataBridgTypeEnum.ROCKETMQ.getType();
  31 + return IotDataBridgeTypeEnum.ROCKETMQ.getType();
31 32 }
32 33  
33 34 @Override
34   - public void execute0(IotDeviceMessage message, IotDataBridgeDO.RocketMQConfig config) throws Exception {
  35 + public void execute0(IotDeviceMessage message, IotDataBridgeRocketMQConfig config) throws Exception {
35 36 // 1. 获取或创建 Producer
36 37 DefaultMQProducer producer = getProducer(config);
37 38  
... ... @@ -52,7 +53,7 @@ public class IotRocketMQDataBridgeExecute extends
52 53 }
53 54  
54 55 @Override
55   - protected DefaultMQProducer initProducer(IotDataBridgeDO.RocketMQConfig config) throws Exception {
  56 + protected DefaultMQProducer initProducer(IotDataBridgeRocketMQConfig config) throws Exception {
56 57 DefaultMQProducer producer = new DefaultMQProducer(config.getGroup());
57 58 producer.setNamesrvAddr(config.getNameServer());
58 59 producer.start();
... ... @@ -70,7 +71,7 @@ public class IotRocketMQDataBridgeExecute extends
70 71 IotRocketMQDataBridgeExecute action = new IotRocketMQDataBridgeExecute();
71 72  
72 73 // 2. 创建共享的配置
73   - IotDataBridgeDO.RocketMQConfig config = new IotDataBridgeDO.RocketMQConfig();
  74 + IotDataBridgeRocketMQConfig config = new IotDataBridgeRocketMQConfig();
74 75 config.setNameServer("127.0.0.1:9876");
75 76 config.setGroup("test-group");
76 77 config.setTopic("test-topic");
... ...