实现设备阈值检查任务

This commit is contained in:
2025-11-09 21:37:35 +08:00
parent a35a9a1038
commit e54c1bbc97
6 changed files with 340 additions and 20 deletions

View File

@@ -1,6 +1,8 @@
package models
import (
"encoding/json"
"errors"
"time"
"gorm.io/datatypes"
@@ -68,3 +70,12 @@ type SensorData struct {
func (SensorData) TableName() string {
return "sensor_data"
}
// ParseData 解析 JSON 数据到一个具体的结构体中。
// 调用方需要传入一个指向目标结构体实例的指针。
func (s *SensorData) ParseData(v interface{}) error {
if s.Data == nil {
return errors.New("传感器数据为空,无法解析")
}
return json.Unmarshal(s.Data, v)
}