【代码评审】IoT:数据桥梁的 review
This commit is contained in:
parent
37fdd6247d
commit
e5a74193ba
|
@ -72,22 +72,20 @@ public class IotThingModelController {
|
|||
@PreAuthorize("@ss.hasPermission('iot:thing-model:query')")
|
||||
public CommonResult<IotThingModelTSLRespVO> getThingModelTsl(@RequestParam("productId") Long productId) {
|
||||
IotThingModelTSLRespVO tslRespVO = new IotThingModelTSLRespVO();
|
||||
// TODO @puhui999:是不是要先查询产品哈?原因是,万一没配置物模型,但是产品已经有了!
|
||||
// 1. 获得产品所有物模型定义
|
||||
List<IotThingModelDO> 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);
|
||||
|
|
|
@ -56,7 +56,6 @@ public class IotRedisStreamDataBridgeExecute extends
|
|||
serverConfig.setPassword(config.getPassword());
|
||||
}
|
||||
|
||||
// TODO @芋艿:看看怎么优化
|
||||
// 创建 RedisTemplate 并配置
|
||||
RedissonClient redisson = Redisson.create(redissonConfig);
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue