【代码评审】IoT:数据桥梁的维护
This commit is contained in:
parent
27e08266e0
commit
34453a3f70
|
@ -15,6 +15,7 @@ public class DictTypeConstants {
|
|||
public static final String VALIDATE_TYPE = "iot_validate_type";
|
||||
|
||||
public static final String DEVICE_STATE = "iot_device_state";
|
||||
|
||||
public static final String IOT_DATA_BRIDGE_DIRECTION_ENUM = "iot_data_bridge_direction_enum";
|
||||
public static final String IOT_DATA_BRIDGE_TYPE_ENUM = "iot_data_bridge_type_enum";
|
||||
|
||||
|
|
|
@ -37,14 +37,14 @@ public class IotDataBridgeController {
|
|||
private IotDataBridgeService dataBridgeService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建IoT 数据桥梁")
|
||||
@Operation(summary = "创建数据桥梁")
|
||||
@PreAuthorize("@ss.hasPermission('iot:data-bridge:create')")
|
||||
public CommonResult<Long> createDataBridge(@Valid @RequestBody IotDataBridgeSaveReqVO createReqVO) {
|
||||
return success(dataBridgeService.createDataBridge(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新IoT 数据桥梁")
|
||||
@Operation(summary = "更新数据桥梁")
|
||||
@PreAuthorize("@ss.hasPermission('iot:data-bridge:update')")
|
||||
public CommonResult<Boolean> updateDataBridge(@Valid @RequestBody IotDataBridgeSaveReqVO updateReqVO) {
|
||||
dataBridgeService.updateDataBridge(updateReqVO);
|
||||
|
@ -52,7 +52,7 @@ public class IotDataBridgeController {
|
|||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除IoT 数据桥梁")
|
||||
@Operation(summary = "删除数据桥梁")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('iot:data-bridge:delete')")
|
||||
public CommonResult<Boolean> deleteDataBridge(@RequestParam("id") Long id) {
|
||||
|
@ -61,7 +61,7 @@ public class IotDataBridgeController {
|
|||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得IoT 数据桥梁")
|
||||
@Operation(summary = "获得数据桥梁")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('iot:data-bridge:query')")
|
||||
public CommonResult<IotDataBridgeRespVO> getDataBridge(@RequestParam("id") Long id) {
|
||||
|
@ -70,15 +70,16 @@ public class IotDataBridgeController {
|
|||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得IoT 数据桥梁分页")
|
||||
@Operation(summary = "获得数据桥梁分页")
|
||||
@PreAuthorize("@ss.hasPermission('iot:data-bridge:query')")
|
||||
public CommonResult<PageResult<IotDataBridgeRespVO>> getDataBridgePage(@Valid IotDataBridgePageReqVO pageReqVO) {
|
||||
PageResult<IotDataBridgeDO> pageResult = dataBridgeService.getDataBridgePage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, IotDataBridgeRespVO.class));
|
||||
}
|
||||
|
||||
// TODO @puhui999:不用导出哈。相关的 IotDataBridgeRespVO 里的导出也注释掉哈
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出IoT 数据桥梁 Excel")
|
||||
@Operation(summary = "导出数据桥梁 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('iot:data-bridge:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportDataBridgeExcel(@Valid IotDataBridgePageReqVO pageReqVO,
|
||||
|
|
|
@ -20,6 +20,7 @@ public class IotDataBridgePageReqVO extends PageParam {
|
|||
@Schema(description = "桥梁名称", example = "赵六")
|
||||
private String name;
|
||||
|
||||
// TODO @puhui999:description、direction、type 不过滤哈
|
||||
@Schema(description = "桥梁描述", example = "随便")
|
||||
private String description;
|
||||
|
||||
|
@ -36,4 +37,5 @@ public class IotDataBridgePageReqVO extends PageParam {
|
|||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
|
||||
}
|
|
@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge;
|
|||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeConfig;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeAbstractConfig;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
@ -48,7 +48,7 @@ public class IotDataBridgeRespVO {
|
|||
|
||||
@Schema(description = "桥梁配置")
|
||||
@ExcelProperty("桥梁配置")
|
||||
private IotDataBridgeConfig config;
|
||||
private IotDataBridgeAbstractConfig config;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeConfig;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeAbstractConfig;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
@ -24,6 +24,7 @@ public class IotDataBridgeSaveReqVO {
|
|||
@NotNull(message = "桥梁状态不能为空")
|
||||
private Integer status;
|
||||
|
||||
// TODO @puhui999:枚举的校验
|
||||
@Schema(description = "桥梁方向", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "桥梁方向不能为空")
|
||||
private Integer direction;
|
||||
|
@ -34,6 +35,6 @@ public class IotDataBridgeSaveReqVO {
|
|||
|
||||
@Schema(description = "桥梁配置")
|
||||
@NotNull(message = "桥梁配置不能为空")
|
||||
private IotDataBridgeConfig config;
|
||||
private IotDataBridgeAbstractConfig config;
|
||||
|
||||
}
|
|
@ -22,7 +22,7 @@ import lombok.Data;
|
|||
@JsonSubTypes.Type(value = IotDataBridgeRedisStreamMQConfig.class, name = "REDIS_STREAM"),
|
||||
@JsonSubTypes.Type(value = IotDataBridgeRocketMQConfig.class, name = "ROCKETMQ"),
|
||||
})
|
||||
public abstract class IotDataBridgeConfig {
|
||||
public abstract class IotDataBridgeAbstractConfig {
|
||||
|
||||
/**
|
||||
* 配置类型
|
|
@ -10,7 +10,7 @@ import java.util.Map;
|
|||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
public class IotDataBridgeHttpConfig extends IotDataBridgeConfig {
|
||||
public class IotDataBridgeHttpConfig extends IotDataBridgeAbstractConfig {
|
||||
|
||||
/**
|
||||
* 请求 URL
|
||||
|
|
|
@ -8,7 +8,7 @@ import lombok.Data;
|
|||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
public class IotDataBridgeKafkaMQConfig extends IotDataBridgeConfig {
|
||||
public class IotDataBridgeKafkaMQConfig extends IotDataBridgeAbstractConfig {
|
||||
|
||||
/**
|
||||
* Kafka 服务器地址
|
||||
|
|
|
@ -8,7 +8,7 @@ import lombok.Data;
|
|||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
public class IotDataBridgeMqttConfig extends IotDataBridgeConfig {
|
||||
public class IotDataBridgeMqttConfig extends IotDataBridgeAbstractConfig {
|
||||
|
||||
/**
|
||||
* MQTT 服务器地址
|
||||
|
|
|
@ -8,7 +8,7 @@ import lombok.Data;
|
|||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
public class IotDataBridgeRabbitMQConfig extends IotDataBridgeConfig {
|
||||
public class IotDataBridgeRabbitMQConfig extends IotDataBridgeAbstractConfig {
|
||||
|
||||
/**
|
||||
* RabbitMQ 服务器地址
|
||||
|
|
|
@ -8,7 +8,7 @@ import lombok.Data;
|
|||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
public class IotDataBridgeRedisStreamMQConfig extends IotDataBridgeConfig {
|
||||
public class IotDataBridgeRedisStreamMQConfig extends IotDataBridgeAbstractConfig {
|
||||
|
||||
/**
|
||||
* Redis 服务器地址
|
||||
|
|
|
@ -8,7 +8,7 @@ import lombok.Data;
|
|||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
public class IotDataBridgeRocketMQConfig extends IotDataBridgeConfig {
|
||||
public class IotDataBridgeRocketMQConfig extends IotDataBridgeAbstractConfig {
|
||||
|
||||
/**
|
||||
* RocketMQ 名称服务器地址
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package cn.iocoder.yudao.module.iot.dal.dataobject.rule;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeConfig;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeAbstractConfig;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeDirectionEnum;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
|
@ -63,6 +63,6 @@ public class IotDataBridgeDO extends BaseDO {
|
|||
* 桥梁配置
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private IotDataBridgeConfig config;
|
||||
private IotDataBridgeAbstractConfig config;
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import jakarta.validation.Valid;
|
|||
public interface IotDataBridgeService {
|
||||
|
||||
/**
|
||||
* 创建IoT 数据桥梁
|
||||
* 创建数据桥梁
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
|
@ -22,32 +22,32 @@ public interface IotDataBridgeService {
|
|||
Long createDataBridge(@Valid IotDataBridgeSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新IoT 数据桥梁
|
||||
* 更新数据桥梁
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateDataBridge(@Valid IotDataBridgeSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除IoT 数据桥梁
|
||||
* 删除数据桥梁
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteDataBridge(Long id);
|
||||
|
||||
/**
|
||||
* 获得IoT 数据桥梁
|
||||
* 获得数据桥梁
|
||||
*
|
||||
* @param id 编号
|
||||
* @return IoT 数据桥梁
|
||||
* @return 数据桥梁
|
||||
*/
|
||||
IotDataBridgeDO getDataBridge(Long id);
|
||||
|
||||
/**
|
||||
* 获得IoT 数据桥梁分页
|
||||
* 获得数据桥梁分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return IoT 数据桥梁分页
|
||||
* @return 数据桥梁分页
|
||||
*/
|
||||
PageResult<IotDataBridgeDO> getDataBridgePage(IotDataBridgePageReqVO pageReqVO);
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cn.iocoder.yudao.module.iot.service.rule.action.databridge;
|
||||
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO;
|
||||
import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
@ -56,6 +57,7 @@ public abstract class AbstractCacheableDataBridgeExecute<Config, Producer> imple
|
|||
}
|
||||
})
|
||||
.build(new CacheLoader<Config, Producer>() {
|
||||
|
||||
@Override
|
||||
public Producer load(Config config) throws Exception {
|
||||
try {
|
||||
|
@ -67,6 +69,7 @@ public abstract class AbstractCacheableDataBridgeExecute<Config, Producer> imple
|
|||
throw e; // 抛出异常,触发缓存加载失败机制
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -98,12 +101,9 @@ public abstract class AbstractCacheableDataBridgeExecute<Config, Producer> imple
|
|||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public void execute(IotDeviceMessage message, IotDataBridgeDO dataBridge) {
|
||||
// 1.1 校验数据桥梁类型
|
||||
if (!getType().equals(dataBridge.getType())) {
|
||||
if (ObjUtil.notEqual(message.getType(), getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 1.2 执行对应的数据桥梁发送消息
|
||||
try {
|
||||
execute0(message, (Config) dataBridge.getConfig());
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cn.iocoder.yudao.module.iot.service.rule.action.databridge;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeAbstractConfig;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO;
|
||||
import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage;
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ public class IotRocketMQDataBridgeExecute extends
|
|||
}
|
||||
|
||||
// TODO @芋艿:测试代码,后续清理
|
||||
// TODO @puhui999:搞到测试类里。
|
||||
public static void main(String[] args) {
|
||||
// 1. 创建一个共享的实例
|
||||
IotRocketMQDataBridgeExecute action = new IotRocketMQDataBridgeExecute();
|
||||
|
|
|
@ -115,6 +115,7 @@
|
|||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<!-- IoT 数据桥梁的执行器所需消息队列。如果您只需要使用 rocketmq 那么则注释掉其它消息队列即可 -->
|
||||
<!-- TODO @puhui999:默认不使用哈。可以在 iot biz 那,作为 optional 进行引入 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.rocketmq</groupId>
|
||||
<artifactId>rocketmq-spring-boot-starter</artifactId>
|
||||
|
|
Loading…
Reference in New Issue