package models

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

type CygxArticleType struct {
	ArticleTypeId      int       `orm:"column(article_type_id);pk";description:"文章类型ID"`
	ArticleTypeName    string    `description:"类型名称"`
	Sort               int       `description:"排序字段"`
	CreateTime         time.Time `description:"创建时间"`
	ModifyTime         time.Time `description:"最后修改时间"`
	IsSendEs           int       `description:"这种报告类型是否同步到Es"`
	YanxPermissionId   int       `description:"研选类型所对应的ID"`
	YanxPermissionName string    `description:"研选类型所对应的名称"`
	IcoLink            string    `description:"图标链接地址"`
	IcoLinkM           string    `description:"移动端图标链接地址"`
	IsShowLinkButton   int       `description:"这种报告类型是否展示查看报告链接"`
	ButtonStyle        string    `description:"按钮展示样式"`
}

type CygxArticleTypeResp struct {
	ArticleTypeId   int    `description:"文章类型ID"`
	ArticleTypeName string `description:"类型名称"`
	ButtonStyle     string `description:"按钮展示样式"`
}

type CygxArticleTypeListResp struct {
	List []*CygxArticleTypeResp
}

// 详情
func GetCygxArticleTypeDetailById(activityTypeId int) (item *CygxArticleType, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM cygx_article_type WHERE article_type_id = ? `
	err = o.Raw(sql, activityTypeId).QueryRow(&item)
	return
}

// 获取数量
func GetCygxArticleTypeCount(condition string) (count int, err error) {
	o := orm.NewOrm()
	sqlCount := `SELECT COUNT(1) AS count  FROM cygx_article_type WHERE  1=1 ` + condition
	err = o.Raw(sqlCount).QueryRow(&count)
	return
}

// 报告类型列表
func GetCygxArticleTypeList() (items []*CygxArticleType, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM cygx_article_type ORDER BY sort DESC`
	_, err = o.Raw(sql).QueryRows(&items)
	return
}

// 报告类型列表
func GetCygxArticleTypeListCondition(condition string) (items []*CygxArticleType, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM cygx_article_type   WHERE  1=1 ` + condition + ` ORDER BY sort DESC`
	_, err = o.Raw(sql).QueryRows(&items)
	return
}

func GetArticleTypeInfo(activityTypeId int) (item *CygxArticleType, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM cygx_article_type   WHERE  article_type_id=? `
	err = o.Raw(sql, activityTypeId).QueryRow(&item)
	return
}
