package model import ( "gorm.io/gorm" "knowledge/global" "time" ) // BaseErrorWord 基础数据-错别字 type BaseErrorWord struct { WordId int64 `gorm:"column:word_id;type:bigint(19);primary_key;comment:主键id" json:"word_id"` WordOld string `gorm:"column:word_old;type:varchar(255);comment:错别字" json:"word_old"` WordNew string `gorm:"column:word_new;type:varchar(255);comment:新字" json:"word_new"` QuestionIds string `gorm:"column:question_ids;type:text;comment:操作关联问题id" json:"question_ids"` OperationTime *LocalTime `gorm:"column:operation_time;type:datetime;comment:操作时间" json:"operation_time"` Model } func (m *BaseErrorWord) TableName() string { return "kb_base_error_word" } func (m *BaseErrorWord) BeforeCreate(tx *gorm.DB) error { if m.WordId == 0 { m.WordId = 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 }