base_from_eia_steo.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. }
  27. func AddBaseFromEiaSteoIndex(item *BaseFromEiaSteoIndex) (lastId int64, err error) {
  28. o := orm.NewOrm()
  29. lastId, err = o.Insert(item)
  30. return
  31. }
  32. func InsertOrUpdateBaseFromEiaSteoIndex(item *BaseFromEiaSteoIndex) (lastId int64, err error) {
  33. o := orm.NewOrm()
  34. lastId, err = o.InsertOrUpdate(item)
  35. return
  36. }
  37. // Add 新增指标
  38. func (item *BaseFromEiaSteoIndex) Add() (err error) {
  39. o := orm.NewOrm()
  40. lastId, err := o.Insert(item)
  41. if err != nil {
  42. return
  43. }
  44. item.BaseFromEiaSteoIndexId = int(lastId)
  45. return
  46. }
  47. func GetBaseFromEiaSteoIndexAll(dateStr string) (list []*BaseFromEiaSteoIndex, err error) {
  48. o := orm.NewOrm()
  49. sql := `SELECT * FROM base_from_eia_steo_index WHERE create_time>=?`
  50. _, err = o.Raw(sql, dateStr).QueryRows(&list)
  51. return
  52. }
  53. func GetBaseFromEiaSteoIndexCodeListByDate(dateStr string) (list []string, err error) {
  54. o := orm.NewOrm()
  55. sql := `SELECT index_code FROM base_from_eia_steo_index WHERE modify_time>=?`
  56. _, err = o.Raw(sql, dateStr).QueryRows(&list)
  57. return
  58. }
  59. // Update 更新作者基础信息
  60. func (item *BaseFromEiaSteoIndex) Update(cols []string) (err error) {
  61. o := orm.NewOrm()
  62. _, err = o.Update(item, cols...)
  63. return
  64. }
  65. // BaseFromEiaSteoClassify EiaSteo分类
  66. type BaseFromEiaSteoClassify struct {
  67. BaseFromEiaSteoClassifyId int `orm:"column(base_from_eia_steo_classify_id);pk"`
  68. ClassifyName string `description:"分类名称(中文名称)"`
  69. ClassifyNameOriginal string `description:"分类名称(原始名称)"`
  70. ParentId int `description:"父级id"`
  71. Level int `description:"层级"`
  72. ModifyTime time.Time `description:"最新更新时间"`
  73. CreateTime time.Time `description:"创建时间"`
  74. }
  75. // 新增分类
  76. func (item *BaseFromEiaSteoClassify) AddBaseFromEiaSteoClassify() (err error) {
  77. o := orm.NewOrm()
  78. lastId, err := o.Insert(item)
  79. if err != nil {
  80. return
  81. }
  82. item.BaseFromEiaSteoClassifyId = int(lastId)
  83. return
  84. }
  85. // BaseFromEiaSteoData EiaSteo数据表
  86. type BaseFromEiaSteoData struct {
  87. BaseFromEiaSteoDataId int `orm:"column(base_from_eia_steo_data_id);pk"`
  88. BaseFromEiaSteoIndexId int `description:"指标id"`
  89. IndexCode string `description:"指标编码"`
  90. DataTime time.Time `description:"数据日期"`
  91. Value float64 `description:"数据值"`
  92. ModifyTime time.Time `description:"最新更新时间"`
  93. CreateTime time.Time `description:"创建时间"`
  94. }
  95. func (b *BaseFromEiaSteoData) Update(cols []string) (err error) {
  96. o := orm.NewOrm()
  97. _, err = o.Update(b, cols...)
  98. return
  99. }
  100. func AddBaseFromEiaSteoData(item *BaseFromEiaSteoData) (lastId int64, err error) {
  101. o := orm.NewOrm()
  102. lastId, err = o.Insert(item)
  103. return
  104. }
  105. // GetBaseFromEiaSteoClassifyAll 获取所有的分类
  106. func GetBaseFromEiaSteoClassifyAll() (list []*BaseFromEiaSteoClassify, err error) {
  107. o := orm.NewOrm()
  108. sql := `SELECT * FROM base_from_eia_steo_classify`
  109. _, err = o.Raw(sql).QueryRows(&list)
  110. return
  111. }
  112. func AddBaseEiaSteoClassify(item *BaseFromEiaSteoClassify) (lastId int64, err error) {
  113. o := orm.NewOrm()
  114. lastId, err = o.Insert(item)
  115. return
  116. }
  117. func (item *BaseFromEiaSteoClassify) Update(cols []string) (err error) {
  118. o := orm.NewOrm()
  119. _, err = o.Update(item, cols...)
  120. return
  121. }
  122. func BatchDeleteBaseFromEiaSteoClassify(id []int) (err error) {
  123. if len(id) == 0 {
  124. return
  125. }
  126. o := orm.NewOrm()
  127. sql := `DELETE FROM base_from_eia_steo_classify WHERE base_from_eia_steo_classify_id IN (` + utils.GetOrmInReplace(len(id)) + `)`
  128. _, err = o.Raw(sql, id).Exec()
  129. return
  130. }
  131. type EiaSteoIndexResp struct {
  132. Ret int
  133. Msg string
  134. ErrMsg string
  135. ErrCode string
  136. Data []*BaseFromEiaSteoIndex
  137. }
  138. type EiaSteoIndexDataResp struct {
  139. Ret int
  140. Msg string
  141. ErrMsg string
  142. ErrCode string
  143. Data []*BaseFromEiaSteoData
  144. }
  145. type EiaSteoClassifyDataResp struct {
  146. Ret int
  147. Msg string
  148. ErrMsg string
  149. ErrCode string
  150. Data []*BaseFromEiaSteoClassify
  151. }
  152. func GetBaseFromEiaSteoIndexDataAll(dateStr string) (list []*BaseFromEiaSteoData, err error) {
  153. o := orm.NewOrm()
  154. sql := `SELECT * FROM base_from_eia_steo_data WHERE create_time>=?`
  155. _, err = o.Raw(sql, dateStr).QueryRows(&list)
  156. return
  157. }
  158. func GetBaseFromEiaSteoIndexDataByIndexCode(indexCode, dateStr string) (list []*BaseFromEiaSteoData, err error) {
  159. o := orm.NewOrm()
  160. sql := `SELECT * FROM base_from_eia_steo_data WHERE index_code=? AND modify_time>=?`
  161. _, err = o.Raw(sql, indexCode, dateStr).QueryRows(&list)
  162. return
  163. }
  164. func GetBaseFromEiaSteoIndexDataByDate(dateStr string) (list []*BaseFromEiaSteoData, err error) {
  165. o := orm.NewOrm()
  166. sql := `SELECT * FROM base_from_eia_steo_data WHERE modify_time>=?`
  167. _, err = o.Raw(sql, dateStr).QueryRows(&list)
  168. return
  169. }
  170. func GetBaseFromEiaSteoIndexMaxDate() (max_date time.Time, err error) {
  171. o := orm.NewOrm()
  172. sql := ` SELECT max(a.data_time)as max_date FROM base_from_eia_steo_data as a `
  173. err = o.Raw(sql).QueryRow(&max_date)
  174. return
  175. }
  176. func GetBaseFromEiaSteoIndexMaxCreateDate() (max_date time.Time, err error) {
  177. o := orm.NewOrm()
  178. sql := ` SELECT max(a.create_time)as max_date FROM base_from_eia_steo_index as a `
  179. err = o.Raw(sql).QueryRow(&max_date)
  180. return
  181. }