package cygx

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

type CygxMorningMeetingReviewChapterHistoryResp struct {
	Id               int    `orm:"column(id);pk"`
	ArticleId        int    `description:"文章ID"`
	UserId           int    `description:"用户ID"`
	CreateTime       string `description:"创建时间"`
	Mobile           string `description:"手机号"`
	Email            string `description:"邮箱"`
	CompanyId        int    `description:"公司id"`
	CompanyName      string `description:"公司名称"`
	RealName         string `description:"用户实际名称"`
	SellerName       string `description:"所属销售"`
	SourcePage       string `description:"页面来源 微信、首页、展开"`
	RegisterPlatform int    `description:"来源 1小程序，2：网页"`
	ModifyTime       string `description:"更新时间"`
	MeetingId        int    `description:"晨会ID"`
}

// Pv数据列表
type CygxMorningMeetingReviewChapterHistoryResptListResp struct {
	//Paging *paging.PagingItem `description:"分页数据"`
	List []*CygxMorningMeetingReviewChapterHistoryResp
}

type ListPvUvResp struct {
	ArticleId int `description:"文章ID"`
	Pv        int `description:"pv"`
	Uv        int `description:"pv"`
}

// 列表
func GetCygxMorningMeetingReviewChapterHistoryPvUv(condition string, pars []interface{}) (items []*ListPvUvResp, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT
			COUNT( 1 ) AS pv,
			COUNT( DISTINCT user_id ) AS uv,
			meeting_id  as article_id
		FROM
			cygx_morning_meeting_review_chapter_history  WHERE 1 = 1  `
	if condition != "" {
		sql += condition
	}
	sql += ` GROUP BY meeting_id `
	_, err = o.Raw(sql, pars).QueryRows(&items)
	return
}

// 列表
func GetCygxMorningMeetingReviewChapterHistoryList(condition string, pars []interface{}) (items []*CygxMorningMeetingReviewChapterHistoryResp, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT * FROM cygx_morning_meeting_review_chapter_history as art WHERE 1= 1 `
	if condition != "" {
		sql += condition
	}
	_, err = o.Raw(sql, pars).QueryRows(&items)
	return
}
