package models import ( "time" "git.huangwc.com/pig/pig-farm-controller/internal/infra/notify" "go.uber.org/zap/zapcore" "gorm.io/gorm" ) // Notification 表示已发送或尝试发送的通知记录。 type Notification struct { gorm.Model // NotifierType 通知器类型 (例如:"邮件", "企业微信", "飞书", "日志") NotifierType notify.NotifierType `gorm:"type:varchar(20);not null;index" json:"notifier_type"` // UserID 接收通知的用户ID,用于追溯通知记录到特定用户 UserID uint `gorm:"index" json:"user_id"` // 增加 UserID 字段,并添加索引 // Title 通知标题 Title string `gorm:"type:varchar(255);not null" json:"title"` // Message 通知内容 Message string `gorm:"type:text;not null" json:"message"` // Level 通知级别 (例如:INFO, WARN, ERROR) Level zapcore.Level `gorm:"type:varchar(10);not null" json:"level"` // AlarmTimestamp 通知内容生成时的时间戳,与 ID 构成复合主键 AlarmTimestamp time.Time `gorm:"primaryKey;not null" json:"alarm_timestamp"` // ToAddress 接收地址 (例如:邮箱地址, 企业微信ID, 日志标识符) ToAddress string `gorm:"type:varchar(255);not null" json:"to_address"` // Status 通知发送尝试的状态 (例如:"success", "failed", "pending") Status string `gorm:"type:varchar(20);not null;default:'pending'" json:"status"` // ErrorMessage 如果通知发送失败,此字段存储错误信息 ErrorMessage string `gorm:"type:text" json:"error_message"` } // TableName 指定 Notification 模型的表名。 func (Notification) TableName() string { return "notifications" }