edb_data_pb.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package data_manage
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type EdbDataPb struct {
  7. EdbDataId int `orm:"column(edb_data_id);pk"`
  8. EdbInfoId int
  9. EdbCode string
  10. DataTime string
  11. Value float64
  12. Status int
  13. CreateTime time.Time
  14. ModifyTime time.Time
  15. Ticker string
  16. Field string
  17. DataTimestamp int64
  18. }
  19. func AddEdbDataPb(items []*EdbDataPb) (err error) {
  20. o := orm.NewOrmUsingDB("data")
  21. _, err = o.InsertMulti(1, items)
  22. return
  23. }
  24. func ModifyEdbDataPb(edbInfoId int64, edbCode, dataTime string, value float64) (err error) {
  25. o := orm.NewOrmUsingDB("data")
  26. sql := ` UPDATE edb_data_pb SET edb_info_id=?,value=?,status=1,modify_time=NOW() WHERE edb_code=? AND data_time=? `
  27. _, err = o.Raw(sql, edbInfoId, value, edbCode, dataTime).Exec()
  28. return
  29. }
  30. func ModifyEdbDataPbStatus(edbInfoId int64, edbCode string) (err error) {
  31. o := orm.NewOrmUsingDB("data")
  32. sql := ` UPDATE edb_data_pb SET edb_info_id=?, status=1,modify_time=NOW() WHERE edb_code=? `
  33. _, err = o.Raw(sql, edbInfoId, edbCode).Exec()
  34. return
  35. }
  36. func GetEdbDataPbCount(edbCode, dataTime string) (count int, err error) {
  37. o := orm.NewOrmUsingDB("data")
  38. sql := ` SELECT COUNT(1) AS count FROM edb_data_pb WHERE edb_code=? AND data_time=? `
  39. err = o.Raw(sql, edbCode, dataTime).QueryRow(&count)
  40. return
  41. }
  42. func GetEdbDataPbMaxOrMinDate(edbInfoId int) (min_date, max_date string, err error) {
  43. o := orm.NewOrmUsingDB("data")
  44. sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_pb WHERE edb_info_id=? `
  45. err = o.Raw(sql, edbInfoId).QueryRow(&min_date, &max_date)
  46. return
  47. }