base_from_changes_visitors_covid.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // 谷歌出行指数
  7. type BaseFromChangesVisitorsCovid struct {
  8. Id uint64 `orm:"column(id);pk"` //序号
  9. Entity string `orm:"column(entity)"` //国家
  10. Code string `orm:"column(code)"` //国家编码
  11. EdbCode string `orm:"column(edb_code)"` //指标ID
  12. Day time.Time `orm:"column(day)"` //统计的日期
  13. RetailAndRecreation string `orm:"column(retail_and_recreation)"`
  14. GroceryAndPharmacy string `orm:"column(grocery_and_pharmacy)"`
  15. Residential string `orm:"column(residential)"`
  16. TransitStations string `orm:"column(transit_stations)"`
  17. Parks string `orm:"column(parks)"`
  18. Workplaces string `orm:"column(workplaces)"`
  19. Total string `orm:"column(total)"`
  20. CreateTime time.Time `orm:"auto_now_add;column(create_time)"` //创建时间
  21. ModifyTime time.Time `orm:"auto_now_add;column(modify_time)"` //修改时间
  22. }
  23. // AddBaseFromChangesVisitorsCovidMulti 批量添加谷歌出行记录
  24. func AddBaseFromChangesVisitorsCovidMulti(list []*BaseFromChangesVisitorsCovid) (err error) {
  25. o := orm.NewOrmUsingDB("data")
  26. _, err = o.InsertMulti(1000, list)
  27. return
  28. }
  29. // GetLatestBaseFromChangesVisitorsCovid 查询最新的日期
  30. func GetLatestBaseFromChangesVisitorsCovid() (item *BaseFromChangesVisitorsCovid, err error) {
  31. o := orm.NewOrmUsingDB("data")
  32. sql := `SELECT * FROM base_from_changes_visitors_covid order by day desc, id desc limit 1`
  33. err = o.Raw(sql).QueryRow(&item)
  34. return
  35. }
  36. // GetBaseFromChangesVisitorsCovidByEntityDay 查询国家和统计日期查询记录是否存在
  37. func GetBaseFromChangesVisitorsCovidByEntityDay(entity, day string) (item *BaseFromChangesVisitorsCovid, err error) {
  38. o := orm.NewOrmUsingDB("data")
  39. sql := `SELECT * FROM base_from_changes_visitors_covid where entity=? and day=? limit 1`
  40. err = o.Raw(sql, entity, day).QueryRow(&item)
  41. return
  42. }