index.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. // 指标
  11. type IndexController struct {
  12. BaseAuthController
  13. }
  14. // @Title 获取指标接口
  15. // @Description 获取指标接口
  16. // @Success 200 {object} models.IndexListReq
  17. // @router /list [post]
  18. func (this *IndexController) IndexList() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. var req models.IndexListReq
  25. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  26. if err != nil {
  27. br.Msg = "参数解析异常!"
  28. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  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().AddDate(0,0,1).Format(utils.FormatDate)
  41. }
  42. list, err := services.GetIndexList(req.Source, 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. }