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 | 55 | @PostMapping("/simulator") |
| 56 | 56 | @Operation(summary = "模拟设备") |
| 57 | 57 | public CommonResult<Boolean> simulatorDevice(@Valid @RequestBody IotDeviceDataSimulatorSaveReqVO simulatorReqVO) { |
| 58 | - //TODO:先生成一下日志 后续完善模拟设备代码逻辑 | |
| 58 | + //TODO:先生成一下设备日志 后续完善模拟设备代码逻辑 | |
| 59 | 59 | iotDeviceLogDataService.createDeviceLog(simulatorReqVO); |
| 60 | 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
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceLogDO.java
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 | 11 | import org.springframework.validation.annotation.Validated; |
| 12 | 12 | |
| 13 | 13 | import java.time.LocalDateTime; |
| 14 | +import java.time.ZoneId; | |
| 14 | 15 | |
| 15 | 16 | /** |
| 16 | 17 | * IoT 设备日志数据 Service 实现了 |
| ... | ... | @@ -19,6 +20,7 @@ import java.time.LocalDateTime; |
| 19 | 20 | */ |
| 20 | 21 | @Service |
| 21 | 22 | @Slf4j |
| 23 | +@Validated | |
| 22 | 24 | public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{ |
| 23 | 25 | |
| 24 | 26 | @Resource |
| ... | ... | @@ -38,8 +40,28 @@ public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{ |
| 38 | 40 | |
| 39 | 41 | @Override |
| 40 | 42 | public void createDeviceLog(IotDeviceDataSimulatorSaveReqVO simulatorReqVO) { |
| 43 | + //TODO:讨论一下,iotkit这块TS和上报时间都是外部传入的 但是看TDengine文档 他是建议对TS在SQL中直接NOW 咱们的TS数据获取是走哪一种 | |
| 44 | + | |
| 45 | + // 1. 转换请求对象为 DO | |
| 41 | 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 | 65 | iotDeviceLogDataMapper.insert(iotDeviceLogDO); |
| 44 | 66 | } |
| 45 | 67 | } | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceLogDataMapper.xml
yudao-server/src/main/resources/application-local.yaml
| ... | ... | @@ -45,7 +45,7 @@ spring: |
| 45 | 45 | primary: master |
| 46 | 46 | datasource: |
| 47 | 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 | 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 | 50 | # url: jdbc:postgresql://127.0.0.1:5432/ruoyi-vue-pro # PostgreSQL 连接的示例 |
| 51 | 51 | # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 |
| ... | ... | @@ -53,8 +53,8 @@ spring: |
| 53 | 53 | # url: jdbc:dm://127.0.0.1:5236?schema=RUOYI_VUE_PRO # DM 连接的示例 |
| 54 | 54 | # url: jdbc:kingbase8://127.0.0.1:54321/test # 人大金仓 KingbaseES 连接的示例 |
| 55 | 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 | 58 | # username: sa # SQL Server 连接的示例 |
| 59 | 59 | # password: Yudao@2024 # SQL Server 连接的示例 |
| 60 | 60 | # username: SYSDBA # DM 连接的示例 |
| ... | ... | @@ -63,17 +63,25 @@ spring: |
| 63 | 63 | # password: Yudao@2024 # OpenGauss 连接的示例 |
| 64 | 64 | slave: # 模拟从库,可根据自己需要修改 |
| 65 | 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 | 73 | username: root |
| 68 | - password: ahh@123456 | |
| 74 | + password: taosdata | |
| 75 | + druid: | |
| 76 | + validation-query: SELECT SERVER_STATUS() # TDengine 数据源的有效性检查 SQL | |
| 69 | 77 | |
| 70 | 78 | # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 |
| 71 | 79 | data: |
| 72 | 80 | redis: |
| 73 | - host: 127.0.0.1 # 地址 | |
| 81 | + host: chaojiniu.top # 地址 | |
| 74 | 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 | 183 | cn.iocoder.yudao.module.crm.dal.mysql: debug |
| 176 | 184 | cn.iocoder.yudao.module.erp.dal.mysql: debug |
| 177 | 185 | cn.iocoder.yudao.module.iot.dal.mysql: debug |
| 186 | + cn.iocoder.yudao.module.iot.dal.tdengine: DEBUG | |
| 178 | 187 | cn.iocoder.yudao.module.ai.dal.mysql: debug |
| 179 | 188 | org.springframework.context.support.PostProcessorRegistrationDelegate: ERROR # TODO 芋艿:先禁用,Spring Boot 3.X 存在部分错误的 WARN 提示 |
| 189 | + com.taosdata: DEBUG # TDengine 的日志级别 | |
| 180 | 190 | |
| 181 | 191 | debug: false |
| 182 | 192 | |
| ... | ... | @@ -259,7 +269,7 @@ justauth: |
| 259 | 269 | iot: |
| 260 | 270 | emq: |
| 261 | 271 | # 账号 |
| 262 | - username: anhaohao | |
| 272 | + username: haohao | |
| 263 | 273 | # 密码 |
| 264 | 274 | password: ahh@123456 |
| 265 | 275 | # 主机地址 |
| ... | ... | @@ -271,4 +281,7 @@ iot: |
| 271 | 281 | # 保持连接 |
| 272 | 282 | keepalive: 60 |
| 273 | 283 | # 清除会话(设置为false,断开连接,重连后使用原来的会话 保留订阅的主题,能接收离线期间的消息) |
| 274 | - clearSession: true | |
| 275 | 284 | \ No newline at end of file |
| 285 | + clearSession: true | |
| 286 | + | |
| 287 | +pf4j: | |
| 288 | + pluginsDir: /Users/anhaohao/code/gitee/ruoyi-vue-pro/plugins | |
| 276 | 289 | \ No newline at end of file | ... | ... |