39 lines
1.4 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"gorm.io/gorm"
"time"
"vote-admin-video-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"`
VideoNumber string `gorm:"column:video_number;type:varchar(10);comment:视频编号;NOT NULL" json:"video_number"`
VoteNum uint `gorm:"column:vote_num;type:int(10) unsigned;default:0;comment:总票数" json:"vote_num"`
VideoNo string `gorm:"column:video_no;type:varchar(255);comment:视频编号(保利)" json:"video_no"`
VideoContent string `gorm:"column:video_content;type:text;comment:视频内容" json:"video_content"`
Model
VideoAuthor []*VideoAuthor `gorm:"foreignKey:VideoId;references:video_id" json:"video_author"`
}
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
}