Commit e5a74193ba58fccaa1afcb1d1044bf019f4e1554

Authored by YunaiV
1 parent 37fdd624

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

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 {
72 72 @PreAuthorize("@ss.hasPermission('iot:thing-model:query')")
73 73 public CommonResult<IotThingModelTSLRespVO> getThingModelTsl(@RequestParam("productId") Long productId) {
74 74 IotThingModelTSLRespVO tslRespVO = new IotThingModelTSLRespVO();
  75 + // TODO @puhui999:是不是要先查询产品哈?原因是,万一没配置物模型,但是产品已经有了!
75 76 // 1. 获得产品所有物模型定义
76 77 List<IotThingModelDO> thingModels = thingModelService.getThingModelListByProductId(productId);
77 78 if (CollUtil.isEmpty(thingModels)) {
78 79 return success(tslRespVO);
79 80 }
80 81  
81   - // 2.1 设置公共部分参数
  82 + // 2. 设置公共部分参数
82 83 IotThingModelDO thingModel = thingModels.get(0);
83 84 tslRespVO.setProductId(thingModel.getProductId()).setProductKey(thingModel.getProductKey());
84   - // 2.2 处理属性列表
85 85 tslRespVO.setProperties(convertList(filterList(thingModels, item ->
86 86 ObjUtil.equal(IotThingModelTypeEnum.PROPERTY.getType(), item.getType())), IotThingModelDO::getProperty));
87   - // 2.3 处理服务列表
88 87 tslRespVO.setServices(convertList(filterList(thingModels, item ->
89 88 ObjUtil.equal(IotThingModelTypeEnum.SERVICE.getType(), item.getType())), IotThingModelDO::getService));
90   - // 2.4 处理事件列表
91 89 tslRespVO.setEvents(convertList(filterList(thingModels, item ->
92 90 ObjUtil.equal(IotThingModelTypeEnum.EVENT.getType(), item.getType())), IotThingModelDO::getEvent));
93 91 return success(tslRespVO);
... ...
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
56 56 serverConfig.setPassword(config.getPassword());
57 57 }
58 58  
59   - // TODO @芋艿:看看怎么优化
60 59 // 创建 RedisTemplate 并配置
61 60 RedissonClient redisson = Redisson.create(redissonConfig);
62 61 RedisTemplate<String, Object> template = new RedisTemplate<>();
... ...
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 {
41 41 @BeforeEach
42 42 public void setUp() {
43 43 // 创建共享的测试消息
44   - message = IotDeviceMessage.builder()
45   - .requestId("TEST-001")
46   - .reportTime(LocalDateTime.now())
47   - .tenantId(1L)
48   - .productKey("testProduct")
49   - .deviceName("testDevice")
50   - .deviceKey("testDeviceKey")
51   - .type("property")
52   - .identifier("temperature")
53   - .data("{\"value\": 60}")
  44 + message = IotDeviceMessage.builder().requestId("TEST-001").reportTime(LocalDateTime.now()).tenantId(1L)
  45 + .productKey("testProduct").deviceName("testDevice").deviceKey("testDeviceKey")
  46 + .type("property").identifier("temperature").data("{\"value\": 60}")
54 47 .build();
55 48 }
56 49  
... ... @@ -132,14 +125,12 @@ public class IotDataBridgeExecuteTest extends BaseMockitoUnitTest {
132 125  
133 126 // 2. 创建配置
134 127 IotDataBridgeHttpConfig config = new IotDataBridgeHttpConfig()
135   - .setUrl("https://doc.iocoder.cn/")
136   - .setMethod(HttpMethod.GET.name());
  128 + .setUrl("https://doc.iocoder.cn/").setMethod(HttpMethod.GET.name());
137 129  
138 130 // 3. 执行测试
139 131 log.info("[testHttpDataBridge][执行HTTP数据桥接测试]");
140 132 httpDataBridgeExecute.execute(message, new IotDataBridgeDO()
141   - .setType(httpDataBridgeExecute.getType())
142   - .setConfig(config));
  133 + .setType(httpDataBridgeExecute.getType()).setConfig(config));
143 134 }
144 135  
145 136 /**
... ... @@ -147,19 +138,16 @@ public class IotDataBridgeExecuteTest extends BaseMockitoUnitTest {
147 138 *
148 139 * @param action 执行器实例
149 140 * @param config 配置对象
150   - * @param mqType MQ类型
  141 + * @param type MQ 类型
151 142 * @throws Exception 如果执行过程中发生异常
152 143 */
153   - private void executeAndVerifyCache(IotDataBridgeExecute<?> action, IotDataBridgeAbstractConfig config, String mqType) throws Exception {
154   - log.info("[test{}DataBridge][第一次执行,应该会创建新的 producer]", mqType);
155   - action.execute(message, new IotDataBridgeDO()
156   - .setType(action.getType())
157   - .setConfig(config));
158   -
159   - log.info("[test{}DataBridge][第二次执行,应该会复用缓存的 producer]", mqType);
160   - action.execute(message, new IotDataBridgeDO()
161   - .setType(action.getType())
162   - .setConfig(config));
  144 + private void executeAndVerifyCache(IotDataBridgeExecute<?> action, IotDataBridgeAbstractConfig config, String type)
  145 + throws Exception {
  146 + log.info("[test{}DataBridge][第一次执行,应该会创建新的 producer]", type);
  147 + action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
  148 +
  149 + log.info("[test{}DataBridge][第二次执行,应该会复用缓存的 producer]", type);
  150 + action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
163 151 }
164 152  
165 153 }
... ...