package models

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

// SearchKeyWord 搜索关键词
type SearchKeyWord struct {
	SearchKeyWordId     int       `orm:"column(search_key_word_id)" description:"主键ID"`
	KeyWord             string    `description:"关键词"`
	From                string    `description:"来源,在什么地方筛选"`
	CreatedTime         time.Time `description:"创建时间"`
	LastUpdatedTime     time.Time `description:"更新时间"`
	TeleconferenceImage string    `description:"电话会对应的类型图片"`
	BannerImage         string    `description:"Banner图"`
}

// AddTrendTagKeyWord 新增趋势标签关键词
func AddTrendTagKeyWord(trend string) (err error) {
	o := orm.NewOrm()
	sql := " REPLACE INTO search_key_word (`key_word`,`from`) values (?,'trend') "
	_, err = o.Raw(sql, trend).Exec()

	return
}

// GetKeyWordListByFrom 根据来源获取搜索关键词列表
func GetKeyWordListByFrom(from string) (list []*SearchKeyWord, err error) {
	o := orm.NewOrm()
	sql := " SELECT * FROM search_key_word WHERE `from` = ? ORDER BY created_time ASC "
	_, err = o.Raw(sql, from).QueryRows(&list)

	return
}