web.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package http
  2. import (
  3. "time"
  4. "go-common/library/log"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. func pastScore(c *bm.Context) {
  8. v := new(struct {
  9. Date string `form:"date" validate:"required"`
  10. })
  11. if err := c.Bind(v); err != nil {
  12. return
  13. }
  14. date, err := time.Parse("2006-01-02", v.Date)
  15. if err != nil {
  16. log.Error("pastScore date error(date:%s)", v.Date)
  17. return
  18. }
  19. err = svr.RunPastScore(c, date)
  20. if err != nil {
  21. log.Error("svr.RunPastScore error(%v)", err)
  22. }
  23. c.JSON(nil, err)
  24. }
  25. func pastRecord(c *bm.Context) {
  26. v := new(struct {
  27. Date string `form:"date" validate:"required"`
  28. })
  29. if err := c.Bind(v); err != nil {
  30. return
  31. }
  32. err := svr.InsertPastRecord(c, v.Date)
  33. if err != nil {
  34. log.Error("svr.InsertPastRecord error(%v)", err)
  35. }
  36. c.JSON(nil, err)
  37. }
  38. func score(c *bm.Context) {
  39. v := new(struct {
  40. Date string `form:"date" validate:"required"`
  41. })
  42. if err := c.Bind(v); err != nil {
  43. return
  44. }
  45. date, err := time.Parse("2006-01-02", v.Date)
  46. if err != nil {
  47. log.Error("score date error(date:%s)", v.Date)
  48. return
  49. }
  50. err = svr.Run(c, date)
  51. if err != nil {
  52. log.Error("svr.Run error(%v)", err)
  53. }
  54. c.JSON(nil, err)
  55. }
  56. func delTrends(c *bm.Context) {
  57. v := new(struct {
  58. Table string `form:"table" validate:"required"`
  59. })
  60. if err := c.Bind(v); err != nil {
  61. return
  62. }
  63. err := svr.DelTrends(c, v.Table)
  64. if err != nil {
  65. log.Error("svr.DelTrends error(%v)", err)
  66. }
  67. c.JSON(nil, err)
  68. }
  69. func delScore(c *bm.Context) {
  70. v := new(struct {
  71. Date string `form:"date" validate:"required"`
  72. })
  73. if err := c.Bind(v); err != nil {
  74. return
  75. }
  76. date, err := time.Parse("2006-01-02", v.Date)
  77. if err != nil {
  78. log.Error("del score date error(date:%s)", v.Date)
  79. return
  80. }
  81. err = svr.DelRatings(c, date)
  82. if err != nil {
  83. log.Error("svr.DelRatings error(%v)", err)
  84. }
  85. c.JSON(nil, err)
  86. }
  87. func statistics(c *bm.Context) {
  88. var err error
  89. v := new(struct {
  90. Date string `form:"date" validate:"required"`
  91. })
  92. if err = c.Bind(v); err != nil {
  93. return
  94. }
  95. date, err := time.Parse("2006-01-02", v.Date)
  96. if err != nil {
  97. log.Error("statistics date error(date:%s)", v.Date)
  98. return
  99. }
  100. err = svr.RunStatistics(c, date)
  101. if err != nil {
  102. log.Error("svr.RunStatistics error(%v)", err)
  103. }
  104. c.JSON(nil, err)
  105. }
  106. func trend(c *bm.Context) {
  107. v := new(struct {
  108. Date string `form:"date" validate:"required"`
  109. })
  110. if err := c.Bind(v); err != nil {
  111. return
  112. }
  113. date, err := time.Parse("2006-01-02", v.Date)
  114. if err != nil {
  115. log.Error("trend date error(date:%s)", v.Date)
  116. return
  117. }
  118. err = svr.CalTrend(c, date)
  119. if err != nil {
  120. log.Error("svr.Trend error(%v)", err)
  121. }
  122. c.JSON(nil, err)
  123. }
  124. func taskStatus(c *bm.Context) {
  125. var err error
  126. v := new(struct {
  127. Date string `form:"date" validate:"required"`
  128. Type int `form:"type"`
  129. Status int `form:"status"`
  130. Message string `form:"message"`
  131. })
  132. if err = c.Bind(v); err != nil {
  133. return
  134. }
  135. if err = svr.InsertTaskStatus(c, v.Type, v.Status, v.Date, v.Message); err != nil {
  136. log.Error("svr.UpdateTaskStatus error(%v)", err)
  137. }
  138. c.JSON(nil, err)
  139. }