edb_data_calculate.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type EdbDataCalculate 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 AddEdbDataCalculateBySql(sqlStr string) (err error) {
  19. o := orm.NewOrmUsingDB("data")
  20. _, err = o.Raw(sqlStr).Exec()
  21. return
  22. }
  23. func ModifyEdbDataCalculate(edbInfoId int64, dataTime string, value float64) (err error) {
  24. o := orm.NewOrmUsingDB("data")
  25. sql := ` UPDATE edb_data_calculate 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 GetEdbDataCalculateByCodeAndDate(edbCode string, startDate string) (count int, err error) {
  30. o := orm.NewOrmUsingDB("data")
  31. sql := ` SELECT COUNT(1) AS count FROM edb_data_calculate WHERE edb_code=? AND data_time=? `
  32. err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
  33. return
  34. }
  35. func GetAddSql(edbInfoId, edbCode, dataTime, timestampStr string, value string) (addSql string) {
  36. nowStr := time.Now().Format(utils.FormatDateTime)
  37. addSql += "("
  38. addSql += edbInfoId + "," + "'" + edbCode + "'" + "," + "'" + dataTime + "'" + "," + value + "," + "'" + nowStr + "'" +
  39. "," + "'" + nowStr + "'" + "," + "1"
  40. addSql += "," + "'" + timestampStr + "'"
  41. addSql += "),"
  42. return
  43. }