feat 修改usn类型为string

This commit is contained in:
2026-01-11 15:58:16 +08:00
parent 63c8fb678c
commit 6bc9f18199
36 changed files with 2054 additions and 702 deletions

View File

@@ -8,7 +8,7 @@ import (
"time"
"gorm.io/gorm"
"common/utils"
"git.hlsq.asia/mmorpg/service-common/utils"
)
const TableNameUser = "users"
@@ -16,7 +16,7 @@ const TableNameUser = "users"
// User mapped from table <users>
type User struct {
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
Name string `gorm:"column:name;not null" json:"name"`
Phone string `gorm:"column:phone;not null" json:"phone"`
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
@@ -29,10 +29,10 @@ func (*User) TableName() string {
return TableNameUser
}
// auto sn
// Auto sn
func (m *User) BeforeCreate(_ *gorm.DB) error {
if m.Sn == 0 {
m.Sn = utils.SnowflakeInstance().Generate().Int64()
if m.Sn == "" {
m.Sn = utils.SnowflakeInstance().Generate().String()
}
return nil
}