feat:simulator1

This commit is contained in:
alwayssuper 2025-01-12 20:13:41 +08:00
parent f1d887d0e0
commit 62a868f497
7 changed files with 40 additions and 74 deletions

View File

@ -21,32 +21,10 @@ public interface IotDeviceLogDataMapper {
/**
* 创建设备日志超级表
<<<<<<< HEAD
* 初始化只创建一次
*/
void createDeviceLogSTable();
=======
*
* 注意初始化时只需创建一次
*/
void createDeviceLogSTable();
// TODO @super是不是删除哈
>>>>>>> deab8c1cc6bb7864d9c40e0c369f649f6f9bfa41
/**
* 创建设备日志子表
*
* @param deviceKey 设备标识
*/
<<<<<<< HEAD
void createDeviceLogTable( @Param("deviceKey") String deviceKey);
/**
* 插入设备日志数据
*
=======
void createDeviceLogTable(@Param("deviceKey") String deviceKey);
// TODO @super单个参数不用加 @Param
/**
@ -54,10 +32,9 @@ public interface IotDeviceLogDataMapper {
*
* 如果子表不存在会自动创建子表
*
>>>>>>> deab8c1cc6bb7864d9c40e0c369f649f6f9bfa41
* @param log 设备日志数据
*/
void insert(@Param("log") IotDeviceLogDO log);
void insert(IotDeviceLogDO log);
/**
* 获得设备日志分页
@ -65,7 +42,7 @@ public interface IotDeviceLogDataMapper {
* @param reqVO 分页查询条件
* @return 设备日志列表
*/
List<IotDeviceLogDO> selectPage(@Param("reqVO") IotDeviceLogPageReqVO reqVO);
List<IotDeviceLogDO> selectPage(IotDeviceLogPageReqVO reqVO);
/**
* 获得设备日志总数
@ -73,6 +50,11 @@ public interface IotDeviceLogDataMapper {
* @param reqVO 查询条件
* @return 日志总数
*/
Long selectCount(@Param("reqVO") IotDeviceLogPageReqVO reqVO);
Long selectCount(IotDeviceLogPageReqVO reqVO);
/**
* 查询设备日志表是否存在
*
*/
Object checkDeviceLogTableExists();
}

View File

@ -1,31 +0,0 @@
package cn.iocoder.yudao.module.iot.dal.tdengine;
import cn.iocoder.yudao.module.iot.framework.tdengine.core.annotation.TDengineDS;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 处理 TD 中物模型消息日志的操作
*/
@Mapper
@Deprecated // TODO super什么时候删除下哈
@TDengineDS
@InterceptorIgnore(tenantLine = "true") // 避免 SQL 解析因为 JSqlParser TDengine SQL 解析会报错
public interface TdThingModelMessageMapper {
/**
* 创建物模型消息日志超级表超级表
*
*/
void createSuperTable(@Param("productKey") String productKey);
/**
* 创建子表
*
*/
void createTableWithTag(@Param("productKey") String productKey,@Param("deviceKey") String deviceKey);
}

View File

@ -25,18 +25,13 @@ public class TDengineTableInitConfiguration implements ApplicationRunner {
public void run(ApplicationArguments args) {
try {
// 初始化设备日志表
deviceLogService.initTDengineSTable();
deviceLogService.defineDeviceLog();
// TODO @super这个日志是不是不用打不然重复啦
log.info("[run]初始化 设备日志表 TDengine 表结构成功");
} catch (Exception ex) {
// TODO @super初始化失败打印 error 日志退出系统不然跑起来就初始啦
if (ex.getMessage().contains("Table already exists")) {
log.info("TDengine 设备日志超级表已存在,跳过创建");
return;
} else{
log.error("初始化 设备日志表 TDengine 表结构失败", ex);
}
throw ex;
// 初始化失败时打印错误日志并退出系统
log.error("[TDengine] 初始化设备日志表结构失败,系统无法正常运行,即将退出", ex);
System.exit(1);
}
}

View File

@ -17,7 +17,7 @@ public interface IotDeviceLogDataService {
*
*系统启动时会自动初始化一次
*/
void initTDengineSTable();
void defineDeviceLog();
/**
* 插入设备日志

View File

@ -28,9 +28,24 @@ public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{
// TODO @super方法名defineDeviceLog未来有可能别人使用别的记录日志例如说 es 之类的
@Override
public void initTDengineSTable() {
public void defineDeviceLog() {
// TODO @super改成不存在才创建
// try {
// // 创建超级表使用 IF NOT EXISTS 语句避免重复创建错误
// iotDeviceLogDataMapper.createDeviceLogSTable();
// } catch (Exception e) {
// if (e.getMessage().contains("already exists")) {
// log.info("[TDengine] 设备日志超级表已存在,跳过创建");
// return;
// }
// throw e;
// }
if(iotDeviceLogDataMapper.checkDeviceLogTableExists()==null){
log.info("[TDengine] 设备日志超级表不存在,开始创建 {}",iotDeviceLogDataMapper.checkDeviceLogTableExists());
iotDeviceLogDataMapper.createDeviceLogSTable();
}else{
log.info("[TDengine] 设备日志超级表已存在,跳过创建");
}
}
@Override

View File

@ -6,13 +6,13 @@
<!-- 创建设备日志超级表 初始化只创建一次-->
<update id="createDeviceLogSTable">
CREATE STABLE device_log (
CREATE STABLE IF NOT EXISTS device_log (
ts TIMESTAMP,
id NCHAR(50),
product_key NCHAR(50),
type NCHAR(50),
<!-- TODO @super下划线 sub_type -->
subType NCHAR(50),
sub_type NCHAR(50),
content NCHAR(1024),
report_time TIMESTAMP
) TAGS (
@ -75,4 +75,9 @@
</where>
</select>
<!-- 检查设备日志超级表是否存在 -->
<select id="checkDeviceLogTableExists" resultType="Object">
SHOW TABLES LIKE 'device_log';
</select>
</mapper>

View File

@ -283,9 +283,9 @@ iot:
# MQTT-RPC 配置
mqtt:
broker: tcp://127.0.0.1:1883
username: root
password: 123456
broker: tcp://chaojiniu.top:1883
username: haohao
password: ahh@123456
clientId: mqtt-rpc-server-${random.int}
requestTopic: rpc/request
responseTopicPrefix: rpc/response/