diff --git a/go.mod b/go.mod index bd92535..863df84 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-user go 1.24.0 require ( - git.hlsq.asia/mmorpg/service-common v0.0.0-20260130025300-427fca7ed19f + git.hlsq.asia/mmorpg/service-common v0.0.0-20260130035320-5dc5391b07ed github.com/judwhite/go-svc v1.2.1 google.golang.org/grpc v1.77.0 gorm.io/gen v0.3.27 diff --git a/go.sum b/go.sum index cc704e3..3d0e6e1 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= -git.hlsq.asia/mmorpg/service-common v0.0.0-20260130025300-427fca7ed19f h1:U0HnB8i3ZTKrg3XBQpwFcI64LB6mraj02yNAqV3MBws= -git.hlsq.asia/mmorpg/service-common v0.0.0-20260130025300-427fca7ed19f/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I= +git.hlsq.asia/mmorpg/service-common v0.0.0-20260130035320-5dc5391b07ed h1:O08p0egfekFqQSnc4sfEJUTI5dGiEyiDRNW/VYa/Ce4= +git.hlsq.asia/mmorpg/service-common v0.0.0-20260130035320-5dc5391b07ed/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I= github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE= diff --git a/internal/dao/model/users.gen.go b/internal/dao/model/users.gen.go index e5905db..1d333cb 100644 --- a/internal/dao/model/users.gen.go +++ b/internal/dao/model/users.gen.go @@ -16,7 +16,7 @@ const TableNameUser = "users" // User mapped from table 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 } diff --git a/internal/dao/query/users.gen.go b/internal/dao/query/users.gen.go index f047106..1dfdb10 100644 --- a/internal/dao/query/users.gen.go +++ b/internal/dao/query/users.gen.go @@ -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") diff --git a/internal/dao/repository/define.go b/internal/dao/repository/define.go index f8ddd3e..c1f11cf 100644 --- a/internal/dao/repository/define.go +++ b/internal/dao/repository/define.go @@ -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) } diff --git a/internal/dao/repository/users.go b/internal/dao/repository/users.go index e0c002e..bff183a 100644 --- a/internal/dao/repository/users.go +++ b/internal/dao/repository/users.go @@ -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 {