123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607 |
- package models
- import (
- "eta/eta_api/models/report"
- "eta/eta_api/utils"
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- 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:人工上传"`
- }
- 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:"报告时间创建时间"`
- }
- 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:"是否有权限"`
- }
- 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
- }
- 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
- }
- type AddReportChapterReq struct {
- ReportId int `description:"报告ID"`
- Title string `description:"标题"`
- PermissionIdList []int `description:"报告关联的品种权限"`
- AdminIdList []int `description:"授权的编辑人id列表"`
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- func (chapterChapterInfo *ReportChapter) Add() (err error) {
- o := orm.NewOrmUsingDB("rddp")
- lastId, err := o.Insert(chapterChapterInfo)
- if err != nil {
- return
- }
- chapterChapterInfo.ReportChapterId = int(lastId)
- return
- }
- func (chapterChapterInfo *ReportChapter) UpdateChapter(cols []string) (err error) {
- o := orm.NewOrmUsingDB("rddp")
- _, err = o.Update(chapterChapterInfo, cols...)
- return
- }
- type EditChapterTrendTagReq struct {
- ReportChapterId int `description:"章节ID"`
- Trend string `description:"趋势"`
- }
- 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
- }
-
- 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
- }
- type ReportChapterVideoList struct {
- ReportId int `description:"报告ID"`
- ReportChapterId int `description:"报告章节ID"`
- VideoUrl string `description:"音频文件URL"`
- VideoName string `description:"音频文件名称"`
- VideoPlaySeconds string `description:"音频播放时长"`
- }
- 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
- }
- 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
- }
- 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
- }
- type PublishReportChapterReq struct {
- ReportChapterId int `description:"报告章节ID"`
- PublishReport int `description:"是否同时发布报告"`
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- type AddReportChapter struct {
- ReportChapter *ReportChapter
- GrantList []*report.ReportChapterGrant
- GrantPermissionList []*report.ReportChapterPermissionMapping
- }
- type EditReportChapterBaseInfoAndPermissionReq struct {
- ReportChapterId int `description:"报告章节ID"`
- Title string `description:"标题"`
- PermissionIdList []int `description:"报告关联的品种权限"`
- AdminIdList []int `description:"授权的编辑人id列表"`
- }
- 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
- }
- type ReportChapterMoveReq struct {
- ReportChapterId int `description:"报告章节id"`
-
- PrevReportChapterId int `description:"上一个兄弟节点报告章节id"`
- NextReportChapterId int `description:"下一个兄弟节点报告章节id"`
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- func (chapterChapterInfo *ReportChapter) Update(cols []string) (err error) {
- o := orm.NewOrmUsingDB("rddp")
- _, err = o.Update(chapterChapterInfo, cols...)
- return
- }
- type DelReportChapterReq struct {
- ReportChapterId int `description:"报告章节ID"`
- }
- 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
- }
- 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
- }
|