package models

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

type DetailCygxMinutesSummaryRep struct {
	ArticleId        int    `description:"报告Id"`
	Title            string `description:"标题"`
	Department       string `description:"作者"`
	PublishDate      string `description:"发布时间"`
	VideoUrl         string `description:"链接"`
	VideoPlaySeconds string `description:"时长"`
	VideoName        string `description:"音频名称"`
	Abstract         string `description:"摘要"`
	VisibleRange     int    `description:"设置可见范围1全部，0内部"`
}

type MinutesSummaryLetailRespV4 struct {
	Detail        *DetailCygxMinutesSummaryRep
	HasPermission int `description:"1:有该行业权限,正常展示，2：无该行业权限，不存在权益客户下，3:无该品类权限,已提交过申请，4：无该行业权限,未提交过申请，5：潜在客户，未提交过申请，6：潜在客户,已提交过申请"`
	List          []*ResearchSummaryChartPermission
	IsShow        bool `description:"是否展示"`
}

type MinutesSummaryLetailResp struct {
	Detail        *DetailCygxMinutesSummaryRep
	HasPermission int `description:"1:有该行业权限,正常展示，2：无该行业权限，不存在权益客户下，3:无该品类权限,已提交过申请，4：无该行业权限,未提交过申请，5：潜在客户，未提交过申请，6：潜在客户,已提交过申请"`
	List          []*MinutesSummaryChartPermission
	IsShow        bool `description:"是否展示"`
}

type MinutesSummaryChartPermission struct {
	PermissionName    string `description:"行业名称"`
	ChartPermissionId int    `description:"行业ID"`
	IcoLink           string `orm:"column(image_url)"description:"图标链接"`
	List              []*CygxMinutesSummaryLogDetail
}

type CygxMinutesSummaryLogDetail struct {
	Body        string `description:"内容"`
	ReportLink  string `orm:"column(link_article_id)"description:"报告链接"`
	VideoUrl    string `description:"链接"`
	IsHaveVideo bool   `description:"是否含有音频文件"`
}
type IndustriaMinutesSummary struct {
	IndustrialManagementId int    `description:"产业Id"`
	IndustryName           string `description:"产业名称"`
}

type MinutesSummaryId struct {
	ArticleId int `description:"报告I"`
}

// 通过纪要ID获取详情
func GetCygxMinutesSummaryInfoById(articleId int) (item *DetailCygxMinutesSummaryRep, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM cygx_minutes_summary  WHERE article_id=? AND publish_status = 1 `
	err = o.Raw(sql, articleId).QueryRow(&item)
	return
}

// 列表
func GetMinutesSummarylogListAllV4(articleId int) (items []*ResearchSummaryChartPermission, err error) {
	o := orm.NewOrm()
	//sql := `SELECT c.permission_name ,c.image_url,l.*
	//		FROM
	//		cygx_minutes_summary_log AS l
	//		INNER JOIN chart_permission AS c ON c.chart_permission_id = l.chart_permission_id
	//		WHERE l.article_id = ?
	//		GROUP BY l.chart_permission_id
	//		ORDER BY l.chart_permission_sort ASC   `
	sql := `SELECT l.* 
			FROM cygx_minutes_summary_log AS l 
			WHERE l.article_id = ? 
			GROUP BY l.type 
			ORDER BY l.sort ASC`
	_, err = o.Raw(sql, articleId).QueryRows(&items)
	return
}

// 列表
func GetMinutesSummarylogListAll(articleId int) (items []*MinutesSummaryChartPermission, err error) {
	o := orm.NewOrm()
	sql := `SELECT l.*
			FROM
			cygx_minutes_summary_log AS l
			WHERE l.article_id = ? 
			GROUP BY l.chart_permission_id
			ORDER BY l.chart_permission_sort ASC   `
	_, err = o.Raw(sql, articleId).QueryRows(&items)
	return
}

// 列表
func GetMinutesSummarylogSonListAll(articleId, chartPermissionId int) (items []*CygxMinutesSummaryLogDetail, err error) {
	o := orm.NewOrm()
	sql := `SELECT   l.link_article_id,l.body ,a.video_url 
			FROM
			cygx_minutes_summary_log AS l
			LEFT JOIN cygx_article as a ON a.article_id = l.link_article_id
			WHERE l.article_id = ? AND l.chart_permission_id =?`
	_, err = o.Raw(sql, articleId, chartPermissionId).QueryRows(&items)
	return
}

// 列表
func GetMinutesSummarylogSonListSecond(articleId int, artType string) (items []*CygxResearchSummaryLogSecond, err error) {
	o := orm.NewOrm()
	sql := `SELECT  l.* 
			FROM
			cygx_minutes_summary_log AS l
			WHERE l.article_id = ? AND l.type =?
			GROUP BY l.chart_permission_id
			ORDER  BY l.chart_permission_sort ASC`
	_, err = o.Raw(sql, articleId, artType).QueryRows(&items)
	return
}

// 列表
func GetMinutesSummarylogListThird(articleId, chartPermissionId int, artType string) (items []*CygxResearchSummaryLogThird, err error) {
	o := orm.NewOrm()
	sql := `SELECT  l.link_article_id,l.body ,a.video_url
			FROM cygx_minutes_summary_log AS l
			LEFT JOIN cygx_article as a ON a.article_id = l.link_article_id
			WHERE l.article_id = ? AND l.type =? AND  l.chart_permission_id = ? 
			ORDER  BY l.chart_permission_sort ASC `
	_, err = o.Raw(sql, articleId, artType, chartPermissionId).QueryRows(&items)
	return
}
