35 lines
969 B
Go
35 lines
969 B
Go
package model
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"time"
|
|
"vote-api/global"
|
|
)
|
|
|
|
// ArticleAuthor 文章-作者表
|
|
type ArticleAuthor struct {
|
|
AuthorId int64 `gorm:"column:author_id;type:bigint(19);primary_key;comment:主键id" json:"author_id"`
|
|
ArticleId int64 `gorm:"column:article_id;type:bigint(19);comment:文章id;NOT NULL" json:"article_id"`
|
|
AuthorName string `gorm:"column:author_name;type:varchar(100);comment:作者姓名" json:"author_name"`
|
|
HospitalId int64 `gorm:"column:hospital_id;type:bigint(19);comment:作者所属医院id" json:"hospital_id"`
|
|
Model
|
|
}
|
|
|
|
func (m *ArticleAuthor) TableName() string {
|
|
return "article_author"
|
|
}
|
|
|
|
func (m *ArticleAuthor) 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
|
|
}
|