37 lines
1.2 KiB
Go
Raw 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"
"hepa-calc-admin-api/global"
"time"
)
// BaseClass 基础数据-分类表
type BaseClass struct {
ClassId int64 `gorm:"column:class_id;type:bigint(19);primary_key;comment:主键id" json:"class_id"`
ClassName string `gorm:"column:class_name;type:varchar(100);comment:分类名称" json:"class_name"`
ClassStatus int `gorm:"column:class_status;type:tinyint(1);default:1;comment:分类状态1:正常 2:隐藏)" json:"class_status"`
ClassIcon string `gorm:"column:class_icon;type:varchar(255);comment:图标地址" json:"class_icon"`
ClassBrief string `gorm:"column:class_brief;type:text;comment:分类简介" json:"class_brief"`
Sort uint `gorm:"column:sort;type:int(10) unsigned;default:1;comment:排序值(越大排名越靠前)" json:"sort"`
Model
}
func (m *BaseClass) TableName() string {
return "base_class"
}
func (m *BaseClass) BeforeCreate(tx *gorm.DB) error {
if m.ClassId == 0 {
m.ClassId = 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
}