gn_index.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package index_data
  2. import (
  3. "eta_gn/eta_bridge/controller/resp"
  4. "eta_gn/eta_bridge/global"
  5. indexDataReq "eta_gn/eta_bridge/models/request/index_data"
  6. "eta_gn/eta_bridge/models/response"
  7. indexDataService "eta_gn/eta_bridge/services/index_data"
  8. "github.com/gin-gonic/gin"
  9. "github.com/go-playground/validator/v10"
  10. )
  11. type GnIndexController struct{}
  12. func (j *GnIndexController) GetPageIndex(c *gin.Context) {
  13. var req indexDataReq.GnPageIndexReq
  14. if e := c.Bind(&req); e != nil {
  15. err, ok := e.(validator.ValidationErrors)
  16. if !ok {
  17. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  18. return
  19. }
  20. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  21. return
  22. }
  23. list, page, err := indexDataService.GetPageIndexesFromGn(req.PageIndex, req.PageSize, req.LastModifyTime, req.IndexId)
  24. if err != nil {
  25. resp.FailMsg("查询失败", err.Error(), c)
  26. return
  27. }
  28. data := response.GnPageIndexResp{
  29. Page: page,
  30. List: list,
  31. }
  32. resp.OkData("操作成功", data, c)
  33. return
  34. }
  35. func (j *GnIndexController) GetIndexData(c *gin.Context) {
  36. var req indexDataReq.GnDataReq
  37. if e := c.Bind(&req); e != nil {
  38. err, ok := e.(validator.ValidationErrors)
  39. if !ok {
  40. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  41. return
  42. }
  43. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  44. return
  45. }
  46. if req.IndexCode == "" {
  47. resp.FailMsg("请输入指标code码", "请输入指标code码", c)
  48. return
  49. }
  50. data, e := indexDataService.GetIndexAndDataFromGn(req.IndexCode, req.StartDate, req.EndDate)
  51. if e != nil {
  52. resp.FailMsg("获取失败", "获取国能指标数据失败, err: "+e.Error(), c)
  53. return
  54. }
  55. resp.OkData("获取成功", data, c)
  56. return
  57. }