configs.go
2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package ht_cardholder
import (
"apigame/api-util/umysql"
"apigame/lx-util/lxalilog"
"apigame/service/constd"
"fmt"
"github.com/astaxie/beego/logs"
)
// Init 初始化
func Init() {
NewRegistryConfigs()
TryUpdateConfigs()
//DumpConfigs()
}
// TryUpdateConfigs 尝试更新配置表
func TryUpdateConfigs() {
LoadConfigs()
}
// LoadConfigs 读取mysql配置
func LoadConfigs() {
// 读取最后修改时间
configsUpdate := make(map[int64]CardActivityUpdateConfig)
{
conf := make([]CardActivityUpdateConfig, 0)
sql := fmt.Sprintf("select id,update_time from %s", configTable)
err := umysql.FindSql(constd.MYSQL_MERGECONFIG, sql, &conf)
if err != nil {
lxalilog.Errors(err, sql, constd.GAME_ID_HT)
return
}
for _, config := range conf {
configsUpdate[config.Id] = config
}
fmt.Println(configsUpdate)
}
// 如果条目不存在 从活动列表中删除
for k, _ := range Registry.CardActivityConfigRaws {
_, ok := configsUpdate[k]
if !ok {
delete(Registry.CardActivityConfigRaws, k)
delete(Registry.CardActivityConfig, k)
}
}
for k, confUpdate := range configsUpdate {
needUpdate := false
confOld, ok := Registry.CardActivityConfigRaws[k]
// 如果条目不存在 或者 修改时间不一致 需要更新
if !ok {
needUpdate = true
} else {
if confOld.UpdateTime != confUpdate.UpdateTime {
needUpdate = true
}
}
// 更新数据
if needUpdate {
logs.Debug("__________________尝试更新活动条目ID:", k)
confNew := CardActivityConfigRaw{}
sql := fmt.Sprintf("select * from %s where id=%d limit 1", configTable, k)
err := umysql.FindOneSql(constd.MYSQL_MERGECONFIG, sql, &confNew)
if err != nil {
lxalilog.Errors(err, sql, constd.GAME_ID_HT, k)
continue
}
logs.Debug("__________________更新活动条目ID:", confNew.Id)
Registry.CardActivityConfigRaws[confNew.Id] = confNew
Registry.Decode(confNew)
}
}
}
func DumpConfigs() {
fmt.Println(CardConfigs)
fmt.Println(CardholderConfigs)
fmt.Println(NormalCardStarSequences)
fmt.Println(CardSequenceConfigs)
}