base_from_eia_steo.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. package data_manage
  2. import (
  3. "eta/eta_task/utils"
  4. "time"
  5. "github.com/beego/beego/v2/client/orm"
  6. )
  7. // BaseFromEiaSteoIndex EiaSteo指标
  8. type BaseFromEiaSteoIndex struct {
  9. BaseFromEiaSteoIndexId int `orm:"column(base_from_eia_steo_index_id);pk"`
  10. BaseFromEiaSteoClassifyId int `description:"指标分类id"`
  11. IndexCode string `description:"指标编码"`
  12. IndexName string `description:"指标名称(中文名称)"`
  13. IndexNameOriginal string `description:"指标名称(原始名称)"`
  14. Frequency string `description:"频度"`
  15. Level int `description:"指标层级(原始层级)"`
  16. Unit string `description:"单位"`
  17. Super string `description:"我也不知道是个啥,反正先存起来,万一用到了呢"`
  18. Precision int `description:"精度,我也不知道会不会用到,反正先存起来,万一用到了呢"`
  19. LastHistorical string `description:"最近的历史记录,我也不知道会不会用到,反正先存起来,万一用到了呢"`
  20. Description string `description:"备注信息,我也不知道会不会用到,反正先存起来,万一用到了呢"`
  21. IsMappable int `description:"是否可映射,我也不知道会不会用到,反正先存起来,万一用到了呢"`
  22. StartDate string `description:"开始日期"`
  23. EndDate string `description:"结束日期"`
  24. ModifyTime string `description:"最新更新时间"`
  25. CreateTime string `description:"创建时间"`
  26. LatestValue float64 `description:"最新值"`
  27. }
  28. func AddBaseFromEiaSteoIndex(item *BaseFromEiaSteoIndex) (lastId int64, err error) {
  29. o := orm.NewOrm()
  30. lastId, err = o.Insert(item)
  31. return
  32. }
  33. func InsertOrUpdateBaseFromEiaSteoIndex(item *BaseFromEiaSteoIndex) (lastId int64, err error) {
  34. o := orm.NewOrm()
  35. lastId, err = o.InsertOrUpdate(item)
  36. return
  37. }
  38. // Add 新增指标
  39. func (item *BaseFromEiaSteoIndex) Add() (err error) {
  40. o := orm.NewOrm()
  41. lastId, err := o.Insert(item)
  42. if err != nil {
  43. return
  44. }
  45. item.BaseFromEiaSteoIndexId = int(lastId)
  46. return
  47. }
  48. func GetBaseFromEiaSteoIndexAll(dateStr string) (list []*BaseFromEiaSteoIndex, err error) {
  49. o := orm.NewOrm()
  50. sql := `SELECT * FROM base_from_eia_steo_index WHERE create_time>=?`
  51. _, err = o.Raw(sql, dateStr).QueryRows(&list)
  52. return
  53. }
  54. func GetBaseFromEiaSteoIndexCodeListByDate(dateStr string) (list []string, err error) {
  55. o := orm.NewOrm()
  56. sql := `SELECT index_code FROM base_from_eia_steo_index WHERE modify_time>=?`
  57. _, err = o.Raw(sql, dateStr).QueryRows(&list)
  58. return
  59. }
  60. // Update 更新作者基础信息
  61. func (item *BaseFromEiaSteoIndex) Update(cols []string) (err error) {
  62. o := orm.NewOrm()
  63. _, err = o.Update(item, cols...)
  64. return
  65. }
  66. // BaseFromEiaSteoClassify EiaSteo分类
  67. type BaseFromEiaSteoClassify struct {
  68. BaseFromEiaSteoClassifyId int `orm:"column(base_from_eia_steo_classify_id);pk"`
  69. ClassifyName string `description:"分类名称(中文名称)"`
  70. ClassifyNameOriginal string `description:"分类名称(原始名称)"`
  71. ParentId int `description:"父级id"`
  72. Level int `description:"层级"`
  73. ModifyTime time.Time `description:"最新更新时间"`
  74. CreateTime time.Time `description:"创建时间"`
  75. }
  76. // 新增分类
  77. func (item *BaseFromEiaSteoClassify) AddBaseFromEiaSteoClassify() (err error) {
  78. o := orm.NewOrm()
  79. lastId, err := o.Insert(item)
  80. if err != nil {
  81. return
  82. }
  83. item.BaseFromEiaSteoClassifyId = int(lastId)
  84. return
  85. }
  86. // BaseFromEiaSteoData EiaSteo数据表
  87. type BaseFromEiaSteoData struct {
  88. BaseFromEiaSteoDataId int `orm:"column(base_from_eia_steo_data_id);pk"`
  89. BaseFromEiaSteoIndexId int `description:"指标id"`
  90. IndexCode string `description:"指标编码"`
  91. DataTime time.Time `description:"数据日期"`
  92. Value float64 `description:"数据值"`
  93. ModifyTime time.Time `description:"最新更新时间"`
  94. CreateTime time.Time `description:"创建时间"`
  95. }
  96. func (b *BaseFromEiaSteoData) Update(cols []string) (err error) {
  97. o := orm.NewOrm()
  98. _, err = o.Update(b, cols...)
  99. return
  100. }
  101. func AddBaseFromEiaSteoData(item *BaseFromEiaSteoData) (lastId int64, err error) {
  102. o := orm.NewOrm()
  103. lastId, err = o.Insert(item)
  104. return
  105. }
  106. // GetBaseFromEiaSteoClassifyAll 获取所有的分类
  107. func GetBaseFromEiaSteoClassifyAll() (list []*BaseFromEiaSteoClassify, err error) {
  108. o := orm.NewOrm()
  109. sql := `SELECT * FROM base_from_eia_steo_classify`
  110. _, err = o.Raw(sql).QueryRows(&list)
  111. return
  112. }
  113. func AddBaseEiaSteoClassify(item *BaseFromEiaSteoClassify) (lastId int64, err error) {
  114. o := orm.NewOrm()
  115. lastId, err = o.Insert(item)
  116. return
  117. }
  118. func (item *BaseFromEiaSteoClassify) Update(cols []string) (err error) {
  119. o := orm.NewOrm()
  120. _, err = o.Update(item, cols...)
  121. return
  122. }
  123. func BatchDeleteBaseFromEiaSteoClassify(id []int) (err error) {
  124. if len(id) == 0 {
  125. return
  126. }
  127. o := orm.NewOrm()
  128. sql := `DELETE FROM base_from_eia_steo_classify WHERE base_from_eia_steo_classify_id IN (` + utils.GetOrmInReplace(len(id)) + `)`
  129. _, err = o.Raw(sql, id).Exec()
  130. return
  131. }
  132. type EiaSteoIndexResp struct {
  133. Ret int
  134. Msg string
  135. ErrMsg string
  136. ErrCode string
  137. Data []*BaseFromEiaSteoIndex
  138. }
  139. type EiaSteoIndexDataResp struct {
  140. Ret int
  141. Msg string
  142. ErrMsg string
  143. ErrCode string
  144. Data []*BaseFromEiaSteoData
  145. }
  146. type EiaSteoClassifyDataResp struct {
  147. Ret int
  148. Msg string
  149. ErrMsg string
  150. ErrCode string
  151. Data []*BaseFromEiaSteoClassify
  152. }
  153. func GetBaseFromEiaSteoIndexDataAll(dateStr string) (list []*BaseFromEiaSteoData, err error) {
  154. o := orm.NewOrm()
  155. sql := `SELECT * FROM base_from_eia_steo_data WHERE create_time>=?`
  156. _, err = o.Raw(sql, dateStr).QueryRows(&list)
  157. return
  158. }
  159. func GetBaseFromEiaSteoIndexDataByIndexCode(indexCode, dateStr string) (list []*BaseFromEiaSteoData, err error) {
  160. o := orm.NewOrm()
  161. sql := `SELECT * FROM base_from_eia_steo_data WHERE index_code=? AND modify_time>=?`
  162. _, err = o.Raw(sql, indexCode, dateStr).QueryRows(&list)
  163. return
  164. }
  165. func GetBaseFromEiaSteoIndexDataByDate(dateStr string) (list []*BaseFromEiaSteoData, err error) {
  166. o := orm.NewOrm()
  167. sql := `SELECT * FROM base_from_eia_steo_data WHERE modify_time>=?`
  168. _, err = o.Raw(sql, dateStr).QueryRows(&list)
  169. return
  170. }
  171. func GetBaseFromEiaSteoIndexMaxDate() (max_date time.Time, err error) {
  172. o := orm.NewOrm()
  173. sql := ` SELECT max(a.data_time)as max_date FROM base_from_eia_steo_data as a `
  174. err = o.Raw(sql).QueryRow(&max_date)
  175. return
  176. }
  177. func GetBaseFromEiaSteoIndexMaxCreateDate() (max_date time.Time, err error) {
  178. o := orm.NewOrm()
  179. sql := ` SELECT max(a.create_time)as max_date FROM base_from_eia_steo_index as a `
  180. err = o.Raw(sql).QueryRow(&max_date)
  181. return
  182. }