base_from_eia_stero.go 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "time"
  5. "github.com/beego/beego/v2/client/orm"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  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. EdbInfoId int `description:"eta指标库的id"`
  35. EdbUniqueCode string `description:"指标库唯一编码"`
  36. EdbClassifyId int `description:"指标库分类ID"`
  37. EdbExist int `description:"指标库是否已添加:0-否;1-是"`
  38. }
  39. // BaseFromEiaSteoClassify EiaSteo分类
  40. type BaseFromEiaSteoClassify struct {
  41. BaseFromEiaSteoClassifyId int `orm:"column(base_from_eia_steo_classify_id);pk"`
  42. ClassifyName string `description:"分类名称(中文名称)"`
  43. ClassifyNameOriginal string `description:"分类名称(原始名称)"`
  44. ParentId int `description:"父级id"`
  45. Level int `description:"层级"`
  46. ModifyTime time.Time `description:"最新更新时间"`
  47. CreateTime time.Time `description:"创建时间"`
  48. }
  49. type BaseFromEiaSteoClassifyView struct {
  50. BaseFromEiaSteoClassifyId int `orm:"column(base_from_eia_steo_classify_id);pk"`
  51. ClassifyName string `description:"分类名称(中文名称)"`
  52. ClassifyNameOriginal string `description:"分类名称(原始名称)"`
  53. ParentId int `description:"父级id"`
  54. Level int `description:"层级"`
  55. Child []*BaseFromEiaSteoClassifyView `description:"子级分类列表"`
  56. }
  57. // BaseFromEiaSteoData EiaSteo数据表
  58. type BaseFromEiaSteoData struct {
  59. BaseFromEiaSteoDataId int `orm:"column(base_from_eia_steo_data_id);pk"`
  60. BaseFromEiaSteoIndexId int `description:"指标id"`
  61. IndexCode string `description:"指标编码"`
  62. DataTime time.Time `description:"数据日期"`
  63. Value float64 `description:"数据值"`
  64. ModifyTime time.Time `description:"最新更新时间"`
  65. CreateTime time.Time `description:"创建时间"`
  66. }
  67. // BaseFromEiaSteoDataItem EiaSteo数据
  68. type BaseFromEiaSteoDataItem struct {
  69. BaseFromEiaSteoDataId int `orm:"column(base_from_eia_steo_data_id);pk"`
  70. BaseFromEiaSteoIndexId int `description:"指标id"`
  71. IndexCode string `description:"指标编码"`
  72. DataTime string `description:"数据日期"`
  73. Value float64 `description:"数据值"`
  74. ModifyTime string `description:"最新更新时间"`
  75. CreateTime string `description:"创建时间"`
  76. }
  77. // GetEiaSteoClassifyList 获取分类列表
  78. func GetEiaSteoClassifyList() (items []*BaseFromEiaSteoClassifyView, err error) {
  79. sql := ` SELECT * FROM base_from_eia_steo_classify ORDER BY base_from_eia_steo_classify_id ASC `
  80. o := orm.NewOrmUsingDB("data")
  81. o.Raw(sql).QueryRows(&items)
  82. return
  83. }
  84. // GetEiaSteoClassifyById 根据分类id获取分类
  85. func GetEiaSteoClassifyById(classifyId int) (item *BaseFromEiaSteoClassify, err error) {
  86. sql := ` SELECT * FROM base_from_eia_steo_classify WHERE base_from_eia_steo_classify_id=? `
  87. o := orm.NewOrmUsingDB("data")
  88. err = o.Raw(sql, classifyId).QueryRow(&item)
  89. return
  90. }
  91. // GetChildEiaSteoClassifyById 获取子分类列表
  92. func GetChildEiaSteoClassifyById(classifyId int) (items []*BaseFromEiaSteoClassify, err error) {
  93. sql := ` SELECT * FROM base_from_eia_steo_classify WHERE parent_id=? `
  94. o := orm.NewOrmUsingDB("data")
  95. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  96. return
  97. }
  98. type EiaSteoIndexListResp struct {
  99. BaseFromEiaSteoIndexId int `orm:"column(base_from_eia_steo_index_id);pk"`
  100. BaseFromEiaSteoClassifyId int `description:"指标分类id"`
  101. IndexCode string `description:"指标编码"`
  102. IndexName string `description:"指标名称(中文名称)"`
  103. EdbInfoId int `description:"指标库id"`
  104. Unit string `description:"单位"`
  105. Frequency string `description:"频度"`
  106. StartDate string `description:"开始日期"`
  107. EndDate string `description:"结束日期"`
  108. ModifyTime string `description:"最新更新时间"`
  109. CreateTime string `description:"创建时间"`
  110. Paging *paging.PagingItem `description:"分页数据"`
  111. DataList []*BaseFromEiaSteoDataItem
  112. }
  113. // GetEiaSteoIndexList 获取指标列表
  114. func GetEiaSteoIndexList(condition string, pars []interface{}) (items []*BaseFromEiaSteoIndex, err error) {
  115. sql := ` SELECT * FROM base_from_eia_steo_index WHERE 1=1 `
  116. sql += condition
  117. sql += ` ORDER BY base_from_eia_steo_index_id ASC `
  118. o := orm.NewOrmUsingDB("data")
  119. _, err = o.Raw(sql, pars).QueryRows(&items)
  120. return
  121. }
  122. // GetEiaSteoIndexDataCount 获取指标数据总数
  123. func GetEiaSteoIndexDataCount(indexCode string) (count int, err error) {
  124. o := orm.NewOrmUsingDB("data")
  125. sql := `SELECT COUNT(1) AS count FROM base_from_eia_steo_data where index_code = ? `
  126. err = o.Raw(sql, indexCode).QueryRow(&count)
  127. return
  128. }
  129. // GetEiaSteoIndexDataList 获取指标数据总数列表
  130. func GetEiaSteoIndexDataList(indexCode string, startSize, pageSize int) (items []*BaseFromEiaSteoDataItem, err error) {
  131. //sql := ` SELECT * FROM mb_index_main_data WHERE INDEX_CODE=? ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC LIMIT ?,?`
  132. sql := ` SELECT * FROM base_from_eia_steo_data AS a WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  133. o := orm.NewOrmUsingDB("data")
  134. _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
  135. return
  136. }
  137. // GetEiaSteoItemList 模糊查询EiaSteo数据库指标列表
  138. func GetEiaSteoItemList(keyword string) (items []*BaseFromEiaSteoIndexItem, err error) {
  139. o := orm.NewOrmUsingDB("data")
  140. sql := "SELECT * FROM base_from_eia_steo_index WHERE index_name LIKE ? OR index_code like ?"
  141. _, err = o.Raw(sql, utils.GetLikeKeyword(keyword), utils.GetLikeKeyword(keyword)).QueryRows(&items)
  142. return
  143. }
  144. // GetEiaSteoDateList 根据指标code获取日期数据
  145. func GetEiaSteoDateList(indexCodeList []string) (items []*BaseFromEiaSteoDataItem, err error) {
  146. num := len(indexCodeList)
  147. if num <= 0 {
  148. return
  149. }
  150. 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 `
  151. o := orm.NewOrmUsingDB("data")
  152. _, err = o.Raw(sql, indexCodeList).QueryRows(&items)
  153. return
  154. }
  155. // GetBaseFromEiaSteoIndexByCode 根据指标code获取指标信息
  156. func GetBaseFromEiaSteoIndexByCode(indexCode string) (item *BaseFromEiaSteoIndex, err error) {
  157. o := orm.NewOrmUsingDB("data")
  158. sql := `SELECT * FROM base_from_eia_steo_index WHERE index_code=? `
  159. err = o.Raw(sql, indexCode).QueryRow(&item)
  160. return
  161. }