base_from_eia_stero.go 8.9 KB

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