gn_index.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. // GnIndexController 国能指标
  12. type GnIndexController struct{}
  13. // GetPageIndex
  14. // @Description 获取国能指标列表-分页
  15. // @Success 200 {string} string "获取成功"
  16. // @Router /gn/page_index [post]
  17. func (j *GnIndexController) GetPageIndex(c *gin.Context) {
  18. var req indexDataReq.GnPageIndexReq
  19. if e := c.Bind(&req); e != nil {
  20. err, ok := e.(validator.ValidationErrors)
  21. if !ok {
  22. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  23. return
  24. }
  25. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  26. return
  27. }
  28. list, page, err := indexDataService.GetPageIndexesFromGn(req.PageIndex, req.PageSize, req.LastModifyTime, req.IndexId)
  29. if err != nil {
  30. resp.FailMsg("查询失败", err.Error(), c)
  31. return
  32. }
  33. data := response.GnPageIndexResp{
  34. Page: page,
  35. List: list,
  36. }
  37. resp.OkData("操作成功", data, c)
  38. return
  39. }
  40. // GetIndexData
  41. // @Description 获取国能指标数据
  42. // @Success 200 {string} string "获取成功"
  43. // @Router /gn/index_data [post]
  44. func (j *GnIndexController) GetIndexData(c *gin.Context) {
  45. var req indexDataReq.GnDataReq
  46. if e := c.Bind(&req); e != nil {
  47. err, ok := e.(validator.ValidationErrors)
  48. if !ok {
  49. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  50. return
  51. }
  52. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  53. return
  54. }
  55. if req.IndexCode == "" {
  56. resp.FailMsg("请输入指标code码", "请输入指标code码", c)
  57. return
  58. }
  59. data, e := indexDataService.GetIndexAndDataFromGn(req.IndexCode, req.StartDate, req.EndDate)
  60. if e != nil {
  61. resp.FailMsg("获取失败", "获取国能指标数据失败, err: "+e.Error(), c)
  62. return
  63. }
  64. resp.OkData("获取成功", data, c)
  65. return
  66. }