package model import ( "gorm.io/gorm" "time" "vote-api/global" ) // Video 视频表 type Video struct { VideoId int64 `gorm:"column:video_id;type:bigint(19);primary_key;comment:主键id" json:"video_id"` VideoTitle string `gorm:"column:video_title;type:varchar(200);comment:视频标题" json:"video_title"` VideoStatus int `gorm:"column:video_status;type:tinyint(1);default:1;comment:视频状态(1:正常 2:禁用)" json:"video_status"` StartTime *LocalTime `gorm:"column:start_time;type:datetime;comment:开始投票时间" json:"start_time"` EndTime *LocalTime `gorm:"column:end_time;type:datetime;comment:结束投票时间" json:"end_time"` VoteNum uint `gorm:"column:vote_num;type:int(10) unsigned;default:0;comment:总票数" json:"vote_num"` VideoUrl string `gorm:"column:video_url;type:varchar(255);comment:视频地址" json:"video_url"` Model } func (m *Video) TableName() string { return "video" } func (m *Video) BeforeCreate(tx *gorm.DB) error { if m.VideoId == 0 { m.VideoId = global.Snowflake.Generate().Int64() } m.CreatedAt = LocalTime(time.Now()) tx.Statement.SetColumn("CreatedAt", m.CreatedAt) m.UpdatedAt = LocalTime(time.Now()) tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt) return nil }