base_from_eia_stero.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. // BaseFromEiaSteoIndex EiaSteo指标
  9. type BaseFromEiaSteoIndex struct {
  10. BaseFromEiaSteoIndexId int `orm:"column(base_from_eia_steo_index_id);pk"`
  11. BaseFromEiaSteoClassifyId int `description:"指标分类id"`
  12. IndexCode string `description:"指标编码"`
  13. IndexName string `description:"指标名称(中文名称)"`
  14. IndexNameOriginal string `description:"指标名称(原始名称)"`
  15. Frequency string `description:"频度"`
  16. Level int `description:"指标层级(原始层级)"`
  17. Unit string `description:"单位"`
  18. Super string `description:"我也不知道是个啥,反正先存起来,万一用到了呢"`
  19. Precision int `description:"精度,我也不知道会不会用到,反正先存起来,万一用到了呢"`
  20. LastHistorical string `description:"最近的历史记录,我也不知道会不会用到,反正先存起来,万一用到了呢"`
  21. Description string `description:"备注信息,我也不知道会不会用到,反正先存起来,万一用到了呢"`
  22. IsMappable int `description:"是否可映射,我也不知道会不会用到,反正先存起来,万一用到了呢"`
  23. StartDate time.Time `description:"开始日期"`
  24. EndDate time.Time `description:"结束日期"`
  25. ModifyTime time.Time `description:"最新更新时间"`
  26. CreateTime time.Time `description:"创建时间"`
  27. }
  28. // BaseFromEiaSteoIndexItem EiaSteo指标
  29. type BaseFromEiaSteoIndexItem struct {
  30. BaseFromEiaSteoIndexId int `orm:"column(base_from_eia_steo_index_id);pk"`
  31. BaseFromEiaSteoClassifyId int `description:"指标分类id"`
  32. IndexCode string `description:"指标编码"`
  33. IndexName string `description:"指标名称(中文名称)"`
  34. IndexNameOriginal string `description:"指标名称(原始名称)"`
  35. Frequency string `description:"频度"`
  36. Level int `description:"指标层级(原始层级)"`
  37. Unit string `description:"单位"`
  38. Super string `description:"我也不知道是个啥,反正先存起来,万一用到了呢"`
  39. Precision int `description:"精度,我也不知道会不会用到,反正先存起来,万一用到了呢"`
  40. LastHistorical string `description:"最近的历史记录,我也不知道会不会用到,反正先存起来,万一用到了呢"`
  41. Description string `description:"备注信息,我也不知道会不会用到,反正先存起来,万一用到了呢"`
  42. IsMappable int `description:"是否可映射,我也不知道会不会用到,反正先存起来,万一用到了呢"`
  43. StartDate string `description:"开始日期"`
  44. EndDate string `description:"结束日期"`
  45. ModifyTime string `description:"最新更新时间"`
  46. CreateTime string `description:"创建时间"`
  47. }
  48. // BaseFromEiaSteoClassify EiaSteo分类
  49. type BaseFromEiaSteoClassify struct {
  50. BaseFromEiaSteoClassifyId int `orm:"column(base_from_eia_steo_classify_id);pk"`
  51. ClassifyName string `description:"分类名称(中文名称)"`
  52. ClassifyNameOriginal string `description:"分类名称(原始名称)"`
  53. ModifyTime time.Time `description:"最新更新时间"`
  54. CreateTime time.Time `description:"创建时间"`
  55. }
  56. // BaseFromEiaSteoData EiaSteo数据表
  57. type BaseFromEiaSteoData struct {
  58. BaseFromEiaSteoDataId int `orm:"column(base_from_eia_steo_data_id);pk"`
  59. BaseFromEiaSteoIndexId int `description:"指标id"`
  60. IndexCode string `description:"指标编码"`
  61. DataTime time.Time `description:"数据日期"`
  62. Value float64 `description:"数据值"`
  63. ModifyTime time.Time `description:"最新更新时间"`
  64. CreateTime time.Time `description:"创建时间"`
  65. }
  66. // BaseFromEiaSteoDataItem EiaSteo数据
  67. type BaseFromEiaSteoDataItem struct {
  68. BaseFromEiaSteoDataId int `orm:"column(base_from_eia_steo_data_id);pk"`
  69. BaseFromEiaSteoIndexId int `description:"指标id"`
  70. IndexCode string `description:"指标编码"`
  71. DataTime string `description:"数据日期"`
  72. Value float64 `description:"数据值"`
  73. ModifyTime string `description:"最新更新时间"`
  74. CreateTime string `description:"创建时间"`
  75. }
  76. // GetEiaSteoClassifyList 获取分类列表
  77. func GetEiaSteoClassifyList() (items []*BaseFromEiaSteoClassify, err error) {
  78. sql := ` SELECT * FROM base_from_eia_steo_classify ORDER BY base_from_eia_steo_classify_id ASC `
  79. o := orm.NewOrmUsingDB("data")
  80. o.Raw(sql).QueryRows(&items)
  81. return
  82. }
  83. type EiaSteoIndexListResp struct {
  84. BaseFromEiaSteoIndexId int `orm:"column(base_from_eia_steo_index_id);pk"`
  85. BaseFromEiaSteoClassifyId int `description:"指标分类id"`
  86. IndexCode string `description:"指标编码"`
  87. IndexName string `description:"指标名称(中文名称)"`
  88. Unit string `description:"单位"`
  89. Frequency string `description:"频度"`
  90. StartDate string `description:"开始日期"`
  91. EndDate string `description:"结束日期"`
  92. ModifyTime string `description:"最新更新时间"`
  93. CreateTime string `description:"创建时间"`
  94. Paging *paging.PagingItem `description:"分页数据"`
  95. DataList []*BaseFromEiaSteoDataItem
  96. }
  97. // GetEiaSteoIndexList 获取指标列表
  98. func GetEiaSteoIndexList(condition string, pars []interface{}) (items []*BaseFromEiaSteoIndex, err error) {
  99. sql := ` SELECT * FROM base_from_eia_steo_index WHERE 1=1 `
  100. sql += condition
  101. sql += ` ORDER BY base_from_eia_steo_index_id ASC `
  102. o := orm.NewOrmUsingDB("data")
  103. _, err = o.Raw(sql, pars).QueryRows(&items)
  104. return
  105. }
  106. // GetEiaSteoIndexDataCount 获取指标数据总数
  107. func GetEiaSteoIndexDataCount(indexCode string) (count int, err error) {
  108. o := orm.NewOrmUsingDB("data")
  109. sql := `SELECT COUNT(1) AS count FROM base_from_eia_steo_data where index_code = ? `
  110. err = o.Raw(sql, indexCode).QueryRow(&count)
  111. return
  112. }
  113. // GetEiaSteoIndexDataList 获取指标数据总数列表
  114. func GetEiaSteoIndexDataList(indexCode string, startSize, pageSize int) (items []*BaseFromEiaSteoDataItem, err error) {
  115. //sql := ` SELECT * FROM mb_index_main_data WHERE INDEX_CODE=? ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC LIMIT ?,?`
  116. sql := ` SELECT * FROM base_from_eia_steo_data AS a WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  117. o := orm.NewOrmUsingDB("data")
  118. _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
  119. return
  120. }
  121. // GetEiaSteoItemList 模糊查询EiaSteo数据库指标列表
  122. func GetEiaSteoItemList(keyword string) (items []*BaseFromEiaSteoIndexItem, err error) {
  123. o := orm.NewOrmUsingDB("data")
  124. sql := "SELECT * FROM base_from_eia_steo_index WHERE index_name LIKE ? OR index_code like ?"
  125. _, err = o.Raw(sql, `%`+keyword+`%`, `%`+keyword+`%`).QueryRows(&items)
  126. return
  127. }
  128. // GetEiaSteoDateList 根据指标code获取日期数据
  129. func GetEiaSteoDateList(indexCodeList []string) (items []*BaseFromEiaSteoDataItem, err error) {
  130. num := len(indexCodeList)
  131. if num <= 0 {
  132. return
  133. }
  134. sql := ` SELECT data_time FROM base_from_eia_steo_data WHERE index_code IN(` + utils.GetOrmInReplace(num) + `) GROUP BY data_time ORDER BY data_time DESC `
  135. o := orm.NewOrmUsingDB("data")
  136. _, err = o.Raw(sql, indexCodeList).QueryRows(&items)
  137. return
  138. }
  139. // GetBaseFromEiaSteoIndexByCode 根据指标code获取指标信息
  140. func GetBaseFromEiaSteoIndexByCode(indexCode string) (item *BaseFromEiaSteoIndex, err error) {
  141. o := orm.NewOrmUsingDB("data")
  142. sql := `SELECT * FROM base_from_eia_steo_index WHERE index_code=? `
  143. err = o.Raw(sql, indexCode).QueryRow(&item)
  144. return
  145. }