Quellcode durchsuchen

Merge remote-tracking branch 'origin/master'

master
huangjiajun vor 1 Tag
Ursprung
Commit
d7b487dce7
5 geänderte Dateien mit 35 neuen und 3 gelöschten Zeilen
  1. +4
    -0
      app/hdl/hdl_points_center.go
  2. +22
    -0
      app/provider/user_info.go
  3. +1
    -0
      app/router/router.go
  4. +6
    -1
      app/svc/svc_auth.go
  5. +2
    -2
      go.mod

+ 4
- 0
app/hdl/hdl_points_center.go Datei anzeigen

@@ -427,3 +427,7 @@ func GetContributionValueFlow(c *gin.Context) {

e.OutSuc(c, resp, nil)
}

func GetEggPointRecord(c *gin.Context) {

}

+ 22
- 0
app/provider/user_info.go Datei anzeigen

@@ -17,6 +17,7 @@ var (
// UserInfoProvider 定义了一个接口来管理用户信息的获取
type UserInfoProvider interface {
GetUserInfo(uid int64) (*model.User, error)
ClearCache()
}

// userInfoProvider 实现了 UserInfoProvider 接口
@@ -25,6 +26,13 @@ type userInfoProvider struct {
mu sync.RWMutex
}

// NewUserInfoProvider 创建一个新的 userInfoProvider 实例
func NewUserInfoProvider() UserInfoProvider {
return &userInfoProvider{
userCache: make(map[int64]string),
}
}

// GetUserInfoProvider 返回 userInfoProvider 的单例实例
func GetUserInfoProvider() UserInfoProvider {
once.Do(func() {
@@ -60,6 +68,13 @@ func (p *userInfoProvider) GetUserInfo(uid int64) (*model.User, error) {
return userModel, err
}

// 将用户信息转换为 JSON 字符串
userBytes, err := json.Marshal(userModel)
if err != nil {
return nil, fmt.Errorf("failed to marshal user info: %w", err)
}
userStr = string(userBytes)

// 缓存到内存中
p.mu.Lock() //上"写"锁
p.userCache[uid] = string(userStr)
@@ -67,3 +82,10 @@ func (p *userInfoProvider) GetUserInfo(uid int64) (*model.User, error) {

return userModel, nil
}

// ClearCache 清空缓存
func (p *userInfoProvider) ClearCache() {
p.mu.Lock() // 上"写"锁
p.userCache = make(map[int64]string)
p.mu.Unlock() // 释放"写"锁
}

+ 1
- 0
app/router/router.go Datei anzeigen

@@ -90,6 +90,7 @@ func route(r *gin.RouterGroup) {
rPointsCenter.POST("/exchangeEnergy", hdl.ExchangeEnergy) // 积分中心-能量兑换
rPointsCenter.GET("/contributionValue", hdl.GetContributionValue) // 积分中心-贡献值
rPointsCenter.GET("/contributionValueFlow", hdl.GetContributionValueFlow) // 积分中心-贡献值明细
rPointsCenter.GET("/record", hdl.GetEggPointRecord) // 积分中心-蛋蛋分历史记录
}

}


+ 6
- 1
app/svc/svc_auth.go Datei anzeigen

@@ -60,11 +60,16 @@ func CheckUser(c *gin.Context) (user *model.User, newToken string, err error) {
return user, newToken, err
}
// 3、获取用户信息
userInfoProvider := provider.GetUserInfoProvider()
//userInfoProvider := provider.GetUserInfoProvider()
userInfoProvider := provider.NewUserInfoProvider()
userInfo, err := userInfoProvider.GetUserInfo(mc.Uid)
if err != nil {
return user, newToken, err
}
userInfo, err = userInfoProvider.GetUserInfo(mc.Uid)
if err != nil {
return user, newToken, err
}

// 4、检验账号是否未激活或被冻结
if userInfo.State == int(enum.UserStateForFreeze) {


+ 2
- 2
go.mod Datei anzeigen

@@ -4,7 +4,7 @@ go 1.19

// replace code.fnuoos.com/EggPlanet/egg_models.git => E:/company/Egg/egg_models
//
//replace code.fnuoos.com/EggPlanet/egg_system_rules.git => E:/company/Egg/egg_system_rules
// replace code.fnuoos.com/EggPlanet/egg_system_rules.git => E:/company/Egg/egg_system_rules

require (
github.com/boombuler/barcode v1.0.1
@@ -32,7 +32,7 @@ require (
)

require (
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241122104932-0eac76d1a591
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241122012509-ceb61ba8203c
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241122112751-6744679ac54a
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5


Laden…
Abbrechen
Speichern