Commit 62a868f497874f5d755ec1bff4b74a08c8bb05a5
1 parent
f1d887d0
feat:simulator1
Showing
7 changed files
with
40 additions
and
74 deletions
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 { | @@ -21,32 +21,10 @@ public interface IotDeviceLogDataMapper { | ||
| 21 | 21 | ||
| 22 | /** | 22 | /** |
| 23 | * 创建设备日志超级表 | 23 | * 创建设备日志超级表 |
| 24 | -<<<<<<< HEAD | ||
| 25 | * 初始化只创建一次 | 24 | * 初始化只创建一次 |
| 26 | */ | 25 | */ |
| 27 | void createDeviceLogSTable(); | 26 | void createDeviceLogSTable(); |
| 28 | 27 | ||
| 29 | -======= | ||
| 30 | - * | ||
| 31 | - * 注意:初始化时只需创建一次 | ||
| 32 | - */ | ||
| 33 | - void createDeviceLogSTable(); | ||
| 34 | - | ||
| 35 | - // TODO @super:是不是删除哈 | ||
| 36 | ->>>>>>> deab8c1cc6bb7864d9c40e0c369f649f6f9bfa41 | ||
| 37 | - /** | ||
| 38 | - * 创建设备日志子表 | ||
| 39 | - * | ||
| 40 | - * @param deviceKey 设备标识 | ||
| 41 | - */ | ||
| 42 | -<<<<<<< HEAD | ||
| 43 | - void createDeviceLogTable( @Param("deviceKey") String deviceKey); | ||
| 44 | - | ||
| 45 | - /** | ||
| 46 | - * 插入设备日志数据 | ||
| 47 | - * | ||
| 48 | -======= | ||
| 49 | - void createDeviceLogTable(@Param("deviceKey") String deviceKey); | ||
| 50 | 28 | ||
| 51 | // TODO @super:单个参数,不用加 @Param | 29 | // TODO @super:单个参数,不用加 @Param |
| 52 | /** | 30 | /** |
| @@ -54,10 +32,9 @@ public interface IotDeviceLogDataMapper { | @@ -54,10 +32,9 @@ public interface IotDeviceLogDataMapper { | ||
| 54 | * | 32 | * |
| 55 | * 如果子表不存在,会自动创建子表 | 33 | * 如果子表不存在,会自动创建子表 |
| 56 | * | 34 | * |
| 57 | ->>>>>>> deab8c1cc6bb7864d9c40e0c369f649f6f9bfa41 | ||
| 58 | * @param log 设备日志数据 | 35 | * @param log 设备日志数据 |
| 59 | */ | 36 | */ |
| 60 | - void insert(@Param("log") IotDeviceLogDO log); | 37 | + void insert(IotDeviceLogDO log); |
| 61 | 38 | ||
| 62 | /** | 39 | /** |
| 63 | * 获得设备日志分页 | 40 | * 获得设备日志分页 |
| @@ -65,7 +42,7 @@ public interface IotDeviceLogDataMapper { | @@ -65,7 +42,7 @@ public interface IotDeviceLogDataMapper { | ||
| 65 | * @param reqVO 分页查询条件 | 42 | * @param reqVO 分页查询条件 |
| 66 | * @return 设备日志列表 | 43 | * @return 设备日志列表 |
| 67 | */ | 44 | */ |
| 68 | - List<IotDeviceLogDO> selectPage(@Param("reqVO") IotDeviceLogPageReqVO reqVO); | 45 | + List<IotDeviceLogDO> selectPage(IotDeviceLogPageReqVO reqVO); |
| 69 | 46 | ||
| 70 | /** | 47 | /** |
| 71 | * 获得设备日志总数 | 48 | * 获得设备日志总数 |
| @@ -73,6 +50,11 @@ public interface IotDeviceLogDataMapper { | @@ -73,6 +50,11 @@ public interface IotDeviceLogDataMapper { | ||
| 73 | * @param reqVO 查询条件 | 50 | * @param reqVO 查询条件 |
| 74 | * @return 日志总数 | 51 | * @return 日志总数 |
| 75 | */ | 52 | */ |
| 76 | - Long selectCount(@Param("reqVO") IotDeviceLogPageReqVO reqVO); | 53 | + Long selectCount(IotDeviceLogPageReqVO reqVO); |
| 77 | 54 | ||
| 55 | + /** | ||
| 56 | + * 查询设备日志表是否存在 | ||
| 57 | + * | ||
| 58 | + */ | ||
| 59 | + Object checkDeviceLogTableExists(); | ||
| 78 | } | 60 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/TdThingModelMessageMapper.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.dal.tdengine; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.module.iot.framework.tdengine.core.annotation.TDengineDS; | ||
| 4 | -import com.baomidou.mybatisplus.annotation.InterceptorIgnore; | ||
| 5 | -import org.apache.ibatis.annotations.Mapper; | ||
| 6 | -import org.apache.ibatis.annotations.Param; | ||
| 7 | - | ||
| 8 | -/** | ||
| 9 | - * 处理 TD 中物模型消息日志的操作 | ||
| 10 | - */ | ||
| 11 | -@Mapper | ||
| 12 | -@Deprecated // TODO super:什么时候,删除下哈。 | ||
| 13 | -@TDengineDS | ||
| 14 | -@InterceptorIgnore(tenantLine = "true") // 避免 SQL 解析,因为 JSqlParser 对 TDengine 的 SQL 解析会报错 | ||
| 15 | -public interface TdThingModelMessageMapper { | ||
| 16 | - | ||
| 17 | - /** | ||
| 18 | - * 创建物模型消息日志超级表超级表 | ||
| 19 | - * | ||
| 20 | - */ | ||
| 21 | - | ||
| 22 | - void createSuperTable(@Param("productKey") String productKey); | ||
| 23 | - | ||
| 24 | - /** | ||
| 25 | - * 创建子表 | ||
| 26 | - * | ||
| 27 | - */ | ||
| 28 | - | ||
| 29 | - void createTableWithTag(@Param("productKey") String productKey,@Param("deviceKey") String deviceKey); | ||
| 30 | - | ||
| 31 | -} |
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 { | @@ -25,18 +25,13 @@ public class TDengineTableInitConfiguration implements ApplicationRunner { | ||
| 25 | public void run(ApplicationArguments args) { | 25 | public void run(ApplicationArguments args) { |
| 26 | try { | 26 | try { |
| 27 | // 初始化设备日志表 | 27 | // 初始化设备日志表 |
| 28 | - deviceLogService.initTDengineSTable(); | 28 | + deviceLogService.defineDeviceLog(); |
| 29 | // TODO @super:这个日志,是不是不用打,不然重复啦!!! | 29 | // TODO @super:这个日志,是不是不用打,不然重复啦!!! |
| 30 | - log.info("[run]初始化 设备日志表 TDengine 表结构成功"); | ||
| 31 | } catch (Exception ex) { | 30 | } catch (Exception ex) { |
| 32 | // TODO @super:初始化失败,打印 error 日志,退出系统。。不然跑起来,就初始啦!!! | 31 | // TODO @super:初始化失败,打印 error 日志,退出系统。。不然跑起来,就初始啦!!! |
| 33 | - if (ex.getMessage().contains("Table already exists")) { | ||
| 34 | - log.info("TDengine 设备日志超级表已存在,跳过创建"); | ||
| 35 | - return; | ||
| 36 | - } else{ | ||
| 37 | - log.error("初始化 设备日志表 TDengine 表结构失败", ex); | ||
| 38 | - } | ||
| 39 | - throw ex; | 32 | + // 初始化失败时打印错误日志并退出系统 |
| 33 | + log.error("[TDengine] 初始化设备日志表结构失败,系统无法正常运行,即将退出", ex); | ||
| 34 | + System.exit(1); | ||
| 40 | } | 35 | } |
| 41 | } | 36 | } |
| 42 | 37 |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataService.java
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{ | @@ -28,9 +28,24 @@ public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{ | ||
| 28 | 28 | ||
| 29 | // TODO @super:方法名。defineDeviceLog。。未来,有可能别人使用别的记录日志,例如说 es 之类的。 | 29 | // TODO @super:方法名。defineDeviceLog。。未来,有可能别人使用别的记录日志,例如说 es 之类的。 |
| 30 | @Override | 30 | @Override |
| 31 | - public void initTDengineSTable() { | 31 | + public void defineDeviceLog() { |
| 32 | // TODO @super:改成不存在才创建。 | 32 | // TODO @super:改成不存在才创建。 |
| 33 | - iotDeviceLogDataMapper.createDeviceLogSTable(); | 33 | +// try { |
| 34 | +// // 创建超级表(使用 IF NOT EXISTS 语句避免重复创建错误) | ||
| 35 | +// iotDeviceLogDataMapper.createDeviceLogSTable(); | ||
| 36 | +// } catch (Exception e) { | ||
| 37 | +// if (e.getMessage().contains("already exists")) { | ||
| 38 | +// log.info("[TDengine] 设备日志超级表已存在,跳过创建"); | ||
| 39 | +// return; | ||
| 40 | +// } | ||
| 41 | +// throw e; | ||
| 42 | +// } | ||
| 43 | + if(iotDeviceLogDataMapper.checkDeviceLogTableExists()==null){ | ||
| 44 | + log.info("[TDengine] 设备日志超级表不存在,开始创建 {}",iotDeviceLogDataMapper.checkDeviceLogTableExists()); | ||
| 45 | + iotDeviceLogDataMapper.createDeviceLogSTable(); | ||
| 46 | + }else{ | ||
| 47 | + log.info("[TDengine] 设备日志超级表已存在,跳过创建"); | ||
| 48 | + } | ||
| 34 | } | 49 | } |
| 35 | 50 | ||
| 36 | @Override | 51 | @Override |
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceLogDataMapper.xml
| @@ -6,13 +6,13 @@ | @@ -6,13 +6,13 @@ | ||
| 6 | 6 | ||
| 7 | <!-- 创建设备日志超级表 初始化只创建一次--> | 7 | <!-- 创建设备日志超级表 初始化只创建一次--> |
| 8 | <update id="createDeviceLogSTable"> | 8 | <update id="createDeviceLogSTable"> |
| 9 | - CREATE STABLE device_log ( | 9 | + CREATE STABLE IF NOT EXISTS device_log ( |
| 10 | ts TIMESTAMP, | 10 | ts TIMESTAMP, |
| 11 | id NCHAR(50), | 11 | id NCHAR(50), |
| 12 | product_key NCHAR(50), | 12 | product_key NCHAR(50), |
| 13 | type NCHAR(50), | 13 | type NCHAR(50), |
| 14 | <!-- TODO @super:下划线 sub_type --> | 14 | <!-- TODO @super:下划线 sub_type --> |
| 15 | - subType NCHAR(50), | 15 | + sub_type NCHAR(50), |
| 16 | content NCHAR(1024), | 16 | content NCHAR(1024), |
| 17 | report_time TIMESTAMP | 17 | report_time TIMESTAMP |
| 18 | ) TAGS ( | 18 | ) TAGS ( |
| @@ -75,4 +75,9 @@ | @@ -75,4 +75,9 @@ | ||
| 75 | </where> | 75 | </where> |
| 76 | </select> | 76 | </select> |
| 77 | 77 | ||
| 78 | + <!-- 检查设备日志超级表是否存在 --> | ||
| 79 | + <select id="checkDeviceLogTableExists" resultType="Object"> | ||
| 80 | + SHOW TABLES LIKE 'device_log'; | ||
| 81 | + </select> | ||
| 82 | + | ||
| 78 | </mapper> | 83 | </mapper> |
| 79 | \ No newline at end of file | 84 | \ No newline at end of file |
yudao-server/src/main/resources/application-local.yaml
| @@ -283,9 +283,9 @@ iot: | @@ -283,9 +283,9 @@ iot: | ||
| 283 | 283 | ||
| 284 | # MQTT-RPC 配置 | 284 | # MQTT-RPC 配置 |
| 285 | mqtt: | 285 | mqtt: |
| 286 | - broker: tcp://127.0.0.1:1883 | ||
| 287 | - username: root | ||
| 288 | - password: 123456 | 286 | + broker: tcp://chaojiniu.top:1883 |
| 287 | + username: haohao | ||
| 288 | + password: ahh@123456 | ||
| 289 | clientId: mqtt-rpc-server-${random.int} | 289 | clientId: mqtt-rpc-server-${random.int} |
| 290 | requestTopic: rpc/request | 290 | requestTopic: rpc/request |
| 291 | responseTopicPrefix: rpc/response/ | 291 | responseTopicPrefix: rpc/response/ |