regmgr.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package register
  2. import (
  3. "fmt"
  4. "sort"
  5. "time"
  6. "bet24.com/log"
  7. )
  8. var mgr *regManager
  9. type regManager struct {
  10. stat_list map[string]*regStatInfo
  11. statHour_list map[string]*regStatByHourInfo
  12. statSource_list map[string][]*regStatSourceInfo
  13. newUserStat_list map[string][]*newUserStatInfo
  14. }
  15. func Run() {
  16. mgr = new(regManager)
  17. mgr.stat_list = make(map[string]*regStatInfo)
  18. mgr.statHour_list = make(map[string]*regStatByHourInfo)
  19. mgr.statSource_list = make(map[string][]*regStatSourceInfo)
  20. mgr.newUserStat_list = make(map[string][]*newUserStatInfo)
  21. }
  22. func (this *regManager) statList(partnerId int, beginTime, endTime string) (int, []*regStatInfo) {
  23. var (
  24. totalRegCount int
  25. list []*regStatInfo
  26. )
  27. end, _ := time.Parse(dateFormat, endTime)
  28. for begin, _ := time.Parse(dateFormat, beginTime); !begin.After(end); begin = begin.AddDate(0, 0, 1) {
  29. dateStr := begin.Format(dateFormat)
  30. key := fmt.Sprintf("%s_%d", dateStr, partnerId)
  31. v, ok := this.stat_list[key]
  32. if ok {
  33. totalRegCount += v.RegUserCount
  34. list = append(list, v)
  35. continue
  36. }
  37. for _, v := range regStatList(partnerId, dateStr, dateStr) {
  38. log.Debug("regmgr.statList ==> %+v", v)
  39. totalRegCount += v.RegUserCount
  40. if begin.Format(dateFormat) == time.Now().Format(dateFormat) {
  41. list = append(list, v)
  42. continue
  43. }
  44. key = fmt.Sprintf("%s_%d", v.DateFlag, partnerId)
  45. this.stat_list[key] = v
  46. list = append(list, v)
  47. }
  48. }
  49. sort.SliceStable(list, func(i, j int) bool {
  50. return list[i].DateFlag > list[j].DateFlag
  51. })
  52. return totalRegCount, list
  53. }
  54. func (this *regManager) statListByHour(beginTime, endTime string) []*regStatByHourInfo {
  55. var list []*regStatByHourInfo
  56. end, _ := time.Parse(dateFormat, endTime)
  57. for begin, _ := time.Parse(dateFormat, beginTime); !begin.After(end); begin = begin.AddDate(0, 0, 1) {
  58. dateStr := begin.Format(dateFormat)
  59. v, ok := this.statHour_list[dateStr]
  60. if ok {
  61. list = append(list, v)
  62. continue
  63. }
  64. for _, v := range regStatListByHour(dateStr, dateStr) {
  65. log.Debug("regmgr.statListByHour ==> %+v", v)
  66. if begin.Format(dateFormat) == time.Now().Format(dateFormat) {
  67. list = append(list, v)
  68. continue
  69. }
  70. this.statHour_list[v.DateFlag] = v
  71. list = append(list, v)
  72. }
  73. }
  74. sort.SliceStable(list, func(i, j int) bool {
  75. return list[i].DateFlag < list[j].DateFlag
  76. })
  77. return list
  78. }
  79. func (this *regManager) sourceStatList(beginTime, endTime string) []*regStatSourceInfo {
  80. var list []*regStatSourceInfo
  81. end, _ := time.Parse(dateFormat, endTime)
  82. for begin, _ := time.Parse(dateFormat, beginTime); !begin.After(end); begin = begin.AddDate(0, 0, 1) {
  83. dateStr := begin.Format(dateFormat)
  84. v, ok := this.statSource_list[dateStr]
  85. if ok {
  86. list = append(list, v...)
  87. continue
  88. }
  89. for _, v := range regStatSourceList(dateStr, dateStr) {
  90. log.Debug("regmgr.sourceStatList ==> %+v", v)
  91. if begin.Format(dateFormat) == time.Now().Format(dateFormat) {
  92. list = append(list, v)
  93. continue
  94. }
  95. this.statSource_list[v.DateFlag] = append(this.statSource_list[v.DateFlag], v)
  96. list = append(list, v)
  97. }
  98. }
  99. sort.SliceStable(list, func(i, j int) bool {
  100. return list[i].DateFlag > list[j].DateFlag
  101. })
  102. return list
  103. }
  104. func (this *regManager) newUserStatList(req *newUserStatInf_req) *newUserStatInfo_resp {
  105. return getNewUserStat(req)
  106. }