Commit 9c3aa5d95f51b59c873b321a08047f77580d9fe7

Authored by alwayssuper
2 parents 1ce9420a c4c63a8f

Merge branch 'feature/iot' of https://gitee.com/alwayssuper/ruoyi-vue-pro into origin/feature/iot

yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceSaveReqVO.java
1 1 package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
  4 +import jakarta.validation.constraints.Size;
4 5 import lombok.Data;
5 6  
6 7 import java.util.Set;
... ... @@ -13,6 +14,7 @@ public class IotDeviceSaveReqVO {
13 14 private Long id;
14 15  
15 16 @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.AUTO, example = "177")
  17 + @Size(max = 50, message = "设备编号长度不能超过50个字符")
16 18 private String deviceKey;
17 19  
18 20 @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThingModelMessageDO.java
... ... @@ -15,10 +15,7 @@ import lombok.NoArgsConstructor;
15 15 @AllArgsConstructor
16 16 public class ThingModelMessageDO {
17 17  
18   - /**
19   - * 数据库名称
20   - */
21   - private String dataBaseName;
  18 +
22 19  
23 20 // TODO @haohao:superTableName 和 tableName 是不是合并。因为每个 mapper 操作的时候,有且只会使用到其中一个。
24 21 /**
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/TdThingModelMessageMapper.java
... ... @@ -2,28 +2,31 @@ package cn.iocoder.yudao.module.iot.dal.tdengine;
2 2  
3 3 import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
4 4 import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessageDO;
  5 +import cn.iocoder.yudao.module.iot.framework.tdengine.core.annotation.TDengineDS;
5 6 import com.baomidou.dynamic.datasource.annotation.DS;
  7 +import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
6 8 import org.apache.ibatis.annotations.Mapper;
7 9  
8 10 /**
9 11 * 处理 TD 中物模型消息日志的操作
10 12 */
11 13 @Mapper
12   -@DS("tdengine")
  14 +@TDengineDS
  15 +@InterceptorIgnore(tenantLine = "true") // 避免 SQL 解析,因为 JSqlParser 对 TDengine 的 SQL 解析会报错
13 16 public interface TdThingModelMessageMapper {
14 17  
15 18 /**
16 19 * 创建物模型消息日志超级表超级表
17 20 *
18 21 */
19   - @TenantIgnore
  22 +
20 23 void createSuperTable(ThingModelMessageDO superTable);
21 24  
22 25 /**
23 26 * 创建子表
24 27 *
25 28 */
26   - @TenantIgnore
  29 +
27 30 void createTableWithTag(ThingModelMessageDO table);
28 31  
29 32 }
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageServiceImpl.java
... ... @@ -7,15 +7,13 @@ import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
7 7 import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceStatusUpdateReqVO;
8 8 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
9 9 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO;
10   -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.FieldParser;
11   -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdFieldDO;
12   -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdTableDO;
13   -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage;
  10 +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.*;
14 11 import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO;
15 12 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
16 13 import cn.iocoder.yudao.module.iot.dal.redis.deviceData.DeviceDataRedisDAO;
17 14 import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDDLMapper;
18 15 import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDMLMapper;
  16 +import cn.iocoder.yudao.module.iot.dal.tdengine.TdThingModelMessageMapper;
19 17 import cn.iocoder.yudao.module.iot.enums.IotConstants;
20 18 import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStatusEnum;
21 19 import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelTypeEnum;
... ... @@ -64,6 +62,9 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
64 62 private TdEngineDMLMapper tdEngineDMLMapper;
65 63  
66 64 @Resource
  65 + private TdThingModelMessageMapper tdThingModelMessageMapper;
  66 +
  67 + @Resource
67 68 private DeviceDataRedisDAO deviceDataRedisDAO;
68 69  
69 70  
... ... @@ -78,7 +79,7 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
78 79 iotDeviceService.updateDeviceStatus(new IotDeviceStatusUpdateReqVO()
79 80 .setId(device.getId()).setStatus(IotDeviceStatusEnum.ONLINE.getStatus()));
80 81 // 1.2 创建物模型日志设备表
81   - createThingModelMessageDeviceTable(device.getProductKey(), device.getDeviceName(), device.getDeviceKey());
  82 + createThingModelMessageDeviceTable(device.getProductKey(), device.getDeviceKey());
82 83 }
83 84  
84 85 // 2. 获取设备属性并进行物模型校验,过滤非物模型属性
... ... @@ -232,23 +233,16 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
232 233 * 创建物模型日志设备数据表
233 234 *
234 235 * @param productKey 产品 Key
235   - * @param deviceName 设备名称
236 236 * @param deviceKey 设备 Key
237 237 *
238 238 */
239   - private void createThingModelMessageDeviceTable(String productKey, String deviceName, String deviceKey){
  239 + private void createThingModelMessageDeviceTable(String productKey, String deviceKey){
240 240  
241   - // 1. 获取超级表的名称、数据库名称、设备日志表名称
242   - String databaseName = IotTdDatabaseUtils.getDatabaseName(url);
243   - String superTableName = IotTdDatabaseUtils.getThingModelMessageSuperTableName(productKey);
244   - // TODO @alwayssuper:最好 databaseName、superTableName、thinkModelMessageDeviceTableName 的处理,放到 tdThinkModelMessageMapper 里。可以考虑,弄个 default 方法
245   - String thinkModelMessageDeviceTableName = IotTdDatabaseUtils.getThingModelMessageDeviceTableName(productKey, deviceName);
246 241  
247 242 // 2. 创建物模型日志设备数据表
248 243 // tdThingModelMessageMapper.createTableWithTag(ThingModelMessageDO.builder().build()
249   -// .setDataBaseName(databaseName)
250   -// .setSuperTableName(superTableName)
251   -// .setTableName(thinkModelMessageDeviceTableName)
  244 +// .setSuperTableName(productKey)
  245 +// .setTableName(deviceKey)
252 246 // .setDeviceKey(deviceKey));
253 247 }
254 248  
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/tdengine/TdThinkModelMessageMapper.xml
... ... @@ -6,21 +6,21 @@
6 6  
7 7 <!-- 创建物模型消息日志超级表 -->
8 8 <update id="createSuperTable">
9   - CREATE STABLE ${dataBaseName}.${superTableName}(
  9 + CREATE STABLE thing_model_message_${superTableName}(
10 10 ts TIMESTAMP,
11   - id VARCHAR(255),
12   - sys VARCHAR(2048),
13   - method VARCHAR(255),
14   - params VARCHAR(2048)
  11 + id NCHAR(64),
  12 + sys NCHAR(2048),
  13 + method NCHAR(255),
  14 + params NCHAR(2048)
15 15 )TAGS (
16   - device_key VARCHAR(255)
  16 + device_key NCHAR(50)
17 17 )
18 18 </update>
19 19  
20 20 <!-- 创建物模型消息日志子表,带有deviceKey的TAG -->
21 21 <update id="createTableWithTag">
22   - CREATE TABLE IF NOT EXISTS ${dataBaseName}.${tableName}
23   - USING ${dataBaseName}.${superTableName}(
  22 + CREATE STABLE ${tableName}
  23 + USING thing_model_message_${superTableName}(
24 24 ts,
25 25 id ,
26 26 sys ,
... ...