stats.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package http
  2. import (
  3. "go-common/library/ecode"
  4. bm "go-common/library/net/http/blademaster"
  5. "strconv"
  6. "time"
  7. )
  8. // statsPoints get stats points data
  9. func statsPoints(c *bm.Context) {
  10. req := c.Request
  11. params := req.Form
  12. stimeStr := params.Get("stime")
  13. etimeStr := params.Get("etime")
  14. typeStr := params.Get("type")
  15. if stimeStr == "" {
  16. stimeStr = time.Now().Format("2006-01-02") + " 00:00:00"
  17. }
  18. if etimeStr == "" {
  19. etimeStr = time.Now().Format("2006-01-02 15:04:05")
  20. }
  21. if typeStr == "" {
  22. c.JSON(nil, ecode.RequestErr)
  23. return
  24. }
  25. local, _ := time.LoadLocation("Local")
  26. stime, err := time.ParseInLocation("2006-01-02 15:04:05", stimeStr, local)
  27. if stime.Unix() < 1 || err != nil {
  28. c.JSON(nil, ecode.RequestErr)
  29. return
  30. }
  31. etime, err := time.ParseInLocation("2006-01-02 15:04:05", etimeStr, local)
  32. if etime.Unix() < 1 || err != nil {
  33. c.JSON(nil, ecode.RequestErr)
  34. return
  35. }
  36. typeInt, err := strconv.Atoi(typeStr)
  37. if err != nil {
  38. c.JSON(nil, ecode.RequestErr)
  39. return
  40. }
  41. points, err := vdaSvc.StatsPoints(c, stime, etime, int8(typeInt))
  42. if err != nil {
  43. c.JSON(nil, err)
  44. return
  45. }
  46. c.JSON(points, nil)
  47. }