@@ -427,3 +427,7 @@ func GetContributionValueFlow(c *gin.Context) { | |||||
e.OutSuc(c, resp, nil) | e.OutSuc(c, resp, nil) | ||||
} | } | ||||
func GetEggPointRecord(c *gin.Context) { | |||||
} |
@@ -17,6 +17,7 @@ var ( | |||||
// UserInfoProvider 定义了一个接口来管理用户信息的获取 | // UserInfoProvider 定义了一个接口来管理用户信息的获取 | ||||
type UserInfoProvider interface { | type UserInfoProvider interface { | ||||
GetUserInfo(uid int64) (*model.User, error) | GetUserInfo(uid int64) (*model.User, error) | ||||
ClearCache() | |||||
} | } | ||||
// userInfoProvider 实现了 UserInfoProvider 接口 | // userInfoProvider 实现了 UserInfoProvider 接口 | ||||
@@ -25,6 +26,13 @@ type userInfoProvider struct { | |||||
mu sync.RWMutex | mu sync.RWMutex | ||||
} | } | ||||
// NewUserInfoProvider 创建一个新的 userInfoProvider 实例 | |||||
func NewUserInfoProvider() UserInfoProvider { | |||||
return &userInfoProvider{ | |||||
userCache: make(map[int64]string), | |||||
} | |||||
} | |||||
// GetUserInfoProvider 返回 userInfoProvider 的单例实例 | // GetUserInfoProvider 返回 userInfoProvider 的单例实例 | ||||
func GetUserInfoProvider() UserInfoProvider { | func GetUserInfoProvider() UserInfoProvider { | ||||
once.Do(func() { | once.Do(func() { | ||||
@@ -60,6 +68,13 @@ func (p *userInfoProvider) GetUserInfo(uid int64) (*model.User, error) { | |||||
return userModel, err | 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.mu.Lock() //上"写"锁 | ||||
p.userCache[uid] = string(userStr) | p.userCache[uid] = string(userStr) | ||||
@@ -67,3 +82,10 @@ func (p *userInfoProvider) GetUserInfo(uid int64) (*model.User, error) { | |||||
return userModel, nil | return userModel, nil | ||||
} | } | ||||
// ClearCache 清空缓存 | |||||
func (p *userInfoProvider) ClearCache() { | |||||
p.mu.Lock() // 上"写"锁 | |||||
p.userCache = make(map[int64]string) | |||||
p.mu.Unlock() // 释放"写"锁 | |||||
} |
@@ -90,6 +90,7 @@ func route(r *gin.RouterGroup) { | |||||
rPointsCenter.POST("/exchangeEnergy", hdl.ExchangeEnergy) // 积分中心-能量兑换 | rPointsCenter.POST("/exchangeEnergy", hdl.ExchangeEnergy) // 积分中心-能量兑换 | ||||
rPointsCenter.GET("/contributionValue", hdl.GetContributionValue) // 积分中心-贡献值 | rPointsCenter.GET("/contributionValue", hdl.GetContributionValue) // 积分中心-贡献值 | ||||
rPointsCenter.GET("/contributionValueFlow", hdl.GetContributionValueFlow) // 积分中心-贡献值明细 | rPointsCenter.GET("/contributionValueFlow", hdl.GetContributionValueFlow) // 积分中心-贡献值明细 | ||||
rPointsCenter.GET("/record", hdl.GetEggPointRecord) // 积分中心-蛋蛋分历史记录 | |||||
} | } | ||||
} | } | ||||
@@ -60,11 +60,16 @@ func CheckUser(c *gin.Context) (user *model.User, newToken string, err error) { | |||||
return user, newToken, err | return user, newToken, err | ||||
} | } | ||||
// 3、获取用户信息 | // 3、获取用户信息 | ||||
userInfoProvider := provider.GetUserInfoProvider() | |||||
//userInfoProvider := provider.GetUserInfoProvider() | |||||
userInfoProvider := provider.NewUserInfoProvider() | |||||
userInfo, err := userInfoProvider.GetUserInfo(mc.Uid) | userInfo, err := userInfoProvider.GetUserInfo(mc.Uid) | ||||
if err != nil { | if err != nil { | ||||
return user, newToken, err | return user, newToken, err | ||||
} | } | ||||
userInfo, err = userInfoProvider.GetUserInfo(mc.Uid) | |||||
if err != nil { | |||||
return user, newToken, err | |||||
} | |||||
// 4、检验账号是否未激活或被冻结 | // 4、检验账号是否未激活或被冻结 | ||||
if userInfo.State == int(enum.UserStateForFreeze) { | if userInfo.State == int(enum.UserStateForFreeze) { | ||||
@@ -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_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 ( | require ( | ||||
github.com/boombuler/barcode v1.0.1 | github.com/boombuler/barcode v1.0.1 | ||||
@@ -32,7 +32,7 @@ require ( | |||||
) | ) | ||||
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/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_es.git v1.0.1-0.20241118083738-0f22da9ba0be | ||||
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 | code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 | ||||