base_from_eia_steo.go 8.3 KB

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