package report_chapter_type

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

type ReportChapterType struct {
	ReportChapterTypeId    uint64    `orm:"column(report_chapter_type_id);pk" description:"报告章节类型id"`
	ReportChapterTypeKey   string    `description:"章节key"`
	ReportChapterTypeThumb string    `description:"H5展示的图片"`
	BannerUrl              string    `description:"banner显示图片"`
	ReportChapterTypeName  string    `description:"报告章节类型名称"`
	Sort                   int       `description:"排序字段"`
	Enabled                int       `description:"启禁用状态"`
	CreatedTime            time.Time `description:"创建时间"`
	LastUpdatedTime        time.Time `description:"更新时间"`
	ResearchType           string    `description:"研报类型"`
	SelectedImage          string    `description:"选中时的图片"`
	UnselectedImage        string    `description:"没选中时的图片"`
	PcSelectedImage        string    `description:"pc选中时的图片"`
	PcUnselectedImage      string    `description:"pc没选中时的图片"`
	EditImgUrl             string    `description:"管理后台编辑时选用的图"`
	TickerTitle            string    `description:"指标列的标题"`
	IsShow                 int       `description:"是否显示"`
	PauseStartTime         time.Time `description:"暂停开始日期"`
	PauseEndTime           time.Time `description:"暂停结束日期"`
	IsSet                  int       `description:"是否设置:0为设置,1已设置"`
	YbIconUrl              string    `description:"研报小程序3.0图标"`
	YbBottomIcon           string    `description:"研报小程序3.0底部菜单图标"`
}

// GetEffectTypes 获取列表数据
func GetEffectTypes() (list []*ReportChapterType, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM report_chapter_type WHERE is_show=?  `
	_, err = o.Raw(sql, 1).QueryRows(&list)
	return
}

// GetEffectTypeID 获取章节id
func GetEffectTypeID() (chapterIds []int, err error) {
	var chapterList []*ReportChapterType
	o := orm.NewOrm()
	sql := `SELECT * FROM report_chapter_type WHERE is_show=? `
	_, err = o.Raw(sql, 1).QueryRows(&chapterList)
	if err != nil {
		return
	}
	if len(chapterList) > 0 {
		for _, v := range chapterList {
			chapterIds = append(chapterIds, int(v.ReportChapterTypeId))
		}
	}
	return
}

// GetTickerTitleByTypeId 根据类型获取指标标题
func GetTickerTitleByTypeId(id int) (chapterType *ReportChapterType, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM report_chapter_type WHERE report_chapter_type_id=? `
	err = o.Raw(sql, id).QueryRow(&chapterType)
	return
}
