edb_data_calculate.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package data_manage
  2. import (
  3. "eta/eta_mobile/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 AddEdbDataCalculate(items []*EdbDataCalculate) (err error) {
  19. o := orm.NewOrmUsingDB("data")
  20. _, err = o.InsertMulti(1, items)
  21. return
  22. }
  23. func AddEdbDataCalculateBySql(sqlStr string) (err error) {
  24. o := orm.NewOrmUsingDB("data")
  25. _, err = o.Raw(sqlStr).Exec()
  26. return
  27. }
  28. func ModifyEdbDataCalculate(edbInfoId int64, dataTime string, value float64) (err error) {
  29. o := orm.NewOrmUsingDB("data")
  30. sql := ` UPDATE edb_data_calculate 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 GetEdbDataCalculateByCodeAndDate(edbCode string, startDate string) (count int, err error) {
  35. o := orm.NewOrmUsingDB("data")
  36. sql := ` SELECT COUNT(1) AS count FROM edb_data_calculate WHERE edb_code=? AND data_time=? `
  37. err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
  38. return
  39. }
  40. func GetAddSql(edbInfoId, edbCode, dataTime, timestampStr string, value string) (addSql string) {
  41. nowStr := time.Now().Format(utils.FormatDateTime)
  42. addSql += "("
  43. addSql += edbInfoId + "," + "'" + edbCode + "'" + "," + "'" + dataTime + "'" + "," + value + "," + "'" + nowStr + "'" +
  44. "," + "'" + nowStr + "'" + "," + "1"
  45. addSql += "," + "'" + timestampStr + "'"
  46. addSql += "),"
  47. return
  48. }