package models

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

// ResearchReport 研究报告表（晨报、周报等）结构体
type ResearchReport struct {
	ResearchReportId    int       `orm:"column(research_report_id);pk" description:"研究报告id"`
	ResearchReportName  string    `description:"研究报告名称"`
	ResearchReportTitle string    `description:"研究报告标题"`
	ResearchReportImg   string    `description:"报告缩略图URL"`
	ResearchReportDate  time.Time `description:"报告日期"`
	Type                string    `description:"报告类型，枚举值：day 晨报  week 周报 twoweek双周报 month 月报；默认：day"`
	Author              string    `description:"作者"`
	ReportVariety       string    `description:"研究报告的品种，双周报和月报有标识"`
	IsHasMenu           int8      `description:"报告是否含有目录"`
	IsSendedMsg         int8      `description:"是否发送过模板消息"`
	Periods             int       `description:"期数"`
	Status              string    `description:"状态，draft：草稿，"`
	Enabled             int8      `description:"报告状态"`
	CreatedTime         string    `description:"创建时间"`
	LastUpdatedTime     time.Time `description:"最近一次更新时间"`
	Viewers             int       `description:"H5观看用户数"`
}

// GetResearchReportListByIds 根据报告id集合获取报告数据列表
func GetResearchReportListByIds(researchReportIds string) (list []*ResearchReport, err error) {
	if researchReportIds == "" {
		return
	}
	o := orm.NewOrm()
	sql := `select * from research_report where research_report_id in (` + researchReportIds + `)`
	_, err = o.Raw(sql).QueryRows(&list)
	return
}

// GetResearchReportListByIdList 根据报告id集合获取报告数据列表
func GetResearchReportListByIdList(researchReportIdList []int) (list []*ResearchReport, err error) {
	num := len(researchReportIdList)
	if num <= 0 {
		return
	}

	o := orm.NewOrm()
	sql := `select * from research_report where research_report_id in (` + utils.GetOrmInReplace(num) + `)`
	_, err = o.Raw(sql, researchReportIdList).QueryRows(&list)
	return
}

// Update 更新数据
func (researchReport *ResearchReport) Update(updateCols []string) (err error) {
	o := orm.NewOrm()
	_, err = o.Update(researchReport, updateCols...)
	return
}

type ResearchReportList struct {
	ResearchReportId    int       `orm:"column(research_report_id);pk" description:"研究报告id"`
	ResearchReportName  string    `description:"研究报告名称"`
	ResearchReportTitle string    `description:"研究报告标题"`
	ResearchReportImg   string    `description:"报告缩略图URL"`
	ResearchReportDate  time.Time `description:"报告日期"`
	Type                string    `description:"报告类型，枚举值：day 晨报  week 周报 twoweek双周报 month 月报；默认：day"`
	Author              string    `description:"作者"`
	ReportVariety       string    `description:"研究报告的品种，双周报和月报有标识"`
	IsHasMenu           int8      `description:"报告是否含有目录"`
	IsSendedMsg         int8      `description:"是否发送过模板消息"`
	Periods             int       `description:"期数"`
	Status              string    `description:"状态，draft：草稿，"`
	Enabled             int8      `description:"报告状态"`
	CreatedTime         string    `description:"创建时间"`
	LastUpdatedTime     time.Time `description:"最近一次更新时间"`
	Viewers             int       `description:"H5观看用户数"`
	LinkUrl             string    `description:"报告阅读地址"`
}
