get.go
1.95 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
package confcardholder
import (
"apigame/configs/confbase"
"apigame/service-common/svconst"
"apigame/service-common/svredis"
"apigame/util/util-lx/lxtime"
"apigame/util/utstring"
"apigame/util/zredis"
"fmt"
)
// GetCurrent 获取 当前配置
func GetCurrent(gameId string) (conf *ActivityConfig, has bool) {
currentKey := fmt.Sprintf("%s:%s:%s:current",
svconst.REDIS_CACHEP_REFIX,
svconst.MYSQL_TABLE_S_CARDHOLDER_CONFIG,
gameId)
currentId := zredis.GetInt64(zredis.GetConn(), currentKey)
timeNow := lxtime.NowUninx()
confRaw := new(ActivityConfigRaw)
hasFind := false
if currentId == 0 {
hasFind = confbase.FindDuringTime(confRaw, gameId)
} else {
conf, has = GetConfig(gameId, currentId)
if has {
if timeNow < conf.StartTime || timeNow > conf.EndTime {
hasFind = confbase.FindDuringTime(confRaw, gameId)
}
} else {
hasFind = confbase.FindDuringTime(confRaw, gameId)
}
}
if hasFind {
conf = new(ActivityConfig)
conf.Decode(gameId, confRaw)
svredis.SaveData(gameId, conf)
has = true
currentId = conf.Id
_ = zredis.Set(zredis.GetConn(), currentKey, utstring.Int64ToString(currentId))
}
return
}
// GetConfig 获取 配置根据Id
func GetConfig(gameId string, confId int64) (conf *ActivityConfig, has bool) {
conf = new(ActivityConfig)
has := confbase.GetConfig[*ActivityConfig, ActivityConfigRaw](gameId, gameId, conf)
if !has {
err = errors.New("confapi.GetConfig error")
return
}
//var err error
//conf = &ActivityConfig{Id: confId}
//has = svredis.LoadData(gameId, conf)
//if has {
// fmt.Println("dwjw confcardholder.GetConfig use cache")
// return
//}
//confRaw := new(ActivityConfigRaw)
//has, err = svmysql.First(confRaw, gameId)
//if err != nil {
// lxalilog.Errors(err, "confcardholder.GetConfig error", gameId)
// return
//}
//if !has {
// return
//}
//
//conf.Decode(gameId, confRaw)
//
//fmt.Println("dwjw confcardholder.GetConfig save cache")
//svredis.SaveData(gameId, conf)
return
}