stats.go 895 B

12345678910111213141516171819202122232425262728293031
  1. package archive
  2. import (
  3. "context"
  4. "go-common/app/admin/main/videoup/model/archive"
  5. "go-common/library/log"
  6. "time"
  7. )
  8. const (
  9. _statsPointSQL = "SELECT id,type,content,ctime,mtime FROM archive_report_sum WHERE mtime>=? AND mtime<? AND type=?"
  10. )
  11. // StatsPoints get archive_report_sum data by type and time
  12. func (d *Dao) StatsPoints(c context.Context, stime, etime time.Time, typeInt int8) (points []*archive.StatsPoint, err error) {
  13. rows, err := d.rddb.Query(c, _statsPointSQL, stime, etime, typeInt)
  14. if err != nil {
  15. log.Error("d.StatsPoints.Query(%v,%v,%v) error(%v)", stime, etime, typeInt, err)
  16. return
  17. }
  18. defer rows.Close()
  19. for rows.Next() {
  20. point := &archive.StatsPoint{}
  21. if err = rows.Scan(&point.ID, &point.Type, &point.Content, &point.Ctime, &point.Mtime); err != nil {
  22. log.Error("rows.Scan error(%v)", err)
  23. return
  24. }
  25. points = append(points, point)
  26. }
  27. return
  28. }