123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- 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
- }
|