package controllers import ( "encoding/json" "eta/eta_data_push/models" "eta/eta_data_push/services" "eta/eta_data_push/utils" "strconv" "time" ) // 指标 type IndexController struct { BaseAuthController } // @Title 获取指标接口 // @Description 获取指标接口 // @Success 200 {object} models.IndexListReq // @router /list [post] func (this *IndexController) IndexList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req models.IndexListReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.Source <= 0 { br.Msg = "渠道编码错误!" br.ErrMsg = "渠道编码错误,Source:" + strconv.Itoa(req.Source) return } if req.StartDate == "" { req.StartDate = time.Now().AddDate(0, 0, -1).Format(utils.FormatDate) } if req.EndDate == "" { req.EndDate = time.Now().AddDate(0,0,1).Format(utils.FormatDate) } list, err := services.GetIndexList(req.Source, req.StartDate, req.EndDate) if err != nil { br.Msg = "获取数据失败!" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = list }