Commit 95c75dc48d142518a8acf9718bc62c59e33e3cd3
1 parent
9ac05728
Exists in
master
and in
1 other branch
feat:解析配置数据
Showing
5 changed files
with
76 additions
and
74 deletions
Show diff stats
api-util/umysql/index.go
| ... | ... | @@ -34,3 +34,22 @@ func FindOneSql(dbName string, sql string, result any) (err error) { |
| 34 | 34 | } |
| 35 | 35 | return |
| 36 | 36 | } |
| 37 | + | |
| 38 | +// | |
| 39 | +//// Find 查询数据 | |
| 40 | +//func Find(dbName string, tableName string, result any) (err error) { | |
| 41 | +// o := orm.NewOrm() | |
| 42 | +// o.Using(dbName) | |
| 43 | +// | |
| 44 | +// // 也可以直接使用对象作为表名 | |
| 45 | +// qs := o.QueryTable(tableName) | |
| 46 | +// | |
| 47 | +// if _, err = qs.All(result); err != nil { | |
| 48 | +// if strings.Contains(err.Error(), "doesn't exist") { | |
| 49 | +// err = nil | |
| 50 | +// return | |
| 51 | +// } | |
| 52 | +// return | |
| 53 | +// } | |
| 54 | +// return | |
| 55 | +//} | ... | ... |
models/ht-cardholder.go
| ... | ... | @@ -5,11 +5,13 @@ import ( |
| 5 | 5 | "github.com/astaxie/beego/orm" |
| 6 | 6 | ) |
| 7 | 7 | |
| 8 | +// HtCardHolderData 卡牌活动持久数据 | |
| 8 | 9 | type HtCardHolderData struct { |
| 9 | - Uid int64 `orm:"pk"` | |
| 10 | + Uid int64 `orm:"pk"` // 玩家唯一ID | |
| 11 | + ActivityId int64 // 活动ID | |
| 10 | 12 | } |
| 11 | 13 | |
| 12 | -func (u *HtCardHolderData) TableName() string { | |
| 14 | +func (d *HtCardHolderData) TableName() string { | |
| 13 | 15 | return constd.MYSQL_TABLE_S_CARD_DATA + constd.GAME_ID_HT |
| 14 | 16 | } |
| 15 | 17 | |
| ... | ... | @@ -20,5 +22,4 @@ func InitHtCardholder() { |
| 20 | 22 | |
| 21 | 23 | // create table |
| 22 | 24 | orm.RunSyncdb("default", false, true) |
| 23 | - | |
| 24 | 25 | } | ... | ... |
service/ht-cardholder/config-registry.go
| ... | ... | @@ -8,26 +8,17 @@ import ( |
| 8 | 8 | ) |
| 9 | 9 | |
| 10 | 10 | var ( |
| 11 | - configTable = constd.MYSQL_TABLE_S_CARD_ACTIVITY + constd.GAME_ID_HT | |
| 12 | - Registry RegistryConfigs // 卡牌活动配置 | |
| 13 | - | |
| 14 | - CardConfigs = make(map[int]CardConfig) // 卡牌表 | |
| 15 | - CardholderConfigs = make(map[int]CardholderConfig) // 卡包开卡规则表 | |
| 16 | - NormalCardStarSequences = make([]NormalCardStarSequence, 0) // 非保底卡星级ID | |
| 17 | - CardSequenceConfigs = make([]CardSequenceConfig, 0) // 星级ID对应的卡片 | |
| 11 | + Registry RegistryConfigs // 卡牌活动配置 | |
| 18 | 12 | ) |
| 19 | 13 | |
| 20 | 14 | // RegistryConfigs 卡牌活动配置 |
| 21 | 15 | type RegistryConfigs struct { |
| 22 | - CardActivityConfigRaws map[int64]CardActivityConfigRaw // 活动配置列表 原始数据 | |
| 23 | - CardActivityConfig map[int64]CardActivityConfig // 活动配置列表 分析后数据 | |
| 16 | + ConfigRaws CardActivityConfigRaw // 活动配置 原始数据 | |
| 17 | + Config CardActivityConfig // 活动配置 分析后数据 | |
| 24 | 18 | } |
| 25 | 19 | |
| 26 | 20 | func NewRegistryConfigs() { |
| 27 | - Registry = RegistryConfigs{ | |
| 28 | - CardActivityConfigRaws: make(map[int64]CardActivityConfigRaw), | |
| 29 | - CardActivityConfig: make(map[int64]CardActivityConfig), | |
| 30 | - } | |
| 21 | + Registry = RegistryConfigs{} | |
| 31 | 22 | } |
| 32 | 23 | |
| 33 | 24 | // Decode 解析配置原始数据 |
| ... | ... | @@ -111,7 +102,7 @@ func (r RegistryConfigs) Decode(confRaw CardActivityConfigRaw) { |
| 111 | 102 | } |
| 112 | 103 | } |
| 113 | 104 | |
| 114 | - r.CardActivityConfig[conf.Id] = conf | |
| 105 | + r.Config = conf | |
| 115 | 106 | logs.Debug(conf.Awards) |
| 116 | 107 | logs.Debug(conf.AlbumConfig) |
| 117 | 108 | logs.Debug(conf.CardConfig) | ... | ... |
service/ht-cardholder/config.go
| 1 | 1 | package ht_cardholder |
| 2 | 2 | |
| 3 | +import "apigame/service/constd" | |
| 4 | + | |
| 3 | 5 | // CardActivityUpdateConfig 卡牌活动更新配置 |
| 4 | 6 | type CardActivityUpdateConfig struct { |
| 5 | - Id int64 `json:"id"` // ID | |
| 6 | - UpdateTime int64 `json:"update_time"` // 修改时间戳 | |
| 7 | + Id int64 // ID | |
| 8 | + Status int // 状态 0=关闭 1=开启 | |
| 9 | + UpdateTime int64 // 修改时间戳 | |
| 7 | 10 | } |
| 8 | 11 | |
| 9 | 12 | // CardActivityConfig 卡牌活动配置 分析后数据 |
| ... | ... | @@ -18,22 +21,27 @@ type CardActivityConfig struct { |
| 18 | 21 | CardSequenceConfig []CardSequenceConfig // 卡片星级对应卡牌配置 |
| 19 | 22 | } |
| 20 | 23 | |
| 24 | +func (c *CardActivityConfig) TableName() string { | |
| 25 | + return constd.MYSQL_TABLE_S_CARD_ACTIVITY + constd.GAME_ID_HT | |
| 26 | +} | |
| 27 | + | |
| 21 | 28 | // CardActivityConfigRaw 卡牌活动配置 原始数据 |
| 22 | 29 | type CardActivityConfigRaw struct { |
| 23 | - Id int64 `json:"id"` // ID | |
| 24 | - OpenLevel int `json:"open_level"` // 开启等级 | |
| 25 | - PreviewTime int64 `json:"preview_time"` // 预告时间 | |
| 26 | - StartTime int64 `json:"start_time"` // 开始时间 | |
| 27 | - EndTime int64 `json:"end_time"` // 结束时间 | |
| 28 | - Round int `json:"round"` // 轮数 | |
| 29 | - Awards string `json:"awards"` // 奖励配置 | |
| 30 | - AlbumConfig string `json:"album_config"` // 卡组配置 | |
| 31 | - CardConfig string `json:"card_config"` // 卡牌配置 | |
| 32 | - CardHolderConfig string `json:"card_holder_config"` // 卡包开卡规则 | |
| 33 | - NormalCardStarSequence string `json:"normal_card_star_sequence"` // 卡片星级配置 | |
| 34 | - CardSequenceConfig string `json:"card_sequence_config"` // 卡片星级对应卡牌配置 | |
| 35 | - Ver string `json:"ver"` // 版本号 | |
| 36 | - UpdateTime int64 `json:"update_time"` // 修改时间戳 | |
| 30 | + Id int64 // ID | |
| 31 | + OpenLevel int // 开启等级 | |
| 32 | + PreviewTime int64 // 预告时间 | |
| 33 | + StartTime int64 // 开始时间 | |
| 34 | + EndTime int64 // 结束时间 | |
| 35 | + Round int // 轮数 | |
| 36 | + Awards string // 奖励配置 | |
| 37 | + AlbumConfig string // 卡组配置 | |
| 38 | + CardConfig string // 卡牌配置 | |
| 39 | + CardHolderConfig string // 卡包开卡规则 | |
| 40 | + NormalCardStarSequence string // 卡片星级配置 | |
| 41 | + CardSequenceConfig string // 卡片星级对应卡牌配置 | |
| 42 | + Ver string // 版本号 | |
| 43 | + Status int // 状态 0=关闭 1=开启 | |
| 44 | + UpdateTime int64 // 修改时间戳 | |
| 37 | 45 | } |
| 38 | 46 | |
| 39 | 47 | // AlbumConfig 卡组表 | ... | ... |
service/ht-cardholder/configs.go
| ... | ... | @@ -25,62 +25,45 @@ func TryUpdateConfigs() { |
| 25 | 25 | |
| 26 | 26 | // LoadConfigs 读取mysql配置 |
| 27 | 27 | func LoadConfigs() { |
| 28 | - // 读取最后修改时间 | |
| 29 | - configsUpdate := make(map[int64]CardActivityUpdateConfig) | |
| 28 | + configTableName := new(CardActivityConfig).TableName() | |
| 29 | + // 找到当前开放的活动 | |
| 30 | + configOpen := CardActivityUpdateConfig{Id: 0} | |
| 30 | 31 | { |
| 31 | 32 | conf := make([]CardActivityUpdateConfig, 0) |
| 32 | - sql := fmt.Sprintf("select id,update_time from %s", configTable) | |
| 33 | + sql := fmt.Sprintf("select id,status,update_time from %s", configTableName) | |
| 33 | 34 | err := umysql.FindSql(constd.MYSQL_MERGECONFIG, sql, &conf) |
| 34 | 35 | if err != nil { |
| 35 | 36 | lxalilog.Errors(err, sql, constd.GAME_ID_HT) |
| 36 | 37 | return |
| 37 | 38 | } |
| 38 | 39 | for _, config := range conf { |
| 39 | - configsUpdate[config.Id] = config | |
| 40 | + if config.Status != 0 { | |
| 41 | + configOpen = config | |
| 42 | + continue | |
| 43 | + } | |
| 40 | 44 | } |
| 41 | - fmt.Println(configsUpdate) | |
| 45 | + fmt.Println(configOpen) | |
| 42 | 46 | } |
| 43 | - // 如果条目不存在 从活动列表中删除 | |
| 44 | - for k, _ := range Registry.CardActivityConfigRaws { | |
| 45 | - _, ok := configsUpdate[k] | |
| 46 | - if !ok { | |
| 47 | - delete(Registry.CardActivityConfigRaws, k) | |
| 48 | - delete(Registry.CardActivityConfig, k) | |
| 49 | - } | |
| 47 | + // 没有开放的活动 | |
| 48 | + if configOpen.Id == 0 { | |
| 49 | + return | |
| 50 | 50 | } |
| 51 | - for k, confUpdate := range configsUpdate { | |
| 52 | - needUpdate := false | |
| 53 | - confOld, ok := Registry.CardActivityConfigRaws[k] | |
| 54 | - // 如果条目不存在 或者 修改时间不一致 需要更新 | |
| 55 | - if !ok { | |
| 56 | - needUpdate = true | |
| 57 | - } else { | |
| 58 | - if confOld.UpdateTime != confUpdate.UpdateTime { | |
| 59 | - needUpdate = true | |
| 60 | - } | |
| 61 | - } | |
| 62 | - // 更新数据 | |
| 63 | - if needUpdate { | |
| 64 | - logs.Debug("__________________尝试更新活动条目ID:", k) | |
| 65 | - confNew := CardActivityConfigRaw{} | |
| 66 | - sql := fmt.Sprintf("select * from %s where id=%d limit 1", configTable, k) | |
| 67 | - err := umysql.FindOneSql(constd.MYSQL_MERGECONFIG, sql, &confNew) | |
| 68 | - if err != nil { | |
| 69 | - lxalilog.Errors(err, sql, constd.GAME_ID_HT, k) | |
| 70 | - continue | |
| 71 | - } | |
| 72 | - logs.Debug("__________________更新活动条目ID:", confNew.Id) | |
| 73 | - Registry.CardActivityConfigRaws[confNew.Id] = confNew | |
| 74 | - Registry.Decode(confNew) | |
| 51 | + // 更新数据 | |
| 52 | + if Registry.Config.Raw.UpdateTime != configOpen.UpdateTime || Registry.Config.Raw.UpdateTime != configOpen.UpdateTime { | |
| 53 | + logs.Debug("__________________尝试更新活动条目ID:", configOpen.Id) | |
| 54 | + confNew := CardActivityConfigRaw{} | |
| 55 | + sql := fmt.Sprintf("select * from %s where id=%d limit 1", configTableName, configOpen.Id) | |
| 56 | + err := umysql.FindOneSql(constd.MYSQL_MERGECONFIG, sql, &confNew) | |
| 57 | + if err != nil { | |
| 58 | + lxalilog.Errors(err, sql, constd.GAME_ID_HT, configOpen.Id) | |
| 59 | + return | |
| 75 | 60 | } |
| 61 | + logs.Debug("__________________更新活动条目ID:", confNew.Id) | |
| 62 | + Registry.ConfigRaws = confNew | |
| 63 | + Registry.Decode(confNew) | |
| 76 | 64 | } |
| 77 | - | |
| 78 | 65 | } |
| 79 | 66 | |
| 80 | 67 | func DumpConfigs() { |
| 81 | 68 | |
| 82 | - fmt.Println(CardConfigs) | |
| 83 | - fmt.Println(CardholderConfigs) | |
| 84 | - fmt.Println(NormalCardStarSequences) | |
| 85 | - fmt.Println(CardSequenceConfigs) | |
| 86 | 69 | } | ... | ... |