package cardholder import ( "apigame/dto" "apigame/service/constd" "fmt" ) // Init 初始化 func Init() { NewConfigs() TryUpdateConfigs() } // TryUpdateConfigs 尝试更新配置表 func TryUpdateConfigs() { LoadConfigs() } // LoadConfigs 读取mysql配置 func LoadConfigs() { for _, gameId := range constd.GameListCardHolder { LoadConfig(gameId) } } // TryUpdateConfig 尝试更新配置表 func TryUpdateConfig(gameId string) (config *CardActivityConfig, has bool) { LoadConfig(gameId) return GetConfig(gameId) } // LoadConfig 读取mysql配置 func LoadConfig(gameId string) { // 找到当前开放的活动 configOpen := CardActivityUpdateConfig{Id: 0} { conf := make([]CardActivityUpdateConfig, 0) _, err := dto.Find(dto.DbConfig, &conf, new(CardActivityUpdateConfig).GetTableName(gameId)) if err != nil { return } for _, config := range conf { if config.Status != 0 { configOpen = config continue } } fmt.Println(configOpen) } // 没有开放的活动 if configOpen.Id == 0 { return } // 判断是否需要更新 needUpdate := false configOld, hasConfigOld := GetConfig(gameId) if hasConfigOld { if configOpen.Id != configOld.Raw.Id || configOpen.UpdateTime != configOld.Raw.UpdateTime { needUpdate = true } } else { needUpdate = true } // 更新数据 if needUpdate { confNew := &CardActivityConfigRaw{} hasConfNew, err := dto.First(dto.DbConfig, confNew, gameId) if err != nil { return } if !hasConfNew { return } ConfigDecode(gameId, confNew) } }