package models

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

type CygxTacticsTimeLine struct {
	TimeLineId  int       `orm:"column(time_line_id);pk"`
	PublishTime time.Time `description:"发布日期"`
	CreateTime  time.Time `description:"创建时间"`
	ModifyTime  time.Time `description:"更新时间"`
	Status      int       `description:"0:未发布，1:已发布"`
	Content     string    `description:"内容"`
	ArticleId   int       `description:"文章ID"`
	ChartId     int       `description:"图表ID"`
	Link        string    `description:"文章或图表链接"`
	AdminId     int       `description:"管理员ID"`
}

type AddTacticsTimeLineReq struct {
	TimeLineId  int    `orm:"column(time_line_id);pk"`
	PublishTime string `description:"发布日期"`
	Content     string `description:"内容"`
	Link        string `description:"文章或图表链接"`
}
type TacticsTimeLineTimeLineIdReq struct {
	TimeLineId int `description:"ID"`
}

type GetCygxTacticsTimeLineResp struct {
	Status int                `description:"0:内部可见，1:全部可见"`
	Paging *paging.PagingItem `description:"分页数据"`
	List   []*CygxTacticsTimeLineResp
}

type CygxTacticsTimeLineResp struct {
	TimeLineId          int    `description:"ID"`
	PublishTime         string `description:"发布日期"`
	Status              int    `description:"0:未发布，1:已发布"`
	Content             string `description:"内容"`
	ArticleId           int    `description:"文章ID"`
	ChartId             int    `description:"图表ID"`
	Link                string `description:"文章或图表链接"`
	Resource            int    `description:"来源类型，1：文章、2：产品内测、3：晨报点评"`
	ChartPermissionName string `description:"行业名称"`
}

// 获取数量
func GetCygxTacticsTimeLineCount(condition string, pars []interface{}) (count int, err error) {
	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_tactics_time_line as art WHERE 1= 1  `
	if condition != "" {
		sqlCount += condition
	}
	o := orm.NewOrm()
	err = o.Raw(sqlCount, pars).QueryRow(&count)
	return
}

// 列表
func GetCygxTacticsTimeLineList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxTacticsTimeLineResp, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM cygx_tactics_time_line as art WHERE 1= 1 `
	if condition != "" {
		sql += condition
	}
	sql += ` LIMIT ?,?  `
	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
	return
}

type GetCygxTacticsTimeLineDetailResp struct {
	Detail *CygxTacticsTimeLineResp
}

// 通过ID获取详情
func GetCygxTacticsTimeLineDetail(timeLineId int) (item *CygxTacticsTimeLineResp, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM cygx_tactics_time_line  WHERE time_line_id=? `
	err = o.Raw(sql, timeLineId).QueryRow(&item)
	return
}
