package models

import (
	"eta/eta_api/utils"
	"github.com/beego/beego/v2/client/orm"
)

type ResearchReportViewPUV struct {
	ResearchReportId int
	Pv               int
	Uv               int
}

// GetPUVByResearchReportIds 通过报告IDs获取老报告PV、UV
func GetPUVByResearchReportIds(reportIds []string) (list []*ResearchReportViewPUV, err error) {
	if len(reportIds) == 0 {
		return
	}
	o := orm.NewOrmUsingDB("weekly")
	sql := `SELECT
				research_report_id,
				COUNT(1) AS pv,
				COUNT(DISTINCT user_id) AS uv
			FROM
				user_view_history
			WHERE
				research_report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)
			GROUP BY
				research_report_id`
	_, err = o.Raw(sql, reportIds).QueryRows(&list)
	return
}