ebd_data_ly.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Package models
  2. // @Author gmy 2024/8/14 19:40:00
  3. package models
  4. import "github.com/beego/beego/v2/client/orm"
  5. type EdbDataLy struct {
  6. edbDataId int `orm:"column(edb_data_id);pk"` // 数据ID
  7. CreateTime string `orm:"column(create_time)"` // 创建时间
  8. ModifyTime string `orm:"column(modify_time)"` // 修改时间
  9. EdbInfoId int `orm:"column(edb_info_id)"` // 指标id
  10. EdbCode string `orm:"column(edb_code)"` // 指标编码
  11. DataTime string `orm:"column(data_time)"` // 数据日期
  12. Value float64 `orm:"column(value)"` // 数据值
  13. DataTimestamp uint64 `orm:"column(data_timestamp)"` // 数据日期时间戳
  14. }
  15. func GetLyEdbDataByIndexCodeAndDataTime(indexCode string, dataTime string) (items []EdbDataLy, err error) {
  16. o := orm.NewOrmUsingDB("data")
  17. sql := `SELECT * FROM edb_data_ly WHERE index_code=? AND data_time like ?`
  18. _, err = o.Raw(sql, indexCode, dataTime+"%").QueryRows(&items)
  19. return
  20. }
  21. func GetLyEdbDataByIndexCodeAndExactDataTime(indexCode string, dataTime string) (items []EdbDataLy, err error) {
  22. o := orm.NewOrmUsingDB("data")
  23. sql := `SELECT * FROM edb_data_ly WHERE edb_code=? AND data_time=?`
  24. _, err = o.Raw(sql, indexCode, dataTime).QueryRows(&items)
  25. return
  26. }
  27. // UpdateLyEdbDataById 更新指标库数据 须根据指标编码和日期更新 仅适合月度数据
  28. func UpdateLyEdbDataById(id int, value float64) (err error) {
  29. o := orm.NewOrmUsingDB("data")
  30. sql := `UPDATE edb_data_ly SET value=? WHERE edb_data_id=?`
  31. _, err = o.Raw(sql, value, id).Exec()
  32. return
  33. }