瀏覽代碼

feat:simulator1

alwayssuper 7 月之前
父節點
當前提交
62a868f497

+ 8 - 26
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<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();
 }

+ 0 - 31
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/TdThingModelMessageMapper.java

@@ -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);
-
-}

+ 4 - 9
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);
         }
     }
 

+ 1 - 1
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();
 
     /**
      * 插入设备日志

+ 17 - 2
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

+ 7 - 2
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceLogDataMapper.xml

@@ -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>

+ 3 - 3
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/