调整 ChirpStackListener
This commit is contained in:
@@ -73,7 +73,7 @@ type DeviceTemplate struct {
|
||||
// Description 提供了关于此设备类型的更多详细信息。
|
||||
Description string `json:"description"`
|
||||
|
||||
// Category 将模板分类为传感器、执行器或复合设备。
|
||||
// Category 将模板分类为传感器、执行器
|
||||
Category DeviceCategory `gorm:"not null;index" json:"category"`
|
||||
|
||||
// Commands 存储了一个从“动作名称”到“原始指令”的映射。
|
||||
|
||||
@@ -7,23 +7,9 @@ import (
|
||||
)
|
||||
|
||||
// SensorDataType 定义了 SensorData 记录中 Data 字段的整体类型
|
||||
type SensorDataType string
|
||||
|
||||
const (
|
||||
SensorDataTypeSignalMetrics SensorDataType = "signal_metrics" // 信号强度
|
||||
SensorDataTypeBatteryLevel SensorDataType = "battery_level" // 电池电量
|
||||
SensorDataTypeTemperature SensorDataType = "temperature" // 温度
|
||||
SensorDataTypeHumidity SensorDataType = "humidity" // 湿度
|
||||
SensorDataTypeWeight SensorDataType = "weight" // 重量
|
||||
)
|
||||
|
||||
// DeviceSubTypeToSensorDataTypeMap 定义了设备子类型到其产生的传感器数据类型的静态映射.
|
||||
// 这个公开的 map 是连接设备定义和数据记录的桥梁, 供其他包直接查询.
|
||||
var DeviceSubTypeToSensorDataTypeMap = map[DeviceSubType]SensorDataType{
|
||||
SubTypeSensorTemp: SensorDataTypeTemperature,
|
||||
SubTypeSensorHumidity: SensorDataTypeHumidity,
|
||||
SubTypeSensorWeight: SensorDataTypeWeight,
|
||||
}
|
||||
|
||||
// SignalMetrics 存储信号强度数据
|
||||
type SignalMetrics struct {
|
||||
@@ -67,7 +53,7 @@ type SensorData struct {
|
||||
RegionalControllerID uint `json:"regional_controller_id"`
|
||||
|
||||
// SensorDataType 是传感数据的类型
|
||||
SensorDataType SensorDataType `gorm:"not null;index" json:"sensor_data_type"`
|
||||
SensorDataType string `gorm:"not null;index" json:"sensor_data_type"`
|
||||
|
||||
// Data 存储一个或多个传感器读数,格式为 JSON。
|
||||
Data datatypes.JSON `gorm:"type:jsonb" json:"data"`
|
||||
|
||||
40
internal/infra/repository/area_controller_repository.go
Normal file
40
internal/infra/repository/area_controller_repository.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// AreaControllerRepository 定义了对 AreaController 模型的数据库操作接口
|
||||
type AreaControllerRepository interface {
|
||||
FindByID(id uint) (*models.AreaController, error)
|
||||
FindByNetworkID(networkID string) (*models.AreaController, error) // New method
|
||||
}
|
||||
|
||||
// gormAreaControllerRepository 是 AreaControllerRepository 的 GORM 实现。
|
||||
type gormAreaControllerRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// NewGormAreaControllerRepository 创建一个新的 AreaControllerRepository GORM 实现实例。
|
||||
func NewGormAreaControllerRepository(db *gorm.DB) AreaControllerRepository {
|
||||
return &gormAreaControllerRepository{db: db}
|
||||
}
|
||||
|
||||
// FindByID 通过 ID 查找一个 AreaController。
|
||||
func (r *gormAreaControllerRepository) FindByID(id uint) (*models.AreaController, error) {
|
||||
var areaController models.AreaController
|
||||
if err := r.db.First(&areaController, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &areaController, nil
|
||||
}
|
||||
|
||||
// FindByNetworkID 通过 NetworkID 查找一个 AreaController。
|
||||
func (r *gormAreaControllerRepository) FindByNetworkID(networkID string) (*models.AreaController, error) {
|
||||
var areaController models.AreaController
|
||||
if err := r.db.Where("network_id = ?", networkID).First(&areaController).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &areaController, nil
|
||||
}
|
||||
Reference in New Issue
Block a user