feat:iotmessage
This commit is contained in:
parent
24a660b5c2
commit
c4c63a8fd6
|
@ -1,6 +1,7 @@
|
||||||
package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device;
|
package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -13,6 +14,7 @@ public class IotDeviceSaveReqVO {
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "设备编号", requiredMode = Schema.RequiredMode.AUTO, example = "177")
|
@Schema(description = "设备编号", requiredMode = Schema.RequiredMode.AUTO, example = "177")
|
||||||
|
@Size(max = 50, message = "设备编号长度不能超过50个字符")
|
||||||
private String deviceKey;
|
private String deviceKey;
|
||||||
|
|
||||||
@Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
@Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||||
|
|
|
@ -15,10 +15,7 @@ import lombok.NoArgsConstructor;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ThingModelMessageDO {
|
public class ThingModelMessageDO {
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据库名称
|
|
||||||
*/
|
|
||||||
private String dataBaseName;
|
|
||||||
|
|
||||||
// TODO @haohao:superTableName 和 tableName 是不是合并。因为每个 mapper 操作的时候,有且只会使用到其中一个。
|
// TODO @haohao:superTableName 和 tableName 是不是合并。因为每个 mapper 操作的时候,有且只会使用到其中一个。
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,28 +2,31 @@ package cn.iocoder.yudao.module.iot.dal.tdengine;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
||||||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessageDO;
|
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessageDO;
|
||||||
|
import cn.iocoder.yudao.module.iot.framework.tdengine.core.annotation.TDengineDS;
|
||||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
|
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理 TD 中物模型消息日志的操作
|
* 处理 TD 中物模型消息日志的操作
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
@DS("tdengine")
|
@TDengineDS
|
||||||
|
@InterceptorIgnore(tenantLine = "true") // 避免 SQL 解析,因为 JSqlParser 对 TDengine 的 SQL 解析会报错
|
||||||
public interface TdThingModelMessageMapper {
|
public interface TdThingModelMessageMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建物模型消息日志超级表超级表
|
* 创建物模型消息日志超级表超级表
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@TenantIgnore
|
|
||||||
void createSuperTable(ThingModelMessageDO superTable);
|
void createSuperTable(ThingModelMessageDO superTable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建子表
|
* 创建子表
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@TenantIgnore
|
|
||||||
void createTableWithTag(ThingModelMessageDO table);
|
void createTableWithTag(ThingModelMessageDO table);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,15 +7,13 @@ import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
||||||
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceStatusUpdateReqVO;
|
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceStatusUpdateReqVO;
|
||||||
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
|
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
|
||||||
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO;
|
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO;
|
||||||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.FieldParser;
|
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.*;
|
||||||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdFieldDO;
|
|
||||||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdTableDO;
|
|
||||||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage;
|
|
||||||
import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO;
|
import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO;
|
||||||
import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
|
import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
|
||||||
import cn.iocoder.yudao.module.iot.dal.redis.deviceData.DeviceDataRedisDAO;
|
import cn.iocoder.yudao.module.iot.dal.redis.deviceData.DeviceDataRedisDAO;
|
||||||
import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDDLMapper;
|
import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDDLMapper;
|
||||||
import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDMLMapper;
|
import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDMLMapper;
|
||||||
|
import cn.iocoder.yudao.module.iot.dal.tdengine.TdThingModelMessageMapper;
|
||||||
import cn.iocoder.yudao.module.iot.enums.IotConstants;
|
import cn.iocoder.yudao.module.iot.enums.IotConstants;
|
||||||
import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStatusEnum;
|
import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStatusEnum;
|
||||||
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelTypeEnum;
|
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelTypeEnum;
|
||||||
|
@ -63,6 +61,9 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
|
||||||
@Resource
|
@Resource
|
||||||
private TdEngineDMLMapper tdEngineDMLMapper;
|
private TdEngineDMLMapper tdEngineDMLMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TdThingModelMessageMapper tdThingModelMessageMapper;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private DeviceDataRedisDAO deviceDataRedisDAO;
|
private DeviceDataRedisDAO deviceDataRedisDAO;
|
||||||
|
|
||||||
|
@ -78,7 +79,7 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
|
||||||
iotDeviceService.updateDeviceStatus(new IotDeviceStatusUpdateReqVO()
|
iotDeviceService.updateDeviceStatus(new IotDeviceStatusUpdateReqVO()
|
||||||
.setId(device.getId()).setStatus(IotDeviceStatusEnum.ONLINE.getStatus()));
|
.setId(device.getId()).setStatus(IotDeviceStatusEnum.ONLINE.getStatus()));
|
||||||
// 1.2 创建物模型日志设备表
|
// 1.2 创建物模型日志设备表
|
||||||
createThingModelMessageDeviceTable(device.getProductKey(), device.getDeviceName(), device.getDeviceKey());
|
createThingModelMessageDeviceTable(device.getProductKey(), device.getDeviceKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 获取设备属性并进行物模型校验,过滤非物模型属性
|
// 2. 获取设备属性并进行物模型校验,过滤非物模型属性
|
||||||
|
@ -232,23 +233,16 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
|
||||||
* 创建物模型日志设备数据表
|
* 创建物模型日志设备数据表
|
||||||
*
|
*
|
||||||
* @param productKey 产品 Key
|
* @param productKey 产品 Key
|
||||||
* @param deviceName 设备名称
|
|
||||||
* @param deviceKey 设备 Key
|
* @param deviceKey 设备 Key
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private void createThingModelMessageDeviceTable(String productKey, String deviceName, String deviceKey){
|
private void createThingModelMessageDeviceTable(String productKey, String deviceKey){
|
||||||
|
|
||||||
// 1. 获取超级表的名称、数据库名称、设备日志表名称
|
|
||||||
String databaseName = IotTdDatabaseUtils.getDatabaseName(url);
|
|
||||||
String superTableName = IotTdDatabaseUtils.getThingModelMessageSuperTableName(productKey);
|
|
||||||
// TODO @alwayssuper:最好 databaseName、superTableName、thinkModelMessageDeviceTableName 的处理,放到 tdThinkModelMessageMapper 里。可以考虑,弄个 default 方法
|
|
||||||
String thinkModelMessageDeviceTableName = IotTdDatabaseUtils.getThingModelMessageDeviceTableName(productKey, deviceName);
|
|
||||||
|
|
||||||
// 2. 创建物模型日志设备数据表
|
// 2. 创建物模型日志设备数据表
|
||||||
// tdThingModelMessageMapper.createTableWithTag(ThingModelMessageDO.builder().build()
|
// tdThingModelMessageMapper.createTableWithTag(ThingModelMessageDO.builder().build()
|
||||||
// .setDataBaseName(databaseName)
|
// .setSuperTableName(productKey)
|
||||||
// .setSuperTableName(superTableName)
|
// .setTableName(deviceKey)
|
||||||
// .setTableName(thinkModelMessageDeviceTableName)
|
|
||||||
// .setDeviceKey(deviceKey));
|
// .setDeviceKey(deviceKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,21 +6,21 @@
|
||||||
|
|
||||||
<!-- 创建物模型消息日志超级表 -->
|
<!-- 创建物模型消息日志超级表 -->
|
||||||
<update id="createSuperTable">
|
<update id="createSuperTable">
|
||||||
CREATE STABLE ${dataBaseName}.${superTableName}(
|
CREATE STABLE thing_model_message_${superTableName}(
|
||||||
ts TIMESTAMP,
|
ts TIMESTAMP,
|
||||||
id VARCHAR(255),
|
id NCHAR(64),
|
||||||
sys VARCHAR(2048),
|
sys NCHAR(2048),
|
||||||
method VARCHAR(255),
|
method NCHAR(255),
|
||||||
params VARCHAR(2048)
|
params NCHAR(2048)
|
||||||
)TAGS (
|
)TAGS (
|
||||||
device_key VARCHAR(255)
|
device_key NCHAR(50)
|
||||||
)
|
)
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<!-- 创建物模型消息日志子表,带有deviceKey的TAG -->
|
<!-- 创建物模型消息日志子表,带有deviceKey的TAG -->
|
||||||
<update id="createTableWithTag">
|
<update id="createTableWithTag">
|
||||||
CREATE TABLE IF NOT EXISTS ${dataBaseName}.${tableName}
|
CREATE STABLE ${tableName}
|
||||||
USING ${dataBaseName}.${superTableName}(
|
USING thing_model_message_${superTableName}(
|
||||||
ts,
|
ts,
|
||||||
id ,
|
id ,
|
||||||
sys ,
|
sys ,
|
||||||
|
|
Loading…
Reference in New Issue