package index_data import ( "encoding/json" "eta/eta_bridge/controller/resp" "eta/eta_bridge/global" indexDataReq "eta/eta_bridge/models/request/index_data" "eta/eta_bridge/models/response" indexDataService "eta/eta_bridge/services/index_data" "fmt" "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" ) // ZhongjiIndexController 中基宁波 type ZhongjiIndexController struct{} // GetIndexList // @Description 获取smm指标列表信息 // @Success 200 {string} string "获取成功" // @Router /smm/list [post] func (j *ZhongjiIndexController) GetIndexList(c *gin.Context) { var req indexDataReq.ZhongjiSmmIndexListReq if e := c.Bind(&req); e != nil { err, ok := e.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+e.Error(), c) return } resp.FailData("参数解析失败", err.Translate(global.Trans), c) return } if req.Page < 1 { resp.FailMsg("请输入页码", "请输入页码", c) return } if req.PageSize <= 0 || req.PageSize > 500 { req.PageSize = 500 } token, err := indexDataService.GetSmmAccessToken(false) if err!= nil { resp.FailData("获取token失败", err.Error(), c) return } body, err := indexDataService.GetEdbDataListFromSmmHttp(req.Page, req.PageSize, token) if err!= nil { resp.FailData("获取token失败", err.Error(), c) return } result := new(response.SmmIndexListResponse) if err = json.Unmarshal(body, &result); err != nil { err = fmt.Errorf("result unmarshal err: %s\nresult: %s", err.Error(), string(body)) return } resp.OkData("获取成功", result, c) return } // GetIndex // @Description 获取smm指标信息 // @Success 200 {string} string "获取成功" // @Router /smm/data [post] func (j *ZhongjiIndexController) GetIndexData(c *gin.Context) { var req indexDataReq.ZhongjiSmmIndexDataReq if e := c.Bind(&req); e != nil { err, ok := e.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+e.Error(), c) return } resp.FailData("参数解析失败", err.Translate(global.Trans), c) return } if req.EdbCode == "" { resp.FailMsg("参数异常", "请输入指标Code", c) return } token, err := indexDataService.GetSmmAccessToken(false) if err!= nil { resp.FailData("获取token失败", err.Error(), c) return } body, err := indexDataService.GetEdbDataFromSmmHttp(req.EdbCode, token) if err!= nil { resp.FailData("获取token失败", err.Error(), c) return } result := new(response.SmmResponse) if err = json.Unmarshal(body, &result); err != nil { err = fmt.Errorf("result unmarshal err: %s\nresult: %s", err.Error(), string(body)) return } resp.OkData("获取成功", result, c) return } // GetIndexLatest // @Description 获取smm指标最新信息 // @Success 200 {string} string "获取成功" // @Router /smm/latest [post] func (j *ZhongjiIndexController) GetIndexDataLatest(c *gin.Context) { var req indexDataReq.ZhongjiSmmIndexLatestDataReq if e := c.Bind(&req); e != nil { err, ok := e.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+e.Error(), c) return } resp.FailData("参数解析失败", err.Translate(global.Trans), c) return } if req.EdbCode == "" { resp.FailMsg("参数异常", "请输入指标Code", c) return } if req.LastTime < 0 { resp.FailMsg("参数异常", "请输入日期", c) return } token, err := indexDataService.GetSmmAccessToken(false) if err!= nil { resp.FailData("获取token失败", err.Error(), c) return } body, err := indexDataService.GetEdbLatestDataFromSmmHttp(req.EdbCode, token, req.LastTime) if err!= nil { resp.FailData("获取token失败", err.Error(), c) return } result := new(response.SmmLatestDataResponse) if err = json.Unmarshal(body, &result); err != nil { err = fmt.Errorf("result unmarshal err: %s\nresult: %s", err.Error(), string(body)) return } resp.OkData("获取成功", result, c) return }