feat:simulator1
This commit is contained in:
parent
f1d887d0e0
commit
62a868f497
|
@ -21,32 +21,10 @@ public interface IotDeviceLogDataMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建设备日志超级表
|
* 创建设备日志超级表
|
||||||
<<<<<<< HEAD
|
|
||||||
* 初始化只创建一次
|
* 初始化只创建一次
|
||||||
*/
|
*/
|
||||||
void createDeviceLogSTable();
|
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
|
// TODO @super:单个参数,不用加 @Param
|
||||||
/**
|
/**
|
||||||
|
@ -54,10 +32,9 @@ public interface IotDeviceLogDataMapper {
|
||||||
*
|
*
|
||||||
* 如果子表不存在,会自动创建子表
|
* 如果子表不存在,会自动创建子表
|
||||||
*
|
*
|
||||||
>>>>>>> deab8c1cc6bb7864d9c40e0c369f649f6f9bfa41
|
|
||||||
* @param log 设备日志数据
|
* @param log 设备日志数据
|
||||||
*/
|
*/
|
||||||
void insert(@Param("log") IotDeviceLogDO log);
|
void insert(IotDeviceLogDO log);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得设备日志分页
|
* 获得设备日志分页
|
||||||
|
@ -65,7 +42,7 @@ public interface IotDeviceLogDataMapper {
|
||||||
* @param reqVO 分页查询条件
|
* @param reqVO 分页查询条件
|
||||||
* @return 设备日志列表
|
* @return 设备日志列表
|
||||||
*/
|
*/
|
||||||
List<IotDeviceLogDO> selectPage(@Param("reqVO") IotDeviceLogPageReqVO reqVO);
|
List<IotDeviceLogDO> selectPage(IotDeviceLogPageReqVO reqVO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得设备日志总数
|
* 获得设备日志总数
|
||||||
|
@ -73,6 +50,11 @@ public interface IotDeviceLogDataMapper {
|
||||||
* @param reqVO 查询条件
|
* @param reqVO 查询条件
|
||||||
* @return 日志总数
|
* @return 日志总数
|
||||||
*/
|
*/
|
||||||
Long selectCount(@Param("reqVO") IotDeviceLogPageReqVO reqVO);
|
Long selectCount(IotDeviceLogPageReqVO reqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询设备日志表是否存在
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Object checkDeviceLogTableExists();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
|
||||||
|
|
||||||
}
|
|
|
@ -25,18 +25,13 @@ public class TDengineTableInitConfiguration implements ApplicationRunner {
|
||||||
public void run(ApplicationArguments args) {
|
public void run(ApplicationArguments args) {
|
||||||
try {
|
try {
|
||||||
// 初始化设备日志表
|
// 初始化设备日志表
|
||||||
deviceLogService.initTDengineSTable();
|
deviceLogService.defineDeviceLog();
|
||||||
// TODO @super:这个日志,是不是不用打,不然重复啦!!!
|
// TODO @super:这个日志,是不是不用打,不然重复啦!!!
|
||||||
log.info("[run]初始化 设备日志表 TDengine 表结构成功");
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
// TODO @super:初始化失败,打印 error 日志,退出系统。。不然跑起来,就初始啦!!!
|
// TODO @super:初始化失败,打印 error 日志,退出系统。。不然跑起来,就初始啦!!!
|
||||||
if (ex.getMessage().contains("Table already exists")) {
|
// 初始化失败时打印错误日志并退出系统
|
||||||
log.info("TDengine 设备日志超级表已存在,跳过创建");
|
log.error("[TDengine] 初始化设备日志表结构失败,系统无法正常运行,即将退出", ex);
|
||||||
return;
|
System.exit(1);
|
||||||
} else{
|
|
||||||
log.error("初始化 设备日志表 TDengine 表结构失败", ex);
|
|
||||||
}
|
|
||||||
throw ex;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ public interface IotDeviceLogDataService {
|
||||||
*
|
*
|
||||||
*系统启动时,会自动初始化一次
|
*系统启动时,会自动初始化一次
|
||||||
*/
|
*/
|
||||||
void initTDengineSTable();
|
void defineDeviceLog();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插入设备日志
|
* 插入设备日志
|
||||||
|
|
|
@ -28,9 +28,24 @@ public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{
|
||||||
|
|
||||||
// TODO @super:方法名。defineDeviceLog。。未来,有可能别人使用别的记录日志,例如说 es 之类的。
|
// TODO @super:方法名。defineDeviceLog。。未来,有可能别人使用别的记录日志,例如说 es 之类的。
|
||||||
@Override
|
@Override
|
||||||
public void initTDengineSTable() {
|
public void defineDeviceLog() {
|
||||||
// TODO @super:改成不存在才创建。
|
// TODO @super:改成不存在才创建。
|
||||||
iotDeviceLogDataMapper.createDeviceLogSTable();
|
// 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
|
@Override
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
|
|
||||||
<!-- 创建设备日志超级表 初始化只创建一次-->
|
<!-- 创建设备日志超级表 初始化只创建一次-->
|
||||||
<update id="createDeviceLogSTable">
|
<update id="createDeviceLogSTable">
|
||||||
CREATE STABLE device_log (
|
CREATE STABLE IF NOT EXISTS device_log (
|
||||||
ts TIMESTAMP,
|
ts TIMESTAMP,
|
||||||
id NCHAR(50),
|
id NCHAR(50),
|
||||||
product_key NCHAR(50),
|
product_key NCHAR(50),
|
||||||
type NCHAR(50),
|
type NCHAR(50),
|
||||||
<!-- TODO @super:下划线 sub_type -->
|
<!-- TODO @super:下划线 sub_type -->
|
||||||
subType NCHAR(50),
|
sub_type NCHAR(50),
|
||||||
content NCHAR(1024),
|
content NCHAR(1024),
|
||||||
report_time TIMESTAMP
|
report_time TIMESTAMP
|
||||||
) TAGS (
|
) TAGS (
|
||||||
|
@ -75,4 +75,9 @@
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 检查设备日志超级表是否存在 -->
|
||||||
|
<select id="checkDeviceLogTableExists" resultType="Object">
|
||||||
|
SHOW TABLES LIKE 'device_log';
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
|
@ -283,9 +283,9 @@ iot:
|
||||||
|
|
||||||
# MQTT-RPC 配置
|
# MQTT-RPC 配置
|
||||||
mqtt:
|
mqtt:
|
||||||
broker: tcp://127.0.0.1:1883
|
broker: tcp://chaojiniu.top:1883
|
||||||
username: root
|
username: haohao
|
||||||
password: 123456
|
password: ahh@123456
|
||||||
clientId: mqtt-rpc-server-${random.int}
|
clientId: mqtt-rpc-server-${random.int}
|
||||||
requestTopic: rpc/request
|
requestTopic: rpc/request
|
||||||
responseTopicPrefix: rpc/response/
|
responseTopicPrefix: rpc/response/
|
||||||
|
|
Loading…
Reference in New Issue