package chart_theme

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

// ChartThemeType
// @Description: 图表主题类型表
type ChartThemeType struct {
	ChartThemeTypeId    int       `description:"图表主题类型ID" orm:"column(chart_theme_type_id);pk"`
	ChartTypeName       string    `description:"类型名称"`
	ChartType           int       `description:"图表类型"`
	ChartSource         int       `description:"图表来源"`
	DefaultChartThemeId int       `description:"默认使用的主题id"`
	ModifyTime          time.Time `description:"修改时间"`
	CreateTime          time.Time `description:"创建时间"`
}

// Update
// @Description: 更新
// @author: Roc
// @receiver m
// @datetime 2023-12-14 16:11:10
// @param cols []string
// @return err error
func (m *ChartThemeType) Update(cols []string) (err error) {
	o := orm.NewOrmUsingDB("data")
	_, err = o.Update(m, cols...)
	return
}

// GetAllChartThemeTypeList
// @Description: 获取所有图表主题类型列表
// @author: Roc
// @datetime 2023-12-13 17:31:03
// @return list []*ChartThemeType
// @return err error
func GetAllChartThemeTypeList() (list []*ChartThemeType, err error) {
	o := orm.NewOrmUsingDB("data")
	sql := `SELECT * FROM chart_theme_type ORDER BY chart_theme_type_id ASC `
	_, err = o.Raw(sql).QueryRows(&list)

	return
}

// GetChartThemeTypeListBySource
// @Description: 根据来源获取图表主题类型列表
// @author: Roc
// @datetime 2023-12-13 17:31:03
// @param source int
// @return list []*ChartThemeType
// @return err error
func GetChartThemeTypeListBySource(source int) (list []*ChartThemeType, err error) {
	o := orm.NewOrmUsingDB("data")
	sql := `SELECT * FROM chart_theme_type WHERE chart_source = ?  ORDER BY chart_theme_type_id ASC `
	_, err = o.Raw(sql, source).QueryRows(&list)

	return
}

// GetChartThemeTypeById
// @Description: 通过类型id获取类型
// @author: Roc
// @datetime 2023-12-14 09:53:58
// @param chartThemeTypeId int
// @return item *ChartThemeType
// @return err error
func GetChartThemeTypeById(chartThemeTypeId int) (item *ChartThemeType, err error) {
	o := orm.NewOrmUsingDB("data")
	sql := `SELECT * FROM chart_theme_type where chart_theme_type_id = ? `
	err = o.Raw(sql, chartThemeTypeId).QueryRow(&item)

	return
}

// GetChartThemeTypeByChartTypeAndSource
// @Description: 通过图表类型和来源获取类型
// @author: Roc
// @datetime 2023-12-14 09:53:58
// @param chartThemeTypeId int
// @return item *ChartThemeType
// @return err error
func GetChartThemeTypeByChartTypeAndSource(chartType, source int) (item *ChartThemeType, err error) {
	o := orm.NewOrmUsingDB("data")
	sql := `SELECT * FROM chart_theme_type where chart_type = ? AND chart_source = ? `
	err = o.Raw(sql, chartType, source).QueryRow(&item)

	return
}
