edb_data_calculate_stl.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package stl
  2. import (
  3. "eta/eta_api/utils"
  4. "time"
  5. "github.com/beego/beego/v2/client/orm"
  6. )
  7. type EdbDataCalculateStl struct {
  8. EdbDataId int `orm:"pk"`
  9. EdbInfoId int `description:"指标id"`
  10. EdbCode string `description:"指标编码"`
  11. DataTime time.Time `description:"数据时间"`
  12. Value float64 `description:"数据值"`
  13. CreateTime time.Time `description:"创建时间"`
  14. ModifyTime time.Time `description:"修改时间"`
  15. DataTimestamp int64 `description:"数据时间戳"`
  16. }
  17. func GetEdbDataCalculateStlByEdbCode(edbCode string) (items []*EdbDataCalculateStl, err error) {
  18. o := orm.NewOrmUsingDB("data")
  19. sql := `SELECT * FROM edb_data_calculate_stl WHERE edb_code =? ORDER BY data_time`
  20. _, err = o.Raw(sql, edbCode).QueryRows(&items)
  21. return
  22. }
  23. func DeleteAndInsertEdbDataCalculateStl(edbCode string, dataList []*EdbDataCalculateStl) (err error) {
  24. tx, err := orm.NewOrmUsingDB("data").Begin()
  25. if err != nil {
  26. return
  27. }
  28. defer func() {
  29. if err != nil {
  30. tx.Rollback()
  31. } else {
  32. tx.Commit()
  33. }
  34. }()
  35. sql := `DELETE FROM edb_data_calculate_stl WHERE edb_code =?`
  36. _, err = tx.Raw(sql, edbCode).Exec()
  37. if err != nil {
  38. return
  39. }
  40. _, err = tx.InsertMulti(utils.MultiAddNum, dataList)
  41. return
  42. }
  43. func (m *EdbDataCalculateStl) GetMaxId() (maxId int, err error) {
  44. o := orm.NewOrmUsingDB("data")
  45. sql := `SELECT max(edb_data_id) id FROM edb_data_calculate_stl limit 1`
  46. err = o.Raw(sql).QueryRow(&maxId)
  47. return
  48. }
  49. func (m *EdbDataCalculateStl) BatchInsert(dataList []*EdbDataCalculateStl) (err error) {
  50. o := orm.NewOrmUsingDB("data")
  51. _, err = o.InsertMulti(utils.MultiAddNum, dataList)
  52. return
  53. }