package models

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

type CygxTemplateRecordSource struct {
	TemplateId int       `orm:"column(template_id);pk"`
	UserId     int       `description:"用户ID"`
	SourceId   int       `description:"资源ID"`
	Source     string    `description:"资源类型 报告 ：article 、图表 ：newchart、活动 ：activity、活动视频：activityvideo、活动音频：activityvoice"`
	CreateTime time.Time `description:"创建时间"`
}

// 添加
func AddCygxTemplateRecordSource(item *CygxTemplateRecordSource) (err error) {
	o := orm.NewOrm()
	_, err = o.Insert(item)
	return
}

// 获取数量
func GetCygxTemplateRecordSourceCount(userId, sourceId int, source, startDate, endDate string) (count int, err error) {
	sqlCount := `SELECT COUNT(1) AS count FROM cygx_template_record_source    WHERE  user_id = ? AND  source_id = ?  AND  source = ?  AND  create_time >= ?  AND  create_time < ?      `
	o := orm.NewOrm()
	err = o.Raw(sqlCount, userId, sourceId, source, startDate, endDate).QueryRow(&count)
	return
}
