[功能添加]:物模型日志表创建.1
This commit is contained in:
parent
4f59ebf462
commit
0249ca9929
|
@ -55,7 +55,7 @@ public class IotDeviceDataController {
|
||||||
@PostMapping("/simulator")
|
@PostMapping("/simulator")
|
||||||
@Operation(summary = "模拟设备")
|
@Operation(summary = "模拟设备")
|
||||||
public CommonResult<Boolean> simulatorDevice(@Valid @RequestBody IotDeviceDataSimulatorSaveReqVO simulatorReqVO) {
|
public CommonResult<Boolean> simulatorDevice(@Valid @RequestBody IotDeviceDataSimulatorSaveReqVO simulatorReqVO) {
|
||||||
//TODO:先生成一下日志 后续完善模拟设备代码逻辑
|
//TODO:先生成一下设备日志 后续完善模拟设备代码逻辑
|
||||||
iotDeviceLogDataService.createDeviceLog(simulatorReqVO);
|
iotDeviceLogDataService.createDeviceLog(simulatorReqVO);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Schema(description = "管理后台 - IoT 模拟设备数据 Request VO")
|
@Schema(description = "管理后台 - IoT 模拟设备数据 Request VO")
|
||||||
|
|
|
@ -51,12 +51,12 @@ public class IotDeviceLogDO {
|
||||||
/**
|
/**
|
||||||
* 上报时间戳
|
* 上报时间戳
|
||||||
*/
|
*/
|
||||||
private DateTime reportTime;
|
private Long reportTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 时序时间
|
* 时序时间
|
||||||
*/
|
*/
|
||||||
private DateTime ts;
|
private Long ts;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package cn.iocoder.yudao.module.iot.dal.tdengine;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IOT 设备日志数据 Mapper 接口
|
||||||
|
*
|
||||||
|
* 基于 TDengine 实现设备日志的存储
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
@TDengineDS
|
||||||
|
@InterceptorIgnore(tenantLine = "true") // 避免 SQL 解析,因为 JSqlParser 对 TDengine 的 SQL 解析会报错
|
||||||
|
public interface IotDeviceLogDataMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建设备日志超级表
|
||||||
|
*
|
||||||
|
* 注意:初始化时只需创建一次
|
||||||
|
*/
|
||||||
|
void createDeviceLogSTable();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插入设备日志数据
|
||||||
|
*
|
||||||
|
* 如果子表不存在,会自动创建子表
|
||||||
|
*
|
||||||
|
* @param log 设备日志数据
|
||||||
|
*/
|
||||||
|
void insert(@Param("log") IotDeviceLogDO log);
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package cn.iocoder.yudao.module.iot.service.device;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataSimulatorSaveReqVO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IoT 设备日志数据 Service 接口
|
||||||
|
*
|
||||||
|
* @author alwayssuper
|
||||||
|
*/
|
||||||
|
public interface IotDeviceLogDataService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化 TDengine 超级表
|
||||||
|
*
|
||||||
|
*系统启动时,会自动初始化一次
|
||||||
|
*/
|
||||||
|
void initTDengineSTable();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插入设备日志
|
||||||
|
*
|
||||||
|
* 当该设备第一次插入日志时,自动创建该设备的设备日志子表
|
||||||
|
*
|
||||||
|
* @param simulatorReqVO 设备日志模拟数据
|
||||||
|
*/
|
||||||
|
void createDeviceLog(IotDeviceDataSimulatorSaveReqVO simulatorReqVO);
|
||||||
|
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IoT 设备日志数据 Service 实现了
|
* IoT 设备日志数据 Service 实现了
|
||||||
|
@ -19,6 +20,7 @@ import java.time.LocalDateTime;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Validated
|
||||||
public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{
|
public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
|
@ -38,8 +40,28 @@ public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createDeviceLog(IotDeviceDataSimulatorSaveReqVO simulatorReqVO) {
|
public void createDeviceLog(IotDeviceDataSimulatorSaveReqVO simulatorReqVO) {
|
||||||
|
//TODO:讨论一下,iotkit这块TS和上报时间都是外部传入的 但是看TDengine文档 他是建议对TS在SQL中直接NOW 咱们的TS数据获取是走哪一种
|
||||||
|
|
||||||
|
// 1. 转换请求对象为 DO
|
||||||
IotDeviceLogDO iotDeviceLogDO = BeanUtils.toBean(simulatorReqVO, IotDeviceLogDO.class);
|
IotDeviceLogDO iotDeviceLogDO = BeanUtils.toBean(simulatorReqVO, IotDeviceLogDO.class);
|
||||||
iotDeviceLogDO.setTs(DateTime.now());
|
|
||||||
|
// 2. 处理时间字段
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
// 2.1 设置时序时间为当前时间
|
||||||
|
iotDeviceLogDO.setTs(currentTime);
|
||||||
|
|
||||||
|
// 2.2 处理上报时间
|
||||||
|
if (simulatorReqVO.getReportTime() != null) {
|
||||||
|
// 将 LocalDateTime 转换为时间戳
|
||||||
|
iotDeviceLogDO.setReportTime(
|
||||||
|
simulatorReqVO.getReportTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// 如果没有上报时间,使用当前时间
|
||||||
|
iotDeviceLogDO.setReportTime(currentTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 插入数据
|
||||||
iotDeviceLogDataMapper.insert(iotDeviceLogDO);
|
iotDeviceLogDataMapper.insert(iotDeviceLogDO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<!-- 创建设备日志超级表 初始化只创建一次-->
|
<!-- 创建设备日志超级表 初始化只创建一次-->
|
||||||
<update id="createDeviceLogSTable">
|
<update id="createDeviceLogSTable">
|
||||||
CREATE STABLE device_log(
|
CREATE STABLE device_log (
|
||||||
ts TIMESTAMP,
|
ts TIMESTAMP,
|
||||||
id NCHAR(50),
|
id NCHAR(50),
|
||||||
product_key NCHAR(50),
|
product_key NCHAR(50),
|
||||||
|
|
|
@ -45,7 +45,7 @@ spring:
|
||||||
primary: master
|
primary: master
|
||||||
datasource:
|
datasource:
|
||||||
master:
|
master:
|
||||||
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 连接的示例
|
url: jdbc:mysql://chaojiniu.top:23306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
|
||||||
# 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 连接的示例
|
# 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 连接的示例
|
||||||
# url: jdbc:postgresql://127.0.0.1:5432/ruoyi-vue-pro # PostgreSQL 连接的示例
|
# url: jdbc:postgresql://127.0.0.1:5432/ruoyi-vue-pro # PostgreSQL 连接的示例
|
||||||
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
|
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
|
||||||
|
@ -53,8 +53,8 @@ spring:
|
||||||
# url: jdbc:dm://127.0.0.1:5236?schema=RUOYI_VUE_PRO # DM 连接的示例
|
# url: jdbc:dm://127.0.0.1:5236?schema=RUOYI_VUE_PRO # DM 连接的示例
|
||||||
# url: jdbc:kingbase8://127.0.0.1:54321/test # 人大金仓 KingbaseES 连接的示例
|
# url: jdbc:kingbase8://127.0.0.1:54321/test # 人大金仓 KingbaseES 连接的示例
|
||||||
# url: jdbc:postgresql://127.0.0.1:5432/postgres # OpenGauss 连接的示例
|
# url: jdbc:postgresql://127.0.0.1:5432/postgres # OpenGauss 连接的示例
|
||||||
username: root
|
username: ruoyi-vue-pro
|
||||||
password: ahh@123456
|
password: ruoyi-@h2ju02hebp
|
||||||
# username: sa # SQL Server 连接的示例
|
# username: sa # SQL Server 连接的示例
|
||||||
# password: Yudao@2024 # SQL Server 连接的示例
|
# password: Yudao@2024 # SQL Server 连接的示例
|
||||||
# username: SYSDBA # DM 连接的示例
|
# username: SYSDBA # DM 连接的示例
|
||||||
|
@ -63,17 +63,25 @@ spring:
|
||||||
# password: Yudao@2024 # OpenGauss 连接的示例
|
# password: Yudao@2024 # OpenGauss 连接的示例
|
||||||
slave: # 模拟从库,可根据自己需要修改
|
slave: # 模拟从库,可根据自己需要修改
|
||||||
lazy: true # 开启懒加载,保证启动速度
|
lazy: true # 开启懒加载,保证启动速度
|
||||||
url: jdbc:mysql://127.0.0.1:3307/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
url: jdbc:mysql://chaojiniu.top:23306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||||
|
username: ruoyi-vue-pro
|
||||||
|
password: ruoyi-@h2ju02hebp
|
||||||
|
tdengine: # IOT 数据库
|
||||||
|
# lazy: true # 开启懒加载,保证启动速度
|
||||||
|
url: jdbc:TAOS-RS://chaojiniu.top:6041/ruoyi_vue_pro
|
||||||
|
driver-class-name: com.taosdata.jdbc.rs.RestfulDriver
|
||||||
username: root
|
username: root
|
||||||
password: ahh@123456
|
password: taosdata
|
||||||
|
druid:
|
||||||
|
validation-query: SELECT SERVER_STATUS() # TDengine 数据源的有效性检查 SQL
|
||||||
|
|
||||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||||
data:
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1 # 地址
|
host: chaojiniu.top # 地址
|
||||||
port: 6379 # 端口
|
port: 6379 # 端口
|
||||||
database: 0 # 数据库索引
|
database: 15 # 数据库索引
|
||||||
# password: dev # 密码,建议生产环境开启
|
password: fsknKD7UvQYZsyf2hXXn # 密码,建议生产环境开启
|
||||||
|
|
||||||
--- #################### 定时任务相关配置 ####################
|
--- #################### 定时任务相关配置 ####################
|
||||||
|
|
||||||
|
@ -175,8 +183,10 @@ logging:
|
||||||
cn.iocoder.yudao.module.crm.dal.mysql: debug
|
cn.iocoder.yudao.module.crm.dal.mysql: debug
|
||||||
cn.iocoder.yudao.module.erp.dal.mysql: debug
|
cn.iocoder.yudao.module.erp.dal.mysql: debug
|
||||||
cn.iocoder.yudao.module.iot.dal.mysql: debug
|
cn.iocoder.yudao.module.iot.dal.mysql: debug
|
||||||
|
cn.iocoder.yudao.module.iot.dal.tdengine: DEBUG
|
||||||
cn.iocoder.yudao.module.ai.dal.mysql: debug
|
cn.iocoder.yudao.module.ai.dal.mysql: debug
|
||||||
org.springframework.context.support.PostProcessorRegistrationDelegate: ERROR # TODO 芋艿:先禁用,Spring Boot 3.X 存在部分错误的 WARN 提示
|
org.springframework.context.support.PostProcessorRegistrationDelegate: ERROR # TODO 芋艿:先禁用,Spring Boot 3.X 存在部分错误的 WARN 提示
|
||||||
|
com.taosdata: DEBUG # TDengine 的日志级别
|
||||||
|
|
||||||
debug: false
|
debug: false
|
||||||
|
|
||||||
|
@ -259,7 +269,7 @@ justauth:
|
||||||
iot:
|
iot:
|
||||||
emq:
|
emq:
|
||||||
# 账号
|
# 账号
|
||||||
username: anhaohao
|
username: haohao
|
||||||
# 密码
|
# 密码
|
||||||
password: ahh@123456
|
password: ahh@123456
|
||||||
# 主机地址
|
# 主机地址
|
||||||
|
@ -272,3 +282,6 @@ iot:
|
||||||
keepalive: 60
|
keepalive: 60
|
||||||
# 清除会话(设置为false,断开连接,重连后使用原来的会话 保留订阅的主题,能接收离线期间的消息)
|
# 清除会话(设置为false,断开连接,重连后使用原来的会话 保留订阅的主题,能接收离线期间的消息)
|
||||||
clearSession: true
|
clearSession: true
|
||||||
|
|
||||||
|
pf4j:
|
||||||
|
pluginsDir: /Users/anhaohao/code/gitee/ruoyi-vue-pro/plugins
|
Loading…
Reference in New Issue