eia_steo.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. }
  123. //func init() {
  124. // for i := 110; i < 115; i++ {
  125. // pushData(i)
  126. // }
  127. // //pushData(110)
  128. //}
  129. //func pushData(index int) {
  130. // edbOb := new(data_manage.EdbInfo)
  131. // dataOb := new(data_manage.EdbData)
  132. // cond := ``
  133. // pars := make([]interface{}, 0)
  134. // //cond += ` AND source in (1,2,3,9,10,11,15,16,17,18,19,20,21,25,26,34,57)`
  135. // cond += ` AND source in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,25,26,28,29,31,32,33,34,35,36,37,38,39,40,41,42,42,44,45,46,47,48,57)`
  136. // //cond += ` AND edb_code = "C2305235333"`
  137. // edbList, e := edbOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC, create_time DESC")
  138. // if e != nil {
  139. // fmt.Println("EdbList GetItemsByCondition err: " + e.Error())
  140. // return
  141. // }
  142. //
  143. // count := len(edbList)
  144. // for k, edb := range edbList {
  145. // fmt.Println("当前第", index, "组,第", k+1, "条,剩余", count-k-1, "条")
  146. // req := data_manage.PushBusinessIndexReq{
  147. // IndexCode: fmt.Sprintf("Roc_%d_%s", index, edb.EdbCode),
  148. // IndexName: fmt.Sprintf("自有数据-%d-%s", index, edb.EdbName),
  149. // Unit: edb.Unit,
  150. // Frequency: edb.Frequency,
  151. // SourceName: edb.SourceName,
  152. // Remark: "",
  153. // DataList: nil,
  154. // }
  155. //
  156. // // 获取指标数据
  157. // tmpDataList := make([]data_manage.AddBusinessDataReq, 0)
  158. // dataList, e := dataOb.GetItemsBySourceAndCode(edb.Source, edb.SubSource, edb.EdbCode, "", []string{}, "")
  159. // if e != nil {
  160. // fmt.Println(edb.EdbCode + ";EdbData GetItemsBySourceAndCode err: " + e.Error())
  161. // continue
  162. // }
  163. // for _, v := range dataList {
  164. // tmpDataList = append(tmpDataList, data_manage.AddBusinessDataReq{
  165. // Value: v.Value,
  166. // Date: v.DataTime.Format(utils.FormatDate),
  167. // })
  168. // }
  169. // req.DataList = tmpDataList
  170. // reqJson, _ := json.Marshal(req)
  171. //
  172. // respItem, err := data.PushEdb(string(reqJson))
  173. // if err != nil {
  174. // fmt.Println(edb.EdbCode + "处理失败,Err:" + err.Error())
  175. // continue
  176. // }
  177. // if respItem.Ret != 200 {
  178. // fmt.Println(edb.EdbCode + "处理失败,Err:" + respItem.ErrMsg)
  179. // }
  180. // }
  181. //
  182. // fmt.Println("end")
  183. //}