eia_steo.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package controllers
  2. import (
  3. "eta/eta_hub/models"
  4. "eta/eta_hub/models/data_manage"
  5. "eta/eta_hub/utils"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. )
  8. // EdbInfoController 数据管理
  9. type EdbInfoController struct {
  10. BaseAuthController
  11. }
  12. // EiaSteoClassify
  13. // @Title EiaSteo数据分类
  14. // @Description EiaSteo数据分类接口
  15. // @Success 200 {object} data_manage.LzClassify
  16. // @router /eia_steo/classify [get]
  17. func (this *EdbInfoController) EiaSteoClassify() {
  18. br := new(models.BaseResponse).Init()
  19. defer func() {
  20. this.Data["json"] = br
  21. this.ServeJSON()
  22. }()
  23. classifyList, err := data_manage.GetEiaSteoClassifyList()
  24. if err != nil {
  25. br.Msg = "获取分类失败"
  26. br.ErrMsg = "获取分类失败,Err:" + err.Error()
  27. return
  28. }
  29. for _, v := range classifyList {
  30. if v.ClassifyName == `` {
  31. v.ClassifyName = v.ClassifyNameOriginal
  32. }
  33. }
  34. br.Ret = 200
  35. br.Msg = "获取成功"
  36. br.Data = classifyList
  37. }
  38. // EiaSteoData
  39. // @Title 获取EiaSteo数据
  40. // @Description 获取EiaSteo数据接口
  41. // @Param BaseFromEiaSteoClassifyId query int true "指标分类id"
  42. // @Param IndexCode query string true "指标code"
  43. // @Param IsExport query bool false "是否导出excel,默认是false"
  44. // @Param PageSize query int true "每页数据条数"
  45. // @Param CurrentIndex query int true "当前页页码,从1开始"
  46. // @Success 200 {object} data_manage.LzFrequency
  47. // @router /eia_steo/data [get]
  48. func (this *EdbInfoController) EiaSteoData() {
  49. br := new(models.BaseResponse).Init()
  50. defer func() {
  51. this.Data["json"] = br
  52. this.ServeJSON()
  53. }()
  54. pageSize, _ := this.GetInt("PageSize")
  55. currentIndex, _ := this.GetInt("CurrentIndex")
  56. var startSize int
  57. if pageSize <= 0 {
  58. pageSize = utils.PageSize20
  59. }
  60. if currentIndex <= 0 {
  61. currentIndex = 1
  62. }
  63. startSize = utils.StartIndex(currentIndex, pageSize)
  64. var condition string
  65. var pars []interface{}
  66. indexCode := this.GetString("IndexCode")
  67. if indexCode != "" {
  68. condition += ` AND index_code = ? `
  69. pars = append(pars, utils.TrimStr(indexCode))
  70. }
  71. classifyId, _ := this.GetInt("BaseFromEiaSteoClassifyId")
  72. if classifyId > 0 {
  73. condition += ` AND base_from_eia_steo_classify_id = ? `
  74. pars = append(pars, classifyId)
  75. }
  76. //获取指标
  77. indexList, err := data_manage.GetEiaSteoIndexList(condition, pars)
  78. if err != nil {
  79. br.Msg = "获取数据失败"
  80. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  81. return
  82. }
  83. resultList := make([]data_manage.EiaSteoIndexListResp, 0)
  84. for _, v := range indexList {
  85. indexName := v.IndexName
  86. if indexName == `` {
  87. indexName = v.IndexNameOriginal
  88. }
  89. product := data_manage.EiaSteoIndexListResp{
  90. BaseFromEiaSteoIndexId: v.BaseFromEiaSteoIndexId,
  91. BaseFromEiaSteoClassifyId: v.BaseFromEiaSteoClassifyId,
  92. IndexCode: v.IndexCode,
  93. IndexName: indexName,
  94. //IndexNameOriginal: v.IndexNameOriginal,
  95. Unit: v.Unit,
  96. Frequency: v.Frequency,
  97. StartDate: v.StartDate.Format(utils.FormatDate),
  98. EndDate: v.EndDate.Format(utils.FormatDate),
  99. ModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
  100. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  101. //Paging: tmpPaging,
  102. //DataList: nil,
  103. }
  104. total, err := data_manage.GetEiaSteoIndexDataCount(v.IndexCode)
  105. page := paging.GetPaging(currentIndex, pageSize, total)
  106. dataList, err := data_manage.GetEiaSteoIndexDataList(v.IndexCode, startSize, pageSize)
  107. if err != nil {
  108. br.Msg = "获取数据失败"
  109. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  110. return
  111. }
  112. if dataList == nil {
  113. dataList = make([]*data_manage.BaseFromEiaSteoDataItem, 0)
  114. }
  115. product.DataList = dataList
  116. product.Paging = page
  117. resultList = append(resultList, product)
  118. }
  119. br.Ret = 200
  120. br.Msg = "获取成功"
  121. br.Data = resultList
  122. }