package controllers import ( "encoding/json" "eta/eta_data_push/models" "eta/eta_data_push/services" "eta/eta_data_push/utils" "strconv" "time" ) // @Title 获取指标接口 // @Description 获取指标接口 // @Success 200 {object} models.IndexDataListReq // @router /data/list [post] func (this *IndexController) IndexDataList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req models.IndexDataListReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.IndexCode == "" { br.Msg = "请输入指标编码" 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().Format(utils.FormatDate) } list, err := services.GetIndexDataList(req.Source, req.IndexCode, 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 } // IndexDataPageList // @Title 分页获取指标接口 // @Description 分页获取指标接口 // @Success 200 {object} models.IndexDataPageListReq // @router /data/list_page [post] func (this *IndexController) IndexDataPageList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req models.IndexDataPageListReq 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.GetIndexDataPageList(req.Source, req.CurrPage, req.PageSize, 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 }