labelconfig.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package handler
  2. import (
  3. "encoding/json"
  4. "os"
  5. "time"
  6. game "bet24.com/servers/micros/game/proto"
  7. platformconfig "bet24.com/servers/micros/platformconfig/proto"
  8. pb "bet24.com/servers/micros/userlabel/proto"
  9. "bet24.com/log"
  10. )
  11. const config_key = "userlabel_config"
  12. func (this *labelMgr) loadConfig() {
  13. this.loadRedisConfig()
  14. go time.AfterFunc(5*time.Minute, this.loadConfig)
  15. }
  16. func (this *labelMgr) loadRedisConfig() {
  17. if data := platformconfig.GetConfig(config_key); data != "" {
  18. err := json.Unmarshal([]byte(data), &this.config_list)
  19. if err == nil {
  20. return
  21. }
  22. log.Release("Unmarshal config [%s] err:%v", string(data), err)
  23. return
  24. }
  25. if data, err := os.ReadFile("serviceconf/userLabelConfig.json"); err == nil {
  26. err = json.Unmarshal([]byte(data), &this.config_list)
  27. if err == nil {
  28. platformconfig.SetConfig(config_key, string(data))
  29. return
  30. }
  31. log.Release("Unmarshal config [%s] err:%v", string(data), err)
  32. } else {
  33. log.Release("read config failed serviceconf/userLabelConfig.json %v", err)
  34. }
  35. return
  36. }
  37. // 获取标签配置列表
  38. func (this *labelMgr) getConfigList() []*pb.LabelConfig {
  39. return this.config_list
  40. }
  41. // 获取标签配置
  42. func (this *labelMgr) getConfigInfo(typeId int) *pb.LabelConfig {
  43. for _, v := range this.config_list {
  44. if v.TypeId == typeId {
  45. return v
  46. }
  47. }
  48. return nil
  49. }
  50. // 获取标签信息
  51. func (this *labelMgr) getLabelName(typeId int, labelId string) (string, int) {
  52. cfg := this.getConfigInfo(typeId)
  53. if cfg == nil {
  54. log.Debug("getLabelName typeId=%d labelId=%s cfg is nil", typeId, labelId)
  55. return "", 0
  56. }
  57. for _, v := range cfg.Content {
  58. if v.LabelId == labelId {
  59. return v.LabelName, v.PoolValue
  60. }
  61. }
  62. return "", 0
  63. }
  64. // 获取标签配置简单信息
  65. func (this *labelMgr) getConfigSimpleInfo() []pb.ConfigSimpleInfo {
  66. var list []pb.ConfigSimpleInfo
  67. for _, v := range this.config_list {
  68. for _, c := range v.Content {
  69. // 普通游戏
  70. if v.TypeId == pb.Type_Game && c.LabelId == "302" {
  71. for _, g := range game.GetGameList() {
  72. list = append(list, pb.ConfigSimpleInfo{
  73. TypeId: v.TypeId,
  74. TypeName: v.TypeName,
  75. Color: v.Color,
  76. LabelId: g.EnglishName,
  77. LabelName: g.EnglishName,
  78. })
  79. }
  80. continue
  81. }
  82. list = append(list, pb.ConfigSimpleInfo{
  83. TypeId: v.TypeId,
  84. TypeName: v.TypeName,
  85. Color: v.Color,
  86. LabelId: c.LabelId,
  87. LabelName: c.LabelName,
  88. })
  89. }
  90. }
  91. return list
  92. }