From e5a74193ba58fccaa1afcb1d1044bf019f4e1554 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 25 Mar 2025 21:01:12 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E8=AF=84=E5=AE=A1?= =?UTF-8?q?=E3=80=91IoT=EF=BC=9A=E6=95=B0=E6=8D=AE=E6=A1=A5=E6=A2=81?= =?UTF-8?q?=E7=9A=84=20review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../thingmodel/IotThingModelController.java | 6 ++-- .../IotRedisStreamDataBridgeExecute.java | 1 - .../databridge/IotDataBridgeExecuteTest.java | 36 +++++++------------ 3 files changed, 14 insertions(+), 29 deletions(-) diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.java index 862c07dfdc..6b143a6bbe 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.java +++ b/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')") public CommonResult getThingModelTsl(@RequestParam("productId") Long productId) { IotThingModelTSLRespVO tslRespVO = new IotThingModelTSLRespVO(); + // TODO @puhui999:是不是要先查询产品哈?原因是,万一没配置物模型,但是产品已经有了! // 1. 获得产品所有物模型定义 List thingModels = thingModelService.getThingModelListByProductId(productId); if (CollUtil.isEmpty(thingModels)) { return success(tslRespVO); } - // 2.1 设置公共部分参数 + // 2. 设置公共部分参数 IotThingModelDO thingModel = thingModels.get(0); tslRespVO.setProductId(thingModel.getProductId()).setProductKey(thingModel.getProductKey()); - // 2.2 处理属性列表 tslRespVO.setProperties(convertList(filterList(thingModels, item -> ObjUtil.equal(IotThingModelTypeEnum.PROPERTY.getType(), item.getType())), IotThingModelDO::getProperty)); - // 2.3 处理服务列表 tslRespVO.setServices(convertList(filterList(thingModels, item -> ObjUtil.equal(IotThingModelTypeEnum.SERVICE.getType(), item.getType())), IotThingModelDO::getService)); - // 2.4 处理事件列表 tslRespVO.setEvents(convertList(filterList(thingModels, item -> ObjUtil.equal(IotThingModelTypeEnum.EVENT.getType(), item.getType())), IotThingModelDO::getEvent)); return success(tslRespVO); diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRedisStreamDataBridgeExecute.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRedisStreamDataBridgeExecute.java index a2d4200b41..5499cfb9a6 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRedisStreamDataBridgeExecute.java +++ b/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()); } - // TODO @芋艿:看看怎么优化 // 创建 RedisTemplate 并配置 RedissonClient redisson = Redisson.create(redissonConfig); RedisTemplate template = new RedisTemplate<>(); diff --git a/yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotDataBridgeExecuteTest.java b/yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotDataBridgeExecuteTest.java index 4a4ca55b74..dd0f66157b 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotDataBridgeExecuteTest.java +++ b/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 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(); } @@ -132,14 +125,12 @@ public class IotDataBridgeExecuteTest extends BaseMockitoUnitTest { // 2. 创建配置 IotDataBridgeHttpConfig config = new IotDataBridgeHttpConfig() - .setUrl("https://doc.iocoder.cn/") - .setMethod(HttpMethod.GET.name()); + .setUrl("https://doc.iocoder.cn/").setMethod(HttpMethod.GET.name()); // 3. 执行测试 log.info("[testHttpDataBridge][执行HTTP数据桥接测试]"); 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 config 配置对象 - * @param mqType MQ类型 + * @param type MQ 类型 * @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)); + 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]", mqType); - 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)); } }