From 141bf7314a1450971b0427f1ffd12ffcfc6e2b49 Mon Sep 17 00:00:00 2001 From: 王家文 Date: Fri, 19 Apr 2024 10:48:24 +0800 Subject: [PATCH] feat✨:房间排行活动逻辑 --- configs/confroomrank/config.go | 28 ++++++++++++++++++++++++++++ configs/confroomrank/decode.go | 23 ++++++++++++----------- configs/confroomrank/get.go | 19 +++++++++++++++++++ configs/init.go | 3 ++- service-common/svconst/mysql.go | 6 +++--- service/roomrank/handle.go | 3 ++- 6 files changed, 66 insertions(+), 16 deletions(-) create mode 100644 configs/confroomrank/get.go diff --git a/configs/confroomrank/config.go b/configs/confroomrank/config.go index d7cb1fb..5edfb4c 100644 --- a/configs/confroomrank/config.go +++ b/configs/confroomrank/config.go @@ -1,9 +1,12 @@ package confroomrank import ( + "apigame/configs/confbase" "apigame/service-common/svconst" "apigame/service-common/svmysql" "apigame/service-common/svredis" + "apigame/util/util-lx/lxtime" + "apigame/util/utstring" "fmt" ) @@ -24,6 +27,31 @@ type ActivityConfig struct { GameId string // 所属游戏ID } +func (c *ActivityConfig) GetUid() string { + return utstring.Int64ToString(c.Id) +} + +func (c *ActivityConfig) CheckCurrent() bool { + timeNow := lxtime.NowUninx() + return timeNow >= c.StartTime && timeNow <= c.EndTime && c.Raw.Status == 1 +} + +func (c *ActivityConfig) ConfInfo(suffix string) *confbase.ConfInfo { + tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG + cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) + timeNow := lxtime.NowUninx() + return &confbase.ConfInfo{ + DbMysql: svconst.DbConfig, + TableName: fmt.Sprintf("%s_%s", tableName, suffix), + KeyName: "id", + CurrentQuery: "start_time <= ? AND end_time >= ? AND status = ?", + CurrentArgs: []any{timeNow, timeNow, 1}, + CacheKey: fmt.Sprintf("%s:%d", cacheKey, c.Id), + CacheCurrent: cacheKey + ":current", + CacheTime: 300, + } +} + func (c *ActivityConfig) RedisInfo(suffix string) *svredis.RedisInfo { tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG return &svredis.RedisInfo{ diff --git a/configs/confroomrank/decode.go b/configs/confroomrank/decode.go index 9150561..d004655 100644 --- a/configs/confroomrank/decode.go +++ b/configs/confroomrank/decode.go @@ -6,15 +6,16 @@ import ( ) // Decode 解析配置原始数据 -func (c *ActivityConfig) Decode(gameId string, configRaw *ActivityConfigRaw) { +func (c *ActivityConfig) Decode(gameId string, rawData any) { + raw := rawData.(*ActivityConfigRaw) c.GameId = gameId - c.Raw = configRaw + c.Raw = raw - c.Id = configRaw.Id - c.OpenLevel = configRaw.OpenLevel - c.PreviewTime = configRaw.PreviewTime - c.StartTime = configRaw.StartTime - c.EndTime = configRaw.EndTime + c.Id = raw.Id + c.OpenLevel = raw.OpenLevel + c.PreviewTime = raw.PreviewTime + c.StartTime = raw.StartTime + c.EndTime = raw.EndTime c.Robot = make(map[int]RobotConfig) c.Room = make(map[int]RoomConfig) @@ -22,9 +23,9 @@ func (c *ActivityConfig) Decode(gameId string, configRaw *ActivityConfigRaw) { // 解析 机器人 { configs := make([]RobotConfig, 0) - err := json.Unmarshal([]byte(configRaw.Robot), &configs) + err := json.Unmarshal([]byte(raw.Robot), &configs) if err != nil { - lxalilog.Errors(err, configRaw.Robot, gameId, configRaw.Id) + lxalilog.Errors(err, raw.Robot, gameId, raw.Id) return } for _, i2 := range configs { @@ -34,9 +35,9 @@ func (c *ActivityConfig) Decode(gameId string, configRaw *ActivityConfigRaw) { // 解析 房间 { configs := make([]RoomConfig, 0) - err := json.Unmarshal([]byte(configRaw.Room), &configs) + err := json.Unmarshal([]byte(raw.Room), &configs) if err != nil { - lxalilog.Errors(err, configRaw.Room, gameId, configRaw.Id) + lxalilog.Errors(err, raw.Room, gameId, raw.Id) return } for _, i2 := range configs { diff --git a/configs/confroomrank/get.go b/configs/confroomrank/get.go new file mode 100644 index 0000000..f6234c9 --- /dev/null +++ b/configs/confroomrank/get.go @@ -0,0 +1,19 @@ +package confroomrank + +import "apigame/configs/confbase" + +// GetCurrent 获取 当前配置 +func GetCurrent(gameId string) (conf *ActivityConfig, has bool) { + conf = new(ActivityConfig) + has = confbase.GetCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) + + return +} + +// GetConfig 获取 配置根据Id +func GetConfig(gameId string, confId int64) (conf *ActivityConfig, has bool) { + conf = new(ActivityConfig) + has = confbase.GetConfig[*ActivityConfig, ActivityConfigRaw](gameId, confId, conf) + + return +} diff --git a/configs/init.go b/configs/init.go index 111e026..5293ff6 100644 --- a/configs/init.go +++ b/configs/init.go @@ -3,6 +3,7 @@ package configs import ( "apigame/configs/confapi" "apigame/configs/confcardholder" + "apigame/configs/confroomrank" "apigame/service-common/svconst" ) @@ -17,7 +18,7 @@ func Init() bool { } for _, gameId := range svconst.GameListRoomRank { - _, _ = GetRoomRankConfig(gameId) + _, _ = confroomrank.GetCurrent(gameId) } return true diff --git a/service-common/svconst/mysql.go b/service-common/svconst/mysql.go index 1bebedc..4fb4769 100644 --- a/service-common/svconst/mysql.go +++ b/service-common/svconst/mysql.go @@ -17,7 +17,7 @@ const ( MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDALBUM = "s_cardholder_record_rewardalbum" // 开卡包活动日志领取卡组奖励 MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDROUND = "s_cardholder_record_rewardround" // 开卡包活动日志领取轮次奖励 - MYSQL_TABLE_S_ROOMRANK_CONFIG = "s_roomrank_activity_" // 房间排行活动配置 - MYSQL_TABLE_S_ROOMRANK_PLAYER = "s_roomrank_player_" // 房间排行玩家数据 - MYSQL_TABLE_S_ROOMRANK_ROOM = "s_roomrank_room" // 房间排行房间数据 + MYSQL_TABLE_S_ROOMRANK_CONFIG = "s_roomrank_activity" // 房间排行活动配置 + MYSQL_TABLE_S_ROOMRANK_PLAYER = "s_roomrank_player" // 房间排行玩家数据 + MYSQL_TABLE_S_ROOMRANK_ROOM = "s_roomrank_room" // 房间排行房间数据 ) diff --git a/service/roomrank/handle.go b/service/roomrank/handle.go index 2c4fe04..380f962 100644 --- a/service/roomrank/handle.go +++ b/service/roomrank/handle.go @@ -2,6 +2,7 @@ package roomrank import ( "apigame/configs" + "apigame/configs/confroomrank" "apigame/models" "apigame/service/code-msg" ) @@ -13,7 +14,7 @@ func HandleGetConfig(req *models.ReqRoomRankGetConfig) (code string, rsp models. gameId := req.GameID // 尝试更新配置 - config, _ := configs.GetRoomRankConfig(gameId) + config, _ := confroomrank.GetCurrent(gameId) rsp.ActivityId = config.Id rsp.Config = config.Client -- libgit2 0.21.0