浏览代码

【代码评审】IoT:数据桥梁的 review

YunaiV 7 月之前
父节点
当前提交
e5a74193ba

+ 2 - 4
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.java

@@ -72,22 +72,20 @@ public class IotThingModelController {
     @PreAuthorize("@ss.hasPermission('iot:thing-model:query')")
     @PreAuthorize("@ss.hasPermission('iot:thing-model:query')")
     public CommonResult<IotThingModelTSLRespVO> getThingModelTsl(@RequestParam("productId") Long productId) {
     public CommonResult<IotThingModelTSLRespVO> getThingModelTsl(@RequestParam("productId") Long productId) {
         IotThingModelTSLRespVO tslRespVO = new IotThingModelTSLRespVO();
         IotThingModelTSLRespVO tslRespVO = new IotThingModelTSLRespVO();
+        // TODO @puhui999:是不是要先查询产品哈?原因是,万一没配置物模型,但是产品已经有了!
         // 1. 获得产品所有物模型定义
         // 1. 获得产品所有物模型定义
         List<IotThingModelDO> thingModels = thingModelService.getThingModelListByProductId(productId);
         List<IotThingModelDO> thingModels = thingModelService.getThingModelListByProductId(productId);
         if (CollUtil.isEmpty(thingModels)) {
         if (CollUtil.isEmpty(thingModels)) {
             return success(tslRespVO);
             return success(tslRespVO);
         }
         }
 
 
-        // 2.1 设置公共部分参数
+        // 2. 设置公共部分参数
         IotThingModelDO thingModel = thingModels.get(0);
         IotThingModelDO thingModel = thingModels.get(0);
         tslRespVO.setProductId(thingModel.getProductId()).setProductKey(thingModel.getProductKey());
         tslRespVO.setProductId(thingModel.getProductId()).setProductKey(thingModel.getProductKey());
-        // 2.2 处理属性列表
         tslRespVO.setProperties(convertList(filterList(thingModels, item ->
         tslRespVO.setProperties(convertList(filterList(thingModels, item ->
                 ObjUtil.equal(IotThingModelTypeEnum.PROPERTY.getType(), item.getType())), IotThingModelDO::getProperty));
                 ObjUtil.equal(IotThingModelTypeEnum.PROPERTY.getType(), item.getType())), IotThingModelDO::getProperty));
-        // 2.3 处理服务列表
         tslRespVO.setServices(convertList(filterList(thingModels, item ->
         tslRespVO.setServices(convertList(filterList(thingModels, item ->
                 ObjUtil.equal(IotThingModelTypeEnum.SERVICE.getType(), item.getType())), IotThingModelDO::getService));
                 ObjUtil.equal(IotThingModelTypeEnum.SERVICE.getType(), item.getType())), IotThingModelDO::getService));
-        // 2.4 处理事件列表
         tslRespVO.setEvents(convertList(filterList(thingModels, item ->
         tslRespVO.setEvents(convertList(filterList(thingModels, item ->
                 ObjUtil.equal(IotThingModelTypeEnum.EVENT.getType(), item.getType())), IotThingModelDO::getEvent));
                 ObjUtil.equal(IotThingModelTypeEnum.EVENT.getType(), item.getType())), IotThingModelDO::getEvent));
         return success(tslRespVO);
         return success(tslRespVO);

+ 0 - 1
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRedisStreamDataBridgeExecute.java

@@ -56,7 +56,6 @@ public class IotRedisStreamDataBridgeExecute extends
             serverConfig.setPassword(config.getPassword());
             serverConfig.setPassword(config.getPassword());
         }
         }
 
 
-        // TODO @芋艿:看看怎么优化
         // 创建 RedisTemplate 并配置
         // 创建 RedisTemplate 并配置
         RedissonClient redisson = Redisson.create(redissonConfig);
         RedissonClient redisson = Redisson.create(redissonConfig);
         RedisTemplate<String, Object> template = new RedisTemplate<>();
         RedisTemplate<String, Object> template = new RedisTemplate<>();

+ 13 - 25
yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotDataBridgeExecuteTest.java

@@ -41,16 +41,9 @@ public class IotDataBridgeExecuteTest extends BaseMockitoUnitTest {
     @BeforeEach
     @BeforeEach
     public void setUp() {
     public void setUp() {
         // 创建共享的测试消息
         // 创建共享的测试消息
-        message = IotDeviceMessage.builder()
-                .requestId("TEST-001")
-                .reportTime(LocalDateTime.now())
-                .tenantId(1L)
-                .productKey("testProduct")
-                .deviceName("testDevice")
-                .deviceKey("testDeviceKey")
-                .type("property")
-                .identifier("temperature")
-                .data("{\"value\": 60}")
+        message = IotDeviceMessage.builder().requestId("TEST-001").reportTime(LocalDateTime.now()).tenantId(1L)
+                .productKey("testProduct").deviceName("testDevice").deviceKey("testDeviceKey")
+                .type("property").identifier("temperature").data("{\"value\": 60}")
                 .build();
                 .build();
     }
     }
 
 
@@ -132,14 +125,12 @@ public class IotDataBridgeExecuteTest extends BaseMockitoUnitTest {
 
 
         // 2. 创建配置
         // 2. 创建配置
         IotDataBridgeHttpConfig config = new IotDataBridgeHttpConfig()
         IotDataBridgeHttpConfig config = new IotDataBridgeHttpConfig()
-                .setUrl("https://doc.iocoder.cn/")
-                .setMethod(HttpMethod.GET.name());
+                .setUrl("https://doc.iocoder.cn/").setMethod(HttpMethod.GET.name());
 
 
         // 3. 执行测试
         // 3. 执行测试
         log.info("[testHttpDataBridge][执行HTTP数据桥接测试]");
         log.info("[testHttpDataBridge][执行HTTP数据桥接测试]");
         httpDataBridgeExecute.execute(message, new IotDataBridgeDO()
         httpDataBridgeExecute.execute(message, new IotDataBridgeDO()
-                .setType(httpDataBridgeExecute.getType())
-                .setConfig(config));
+                .setType(httpDataBridgeExecute.getType()).setConfig(config));
     }
     }
 
 
     /**
     /**
@@ -147,19 +138,16 @@ public class IotDataBridgeExecuteTest extends BaseMockitoUnitTest {
      *
      *
      * @param action 执行器实例
      * @param action 执行器实例
      * @param config 配置对象
      * @param config 配置对象
-     * @param mqType MQ类型
+     * @param type MQ 类型
      * @throws Exception 如果执行过程中发生异常
      * @throws Exception 如果执行过程中发生异常
      */
      */
-    private void executeAndVerifyCache(IotDataBridgeExecute<?> action, IotDataBridgeAbstractConfig config, String mqType) throws Exception {
-        log.info("[test{}DataBridge][第一次执行,应该会创建新的 producer]", mqType);
-        action.execute(message, new IotDataBridgeDO()
-                .setType(action.getType())
-                .setConfig(config));
-
-        log.info("[test{}DataBridge][第二次执行,应该会复用缓存的 producer]", mqType);
-        action.execute(message, new IotDataBridgeDO()
-                .setType(action.getType())
-                .setConfig(config));
+    private void executeAndVerifyCache(IotDataBridgeExecute<?> action, IotDataBridgeAbstractConfig config, String type)
+            throws Exception {
+        log.info("[test{}DataBridge][第一次执行,应该会创建新的 producer]", type);
+        action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
+
+        log.info("[test{}DataBridge][第二次执行,应该会复用缓存的 producer]", type);
+        action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
     }
     }
 
 
 }
 }