edb_data_wind.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package data_manage
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type EdbDataWind 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. DataTimestamp int64
  16. }
  17. func AddEdbDataWindBySql(sqlStr string) (err error) {
  18. o := orm.NewOrmUsingDB("data")
  19. _, err = o.Raw(sqlStr).Exec()
  20. return
  21. }
  22. func DeleteEdbDataWind(edbCode string) (err error) {
  23. o := orm.NewOrmUsingDB("data")
  24. sql := `DELETE FROM edb_data_wind WHERE edb_code=? `
  25. _, err = o.Raw(sql, edbCode).Exec()
  26. return
  27. }
  28. func ModifyEdbDataWind(edbInfoId int64, dataTime string, value float64) (err error) {
  29. o := orm.NewOrmUsingDB("data")
  30. sql := ` UPDATE edb_data_wind SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
  31. _, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
  32. return
  33. }
  34. func GetEdbDataWindByCode(edbCode string, size int) (items []*EdbInfoSearchData, err error) {
  35. o := orm.NewOrmUsingDB("data")
  36. sql := ` SELECT * FROM edb_data_wind WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
  37. _, err = o.Raw(sql, edbCode, size).QueryRows(&items)
  38. return
  39. }
  40. func GetEdbDataWindMaxOrMinDate(edbCode string) (min_date, max_date string, err error) {
  41. o := orm.NewOrmUsingDB("data")
  42. sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_wind WHERE edb_code=? `
  43. err = o.Raw(sql, edbCode).QueryRow(&min_date, &max_date)
  44. return
  45. }
  46. func GetEdbDataWindByCodeAndDate(edbCode string, startDate string) (count int, err error) {
  47. o := orm.NewOrmUsingDB("data")
  48. sql := ` SELECT COUNT(1) AS count FROM edb_data_wind WHERE edb_code=? AND data_time=? `
  49. err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
  50. return
  51. }
  52. type EdbDataFromWind struct {
  53. Close map[string]float64 `json:"CLOSE"`
  54. Dt map[string]int64 `json:"DT"`
  55. ErrMsg string
  56. }