edb_data_fubao.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package data_manage
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. //富宝数据
  7. type EdbDataFubao struct {
  8. EdbDataId int `orm:"column(edb_data_id);pk"`
  9. EdbInfoId int
  10. EdbCode string
  11. DataTime string
  12. Value float64
  13. Status int
  14. CreateTime time.Time
  15. ModifyTime time.Time
  16. DataTimestamp int64
  17. }
  18. func AddEdbDataFubaoBySql(sqlStr string) (err error) {
  19. o := orm.NewOrmUsingDB("data")
  20. _, err = o.Raw(sqlStr).Exec()
  21. return
  22. }
  23. func ModifyEdbDataFubao(edbInfoId int64, dataTime string, value float64) (err error) {
  24. o := orm.NewOrmUsingDB("data")
  25. sql := ` UPDATE edb_data_ths SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
  26. _, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
  27. return
  28. }
  29. func GetEdbDataFubaoMaxOrMinDate(edbCode string) (min_date, max_date string, err error) {
  30. o := orm.NewOrmUsingDB("data")
  31. sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_ths WHERE edb_code=? `
  32. err = o.Raw(sql, edbCode).QueryRow(&min_date, &max_date)
  33. return
  34. }
  35. func GetEdbDataFubaoByCodeAndDate(edbCode string, startDate string) (count int, err error) {
  36. o := orm.NewOrmUsingDB("data")
  37. sql := ` SELECT COUNT(1) AS count FROM edb_data_ths WHERE edb_code=? AND data_time=? `
  38. err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
  39. return
  40. }
  41. func GetEdbDataFubaoByCode(edbCode string, size int) (items []*EdbInfoSearchData, err error) {
  42. o := orm.NewOrmUsingDB("data")
  43. sql := ` SELECT * FROM edb_data_ths WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
  44. _, err = o.Raw(sql, edbCode, size).QueryRows(&items)
  45. return
  46. }
  47. type EdbDataFromFubao struct {
  48. DataVol int64 `json:"dataVol"`
  49. Errmsg string `json:"errmsg"`
  50. Errorcode int64 `json:"errorcode"`
  51. Perf interface{} `json:"perf"`
  52. Tables []struct {
  53. ID []string `json:"id"`
  54. Time []string `json:"time"`
  55. Value []float64 `json:"value"`
  56. } `json:"tables"`
  57. }