base_from_eia_steo.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package data_manage
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // BaseFromEiaSteoIndex EiaSteo指标
  7. type BaseFromEiaSteoIndex struct {
  8. BaseFromEiaSteoIndexId int `orm:"column(base_from_eia_steo_index_id);pk"`
  9. BaseFromEiaSteoClassifyId int `description:"指标分类id"`
  10. IndexCode string `description:"指标编码"`
  11. IndexName string `description:"指标名称(中文名称)"`
  12. IndexNameOriginal string `description:"指标名称(原始名称)"`
  13. Frequency string `description:"频度"`
  14. Level int `description:"指标层级(原始层级)"`
  15. Unit string `description:"单位"`
  16. Super string `description:"我也不知道是个啥,反正先存起来,万一用到了呢"`
  17. Precision int `description:"精度,我也不知道会不会用到,反正先存起来,万一用到了呢"`
  18. LastHistorical string `description:"最近的历史记录,我也不知道会不会用到,反正先存起来,万一用到了呢"`
  19. Description string `description:"备注信息,我也不知道会不会用到,反正先存起来,万一用到了呢"`
  20. IsMappable int `description:"是否可映射,我也不知道会不会用到,反正先存起来,万一用到了呢"`
  21. StartDate string `description:"开始日期"`
  22. EndDate string `description:"结束日期"`
  23. ModifyTime string `description:"最新更新时间"`
  24. CreateTime string `description:"创建时间"`
  25. }
  26. func AddBaseFromEiaSteoIndex(item *BaseFromEiaSteoIndex) (lastId int64, err error) {
  27. o := orm.NewOrm()
  28. lastId, err = o.Insert(item)
  29. return
  30. }
  31. func InsertOrUpdateBaseFromEiaSteoIndex(item *BaseFromEiaSteoIndex) (lastId int64, err error) {
  32. o := orm.NewOrm()
  33. lastId, err = o.InsertOrUpdate(item)
  34. return
  35. }
  36. // Add 新增指标
  37. func (item *BaseFromEiaSteoIndex) Add() (err error) {
  38. o := orm.NewOrm()
  39. lastId, err := o.Insert(item)
  40. if err != nil {
  41. return
  42. }
  43. item.BaseFromEiaSteoIndexId = int(lastId)
  44. return
  45. }
  46. func GetBaseFromEiaSteoIndexAll(dateStr string) (list []*BaseFromEiaSteoIndex, err error) {
  47. o := orm.NewOrm()
  48. sql := `SELECT * FROM base_from_eia_steo_index WHERE create_time>=?`
  49. _, err = o.Raw(sql, dateStr).QueryRows(&list)
  50. return
  51. }
  52. // Update 更新作者基础信息
  53. func (item *BaseFromEiaSteoIndex) Update(cols []string) (err error) {
  54. o := orm.NewOrm()
  55. _, err = o.Update(item, cols...)
  56. return
  57. }
  58. // BaseFromEiaSteoClassify EiaSteo分类
  59. type BaseFromEiaSteoClassify struct {
  60. BaseFromEiaSteoClassifyId int `orm:"column(base_from_eia_steo_classify_id);pk"`
  61. ClassifyName string `description:"分类名称(中文名称)"`
  62. ClassifyNameOriginal string `description:"分类名称(原始名称)"`
  63. ModifyTime time.Time `description:"最新更新时间"`
  64. CreateTime time.Time `description:"创建时间"`
  65. }
  66. // 新增分类
  67. func (item *BaseFromEiaSteoClassify) AddBaseFromEiaSteoClassify() (err error) {
  68. o := orm.NewOrm()
  69. lastId, err := o.Insert(item)
  70. if err != nil {
  71. return
  72. }
  73. item.BaseFromEiaSteoClassifyId = int(lastId)
  74. return
  75. }
  76. // BaseFromEiaSteoData EiaSteo数据表
  77. type BaseFromEiaSteoData struct {
  78. BaseFromEiaSteoDataId int `orm:"column(base_from_eia_steo_data_id);pk"`
  79. BaseFromEiaSteoIndexId int `description:"指标id"`
  80. IndexCode string `description:"指标编码"`
  81. DataTime time.Time `description:"数据日期"`
  82. Value float64 `description:"数据值"`
  83. ModifyTime time.Time `description:"最新更新时间"`
  84. CreateTime time.Time `description:"创建时间"`
  85. }
  86. func AddBaseFromEiaSteoData(item *BaseFromEiaSteoData) (lastId int64, err error) {
  87. o := orm.NewOrm()
  88. lastId, err = o.Insert(item)
  89. return
  90. }
  91. // GetBaseFromEiaSteoClassifyAll 获取所有的分类
  92. func GetBaseFromEiaSteoClassifyAll() (list []*BaseFromEiaSteoClassify, err error) {
  93. o := orm.NewOrm()
  94. sql := `SELECT * FROM base_from_eia_steo_classify`
  95. _, err = o.Raw(sql).QueryRows(&list)
  96. return
  97. }
  98. type EiaSteoIndexResp struct {
  99. Ret int
  100. Msg string
  101. ErrMsg string
  102. ErrCode string
  103. Data []*BaseFromEiaSteoIndex
  104. }
  105. type EiaSteoIndexDataResp struct {
  106. Ret int
  107. Msg string
  108. ErrMsg string
  109. ErrCode string
  110. Data []*BaseFromEiaSteoData
  111. }
  112. func GetBaseFromEiaSteoIndexDataAll(dateStr string) (list []*BaseFromEiaSteoData, err error) {
  113. o := orm.NewOrm()
  114. sql := `SELECT * FROM base_from_eia_steo_data WHERE create_time>=?`
  115. _, err = o.Raw(sql, dateStr).QueryRows(&list)
  116. return
  117. }
  118. func GetBaseFromEiaSteoIndexMaxDate() (max_date time.Time, err error) {
  119. o := orm.NewOrm()
  120. sql := ` SELECT max(a.data_time)as max_date FROM base_from_eia_steo_data as a `
  121. err = o.Raw(sql).QueryRow(&max_date)
  122. return
  123. }