edb_data_ths.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package data_manage
  2. import (
  3. "eta_gn/eta_task/global"
  4. "eta_gn/eta_task/utils"
  5. "time"
  6. )
  7. type EdbDataThs 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 AddEdbDataThs(items []*EdbDataThs) (err error) {
  19. //o := orm.NewOrm()
  20. //_, err = o.InsertMulti(1, items)
  21. err = global.DEFAULT_DmSQL.CreateInBatches(items, utils.MultiAddNum).Error
  22. return
  23. }
  24. func ModifyEdbDataThs(edbInfoId int64, edbCode, dataTime string, value float64) (err error) {
  25. //o := orm.NewOrm()
  26. sql := ` UPDATE edb_data_ths 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. err = global.DEFAULT_DmSQL.Exec(sql, edbInfoId, value, edbCode, dataTime).Error
  29. return
  30. }
  31. func GetEdbDataThsCount(ebdCode, dataTime string) (count int, err error) {
  32. //o := orm.NewOrm()
  33. sql := ` SELECT COUNT(1) AS count FROM edb_data_ths WHERE edb_code=? AND data_time=? `
  34. //err = o.Raw(sql, ebdCode, dataTime).QueryRow(&count)
  35. err = global.DEFAULT_DmSQL.Raw(sql, ebdCode, dataTime).Scan(&count).Error
  36. return
  37. }
  38. func GetEdbDataThsMaxOrMinDate(edbInfoId int) (min_date, max_date string, err error) {
  39. //o := orm.NewOrm()
  40. sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_ths WHERE edb_info_id=? `
  41. //err = o.Raw(sql, edbInfoId).QueryRow(&min_date, &max_date)
  42. err = global.DEFAULT_DmSQL.Raw(sql, edbInfoId).First(&min_date, &max_date).Error
  43. return
  44. }