Commit 0249ca9929141c8520e67065b3573aa26fdcf7c0
1 parent
4f59ebf4
[功能添加]:物模型日志表创建.1
Showing
8 changed files
with
115 additions
and
16 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceDataController.java
| @@ -55,7 +55,7 @@ public class IotDeviceDataController { | @@ -55,7 +55,7 @@ public class IotDeviceDataController { | ||
| 55 | @PostMapping("/simulator") | 55 | @PostMapping("/simulator") |
| 56 | @Operation(summary = "模拟设备") | 56 | @Operation(summary = "模拟设备") |
| 57 | public CommonResult<Boolean> simulatorDevice(@Valid @RequestBody IotDeviceDataSimulatorSaveReqVO simulatorReqVO) { | 57 | public CommonResult<Boolean> simulatorDevice(@Valid @RequestBody IotDeviceDataSimulatorSaveReqVO simulatorReqVO) { |
| 58 | - //TODO:先生成一下日志 后续完善模拟设备代码逻辑 | 58 | + //TODO:先生成一下设备日志 后续完善模拟设备代码逻辑 |
| 59 | iotDeviceLogDataService.createDeviceLog(simulatorReqVO); | 59 | iotDeviceLogDataService.createDeviceLog(simulatorReqVO); |
| 60 | return success(true); | 60 | return success(true); |
| 61 | } | 61 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/deviceData/IotDeviceDataSimulatorSaveReqVO.java
| @@ -4,7 +4,6 @@ import io.swagger.v3.oas.annotations.media.Schema; | @@ -4,7 +4,6 @@ import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | import jakarta.validation.constraints.NotEmpty; | 4 | import jakarta.validation.constraints.NotEmpty; |
| 5 | import lombok.Data; | 5 | import lombok.Data; |
| 6 | 6 | ||
| 7 | - | ||
| 8 | import java.time.LocalDateTime; | 7 | import java.time.LocalDateTime; |
| 9 | 8 | ||
| 10 | @Schema(description = "管理后台 - IoT 模拟设备数据 Request VO") | 9 | @Schema(description = "管理后台 - IoT 模拟设备数据 Request VO") |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceLogDO.java
| @@ -51,12 +51,12 @@ public class IotDeviceLogDO { | @@ -51,12 +51,12 @@ public class IotDeviceLogDO { | ||
| 51 | /** | 51 | /** |
| 52 | * 上报时间戳 | 52 | * 上报时间戳 |
| 53 | */ | 53 | */ |
| 54 | - private DateTime reportTime; | 54 | + private Long reportTime; |
| 55 | 55 | ||
| 56 | /** | 56 | /** |
| 57 | * 时序时间 | 57 | * 时序时间 |
| 58 | */ | 58 | */ |
| 59 | - private DateTime ts; | 59 | + private Long ts; |
| 60 | 60 | ||
| 61 | 61 | ||
| 62 | } | 62 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceLogDataMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.dal.tdengine; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; | ||
| 4 | +import cn.iocoder.yudao.module.iot.framework.tdengine.core.annotation.TDengineDS; | ||
| 5 | +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; | ||
| 6 | +import org.apache.ibatis.annotations.Mapper; | ||
| 7 | +import org.apache.ibatis.annotations.Param; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * IOT 设备日志数据 Mapper 接口 | ||
| 11 | + * | ||
| 12 | + * 基于 TDengine 实现设备日志的存储 | ||
| 13 | + */ | ||
| 14 | +@Mapper | ||
| 15 | +@TDengineDS | ||
| 16 | +@InterceptorIgnore(tenantLine = "true") // 避免 SQL 解析,因为 JSqlParser 对 TDengine 的 SQL 解析会报错 | ||
| 17 | +public interface IotDeviceLogDataMapper { | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * 创建设备日志超级表 | ||
| 21 | + * | ||
| 22 | + * 注意:初始化时只需创建一次 | ||
| 23 | + */ | ||
| 24 | + void createDeviceLogSTable(); | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 插入设备日志数据 | ||
| 31 | + * | ||
| 32 | + * 如果子表不存在,会自动创建子表 | ||
| 33 | + * | ||
| 34 | + * @param log 设备日志数据 | ||
| 35 | + */ | ||
| 36 | + void insert(@Param("log") IotDeviceLogDO log); | ||
| 37 | +} |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.service.device; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataSimulatorSaveReqVO; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * IoT 设备日志数据 Service 接口 | ||
| 7 | + * | ||
| 8 | + * @author alwayssuper | ||
| 9 | + */ | ||
| 10 | +public interface IotDeviceLogDataService { | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * 初始化 TDengine 超级表 | ||
| 14 | + * | ||
| 15 | + *系统启动时,会自动初始化一次 | ||
| 16 | + */ | ||
| 17 | + void initTDengineSTable(); | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * 插入设备日志 | ||
| 21 | + * | ||
| 22 | + * 当该设备第一次插入日志时,自动创建该设备的设备日志子表 | ||
| 23 | + * | ||
| 24 | + * @param simulatorReqVO 设备日志模拟数据 | ||
| 25 | + */ | ||
| 26 | + void createDeviceLog(IotDeviceDataSimulatorSaveReqVO simulatorReqVO); | ||
| 27 | + | ||
| 28 | +} |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataServiceImpl.java
| @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; | @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; | ||
| 11 | import org.springframework.validation.annotation.Validated; | 11 | import org.springframework.validation.annotation.Validated; |
| 12 | 12 | ||
| 13 | import java.time.LocalDateTime; | 13 | import java.time.LocalDateTime; |
| 14 | +import java.time.ZoneId; | ||
| 14 | 15 | ||
| 15 | /** | 16 | /** |
| 16 | * IoT 设备日志数据 Service 实现了 | 17 | * IoT 设备日志数据 Service 实现了 |
| @@ -19,6 +20,7 @@ import java.time.LocalDateTime; | @@ -19,6 +20,7 @@ import java.time.LocalDateTime; | ||
| 19 | */ | 20 | */ |
| 20 | @Service | 21 | @Service |
| 21 | @Slf4j | 22 | @Slf4j |
| 23 | +@Validated | ||
| 22 | public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{ | 24 | public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{ |
| 23 | 25 | ||
| 24 | @Resource | 26 | @Resource |
| @@ -38,8 +40,28 @@ public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{ | @@ -38,8 +40,28 @@ public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{ | ||
| 38 | 40 | ||
| 39 | @Override | 41 | @Override |
| 40 | public void createDeviceLog(IotDeviceDataSimulatorSaveReqVO simulatorReqVO) { | 42 | public void createDeviceLog(IotDeviceDataSimulatorSaveReqVO simulatorReqVO) { |
| 43 | + //TODO:讨论一下,iotkit这块TS和上报时间都是外部传入的 但是看TDengine文档 他是建议对TS在SQL中直接NOW 咱们的TS数据获取是走哪一种 | ||
| 44 | + | ||
| 45 | + // 1. 转换请求对象为 DO | ||
| 41 | IotDeviceLogDO iotDeviceLogDO = BeanUtils.toBean(simulatorReqVO, IotDeviceLogDO.class); | 46 | IotDeviceLogDO iotDeviceLogDO = BeanUtils.toBean(simulatorReqVO, IotDeviceLogDO.class); |
| 42 | - iotDeviceLogDO.setTs(DateTime.now()); | 47 | + |
| 48 | + // 2. 处理时间字段 | ||
| 49 | + long currentTime = System.currentTimeMillis(); | ||
| 50 | + // 2.1 设置时序时间为当前时间 | ||
| 51 | + iotDeviceLogDO.setTs(currentTime); | ||
| 52 | + | ||
| 53 | + // 2.2 处理上报时间 | ||
| 54 | + if (simulatorReqVO.getReportTime() != null) { | ||
| 55 | + // 将 LocalDateTime 转换为时间戳 | ||
| 56 | + iotDeviceLogDO.setReportTime( | ||
| 57 | + simulatorReqVO.getReportTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() | ||
| 58 | + ); | ||
| 59 | + } else { | ||
| 60 | + // 如果没有上报时间,使用当前时间 | ||
| 61 | + iotDeviceLogDO.setReportTime(currentTime); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + // 3. 插入数据 | ||
| 43 | iotDeviceLogDataMapper.insert(iotDeviceLogDO); | 65 | iotDeviceLogDataMapper.insert(iotDeviceLogDO); |
| 44 | } | 66 | } |
| 45 | } | 67 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceLogDataMapper.xml
| @@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
| 6 | 6 | ||
| 7 | <!-- 创建设备日志超级表 初始化只创建一次--> | 7 | <!-- 创建设备日志超级表 初始化只创建一次--> |
| 8 | <update id="createDeviceLogSTable"> | 8 | <update id="createDeviceLogSTable"> |
| 9 | - CREATE STABLE device_log( | 9 | + CREATE STABLE 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), |
yudao-server/src/main/resources/application-local.yaml
| @@ -45,7 +45,7 @@ spring: | @@ -45,7 +45,7 @@ spring: | ||
| 45 | primary: master | 45 | primary: master |
| 46 | datasource: | 46 | datasource: |
| 47 | master: | 47 | master: |
| 48 | - url: jdbc:mysql://127.0.0.1:3307/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 | 48 | + url: jdbc:mysql://chaojiniu.top:23306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 |
| 49 | # url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=true&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai # MySQL Connector/J 5.X 连接的示例 | 49 | # url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=true&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai # MySQL Connector/J 5.X 连接的示例 |
| 50 | # url: jdbc:postgresql://127.0.0.1:5432/ruoyi-vue-pro # PostgreSQL 连接的示例 | 50 | # url: jdbc:postgresql://127.0.0.1:5432/ruoyi-vue-pro # PostgreSQL 连接的示例 |
| 51 | # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 | 51 | # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 |
| @@ -53,8 +53,8 @@ spring: | @@ -53,8 +53,8 @@ spring: | ||
| 53 | # url: jdbc:dm://127.0.0.1:5236?schema=RUOYI_VUE_PRO # DM 连接的示例 | 53 | # url: jdbc:dm://127.0.0.1:5236?schema=RUOYI_VUE_PRO # DM 连接的示例 |
| 54 | # url: jdbc:kingbase8://127.0.0.1:54321/test # 人大金仓 KingbaseES 连接的示例 | 54 | # url: jdbc:kingbase8://127.0.0.1:54321/test # 人大金仓 KingbaseES 连接的示例 |
| 55 | # url: jdbc:postgresql://127.0.0.1:5432/postgres # OpenGauss 连接的示例 | 55 | # url: jdbc:postgresql://127.0.0.1:5432/postgres # OpenGauss 连接的示例 |
| 56 | - username: root | ||
| 57 | - password: ahh@123456 | 56 | + username: ruoyi-vue-pro |
| 57 | + password: ruoyi-@h2ju02hebp | ||
| 58 | # username: sa # SQL Server 连接的示例 | 58 | # username: sa # SQL Server 连接的示例 |
| 59 | # password: Yudao@2024 # SQL Server 连接的示例 | 59 | # password: Yudao@2024 # SQL Server 连接的示例 |
| 60 | # username: SYSDBA # DM 连接的示例 | 60 | # username: SYSDBA # DM 连接的示例 |
| @@ -63,17 +63,25 @@ spring: | @@ -63,17 +63,25 @@ spring: | ||
| 63 | # password: Yudao@2024 # OpenGauss 连接的示例 | 63 | # password: Yudao@2024 # OpenGauss 连接的示例 |
| 64 | slave: # 模拟从库,可根据自己需要修改 | 64 | slave: # 模拟从库,可根据自己需要修改 |
| 65 | lazy: true # 开启懒加载,保证启动速度 | 65 | lazy: true # 开启懒加载,保证启动速度 |
| 66 | - url: jdbc:mysql://127.0.0.1:3307/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true | 66 | + url: jdbc:mysql://chaojiniu.top:23306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true |
| 67 | + username: ruoyi-vue-pro | ||
| 68 | + password: ruoyi-@h2ju02hebp | ||
| 69 | + tdengine: # IOT 数据库 | ||
| 70 | +# lazy: true # 开启懒加载,保证启动速度 | ||
| 71 | + url: jdbc:TAOS-RS://chaojiniu.top:6041/ruoyi_vue_pro | ||
| 72 | + driver-class-name: com.taosdata.jdbc.rs.RestfulDriver | ||
| 67 | username: root | 73 | username: root |
| 68 | - password: ahh@123456 | 74 | + password: taosdata |
| 75 | + druid: | ||
| 76 | + validation-query: SELECT SERVER_STATUS() # TDengine 数据源的有效性检查 SQL | ||
| 69 | 77 | ||
| 70 | # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 | 78 | # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 |
| 71 | data: | 79 | data: |
| 72 | redis: | 80 | redis: |
| 73 | - host: 127.0.0.1 # 地址 | 81 | + host: chaojiniu.top # 地址 |
| 74 | port: 6379 # 端口 | 82 | port: 6379 # 端口 |
| 75 | - database: 0 # 数据库索引 | ||
| 76 | -# password: dev # 密码,建议生产环境开启 | 83 | + database: 15 # 数据库索引 |
| 84 | + password: fsknKD7UvQYZsyf2hXXn # 密码,建议生产环境开启 | ||
| 77 | 85 | ||
| 78 | --- #################### 定时任务相关配置 #################### | 86 | --- #################### 定时任务相关配置 #################### |
| 79 | 87 | ||
| @@ -175,8 +183,10 @@ logging: | @@ -175,8 +183,10 @@ logging: | ||
| 175 | cn.iocoder.yudao.module.crm.dal.mysql: debug | 183 | cn.iocoder.yudao.module.crm.dal.mysql: debug |
| 176 | cn.iocoder.yudao.module.erp.dal.mysql: debug | 184 | cn.iocoder.yudao.module.erp.dal.mysql: debug |
| 177 | cn.iocoder.yudao.module.iot.dal.mysql: debug | 185 | cn.iocoder.yudao.module.iot.dal.mysql: debug |
| 186 | + cn.iocoder.yudao.module.iot.dal.tdengine: DEBUG | ||
| 178 | cn.iocoder.yudao.module.ai.dal.mysql: debug | 187 | cn.iocoder.yudao.module.ai.dal.mysql: debug |
| 179 | org.springframework.context.support.PostProcessorRegistrationDelegate: ERROR # TODO 芋艿:先禁用,Spring Boot 3.X 存在部分错误的 WARN 提示 | 188 | org.springframework.context.support.PostProcessorRegistrationDelegate: ERROR # TODO 芋艿:先禁用,Spring Boot 3.X 存在部分错误的 WARN 提示 |
| 189 | + com.taosdata: DEBUG # TDengine 的日志级别 | ||
| 180 | 190 | ||
| 181 | debug: false | 191 | debug: false |
| 182 | 192 | ||
| @@ -259,7 +269,7 @@ justauth: | @@ -259,7 +269,7 @@ justauth: | ||
| 259 | iot: | 269 | iot: |
| 260 | emq: | 270 | emq: |
| 261 | # 账号 | 271 | # 账号 |
| 262 | - username: anhaohao | 272 | + username: haohao |
| 263 | # 密码 | 273 | # 密码 |
| 264 | password: ahh@123456 | 274 | password: ahh@123456 |
| 265 | # 主机地址 | 275 | # 主机地址 |
| @@ -271,4 +281,7 @@ iot: | @@ -271,4 +281,7 @@ iot: | ||
| 271 | # 保持连接 | 281 | # 保持连接 |
| 272 | keepalive: 60 | 282 | keepalive: 60 |
| 273 | # 清除会话(设置为false,断开连接,重连后使用原来的会话 保留订阅的主题,能接收离线期间的消息) | 283 | # 清除会话(设置为false,断开连接,重连后使用原来的会话 保留订阅的主题,能接收离线期间的消息) |
| 274 | - clearSession: true | ||
| 275 | \ No newline at end of file | 284 | \ No newline at end of file |
| 285 | + clearSession: true | ||
| 286 | + | ||
| 287 | +pf4j: | ||
| 288 | + pluginsDir: /Users/anhaohao/code/gitee/ruoyi-vue-pro/plugins | ||
| 276 | \ No newline at end of file | 289 | \ No newline at end of file |