2024-06-19 14:30:11 +08:00

35 lines
949 B
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"
"knowledge/global"
"time"
)
// Label 标签表
type Label struct {
LabelId int64 `gorm:"column:label_id;type:bigint(19);primary_key;comment:主键id" json:"label_id"`
LabelName string `gorm:"column:label_name;type:varchar(255);comment:标签名称" json:"label_name"`
ParentId int64 `gorm:"column:parent_id;type:bigint(19);comment:父级ID0表示一级" json:"parent_id"`
LabelLevel int `gorm:"column:label_level;type:tinyint(1);default:1;comment:级别1:1级 2:2级 3:3级" json:"label_level"`
Model
}
func (m *Label) TableName() string {
return "kb_label"
}
func (m *Label) BeforeCreate(tx *gorm.DB) error {
if m.LabelId == 0 {
m.LabelId = 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
}