edb_data_ths.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package data_manage
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type EdbDataThs 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 AddEdbDataThs(items []*EdbDataThs) (err error) {
  18. o := orm.NewOrm()
  19. _, err = o.InsertMulti(1, items)
  20. return
  21. }
  22. func ModifyEdbDataThs(edbInfoId int64, edbCode, dataTime string, value float64) (err error) {
  23. o := orm.NewOrm()
  24. sql := ` UPDATE edb_data_ths SET edb_info_id=?,value=?,status=1,modify_time=NOW() WHERE edb_code=? AND data_time=? `
  25. _, err = o.Raw(sql, edbInfoId, value, edbCode, dataTime).Exec()
  26. return
  27. }
  28. func GetEdbDataThsCount(ebdCode, dataTime string) (count int, err error) {
  29. o := orm.NewOrm()
  30. sql := ` SELECT COUNT(1) AS count FROM edb_data_ths WHERE edb_code=? AND data_time=? `
  31. err = o.Raw(sql, ebdCode, dataTime).QueryRow(&count)
  32. return
  33. }
  34. func GetEdbDataThsMaxOrMinDate(edbInfoId int) (min_date, max_date string, err error) {
  35. o := orm.NewOrm()
  36. sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_ths WHERE edb_info_id=? `
  37. err = o.Raw(sql, edbInfoId).QueryRow(&min_date, &max_date)
  38. return
  39. }