feat sn 改成 int64
This commit is contained in:
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-user
|
|||||||
go 1.24.0
|
go 1.24.0
|
||||||
|
|
||||||
require (
|
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
|
github.com/judwhite/go-svc v1.2.1
|
||||||
google.golang.org/grpc v1.77.0
|
google.golang.org/grpc v1.77.0
|
||||||
gorm.io/gen v0.3.27
|
gorm.io/gen v0.3.27
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -1,7 +1,7 @@
|
|||||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
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-20260130035320-5dc5391b07ed h1:O08p0egfekFqQSnc4sfEJUTI5dGiEyiDRNW/VYa/Ce4=
|
||||||
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/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I=
|
||||||
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
||||||
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||||
github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE=
|
github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE=
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const TableNameUser = "users"
|
|||||||
// User mapped from table <users>
|
// User mapped from table <users>
|
||||||
type User struct {
|
type User struct {
|
||||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
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"`
|
Name string `gorm:"column:name;not null" json:"name"`
|
||||||
Phone string `gorm:"column:phone" json:"phone"`
|
Phone string `gorm:"column:phone" json:"phone"`
|
||||||
WxUnionID string `gorm:"column:wx_union_id;comment:微信用户唯一标识" json:"wx_union_id"` // 微信用户唯一标识
|
WxUnionID string `gorm:"column:wx_union_id;comment:微信用户唯一标识" json:"wx_union_id"` // 微信用户唯一标识
|
||||||
@@ -33,8 +33,8 @@ func (*User) TableName() string {
|
|||||||
|
|
||||||
// Auto sn
|
// Auto sn
|
||||||
func (m *User) BeforeCreate(_ *gorm.DB) error {
|
func (m *User) BeforeCreate(_ *gorm.DB) error {
|
||||||
if m.Sn == "" {
|
if m.Sn == 0 {
|
||||||
m.Sn = utils.SnowflakeInstance().Generate().String()
|
m.Sn = utils.SnowflakeInstance().Generate().Int64()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) user {
|
|||||||
tableName := _user.userDo.TableName()
|
tableName := _user.userDo.TableName()
|
||||||
_user.ALL = field.NewAsterisk(tableName)
|
_user.ALL = field.NewAsterisk(tableName)
|
||||||
_user.ID = field.NewUint64(tableName, "id")
|
_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.Name = field.NewString(tableName, "name")
|
||||||
_user.Phone = field.NewString(tableName, "phone")
|
_user.Phone = field.NewString(tableName, "phone")
|
||||||
_user.WxUnionID = field.NewString(tableName, "wx_union_id")
|
_user.WxUnionID = field.NewString(tableName, "wx_union_id")
|
||||||
@@ -47,7 +47,7 @@ type user struct {
|
|||||||
|
|
||||||
ALL field.Asterisk
|
ALL field.Asterisk
|
||||||
ID field.Uint64
|
ID field.Uint64
|
||||||
Sn field.String // 业务唯一编号
|
Sn field.Int64 // 业务唯一编号
|
||||||
Name field.String
|
Name field.String
|
||||||
Phone field.String
|
Phone field.String
|
||||||
WxUnionID field.String // 微信用户唯一标识
|
WxUnionID field.String // 微信用户唯一标识
|
||||||
@@ -72,7 +72,7 @@ func (u user) As(alias string) *user {
|
|||||||
func (u *user) updateTableName(table string) *user {
|
func (u *user) updateTableName(table string) *user {
|
||||||
u.ALL = field.NewAsterisk(table)
|
u.ALL = field.NewAsterisk(table)
|
||||||
u.ID = field.NewUint64(table, "id")
|
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.Name = field.NewString(table, "name")
|
||||||
u.Phone = field.NewString(table, "phone")
|
u.Phone = field.NewString(table, "phone")
|
||||||
u.WxUnionID = field.NewString(table, "wx_union_id")
|
u.WxUnionID = field.NewString(table, "wx_union_id")
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func Query() *query.Query {
|
|||||||
return query.Use(mysql.GetDB(dbName))
|
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)
|
return fmt.Sprintf(cacheBySn, tableName, sn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func (d *UserDao) Updates(user *model.User) error {
|
|||||||
return info.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 {
|
if d.cache != nil {
|
||||||
var user model.User
|
var user model.User
|
||||||
if ok := d.cache.Get(d.ctx, keyCacheBySn(sn, user.TableName()), &user); ok {
|
if ok := d.cache.Get(d.ctx, keyCacheBySn(sn, user.TableName()), &user); ok {
|
||||||
|
|||||||
Reference in New Issue
Block a user