reply_record.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. "go-common/library/xstr"
  7. )
  8. func replyRecord(c *bm.Context) {
  9. var (
  10. err error
  11. types []int64
  12. mid, stime, etime int64
  13. pn = int64(1)
  14. ps = int64(10)
  15. )
  16. params := c.Request.Form
  17. stimeStr := params.Get("stime")
  18. etimeStr := params.Get("etime")
  19. typesStr := params.Get("types")
  20. sortStr := params.Get("sort")
  21. orderStr := params.Get("order")
  22. pnStr := params.Get("pn")
  23. psStr := params.Get("ps")
  24. midStr := params.Get("mid")
  25. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  26. err = ecode.RequestErr
  27. c.JSON(nil, err)
  28. return
  29. }
  30. if typesStr != "" {
  31. if types, err = xstr.SplitInts(typesStr); err != nil {
  32. err = ecode.RequestErr
  33. c.JSON(nil, err)
  34. return
  35. }
  36. }
  37. if stime, err = strconv.ParseInt(stimeStr, 10, 64); err != nil {
  38. err = ecode.RequestErr
  39. c.JSON(nil, err)
  40. return
  41. }
  42. if etime, err = strconv.ParseInt(etimeStr, 10, 64); err != nil {
  43. err = ecode.RequestErr
  44. c.JSON(nil, err)
  45. return
  46. }
  47. if pnStr != "" {
  48. if pn, err = strconv.ParseInt(pnStr, 10, 32); err != nil {
  49. err = ecode.RequestErr
  50. c.JSON(nil, err)
  51. return
  52. }
  53. }
  54. if psStr != "" {
  55. if ps, err = strconv.ParseInt(psStr, 10, 32); err != nil {
  56. err = ecode.RequestErr
  57. c.JSON(nil, err)
  58. return
  59. }
  60. }
  61. if orderStr == "" {
  62. orderStr = "ctime"
  63. }
  64. if sortStr == "" {
  65. sortStr = "desc"
  66. }
  67. records, total, err := rpSvr.Records(c, types, mid, stime, etime, orderStr, sortStr, int32(pn), int32(ps))
  68. if err != nil {
  69. c.JSON(nil, err)
  70. return
  71. }
  72. data := map[string]interface{}{
  73. "page": map[string]int64{
  74. "num": pn,
  75. "size": ps,
  76. "total": int64(total),
  77. },
  78. "records": records,
  79. }
  80. c.JSON(data, err)
  81. }