Commit 5e71d1fc851746c3366ce8f1a02f474a5ee434eb
1 parent
48cfcdad
【代码优化】IoT:增加 IotDataBridgeDO 数据桥梁的定义
Showing
4 changed files
with
244 additions
and
0 deletions
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotDataBridgDirectionEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.enums.rule; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.core.ArrayValuable; | |
| 4 | +import lombok.Getter; | |
| 5 | +import lombok.RequiredArgsConstructor; | |
| 6 | + | |
| 7 | +import java.util.Arrays; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * Iot 数据桥接的方向枚举 | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +@RequiredArgsConstructor | |
| 15 | +@Getter | |
| 16 | +public enum IotDataBridgDirectionEnum implements ArrayValuable<Integer> { | |
| 17 | + | |
| 18 | + INPUT(1), // 输入 | |
| 19 | + OUTPUT(2); // 输出 | |
| 20 | + | |
| 21 | + private final Integer type; | |
| 22 | + | |
| 23 | + public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotDataBridgDirectionEnum::getType).toArray(Integer[]::new); | |
| 24 | + | |
| 25 | + @Override | |
| 26 | + public Integer[] array() { | |
| 27 | + return ARRAYS; | |
| 28 | + } | |
| 29 | + | |
| 30 | +} | ... | ... |
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotDataBridgTypeEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.enums.rule; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.core.ArrayValuable; | |
| 4 | +import lombok.Getter; | |
| 5 | +import lombok.RequiredArgsConstructor; | |
| 6 | + | |
| 7 | +import java.util.Arrays; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * Iot 数据桥接的类型枚举 | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +@RequiredArgsConstructor | |
| 15 | +@Getter | |
| 16 | +public enum IotDataBridgTypeEnum implements ArrayValuable<Integer> { | |
| 17 | + | |
| 18 | + HTTP(1), | |
| 19 | + TCP(2), | |
| 20 | + WEBSOCKET(3), | |
| 21 | + | |
| 22 | + MQTT(10), | |
| 23 | + | |
| 24 | + DATABASE(20), | |
| 25 | + REDIS(21), | |
| 26 | + | |
| 27 | + ROCKETMQ(30), | |
| 28 | + RABBITMQ(31), | |
| 29 | + KAFKA(32) | |
| 30 | + ; | |
| 31 | + | |
| 32 | + private final Integer type; | |
| 33 | + | |
| 34 | + public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotDataBridgTypeEnum::getType).toArray(Integer[]::new); | |
| 35 | + | |
| 36 | + @Override | |
| 37 | + public Integer[] array() { | |
| 38 | + return ARRAYS; | |
| 39 | + } | |
| 40 | + | |
| 41 | +} | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotDataBridgeDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.dal.dataobject.rule; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 4 | +import com.baomidou.mybatisplus.annotation.KeySequence; | |
| 5 | +import com.baomidou.mybatisplus.annotation.TableField; | |
| 6 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 7 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 8 | +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | |
| 9 | +import com.fasterxml.jackson.annotation.JsonTypeInfo; | |
| 10 | +import lombok.*; | |
| 11 | + | |
| 12 | +import java.util.Map; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * IoT 数据桥梁 DO | |
| 16 | + * | |
| 17 | + * @author 芋道源码 | |
| 18 | + */ | |
| 19 | +@TableName("iot_data_bridge") | |
| 20 | +@KeySequence("iot_data_bridge_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 21 | +@Data | |
| 22 | +@EqualsAndHashCode(callSuper = true) | |
| 23 | +@ToString(callSuper = true) | |
| 24 | +@Builder | |
| 25 | +@NoArgsConstructor | |
| 26 | +@AllArgsConstructor | |
| 27 | +public class IotDataBridgeDO extends BaseDO { | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * 桥梁编号 | |
| 31 | + */ | |
| 32 | + @TableId | |
| 33 | + private Long id; | |
| 34 | + /** | |
| 35 | + * 桥梁名称 | |
| 36 | + */ | |
| 37 | + private String name; | |
| 38 | + /** | |
| 39 | + * 桥梁描述 | |
| 40 | + */ | |
| 41 | + private String description; | |
| 42 | + /** | |
| 43 | + * 桥梁状态 | |
| 44 | + * | |
| 45 | + * 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum} | |
| 46 | + */ | |
| 47 | + private Integer status; | |
| 48 | + /** | |
| 49 | + * 桥梁方向 | |
| 50 | + * | |
| 51 | + * 枚举 {@link cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgDirectionEnum} | |
| 52 | + */ | |
| 53 | + private Integer direction; | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * 桥梁类型 | |
| 57 | + * | |
| 58 | + * 枚举 {@link cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgTypeEnum} | |
| 59 | + */ | |
| 60 | + private Integer type; | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * 桥梁配置 | |
| 64 | + */ | |
| 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 | +} | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneDataBridgeAction.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.service.rule.action; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; | |
| 4 | +import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; | |
| 5 | +import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; | |
| 6 | +import org.springframework.stereotype.Component; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * IoT 数据桥梁的 {@link IotRuleSceneAction} 实现类 | |
| 10 | + * | |
| 11 | + * @author 芋道源码 | |
| 12 | + */ | |
| 13 | +@Component | |
| 14 | +public class IotRuleSceneDataBridgeAction implements IotRuleSceneAction { | |
| 15 | + | |
| 16 | + @Override | |
| 17 | + public void execute(IotDeviceMessage message, IotRuleSceneDO.ActionConfig config) { | |
| 18 | + // TODO @芋艿:http | |
| 19 | + // TODO @芋艿:mq-redis | |
| 20 | + // TODO @芋艿:mq-数据库 | |
| 21 | + // TODO @芋艿:kafka | |
| 22 | + // TODO @芋艿:rocketmq | |
| 23 | + // TODO @芋艿:rabbitmq | |
| 24 | + // TODO @芋艿:mqtt | |
| 25 | + // TODO @芋艿:tcp | |
| 26 | + } | |
| 27 | + | |
| 28 | + @Override | |
| 29 | + public IotRuleSceneActionTypeEnum getType() { | |
| 30 | + return IotRuleSceneActionTypeEnum.DATA_BRIDGE; | |
| 31 | + } | |
| 32 | + | |
| 33 | +} | ... | ... |