base_from_sci_hq_data.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "time"
  5. "github.com/beego/beego/v2/client/orm"
  6. )
  7. type BaseFromSciHqData struct {
  8. SciHqDataId int `orm:"column(sci_hq_data_id);pk"`
  9. BaseFromSciHqIndexId int `description:"指标id"`
  10. IndexCode string `description:"指标编码"`
  11. DataTime string `description:"数据日期"`
  12. Value float64 `description:"数据值"`
  13. CreateTime time.Time `description:"创建时间"`
  14. ModifyTime time.Time `description:"修改时间"`
  15. DataTimestamp int64 `description:"数据时间戳"`
  16. }
  17. // GetSciHqDataByIndexId 根据指标id获取指标数据
  18. func GetSciHqDataByIndexId(indexId int) (items []*BaseFromSciHqData, err error) {
  19. o := orm.NewOrmUsingDB("data")
  20. sql := ` SELECT * FROM base_from_sci_hq_data WHERE base_from_sci_hq_index_id=? ORDER BY data_time DESC`
  21. _, err = o.Raw(sql, indexId).QueryRows(&items)
  22. return
  23. }
  24. // GetSciHqDataDataTimeByIndexId 根据指标id获取指标数据的日期列表
  25. func GetSciHqDataDataTimeByIndexId(indexIdList []int) (items []string, err error) {
  26. if len(indexIdList) == 0 {
  27. return
  28. }
  29. o := orm.NewOrmUsingDB("data")
  30. sql := ` SELECT DISTINCT data_time FROM base_from_sci_hq_data WHERE base_from_sci_hq_index_id IN (` + utils.GetOrmInReplace(len(indexIdList)) + `) ORDER BY data_time DESC`
  31. _, err = o.Raw(sql, indexIdList).QueryRows(&items)
  32. return
  33. }
  34. func GetSciHqIndexDataByCode(indexCode string) (items []*BaseFromSciHqData, err error) {
  35. o := orm.NewOrmUsingDB("data")
  36. sql := ` SELECT * FROM base_from_sci_hq_data WHERE index_code=? ORDER BY data_time DESC `
  37. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  38. return
  39. }
  40. func GetSciHqIndexDataCount(indexCode string) (count int, err error) {
  41. o := orm.NewOrmUsingDB("data")
  42. sql := ` SELECT COUNT(1) AS count FROM base_from_sci_hq_data WHERE index_code=? `
  43. err = o.Raw(sql, indexCode).QueryRow(&count)
  44. return
  45. }