package model import ( "gorm.io/gorm" "hospital-open-api/global" "time" ) // OpenKey 开放平台密钥表 type OpenKey struct { OpenId int64 `gorm:"column:open_id;type:bigint(19) unsigned;primary_key;comment:主键id" json:"open_id"` AppId string `gorm:"column:app_id;type:varchar(50);NOT NULL" json:"app_id"` AppSecret string `gorm:"column:app_secret;type:varchar(200);comment:秘钥" json:"app_secret"` Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态(1:正常 2:作废)" json:"status"` UserType string `gorm:"column:user_type;type:varchar(255);comment:下发用户类型" json:"user_type"` Model } func (m *OpenKey) TableName() string { return "gdxz_open_key" } func (m *OpenKey) BeforeCreate(tx *gorm.DB) error { if m.OpenId == 0 { m.OpenId = 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 }