hepa-calc-admin-api/api/model/QuestionClass.go

34 lines
917 B
Go

package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
// QuestionClass 中间表-问题/分类
type QuestionClass struct {
QuestionClassId int64 `gorm:"column:question_class_id;type:bigint(19);primary_key;comment:主键id" json:"question_class_id"`
QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:问题id;NOT NULL" json:"question_id"`
ClassId int64 `gorm:"column:class_id;type:bigint(19);comment:分类id;NOT NULL" json:"class_id"`
Model
}
func (m *QuestionClass) TableName() string {
return "question_class"
}
func (m *QuestionClass) BeforeCreate(tx *gorm.DB) error {
if m.QuestionClassId == 0 {
m.QuestionClassId = 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
}