jiayue_index.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package index_data
  2. import (
  3. "eta/eta_bridge/controller/resp"
  4. "eta/eta_bridge/global"
  5. "eta/eta_bridge/models/jiayue"
  6. indexDataReq "eta/eta_bridge/models/request/index_data"
  7. "eta/eta_bridge/models/response"
  8. indexDataService "eta/eta_bridge/services/index_data"
  9. "github.com/gin-gonic/gin"
  10. "github.com/go-playground/validator/v10"
  11. "strings"
  12. )
  13. // JiaYueIndexController 嘉悦指标
  14. type JiaYueIndexController struct{}
  15. // GetData
  16. // @Description 获取嘉悦指标数据
  17. // @Success 200 {string} string "操作成功"
  18. // @Router /jiayue/index [post]
  19. func (j *JiaYueIndexController) GetData(c *gin.Context) {
  20. var req indexDataReq.JiaYueIndexReq
  21. if e := c.Bind(&req); e != nil {
  22. err, ok := e.(validator.ValidationErrors)
  23. if !ok {
  24. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  25. return
  26. }
  27. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  28. return
  29. }
  30. if req.IndexCode == "" {
  31. resp.FailMsg("请输入指标code码", "请输入指标code码", c)
  32. return
  33. }
  34. if req.Source == "" {
  35. resp.FailMsg("请输入指标来源", "请输入指标来源", c)
  36. return
  37. }
  38. data, err, errMsg := indexDataService.GetIndexFromJiaYue(req.IndexCode, req.Source, req.StartDate, req.EndDate)
  39. if err != nil {
  40. resp.FailMsg("查询失败", err.Error()+errMsg, c)
  41. return
  42. }
  43. resp.OkData("操作成功", data, c)
  44. return
  45. }
  46. // GetPageIndex
  47. // @Description 获取嘉悦指标列表-分页
  48. // @Success 200 {string} string "获取成功"
  49. // @Router /jiayue/page_index [post]
  50. func (j *JiaYueIndexController) GetPageIndex(c *gin.Context) {
  51. var req indexDataReq.JiaYuePageIndexReq
  52. if e := c.Bind(&req); e != nil {
  53. err, ok := e.(validator.ValidationErrors)
  54. if !ok {
  55. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  56. return
  57. }
  58. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  59. return
  60. }
  61. if req.SourceExtend == "" {
  62. resp.FailMsg("请输入指标来源", "请输入指标来源", c)
  63. return
  64. }
  65. sourceArr := strings.Split(req.SourceExtend, ",")
  66. if len(sourceArr) == 0 {
  67. resp.FailMsg("指标来源有误", "指标来源有误", c)
  68. return
  69. }
  70. total, list, err := indexDataService.GetPageIndexesFromJiaYue(req.PageIndex, req.PageSize, sourceArr, req.Keyword, req.Frequency, req.SortField, req.SortRule)
  71. if err != nil {
  72. resp.FailMsg("查询失败", err.Error(), c)
  73. return
  74. }
  75. var data response.JiaYuePageIndexResp
  76. data.Total = total
  77. data.List = list
  78. resp.OkData("操作成功", data, c)
  79. return
  80. }
  81. // GetIndexFrequency
  82. // @Description 获取指标频度列表
  83. // @Success 200 {string} string "获取成功"
  84. // @Router /jiayue/frequency_list [post]
  85. func (j *JiaYueIndexController) GetIndexFrequency(c *gin.Context) {
  86. list, err := jiayue.GetDictFrequency()
  87. if err != nil {
  88. resp.FailMsg("获取失败", err.Error(), c)
  89. return
  90. }
  91. // 过滤一下空的和斜杠
  92. data := make([]string, 0)
  93. for _, v := range list {
  94. if v != "" && v != "/" {
  95. data = append(data, v)
  96. }
  97. }
  98. resp.OkData("获取成功", data, c)
  99. return
  100. }