diff --git a/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/IotConstants.java b/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/IotConstants.java index 0762ade9de..631ca24a36 100644 --- a/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/IotConstants.java +++ b/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/IotConstants.java @@ -40,6 +40,6 @@ public interface IotConstants { *
* 格式为 thing_model_message_{productKey}_{deviceName}
*/
- String THINK_MODEL_MESSAGE_TABLE_NAME_FORMAT = "thing_model_message_%s_%s";
+ String THING_MODEL_MESSAGE_TABLE_NAME_FORMAT = "thing_model_message_%s_%s";
}
\ No newline at end of file
diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThinkModelMessageDO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThingModelMessageDO.java
similarity index 85%
rename from yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThinkModelMessageDO.java
rename to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThingModelMessageDO.java
index 13309c81ed..c57ec1c7be 100644
--- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThinkModelMessageDO.java
+++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThingModelMessageDO.java
@@ -4,9 +4,8 @@ import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
-import org.apache.xmlbeans.impl.xb.xsdschema.Public;
-
+// TODO @芋艿:纠结下字段
/**
* TD 物模型消息日志的数据库
*/
@@ -14,7 +13,8 @@ import org.apache.xmlbeans.impl.xb.xsdschema.Public;
@Builder
@NoArgsConstructor
@AllArgsConstructor
-public class ThinkModelMessageDO {
+public class ThingModelMessageDO {
+
/**
* 数据库名称
*/
@@ -32,7 +32,7 @@ public class ThinkModelMessageDO {
private String tableName;
/**
- * 消息ID
+ * 消息 ID
*/
private String id;
@@ -42,7 +42,9 @@ public class ThinkModelMessageDO {
private Object sys;
/**
- * 请求方法 例如:thing.event.property.post
+ * 请求方法
+ *
+ * 例如:thing.event.property.post
*/
private String method;
@@ -56,11 +58,9 @@ public class ThinkModelMessageDO {
*/
private Long time;
-
/**
* 设备 key
*/
private String deviceKey;
-
}
diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/TdThinkModelMessageMapper.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/TdThinkModelMessageMapper.java
index 90f66d508c..da9730e74b 100644
--- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/TdThinkModelMessageMapper.java
+++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/TdThinkModelMessageMapper.java
@@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.iot.dal.tdengine;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
-import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThinkModelMessageDO;
+import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessageDO;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.apache.ibatis.annotations.Mapper;
@@ -17,12 +17,13 @@ public interface TdThinkModelMessageMapper {
*
*/
@TenantIgnore
- void createSuperTable(ThinkModelMessageDO superTable);
+ void createSuperTable(ThingModelMessageDO superTable);
/**
* 创建子表
*
*/
@TenantIgnore
- void createTableWithTag(ThinkModelMessageDO table);
+ void createTableWithTag(ThingModelMessageDO table);
+
}
diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/producer/simulatesend/SimulateSendProducer.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/producer/simulatesend/SimulateSendProducer.java
index 76cde71be7..411ddd6f2b 100644
--- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/producer/simulatesend/SimulateSendProducer.java
+++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/producer/simulatesend/SimulateSendProducer.java
@@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
+// TODO @alwayssuper:是不是还没用起来哈?Producer 最好属于某个模块;
/**
* SimulateSend 模拟设备上报的 Producer
*
@@ -14,6 +15,7 @@ import org.springframework.stereotype.Component;
@Slf4j
@Component
public class SimulateSendProducer {
+
@Resource
private ApplicationContext applicationContext;
diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java
index a53aee55d2..628805a97e 100644
--- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java
+++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java
@@ -122,7 +122,7 @@ public class IotProductServiceImpl implements IotProductService {
thingModelFunctionService.createSuperTableDataModel(id);
// 3.2 创建物模型日志超级表数据模型
thingModelMessageService.createSuperTable(id);
- }
+ }x
productMapper.updateById(updateObj);
}
diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageServiceImpl.java
index 9ea237ce84..454a2e072d 100644
--- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageServiceImpl.java
+++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageServiceImpl.java
@@ -57,12 +57,14 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
private IotProductThingModelService iotProductThingModelService;
@Resource
private IotDeviceService iotDeviceService;
+ @Resource
+ private IotProductService productService;
+
@Resource
private TdEngineDDLMapper tdEngineDDLMapper;
@Resource
private TdEngineDMLMapper tdEngineDMLMapper;
- @Resource
- private IotProductService productService;
+
@Resource
private DeviceDataRedisDAO deviceDataRedisDAO;
@@ -119,11 +121,12 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
IotProductDO product = productService.getProduct(productId);
// 2. 获取超级表的名称和数据库名称
+ // TODO @alwayssuper:最好 databaseName、superTableName 的处理,放到 tdThinkModelMessageMapper 里。可以考虑,弄个 default 方法
String databaseName = iotTdDatabaseUtils.getDatabaseName();
- String superTableName = IotTdDatabaseUtils.getThinkModelMessageSuperTableName(product.getProductKey());
+ String superTableName = IotTdDatabaseUtils.getThingModelMessageSuperTableName(product.getProductKey());
// 3. 创建超级表
- tdThinkModelMessageMapper.createSuperTable(ThinkModelMessageDO.builder().build()
+ tdThinkModelMessageMapper.createSuperTable(ThingModelMessageDO.builder().build()
.setDataBaseName(databaseName)
.setSuperTableName(superTableName));
}
@@ -238,16 +241,16 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
// 1. 获取超级表的名称、数据库名称、设备日志表名称
String databaseName = iotTdDatabaseUtils.getDatabaseName();
- String superTableName = IotTdDatabaseUtils.getThinkModelMessageSuperTableName(productKey);
+ String superTableName = IotTdDatabaseUtils.getThingModelMessageSuperTableName(productKey);
+ // TODO @alwayssuper:最好 databaseName、superTableName、thinkModelMessageDeviceTableName 的处理,放到 tdThinkModelMessageMapper 里。可以考虑,弄个 default 方法
String thinkModelMessageDeviceTableName = IotTdDatabaseUtils.getThinkModelMessageDeviceTableName(productKey, deviceName);
// 2. 创建物模型日志设备数据表
- tdThinkModelMessageMapper.createTableWithTag(ThinkModelMessageDO.builder().build()
+ tdThinkModelMessageMapper.createTableWithTag(ThingModelMessageDO.builder().build()
.setDataBaseName(databaseName)
.setSuperTableName(superTableName)
.setTableName(thinkModelMessageDeviceTableName)
.setDeviceKey(deviceKey));
-
}
/**
diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/util/IotTdDatabaseUtils.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/util/IotTdDatabaseUtils.java
index b928ec7169..8feef7bf60 100644
--- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/util/IotTdDatabaseUtils.java
+++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/util/IotTdDatabaseUtils.java
@@ -4,8 +4,10 @@ import cn.iocoder.yudao.module.iot.enums.IotConstants;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
+// TODO @芋艿:可能要思索下,有没更好的处理方式
+// TODO @芋艿:怎么改成无状态
/**
- * TD数据库工具类
+ * TD 数据库工具类
*
* @author AlwaysSuper
*/
@@ -19,6 +21,7 @@ public class IotTdDatabaseUtils {
* 获取数据库名称
*/
public String getDatabaseName() {
+// TODO @alwayssuper:StrUtil.subAfter("/")
int index = url.lastIndexOf("/");
return index != -1 ? url.substring(index + 1) : url;
}
@@ -31,6 +34,7 @@ public class IotTdDatabaseUtils {
* @return 产品超级表表名
*/
public static String getProductSuperTableName(Integer deviceType, String productKey) {
+ // TODO @alwayssuper:枚举字段,不要 1、2、3;不符合预期,抛出异常
return switch (deviceType) {
case 1 -> String.format(IotConstants.GATEWAY_SUB_STABLE_NAME_FORMAT, productKey).toLowerCase();
case 2 -> String.format(IotConstants.GATEWAY_STABLE_NAME_FORMAT, productKey).toLowerCase();
@@ -45,7 +49,8 @@ public class IotTdDatabaseUtils {
* @return 物模型日志超级表表名
*
*/
- public static String getThinkModelMessageSuperTableName(String productKey) {
+ public static String getThingModelMessageSuperTableName(String productKey) {
+ // TODO @alwayssuper:是不是应该 + 拼接就好,不用 format
return String.format("thing_model_message_", productKey).toLowerCase();
}
@@ -57,7 +62,7 @@ public class IotTdDatabaseUtils {
* @return 物模型日志设备表名
*/
public static String getThinkModelMessageDeviceTableName(String productKey, String deviceName) {
- return String.format(IotConstants.THINK_MODEL_MESSAGE_TABLE_NAME_FORMAT, productKey.toLowerCase(), deviceName.toLowerCase());
+ return String.format(IotConstants.THING_MODEL_MESSAGE_TABLE_NAME_FORMAT, productKey.toLowerCase(), deviceName.toLowerCase());
}
}
diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/tdengine/TdThinkModelMessageMapper.xml b/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/tdengine/TdThinkModelMessageMapper.xml
index 476ca97abc..aeecd5dc1e 100644
--- a/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/tdengine/TdThinkModelMessageMapper.xml
+++ b/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/tdengine/TdThinkModelMessageMapper.xml
@@ -4,17 +4,17 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">