vote-video-api/api/model/VideoAuthor.go
2025-12-12 15:10:08 +08:00

38 lines
1.2 KiB
Go

package model
import (
"time"
"vote-video-api/global"
"gorm.io/gorm"
)
// VideoAuthor 视频-作者表
type VideoAuthor struct {
AuthorId int64 `gorm:"column:author_id;type:bigint(19);primary_key;comment:主键id" json:"author_id"`
VideoId int64 `gorm:"column:video_id;type:bigint(19);comment:视频id;NOT NULL" json:"video_id"`
AuthorName string `gorm:"column:author_name;type:varchar(100);comment:作者姓名" json:"author_name"`
AuthorAvatar string `gorm:"column:author_avatar;type:varchar(255);comment:作者头像" json:"author_avatar"`
HospitalId int64 `gorm:"column:hospital_id;type:bigint(19);comment:作者所属医院id" json:"hospital_id"`
Model
BaseHospital *BaseHospital `gorm:"foreignKey:HospitalId;references:hospital_id" json:"base_hospital"`
}
func (m *VideoAuthor) TableName() string {
return "video_author"
}
func (m *VideoAuthor) BeforeCreate(tx *gorm.DB) error {
if m.AuthorId == 0 {
m.AuthorId = 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
}