feat sn 改成 int64

This commit is contained in:
2026-01-30 11:56:14 +08:00
parent 9781cd126f
commit e2fa47fd27
6 changed files with 11 additions and 11 deletions

View File

@@ -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 string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
Name string `gorm:"column:name;not null" json:"name"`
Phone string `gorm:"column:phone" json:"phone"`
WxUnionID string `gorm:"column:wx_union_id;comment:微信用户唯一标识" json:"wx_union_id"` // 微信用户唯一标识
@@ -33,8 +33,8 @@ func (*User) TableName() string {
// Auto sn
func (m *User) BeforeCreate(_ *gorm.DB) error {
if m.Sn == "" {
m.Sn = utils.SnowflakeInstance().Generate().String()
if m.Sn == 0 {
m.Sn = utils.SnowflakeInstance().Generate().Int64()
}
return nil
}

View File

@@ -28,7 +28,7 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) user {
tableName := _user.userDo.TableName()
_user.ALL = field.NewAsterisk(tableName)
_user.ID = field.NewUint64(tableName, "id")
_user.Sn = field.NewString(tableName, "sn")
_user.Sn = field.NewInt64(tableName, "sn")
_user.Name = field.NewString(tableName, "name")
_user.Phone = field.NewString(tableName, "phone")
_user.WxUnionID = field.NewString(tableName, "wx_union_id")
@@ -47,7 +47,7 @@ type user struct {
ALL field.Asterisk
ID field.Uint64
Sn field.String // 业务唯一编号
Sn field.Int64 // 业务唯一编号
Name field.String
Phone field.String
WxUnionID field.String // 微信用户唯一标识
@@ -72,7 +72,7 @@ func (u user) As(alias string) *user {
func (u *user) updateTableName(table string) *user {
u.ALL = field.NewAsterisk(table)
u.ID = field.NewUint64(table, "id")
u.Sn = field.NewString(table, "sn")
u.Sn = field.NewInt64(table, "sn")
u.Name = field.NewString(table, "name")
u.Phone = field.NewString(table, "phone")
u.WxUnionID = field.NewString(table, "wx_union_id")

View File

@@ -17,7 +17,7 @@ func Query() *query.Query {
return query.Use(mysql.GetDB(dbName))
}
func keyCacheBySn(sn string, tableName string) string {
func keyCacheBySn(sn int64, tableName string) string {
return fmt.Sprintf(cacheBySn, tableName, sn)
}

View File

@@ -44,7 +44,7 @@ func (d *UserDao) Updates(user *model.User) error {
return info.Error
}
func (d *UserDao) FindBySn(sn string) (*model.User, error) {
func (d *UserDao) FindBySn(sn int64) (*model.User, error) {
if d.cache != nil {
var user model.User
if ok := d.cache.Get(d.ctx, keyCacheBySn(sn, user.TableName()), &user); ok {