index_data.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_data_push/models"
  5. "eta/eta_data_push/services"
  6. "eta/eta_data_push/utils"
  7. "strconv"
  8. "time"
  9. )
  10. // @Title 获取指标接口
  11. // @Description 获取指标接口
  12. // @Success 200 {object} models.IndexDataListReq
  13. // @router /data/list [post]
  14. func (this *IndexController) IndexDataList() {
  15. br := new(models.BaseResponse).Init()
  16. defer func() {
  17. this.Data["json"] = br
  18. this.ServeJSON()
  19. }()
  20. var req models.IndexDataListReq
  21. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  22. if err != nil {
  23. br.Msg = "参数解析异常!"
  24. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  25. return
  26. }
  27. if req.IndexCode == "" {
  28. br.Msg = "请输入指标编码"
  29. return
  30. }
  31. if req.Source <= 0 {
  32. br.Msg = "渠道编码错误!"
  33. br.ErrMsg = "渠道编码错误,Source:" + strconv.Itoa(req.Source)
  34. return
  35. }
  36. if req.StartDate == "" {
  37. req.StartDate = time.Now().AddDate(0, 0, -1).Format(utils.FormatDate)
  38. }
  39. if req.EndDate == "" {
  40. req.EndDate = time.Now().Format(utils.FormatDate)
  41. }
  42. list, err := services.GetIndexDataList(req.Source, req.IndexCode, req.StartDate, req.EndDate)
  43. if err != nil {
  44. br.Msg = "获取数据失败!"
  45. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  46. return
  47. }
  48. br.Ret = 200
  49. br.Success = true
  50. br.Msg = "获取成功"
  51. br.Data = list
  52. }
  53. // IndexDataPageList
  54. // @Title 分页获取指标接口
  55. // @Description 分页获取指标接口
  56. // @Success 200 {object} models.IndexDataPageListReq
  57. // @router /data/list_page [post]
  58. func (this *IndexController) IndexDataPageList() {
  59. br := new(models.BaseResponse).Init()
  60. defer func() {
  61. this.Data["json"] = br
  62. this.ServeJSON()
  63. }()
  64. var req models.IndexDataPageListReq
  65. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  66. if err != nil {
  67. br.Msg = "参数解析异常!"
  68. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  69. return
  70. }
  71. if req.Source <= 0 {
  72. br.Msg = "渠道编码错误!"
  73. br.ErrMsg = "渠道编码错误,Source:" + strconv.Itoa(req.Source)
  74. return
  75. }
  76. if req.StartDate == "" {
  77. req.StartDate = time.Now().AddDate(0, 0, -1).Format(utils.FormatDate)
  78. }
  79. if req.EndDate == "" {
  80. req.EndDate = time.Now().AddDate(0, 0, 1).Format(utils.FormatDate)
  81. }
  82. list, err := services.GetIndexDataPageList(req.Source, req.CurrPage, req.PageSize, req.StartDate, req.EndDate)
  83. if err != nil {
  84. br.Msg = "获取数据失败!"
  85. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  86. return
  87. }
  88. br.Ret = 200
  89. br.Success = true
  90. br.Msg = "获取成功"
  91. br.Data = list
  92. }