package cygx

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

type CygxResearchSummaryLog struct {
	ArticleSunId        int       `orm:"column(article_sun_id);pk"description:"子级报告id"`
	ArticleId           int       `description:"父级报告Id"`
	Type                string    `description:"类型'SDBG：深度报告片篇,’CYDYJY：产业调研纪要’,’SJDP：事件点评,’BZCHJH：本周晨会精华’"`
	Sort                string    `description:"排序"`
	ChartPermissionId   int       `description:"行业ID"`
	ChartPermissionSort string    `description:"行业排序"`
	CreateTime          time.Time `description:"创建时间"`
	Body                string    `description:"内容"`
	ReportLink          string    `description:"报告链接"`
	LinkArticleId       int       `description:"报告ID链接"`
}

type CygxResearchSummaryLogRep struct {
	Sort                string `description:"排序"`
	ChartPermissionId   int    `description:"行业ID"`
	ChartPermissionName string `description:"行业名称"`
	ChartPermissionSort string `description:"行业排序"`
	Body                string `description:"内容"`
	ReportLink          string `description:"报告链接"`
	IcoLink             string `description:"图标链接"`
}

type AddCygxResearchSummaryLog struct {
	Body                string `description:"内容"`
	ReportLink          string `description:"报告链接"`
	ChartPermissionSort string `description:"行业排序"`
}

type CygxRSlChartPermission struct {
	ChartPermissionId   int    `description:"行业ID"`
	ChartPermissionSort string `description:"行业排序"`
	List                []*AddCygxResearchSummaryLog
}

type CygxChartPermissionName struct {
	ChartPermissionName string `description:"行业名称"`
}

type CygxRSlChartPermissionIco struct {
	ChartPermissionId   int    `description:"行业ID"`
	ChartPermissionName string `description:"行业名称"`
	ChartPermissionSort string `description:"行业排序"`
	IcoLink             string `description:"图标链接"`
	List                []*AddCygxResearchSummaryLog
}

type CygxRSlChartPermissionIcoTmp struct {
	ChartPermissionId   int    `description:"行业ID"`
	ChartPermissionName string `description:"行业名称"`
	ChartPermissionSort string `description:"行业排序"`
	IcoLink             string `description:"图标链接"`
	BodyChartSummary    string `description:"内容"`
	List                []string
	//List                make([]string, 0)
}

type CygxRSlChartPermissionIcoTmpList struct {
	List []*CygxRSlChartPermissionIcoTmp
}

type CygxRSlFirstList struct {
	ListSdbg   []*CygxRSlChartPermission    `description:"类型——’SDBG：深度报告片篇’"`
	SortSdbg   string                       `description:"深度报告排序"`
	ListCydyjy []*CygxRSlChartPermission    `description:"类型——’CYDYJY：产业调研纪要’"`
	SortCydyjy string                       `description:"产业调研纪要排序"`
	ListSsgs   []*CygxRSlChartPermission    `description:"类型——’SSGS：上市公司调研纪要篇’"`
	SortSsgs   string                       `description:"上市公司调研纪要篇排序"`
	ListSjdp   []*AddCygxResearchSummaryLog `description:"类型——’SJDP：事件点评"`
	SortSjdp   string                       `description:"事件点评排序"`
	ListBzchjh []*CygxRSlChartPermission    `description:"类型——’BZCHJH：本周晨会精华’"`
	SortBzchjh string                       `description:"本周晨会精华排序"`
	SortYanx   string                       `description:"研选排序"`
	ListYanx   []*CygxRSlChartPermission    `description:"类型——’YANX：研选’"`
}

func GetCygxResearchSummaryLogRepList(articleId int, typeStr string) (items []*CygxResearchSummaryLogRep, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT l.*
			FROM cygx_research_summary_log AS l
			WHERE  1= 1 AND article_id=?  AND type =? GROUP BY l.chart_permission_id `
	_, err = o.Raw(sql, articleId, typeStr).QueryRows(&items)
	return
}

func GetCygxResearchSummaryLogRepListSon(articleId, chartPermissionId int, typeStr string) (items []*AddCygxResearchSummaryLog, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT l.* FROM cygx_research_summary_log AS l
			WHERE  1= 1 AND l.article_id=?  AND l.chart_permission_id =? AND l.type =?  `
	_, err = o.Raw(sql, articleId, chartPermissionId, typeStr).QueryRows(&items)
	return
}

func GetCygxResearchSummarySjdpList(articleId int, typeStr string) (items []*AddCygxMinutesSummaryLog, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT l.* FROM cygx_research_summary_log AS l
			WHERE  1= 1 AND l.article_id=? AND l.type =?  `
	_, err = o.Raw(sql, articleId, typeStr).QueryRows(&items)
	return
}

type RSList []*CygxRSlChartPermissionIco

func (m RSList) Len() int {
	return len(m)
}

func (m RSList) Less(i, j int) bool {
	return m[i].ChartPermissionSort < m[j].ChartPermissionSort
}

func (m RSList) Swap(i, j int) {
	m[i], m[j] = m[j], m[i]
}
