重构部分枚举, 让models包不依赖其他项目中的包
This commit is contained in:
@@ -10,14 +10,14 @@ import (
|
||||
// 活跃告警会被更新(如确认状态),因此保留 gorm.Model 以包含所有标准字段。
|
||||
type ActiveAlarm struct {
|
||||
gorm.Model
|
||||
FarmID uint `gorm:"not null;comment:猪场ID" json:"farm_id,omitempty"`
|
||||
DeviceID uint `gorm:"not null;comment:设备ID" json:"device_id,omitempty"`
|
||||
AlarmType string `gorm:"comment:告警类型" json:"alarm_type,omitempty"`
|
||||
AlarmLevel string `gorm:"comment:告警级别" json:"alarm_level,omitempty"`
|
||||
AlarmContent string `gorm:"comment:告警内容描述" json:"alarm_content,omitempty"`
|
||||
TriggerTime time.Time `gorm:"not null;comment:告警触发时间" json:"trigger_time"`
|
||||
IsAcknowledged bool `gorm:"default:false;comment:是否已确认" json:"is_acknowledged,omitempty"`
|
||||
AcknowledgedBy string `gorm:"comment:确认人" json:"acknowledged_by,omitempty"`
|
||||
FarmID uint `gorm:"not null;comment:猪场ID" json:"farm_id,omitempty"`
|
||||
DeviceID uint `gorm:"not null;comment:设备ID" json:"device_id,omitempty"`
|
||||
AlarmType string `gorm:"comment:告警类型" json:"alarm_type,omitempty"`
|
||||
AlarmLevel SeverityLevel `gorm:"comment:告警级别" json:"alarm_level,omitempty"`
|
||||
AlarmContent string `gorm:"comment:告警内容描述" json:"alarm_content,omitempty"`
|
||||
TriggerTime time.Time `gorm:"not null;comment:告警触发时间" json:"trigger_time"`
|
||||
IsAcknowledged bool `gorm:"default:false;comment:是否已确认" json:"is_acknowledged,omitempty"`
|
||||
AcknowledgedBy string `gorm:"comment:确认人" json:"acknowledged_by,omitempty"`
|
||||
// 使用指针类型 *time.Time 来表示可为空的确认时间
|
||||
AcknowledgedTime *time.Time `gorm:"comment:确认时间" json:"acknowledged_time,omitempty"`
|
||||
}
|
||||
@@ -32,16 +32,16 @@ func (ActiveAlarm) TableName() string {
|
||||
// ID 和 CreatedAt 共同构成联合主键,以满足 TimescaleDB 超表的要求。
|
||||
type HistoricalAlarm struct {
|
||||
// 手动定义主键,ID 仍然自增
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id,omitempty"`
|
||||
FarmID uint `gorm:"not null;comment:猪场ID" json:"farm_id,omitempty"`
|
||||
DeviceID uint `gorm:"not null;comment:设备ID" json:"device_id,omitempty"`
|
||||
AlarmType string `gorm:"comment:告警类型" json:"alarm_type,omitempty"`
|
||||
AlarmLevel string `gorm:"comment:告警级别" json:"alarm_level,omitempty"`
|
||||
AlarmContent string `gorm:"comment:告警内容描述" json:"alarm_content,omitempty"`
|
||||
TriggerTime time.Time `gorm:"not null;comment:告警触发时间" json:"trigger_time"`
|
||||
ResolveTime time.Time `gorm:"not null;comment:告警解决时间" json:"resolve_time"`
|
||||
ResolveMethod string `gorm:"comment:告警解决方式" json:"resolve_method,omitempty"`
|
||||
ResolvedBy string `gorm:"comment:告警解决人" json:"resolved_by,omitempty"`
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id,omitempty"`
|
||||
FarmID uint `gorm:"not null;comment:猪场ID" json:"farm_id,omitempty"`
|
||||
DeviceID uint `gorm:"not null;comment:设备ID" json:"device_id,omitempty"`
|
||||
AlarmType string `gorm:"comment:告警类型" json:"alarm_type,omitempty"`
|
||||
AlarmLevel SeverityLevel `gorm:"comment:告警级别" json:"alarm_level,omitempty"`
|
||||
AlarmContent string `gorm:"comment:告警内容描述" json:"alarm_content,omitempty"`
|
||||
TriggerTime time.Time `gorm:"not null;comment:告警触发时间" json:"trigger_time"`
|
||||
ResolveTime time.Time `gorm:"not null;comment:告警解决时间" json:"resolve_time"`
|
||||
ResolveMethod string `gorm:"comment:告警解决方式" json:"resolve_method,omitempty"`
|
||||
ResolvedBy string `gorm:"comment:告警解决人" json:"resolved_by,omitempty"`
|
||||
// 将 CreatedAt 作为联合主键的一部分,用于 TimescaleDB 分区
|
||||
CreatedAt time.Time `gorm:"primaryKey;comment:创建时间" json:"created_at"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user