package advisory

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

//根据用户id字符串获取用户的浏览数
type UserViewTotalSlice struct {
	UserId      int       `description:"用户id"`
	Total       int       `description:"总阅读数"`
	CreatedTime time.Time `description:"用户浏览时间"`
}

func GetCountUserViewHistoryByUserIds(userIds string) (items []*UserViewTotalSlice, err error) {
	o := orm.NewOrm()
	sql := `SELECT count(1) total,user_id,max(create_time) as created_time FROM advisory_article_view_record WHERE user_id in (` + userIds + `) group by user_id`
	_, err = o.Raw(sql).QueryRows(&items)
	return
	//return items2,err
}

//根据用户手机号字符串获取用户的浏览数
type UserViewMobileTotalSlice struct {
	Mobile      string    `description:"用户手机号"`
	Total       int       `description:"总阅读数"`
	CreatedTime time.Time `description:"用户浏览时间"`
}

func GetCountUserViewHistoryByMobiles(mobiles string) (items []*UserViewMobileTotalSlice, err error) {
	o := orm.NewOrm()
	sql := `SELECT count(1) total,mobile,max(create_time) as created_time FROM advisory_user_chart_article_record WHERE mobile in (` + mobiles + `) group by mobile`
	_, err = o.Raw(sql).QueryRows(&items)
	return
}

//根据用户id字符串获取用户的浏览数
type UserViewEmailTotalSlice struct {
	Email       string    `description:"用户邮箱"`
	Total       int       `description:"总阅读数"`
	CreatedTime time.Time `description:"用户浏览时间"`
}

func GetCountUserViewHistoryByEmails(emails string) (items []*UserViewEmailTotalSlice, err error) {
	o := orm.NewOrm()
	sql := `SELECT count(1) total,email,max(create_time) as created_time FROM advisory_user_chart_article_record WHERE email in (` + emails + `) group by email`
	_, err = o.Raw(sql).QueryRows(&items)
	return
	//return items2,err
}
