package models

import (
	"eta/eta_mobile/models/report"
	"eta/eta_mobile/utils"
	"github.com/beego/beego/v2/client/orm"
	"time"
)

// ReportChapter 报告章节
type ReportChapter struct {
	ReportChapterId     int       `orm:"column(report_chapter_id);pk" description:"报告章节ID"`
	ReportId            int       `description:"报告ID"`
	ReportType          string    `description:"报告类型 day-晨报 week-周报"`
	ClassifyIdFirst     int       `description:"一级分类id"`
	ClassifyNameFirst   string    `description:"一级分类名称"`
	TypeId              int       `description:"品种ID"`
	TypeName            string    `description:"品种名称"`
	Title               string    `description:"标题"`
	Abstract            string    `description:"摘要"`
	AddType             int       `description:"新增方式：1:新增报告，2:继承报告"`
	Author              string    `description:"作者"`
	Content             string    `description:"内容"`
	ContentSub          string    `description:"内容前两个章节"`
	Stage               int       `description:"期数"`
	Trend               string    `description:"趋势观点"`
	Sort                int       `description:"排序: 数值越小越靠前"`
	IsEdit              int       `description:"是否已编辑 0-待编辑 1-已编辑"`
	PublishState        int       `description:"发布状态 1-待发布，2-已发布"`
	PublishTime         time.Time `description:"发布时间"`
	VideoUrl            string    `description:"音频文件URL"`
	VideoName           string    `description:"音频文件名称"`
	VideoPlaySeconds    string    `description:"音频播放时长"`
	VideoSize           string    `description:"音频文件大小，单位M"`
	VideoKind           int       `description:"音频生成方式:1,手动上传,2:自动生成"`
	CreateTime          string    `description:"创建时间"`
	ModifyTime          time.Time `description:"修改时间"`
	OriginalVideoUrl    string    `description:"原始音频文件URL"`
	ContentStruct       string    `description:"内容组件"`
	LastModifyAdminId   int       `description:"最后更新人ID"`
	LastModifyAdminName string    `description:"最后更新人姓名"`
	ContentModifyTime   time.Time `description:"内容更新时间"`
	ReportLayout        int8      `description:"报告布局，1：常规布局，2：智能布局。默认：1"`
	ReportCreateTime    time.Time `description:"报告时间创建时间"`
	VoiceGenerateType   int       `description:"音频生成方式，0：系统生成，1：人工上传"`
}

// ReportChapterItem 报告章节详情
type ReportChapterItem struct {
	ReportChapterId     int    `orm:"column(report_chapter_id);pk" description:"报告章节ID"`
	ReportId            int    `description:"报告ID"`
	ReportType          string `description:"报告类型 day-晨报 week-周报"`
	ClassifyIdFirst     int    `description:"一级分类id"`
	ClassifyNameFirst   string `description:"一级分类名称"`
	TypeId              int    `description:"品种ID"`
	TypeName            string `description:"品种名称"`
	Title               string `description:"标题"`
	Abstract            string `description:"摘要"`
	AddType             int    `description:"新增方式：1:新增报告，2:继承报告"`
	Author              string `description:"作者"`
	Content             string `description:"内容"`
	ContentSub          string `description:"内容前两个章节"`
	Stage               int    `description:"期数"`
	Trend               string `description:"趋势观点"`
	Sort                int    `description:"排序: 数值越小越靠前"`
	IsEdit              int    `description:"是否已编辑 0-待编辑 1-已编辑"`
	PublishState        int    `description:"发布状态 1-待发布，2-已发布"`
	PublishTime         string `description:"发布时间"`
	VideoUrl            string `description:"音频文件URL"`
	VideoName           string `description:"音频文件名称"`
	VideoPlaySeconds    string `description:"音频播放时长"`
	VideoSize           string `description:"音频文件大小，单位M"`
	VideoKind           int    `description:"音频生成方式:1,手动上传,2:自动生成"`
	CreateTime          string `description:"创建时间"`
	ModifyTime          string `description:"修改时间"`
	OriginalVideoUrl    string `description:"原始音频文件URL"`
	ContentStruct       string `description:"内容组件"`
	LastModifyAdminId   int    `description:"最后更新人ID"`
	LastModifyAdminName string `description:"最后更新人姓名"`
	ContentModifyTime   string `description:"内容更新时间"`
	ReportLayout        int8   `description:"报告布局，1：常规布局，2：智能布局。默认：1"`
	ReportCreateTime    string `description:"报告时间创建时间"`
}

// ReportChapterItemResp
// @Description: 章节详情（带有一些额外的数据）
type ReportChapterItemResp struct {
	ReportChapterItem
	GrandAdminIdList []int  `description:"授权的用户id列表"`
	PermissionIdList []int  `description:"关联的品种id列表"`
	CanEdit          bool   `description:"是否可编辑"`
	Editor           string `description:"编辑人"`
	HeadImg          string `description:"报告头图地址"`
	EndImg           string `description:"报告尾图地址"`
	HeadStyle        string `description:"版头样式"`
	EndStyle         string `description:"版尾样式"`
}

type ReportChapterResp struct {
	ReportChapterId  int    `description:"报告章节ID"`
	ReportId         int    `description:"报告ID"`
	ReportType       string `description:"报告类型 day-晨报 week-周报"`
	TypeId           int    `description:"品种ID"`
	TypeName         string `description:"品种名称"`
	TypeEditImg      string `description:"后台编辑时的图片"`
	Title            string `description:"标题"`
	Abstract         string `description:"摘要"`
	Author           string `description:"作者"`
	Content          string `description:"内容"`
	ContentSub       string `description:"内容前两个章节"`
	Stage            int    `description:"期数"`
	Trend            string `description:"趋势观点"`
	Sort             int    `description:"排序: 数值越小越靠前"`
	IsEdit           int    `description:"是否已编辑 0-待编辑 1-已编辑"`
	PublishState     int    `description:"发布状态 1-待发布，2-已发布"`
	VideoUrl         string `description:"音频文件URL"`
	VideoName        string `description:"音频文件名称"`
	VideoPlaySeconds string `description:"音频播放时长"`
	VideoSize        string `description:"音频文件大小，单位M"`
	VideoKind        int    `description:"音频生成方式:1,手动上传,2:自动生成"`
	PublishTime      string `description:"发布时间"`
	CreateTime       string `description:"创建时间"`
	ModifyTime       string `description:"修改时间"`
	GrandAdminIdList []int  `description:"授权的用户id列表"`
	PermissionIdList []int  `description:"关联的品种id列表"`
	CanEdit          bool   `description:"是否可编辑"`
	Editor           string `description:"编辑人"`
	IsAuth           bool   `description:"是否有权限"`
}

// GetChapterListByReportId 根据ReportId获取章节列表
func GetChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT * FROM report_chapter WHERE report_id = ? ORDER BY sort ASC`
	_, err = o.Raw(sql, reportId).QueryRows(&list)

	return
}

// GetPublishedChapterListByReportId 根据ReportId获取已发布章节列表
func GetPublishedChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT * FROM report_chapter WHERE report_id = ? AND publish_state = 2 ORDER BY sort ASC`
	_, err = o.Raw(sql, reportId).QueryRows(&list)

	return
}

// AddReportChapterReq
// @Description: 新增报告章节请求体
type AddReportChapterReq struct {
	ReportId         int    `description:"报告ID"`
	Title            string `description:"标题"`
	PermissionIdList []int  `description:"报告关联的品种权限"`
	AdminIdList      []int  `description:"授权的编辑人id列表"`
}

// EditReportChapterReq 编辑报告章节请求体
type EditReportChapterReq struct {
	ReportChapterId  int            `description:"报告章节ID"`
	Title            string         `description:"标题"`
	AddType          int            `description:"新增方式：1:新增报告，2:继承报告"`
	Author           string         `description:"作者"`
	Content          string         `description:"内容"`
	TickerList       []EditTickList `description:"指标信息"`
	CreateTime       string         `description:"发布时间"`
	VideoUrl         string         `description:"音频文件URL"`
	VideoName        string         `description:"音频文件名称"`
	VideoPlaySeconds string         `description:"音频播放时长"`
	VideoSize        string         `description:"音频文件大小，单位M"`

	// 以下是智能研报相关
	ContentStruct  string `description:"内容组件"`
	HeadImg        string `description:"报告头图地址"`
	EndImg         string `description:"报告尾图地址"`
	CanvasColor    string `description:"画布颜色"`
	HeadResourceId int    `description:"版头资源ID"`
	EndResourceId  int    `description:"版尾资源ID"`
}

type EditTickList struct {
	Label  string
	Ticker string
	Sort   int
}

// GetReportChapterInfoById 根据主键获取报告章节
func GetReportChapterInfoById(reportChapterId int) (item *ReportChapter, err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ? `
	err = o.Raw(sql, reportChapterId).QueryRow(&item)

	return
}

// GetReportChapterItemById
// @Description: 根据主键获取报告章节（时间格式为字符串的数据）
// @author: Roc
// @datetime 2024-06-27 14:10:29
// @param reportChapterId int
// @return item *ReportChapterItem
// @return err error
func GetReportChapterItemById(reportChapterId int) (item *ReportChapterItem, err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ? `
	err = o.Raw(sql, reportChapterId).QueryRow(&item)

	return
}

// GetLastPublishedReportChapter 获取上一篇已发表的晨周报章节
func GetLastPublishedReportChapter(typeId int, reportType string) (item *ReportChapter, err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT * FROM report_chapter WHERE publish_state = 2 AND type_id = ? AND report_type = ? ORDER BY report_chapter_id DESC limit 1 `
	err = o.Raw(sql, typeId, reportType).QueryRow(&item)

	return
}

// Add
// @Description: 新增章节报告
// @author: Roc
// @receiver chapterInfo
// @datetime 2024-06-04 15:14:41
// @return err error
func (chapterChapterInfo *ReportChapter) Add() (err error) {
	o := orm.NewOrmUsingDB("rddp")
	lastId, err := o.Insert(chapterChapterInfo)
	if err != nil {
		return
	}
	chapterChapterInfo.ReportChapterId = int(lastId)

	return
}

// UpdateChapter 更新报表章节
func (chapterChapterInfo *ReportChapter) UpdateChapter(cols []string) (err error) {
	o := orm.NewOrmUsingDB("rddp")
	_, err = o.Update(chapterChapterInfo, cols...)

	return
}

// EditChapterTrendTagReq 编辑章节趋势标签请求体
type EditChapterTrendTagReq struct {
	ReportChapterId int    `description:"章节ID"`
	Trend           string `description:"趋势"`
}

// UpdateChapterAndTicker 更新章节及ticker
func UpdateChapterAndTicker(reportInfo *Report, chapterInfo *ReportChapter, updateCols []string, tickerList []*ReportChapterTicker) (err error) {
	// 更新报告的最近编辑人信息
	if err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"}); err != nil {
		return
	}
	// 更新章节
	if err = chapterInfo.UpdateChapter(updateCols); err != nil {
		return
	}
	// 清空并新增章节ticker
	if err = ClearReportChapterTicker(chapterInfo.ReportChapterId); err != nil {
		return
	}
	tickerLen := len(tickerList)
	if tickerLen > 0 {
		for i := 0; i < tickerLen; i++ {
			_, tmpErr := InsertChapterTicker(tickerList[i])
			if tmpErr != nil {
				return
			}
		}
	}

	return
}

// ReportChapterVideoList 报告章节音频列表
type ReportChapterVideoList struct {
	ReportId         int    `description:"报告ID"`
	ReportChapterId  int    `description:"报告章节ID"`
	VideoUrl         string `description:"音频文件URL"`
	VideoName        string `description:"音频文件名称"`
	VideoPlaySeconds string `description:"音频播放时长"`
}

// GetReportChapterVideoList 获取报告章节音频列表
func GetReportChapterVideoList(reportId int) (list []*ReportChapterVideoList, err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT
				report_id,
				report_chapter_id,
				video_url,
				video_name,
				video_play_seconds
			FROM
				report_chapter
			WHERE
				report_id = ? AND publish_state = 2 AND video_url != ""
			ORDER BY
				report_chapter_id ASC `
	_, err = o.Raw(sql, reportId).QueryRows(&list)

	return
}

// GetReportChapterVideoListByReportIds 根据报告ID集合获取报告章节音频列表
func GetReportChapterVideoListByReportIds(reportIds []int) (list []*ReportChapterVideoList, err error) {
	if len(reportIds) == 0 {
		return
	}
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT
				report_id,
				report_chapter_id,
				video_url,
				video_name,
				video_play_seconds
			FROM
				report_chapter
			WHERE
				report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `) AND publish_state = 2 AND video_url != ""
			ORDER BY
				report_chapter_id ASC `
	_, err = o.Raw(sql, reportIds).QueryRows(&list)

	return
}

// GetReportChapterVideoListByChapterIds 根据章节ID集合获取报告章节音频列表
func GetReportChapterVideoListByChapterIds(chapterIds []int) (list []*ReportChapterVideoList, err error) {
	if len(chapterIds) == 0 {
		return
	}
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT
				report_id,
				report_chapter_id,
				video_url,
				video_name,
				video_play_seconds
			FROM
				report_chapter
			WHERE
				report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) AND publish_state = 2
			ORDER BY
				report_chapter_id ASC `
	_, err = o.Raw(sql, chapterIds).QueryRows(&list)
	return
}

// PublishReportChapterReq 发布报告章节请求体
type PublishReportChapterReq struct {
	ReportChapterId int `description:"报告章节ID"`
	PublishReport   int `description:"是否同时发布报告"`
}

// CountPublishedChapterNum 获取报告已发布的章节数
func CountPublishedChapterNum(reportId int) (count int, err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 2 `
	err = o.Raw(sql, reportId).QueryRow(&count)

	return
}

// CountUnPublishedChapterNum
// @Description: 获取报告未发布的章节数
// @author: Roc
// @datetime 2024-06-14 15:59:23
// @param reportId int
// @return count int
// @return err error
func CountUnPublishedChapterNum(reportId int) (count int, err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 1 `
	err = o.Raw(sql, reportId).QueryRow(&count)

	return
}

// GetUnPublishedChapterList
// @Description: 获取报告未发布的章节列表
// @author: Roc
// @datetime 2024-06-14 15:59:23
// @param reportId int
// @return list []*ReportChapter
// @return err error
func GetUnPublishedChapterList(reportId int) (list []*ReportChapter, err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT report_chapter_id,report_id,title FROM report_chapter WHERE report_id = ? AND publish_state = 1 ORDER BY sort ASC`
	_, err = o.Raw(sql, reportId).QueryRows(&list)

	return
}

// GetChapterListByChapterIds 根据ReportId获取章节列表
func GetChapterListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
	if len(chapterIds) == 0 {
		return
	}
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT * FROM report_chapter WHERE report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) ORDER BY sort ASC`
	_, err = o.Raw(sql, chapterIds).QueryRows(&list)
	return
}

// GetChapterSimpleListByChapterIds 根据章节ID获取章节列表
func GetChapterSimpleListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
	if len(chapterIds) == 0 {
		return
	}
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT report_id, report_chapter_id, title, type_name, create_time, IF(publish_time,publish_time,create_time) as publish_time FROM report_chapter WHERE report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) ORDER BY publish_time desc, sort ASC`
	_, err = o.Raw(sql, chapterIds).QueryRows(&list)
	return
}

// GetChapterSimpleListByReportIds 根据ReportId获取章节列表
func GetChapterSimpleListByReportIds(reportIds []int) (list []*ReportChapter, err error) {
	if len(reportIds) == 0 {
		return
	}
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT report_id, report_chapter_id, title, type_name, create_time, IF(publish_time,publish_time,create_time) as publish_time FROM report_chapter WHERE publish_state = 2 and report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `) ORDER BY publish_time desc, sort ASC`
	_, err = o.Raw(sql, reportIds).QueryRows(&list)
	return
}

// UpdateReportChapterTypeNameByTypeId 更新章节类型名称
func UpdateReportChapterTypeNameByTypeId(typeId int, typeName string) (err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := `UPDATE report_chapter SET type_name = ? WHERE type_id = ?`
	_, err = o.Raw(sql, typeName, typeId).Exec()
	return
}

// CountReportChapterByTypeId 通过章节类型ID获取章节数
func CountReportChapterByTypeId(typeId int) (count int, err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE type_id = ?`
	err = o.Raw(sql, typeId).QueryRow(&count)
	return
}

// AddReportChapter
// @Description: 待添加的报告章节
type AddReportChapter struct {
	ReportChapter       *ReportChapter
	GrantList           []*report.ReportChapterGrant
	GrantPermissionList []*report.ReportChapterPermissionMapping
}

// EditReportChapterBaseInfoAndPermissionReq
// @Description: 编辑报告章节的基础信息请求
type EditReportChapterBaseInfoAndPermissionReq struct {
	ReportChapterId  int    `description:"报告章节ID"`
	Title            string `description:"标题"`
	PermissionIdList []int  `description:"报告关联的品种权限"`
	AdminIdList      []int  `description:"授权的编辑人id列表"`
}

// GetReportChapterIdList
// @Description: 获取报告的所有章节id列表
// @author: Roc
// @datetime 2024-06-05 11:09:40
// @param reportId int
// @return list []int
// @return err error
func GetReportChapterIdList(reportId int) (list []int, err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT report_chapter_id FROM report_chapter
			WHERE report_id = ? 
			ORDER BY report_chapter_id ASC `
	_, err = o.Raw(sql, reportId).QueryRows(&list)

	return
}

// ReportChapterMoveReq
// @Description:  报告章节移动请求
type ReportChapterMoveReq struct {
	ReportChapterId int `description:"报告章节id"`
	//	ParentChartPermissionId int `description:"父级品种id"`
	PrevReportChapterId int `description:"上一个兄弟节点报告章节id"`
	NextReportChapterId int `description:"下一个兄弟节点报告章节id"`
}

// GetReportChapterById
// @Description: 获取具体章节
// @author: Roc
// @receiver r
// @datetime 2024-06-06 09:32:40
// @param reportChapterId int
// @return item *ReportChapter
// @return err error
func (chapterChapterInfo *ReportChapter) GetReportChapterById(reportChapterId int) (item *ReportChapter, err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ?`
	err = o.Raw(sql, reportChapterId).QueryRow(&item)
	return
}

// UpdateReportChapterSortByReportId
// @Description: 根据父类id更新排序
// @author: Roc
// @receiver chapterChapterInfo
// @datetime 2024-06-06 09:39:28
// @param reportId int
// @param reportChapterId int
// @param nowSort int
// @param updateSort string
// @return err error
func (chapterChapterInfo *ReportChapter) UpdateReportChapterSortByReportId(reportId, reportChapterId, nowSort int, updateSort string) (err error) {
	o := orm.NewOrmUsingDB("rddp")
	pars := make([]interface{}, 0)
	sql := ` update report_chapter set sort = ` + updateSort + ` WHERE report_id = ? AND sort > ?`
	pars = append(pars, reportId, nowSort)

	if reportChapterId > 0 {
		sql += ` or ( report_chapter_id > ?  and sort = ? )`
		pars = append(pars, reportChapterId, nowSort)
	}

	_, err = o.Raw(sql, pars).Exec()

	return
}

// GetFirstReportChapterByReportId
// @Description: 获取当前报告下，且排序数相同 的排序第一条的数据
// @author: Roc
// @receiver chapterChapterInfo
// @datetime 2024-06-06 09:45:32
// @param reportId int
// @return item *ReportChapter
// @return err error
func (chapterChapterInfo *ReportChapter) GetFirstReportChapterByReportId(reportId int) (item *ReportChapter, err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT * FROM report_chapter WHERE 1 = 1 AND report_id = ? ORDER BY sort ASC, report_chapter_id ASC LIMIT 1`
	err = o.Raw(sql, reportId).QueryRow(&item)
	return
}

// GetMaxSortByReportId
// @Description: 获取最大的排序值
// @author: Roc
// @receiver chapterChapterInfo
// @datetime 2024-06-06 09:44:13
// @param reportId int
// @return maxSort int
// @return err error
func (chapterChapterInfo *ReportChapter) GetMaxSortByReportId(reportId int) (maxSort int, err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := `SELECT max(sort) AS sort FROM report_chapter WHERE report_id = ?`
	err = o.Raw(sql, reportId).QueryRow(&maxSort)

	return
}

// Update
// @Description: 数据变更
// @author: Roc
// @receiver chapterChapterInfo
// @datetime 2024-06-06 09:47:46
// @param cols []string
// @return err error
func (chapterChapterInfo *ReportChapter) Update(cols []string) (err error) {
	o := orm.NewOrmUsingDB("rddp")
	_, err = o.Update(chapterChapterInfo, cols...)

	return
}

// DelReportChapterReq
// @Description: 删除报告章节请求体
type DelReportChapterReq struct {
	ReportChapterId int `description:"报告章节ID"`
}

// GetAllReportChapter 获取所有的报告章节
func GetAllReportChapter() (items []*ReportChapter, err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT * FROM report_chapter ORDER BY report_chapter_id asc `
	_, err = o.Raw(sql).QueryRows(&items)

	return
}

// GetCountReportChapterByCondition
// @Description: 根据条件获取章节数量
// @author: Roc
// @datetime 2024-07-15 15:37:50
// @param condition string
// @param pars []interface{}
// @return count int
// @return err error
func GetCountReportChapterByCondition(condition string, pars []interface{}) (count int, err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := ` SELECT COUNT(1) AS count FROM report_chapter WHERE 1=1 `
	if condition != "" {
		sql += condition
	}
	err = o.Raw(sql, pars).QueryRow(&count)

	return
}

// GetNewestPreReportChapterByClassifyIdAndTypeId 获取分类下往期中最新发布的系统章节
func GetNewestPreReportChapterByClassifyIdAndTypeId(classifyId, typeId int) (item *ReportChapter, err error) {
	o := orm.NewOrmUsingDB("rddp")
	sql := `SELECT a.* FROM report_chapter AS a JOIN report AS b ON a.report_id = b.id WHERE a.classify_id_first = ? AND a.type_id = ? AND a.publish_state = 2 AND b.state IN (2,6) ORDER BY a.publish_time DESC LIMIT 1`
	err = o.Raw(sql, classifyId, typeId).QueryRow(&item)
	return
}
