user_view_history.go 907 B

123456789101112131415161718192021222324252627282930
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. )
  6. type ResearchReportViewPUV struct {
  7. ResearchReportId int `gorm:"column:research_report_id;primaryKey;type:int" orm:"column(research_report_id);pk" description:"研究报告ID"`
  8. Pv int `gorm:"column:pv;type:int" orm:"column(pv)" description:"页面浏览量"`
  9. Uv int `gorm:"column:uv;type:int" orm:"column(uv)" description:"独立访客数"`
  10. }
  11. func GetPUVByResearchReportIds(reportIds []string) (list []*ResearchReportViewPUV, err error) {
  12. if len(reportIds) == 0 {
  13. return
  14. }
  15. sql := `SELECT
  16. research_report_id,
  17. COUNT(1) AS pv,
  18. COUNT(DISTINCT user_id) AS uv
  19. FROM
  20. user_view_history
  21. WHERE
  22. research_report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)
  23. GROUP BY
  24. research_report_id`
  25. err = global.DmSQL["weekly"].Raw(sql, reportIds).Scan(&list).Error
  26. return
  27. }