upstream-summary.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package http
  2. import (
  3. "fmt"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. "strconv"
  7. "time"
  8. )
  9. // getSummaryUpStreamRtmp 查询统计信息
  10. func getSummaryUpStreamRtmp(c *bm.Context) {
  11. st, ed, err := analysisTimeParams(c)
  12. if err != nil {
  13. c.Set("output_data", err.Error())
  14. c.JSONMap(map[string]interface{}{"message": err.Error()}, ecode.RequestErr)
  15. c.Abort()
  16. return
  17. }
  18. res, err := srv.GetSummaryUpStreamRtmp(c, st, ed)
  19. if err != nil {
  20. c.Set("output_data", err.Error())
  21. c.JSONMap(map[string]interface{}{"message": err.Error()}, ecode.RequestErr)
  22. c.Abort()
  23. return
  24. }
  25. c.JSONMap(map[string]interface{}{"data": res}, nil)
  26. }
  27. // getSummaryUpStreamISP 获取运营商信息统计
  28. func getSummaryUpStreamISP(c *bm.Context) {
  29. st, ed, err := analysisTimeParams(c)
  30. if err != nil {
  31. c.Set("output_data", err.Error())
  32. c.JSONMap(map[string]interface{}{"message": err.Error()}, ecode.RequestErr)
  33. c.Abort()
  34. return
  35. }
  36. res, err := srv.GetSummaryUpStreamISP(c, st, ed)
  37. if err != nil {
  38. c.Set("output_data", err.Error())
  39. c.JSONMap(map[string]interface{}{"message": err.Error()}, ecode.RequestErr)
  40. c.Abort()
  41. return
  42. }
  43. c.JSONMap(map[string]interface{}{"data": res}, nil)
  44. }
  45. // getSummaryUpStreamISP 获取运营商信息统计
  46. func getSummaryUpStreamCountry(c *bm.Context) {
  47. st, ed, err := analysisTimeParams(c)
  48. if err != nil {
  49. c.Set("output_data", err.Error())
  50. c.JSONMap(map[string]interface{}{"message": err.Error()}, ecode.RequestErr)
  51. c.Abort()
  52. return
  53. }
  54. res, err := srv.GetSummaryUpStreamCountry(c, st, ed)
  55. if err != nil {
  56. c.Set("output_data", err.Error())
  57. c.JSONMap(map[string]interface{}{"message": err.Error()}, ecode.RequestErr)
  58. c.Abort()
  59. return
  60. }
  61. c.JSONMap(map[string]interface{}{"data": res}, nil)
  62. }
  63. // getSummaryUpStreamPlatform 获取Platform信息统计
  64. func getSummaryUpStreamPlatform(c *bm.Context) {
  65. st, ed, err := analysisTimeParams(c)
  66. if err != nil {
  67. c.Set("output_data", err.Error())
  68. c.JSONMap(map[string]interface{}{"message": err.Error()}, ecode.RequestErr)
  69. c.Abort()
  70. return
  71. }
  72. res, err := srv.GetSummaryUpStreamPlatform(c, st, ed)
  73. if err != nil {
  74. c.Set("output_data", err.Error())
  75. c.JSONMap(map[string]interface{}{"message": err.Error()}, ecode.RequestErr)
  76. c.Abort()
  77. return
  78. }
  79. c.JSONMap(map[string]interface{}{"data": res}, nil)
  80. }
  81. // getSummaryUpStreamCity 获取City信息统计
  82. func getSummaryUpStreamCity(c *bm.Context) {
  83. st, ed, err := analysisTimeParams(c)
  84. if err != nil {
  85. c.Set("output_data", err.Error())
  86. c.JSONMap(map[string]interface{}{"message": err.Error()}, ecode.RequestErr)
  87. c.Abort()
  88. return
  89. }
  90. res, err := srv.GetSummaryUpStreamCity(c, st, ed)
  91. if err != nil {
  92. c.Set("output_data", err.Error())
  93. c.JSONMap(map[string]interface{}{"message": err.Error()}, ecode.RequestErr)
  94. c.Abort()
  95. return
  96. }
  97. c.JSONMap(map[string]interface{}{"data": res}, nil)
  98. }
  99. // analysisTimeParams 分析传入参数
  100. func analysisTimeParams(c *bm.Context) (int64, int64, error) {
  101. params := c.Request.URL.Query()
  102. start := params.Get("start")
  103. end := params.Get("end")
  104. var st int64
  105. var ed int64
  106. var err error
  107. if start == "" {
  108. t := time.Now()
  109. year, month, day := t.Date()
  110. st = time.Date(year, month, day, 0, 0, 0, 0, t.Location()).Unix()
  111. } else {
  112. st, err = strconv.ParseInt(start, 10, 64)
  113. if err != nil {
  114. return 0, 0, fmt.Errorf("start is not right")
  115. }
  116. }
  117. if end == "" {
  118. ed = time.Now().Unix()
  119. } else {
  120. ed, err = strconv.ParseInt(end, 10, 64)
  121. if err != nil {
  122. return 0, 0, fmt.Errorf("end is not right")
  123. }
  124. }
  125. return st, ed, nil
  126. }