package models

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

type CygxArticleHistoryRecordAll struct {
	Id             int `orm:"column(id);pk"`
	ArticleId      int
	UserId         int
	CreateTime     string
	ModifyTime     time.Time
	Mobile         string    `description:"手机号"`
	Email          string    `description:"邮箱"`
	CompanyId      int       `description:"公司id"`
	CompanyName    string    `description:"公司名称"`
	StopTime       int       `description:"停留时间"`
	OutType        int       `description:"退出方式，1正常退出，2强制关闭"`
	Source         string    `description:"来源，MOBILE：手机端，PC：电脑端"`
	RealName       string    `description:"用户实际名称"`
	CreateDateApi  time.Time `description:"同步创建时间"`
	CelueHistoryId int       `description:"策略平台记录的ID"`
	Platfor        int       `description:"PV阅读记录来源，1：查研观向，2：策略平台"`
	IsDel          int       `description:"是否删除"`
}

// 获取数量
func GetCygxArticleHistoryRecordAllCountBycondition(condition string, pars []interface{}) (count int, err error) {
	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_article_history_record_all as art WHERE 1= 1  `
	if condition != "" {
		sqlCount += condition
	}
	o := orm.NewOrm()
	err = o.Raw(sqlCount, pars).QueryRow(&count)
	return
}

// 列表
func GetCygxArticleHistoryRecordAllList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxArticleHistoryRecordAll, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM cygx_article_history_record_all as art WHERE 1= 1 `
	if condition != "" {
		sql += condition
	}
	sql += ` LIMIT ?,?  `
	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
	return
}
