From 62a868f497874f5d755ec1bff4b74a08c8bb05a5 Mon Sep 17 00:00:00 2001 From: alwayssuper <12851801+alwayssuper@user.noreply.gitee.com> Date: Sun, 12 Jan 2025 20:13:41 +0800 Subject: [PATCH] feat:simulator1 --- .../dal/tdengine/IotDeviceLogDataMapper.java | 34 +++++-------------- .../tdengine/TdThingModelMessageMapper.java | 31 ----------------- .../TDengineTableInitConfiguration.java | 13 +++---- .../device/IotDeviceLogDataService.java | 2 +- .../device/IotDeviceLogDataServiceImpl.java | 19 +++++++++-- .../mapper/device/IotDeviceLogDataMapper.xml | 9 +++-- .../src/main/resources/application-local.yaml | 6 ++-- 7 files changed, 40 insertions(+), 74 deletions(-) delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/TdThingModelMessageMapper.java diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceLogDataMapper.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceLogDataMapper.java index 9584262dff..42dcc0cf38 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceLogDataMapper.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceLogDataMapper.java @@ -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 selectPage(@Param("reqVO") IotDeviceLogPageReqVO reqVO); + List 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(); } diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/TdThingModelMessageMapper.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/TdThingModelMessageMapper.java deleted file mode 100644 index cbc6e88366..0000000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/TdThingModelMessageMapper.java +++ /dev/null @@ -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); - -} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/config/TDengineTableInitConfiguration.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/config/TDengineTableInitConfiguration.java index e0057e1808..c9f08903e8 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/config/TDengineTableInitConfiguration.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/config/TDengineTableInitConfiguration.java @@ -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); } } diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataService.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataService.java index 1a3b48503c..a92d46bf49 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataService.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataService.java @@ -17,7 +17,7 @@ public interface IotDeviceLogDataService { * *系统启动时,会自动初始化一次 */ - void initTDengineSTable(); + void defineDeviceLog(); /** * 插入设备日志 diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataServiceImpl.java index d0659e5073..769821e3e4 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataServiceImpl.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataServiceImpl.java @@ -28,9 +28,24 @@ public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{ // TODO @super:方法名。defineDeviceLog。。未来,有可能别人使用别的记录日志,例如说 es 之类的。 @Override - public void initTDengineSTable() { + public void defineDeviceLog() { // 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 diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceLogDataMapper.xml b/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceLogDataMapper.xml index 09e5dd4681..1554b7d1e0 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceLogDataMapper.xml +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceLogDataMapper.xml @@ -6,13 +6,13 @@ - CREATE STABLE device_log ( + CREATE STABLE IF NOT EXISTS device_log ( ts TIMESTAMP, id NCHAR(50), product_key NCHAR(50), type NCHAR(50), - subType NCHAR(50), + sub_type NCHAR(50), content NCHAR(1024), report_time TIMESTAMP ) TAGS ( @@ -75,4 +75,9 @@ + + + \ No newline at end of file diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index 518aa69a4c..08918a667b 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -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/