123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- package models
- import (
- "eta_gn/eta_api/global"
- "eta_gn/eta_api/models/report"
- "eta_gn/eta_api/utils"
- "time"
- )
- // ReportChapter 报告章节
- type ReportChapter struct {
- ReportChapterId int `gorm:"column:report_chapter_id;primaryKey;autoIncrement:true;not null" description:"报告章节ID"`
- ReportId int `gorm:"column:report_id" description:"报告ID"`
- ReportType string `gorm:"column:report_type" description:"报告类型 day-晨报 week-周报"`
- ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
- ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
- TypeId int `gorm:"column:type_id" description:"品种ID"`
- TypeName string `gorm:"column:type_name" description:"品种名称"`
- Title string `gorm:"column:title" description:"标题"`
- Abstract string `gorm:"column:abstract" description:"摘要"`
- AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
- Author string `gorm:"column:author" description:"作者"`
- Content string `gorm:"column:content" description:"内容"`
- ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
- Stage int `gorm:"column:stage" description:"期数"`
- Trend string `gorm:"column:trend" description:"趋势观点"`
- Sort int `gorm:"column:sort" description:"排序: 数值越小越靠前"`
- IsEdit int `gorm:"column:is_edit" description:"是否已编辑 0-待编辑 1-已编辑"`
- PublishState int `gorm:"column:publish_state" description:"发布状态 1-待发布,2-已发布"`
- PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
- VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
- VideoName string `gorm:"column:video_name" description:"音频文件名称"`
- VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
- VideoSize string `gorm:"column:video_size" description:"音频文件大小,单位M"`
- VideoKind int `gorm:"column:video_kind" description:"音频生成方式:1,手动上传,2:自动生成"`
- CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
- ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
- OriginalVideoUrl string `gorm:"column:original_video_url" description:"原始音频文件URL"`
- ContentStruct string `gorm:"column:content_struct" description:"内容组件"`
- LastModifyAdminId int `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
- LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
- ContentModifyTime time.Time `gorm:"column:content_modify_time" description:"内容更新时间"`
- ReportLayout int8 `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
- ReportCreateTime time.Time `gorm:"column:report_create_time" description:"报告时间创建时间"`
- VoiceGenerateType int `gorm:"column:voice_generate_type" description:"音频生成方式,0:系统生成,1:人工上传"`
- }
- // ReportChapterItem 报告章节详情
- type ReportChapterItem struct {
- ReportChapterId int `gorm:"column:report_chapter_id;primaryKey;autoIncrement:true;not null" description:"报告章节ID"`
- ReportId int `gorm:"column:report_id" description:"报告ID"`
- ReportType string `gorm:"column:report_type" description:"报告类型 day-晨报 week-周报"`
- ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
- ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
- TypeId int `gorm:"column:type_id" description:"品种ID"`
- TypeName string `gorm:"column:type_name" description:"品种名称"`
- Title string `gorm:"column:title" description:"标题"`
- Abstract string `gorm:"column:abstract" description:"摘要"`
- AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
- Author string `gorm:"column:author" description:"作者"`
- Content string `gorm:"column:content" description:"内容"`
- ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
- Stage int `gorm:"column:stage" description:"期数"`
- Trend string `gorm:"column:trend" description:"趋势观点"`
- Sort int `gorm:"column:sort" description:"排序: 数值越小越靠前"`
- IsEdit int `gorm:"column:is_edit" description:"是否已编辑 0-待编辑 1-已编辑"`
- PublishState int `gorm:"column:publish_state" description:"发布状态 1-待发布,2-已发布"`
- PublishTime string `gorm:"column:publish_time" description:"发布时间"`
- VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
- VideoName string `gorm:"column:video_name" description:"音频文件名称"`
- VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
- VideoSize string `gorm:"column:video_size" description:"音频文件大小,单位M"`
- VideoKind int `gorm:"column:video_kind" description:"音频生成方式:1,手动上传,2:自动生成"`
- CreateTime string `gorm:"column:create_time" description:"创建时间"`
- ModifyTime string `gorm:"column:modify_time" description:"修改时间"`
- OriginalVideoUrl string `gorm:"column:original_video_url" description:"原始音频文件URL"`
- ContentStruct string `gorm:"column:content_struct" description:"内容组件"`
- LastModifyAdminId int `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
- LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
- ContentModifyTime string `gorm:"column:content_modify_time" description:"内容更新时间"`
- ReportLayout int8 `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
- ReportCreateTime string `gorm:"column:report_create_time" 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) {
- sql := ` SELECT * FROM report_chapter WHERE report_id = ? ORDER BY sort ASC`
- err = global.DmSQL["rddp"].Raw(sql, reportId).Find(&list).Error
- return
- }
- // GetPublishedChapterListByReportId 根据ReportId获取已发布章节列表
- func GetPublishedChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
- sql := ` SELECT * FROM report_chapter WHERE report_id = ? AND publish_state = 2 ORDER BY sort ASC`
- err = global.DmSQL["rddp"].Raw(sql, reportId).Find(&list).Error
- 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) {
- sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ? `
- err = global.DmSQL["rddp"].Raw(sql, reportChapterId).First(&item).Error
- 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) {
- sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ? `
- err = global.DmSQL["rddp"].Raw(sql, reportChapterId).First(&item).Error
- return
- }
- // Add
- // @Description: 新增章节报告
- // @author: Roc
- // @receiver chapterInfo
- // @datetime 2024-06-04 15:14:41
- // @return err error
- func (chapterChapterInfo *ReportChapter) Add() (err error) {
- err = global.DmSQL["rddp"].Create(chapterChapterInfo).Error
- return
- }
- // UpdateChapter 更新报表章节
- func (chapterChapterInfo *ReportChapter) UpdateChapter(cols []string) (err error) {
- err = global.DmSQL["rddp"].Select(cols).Updates(chapterChapterInfo).Error
- 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 `gorm:"column:report_id"` //`description:"报告ID"`
- ReportChapterId int `gorm:"column:report_chapter_id"` //`description:"报告章节ID"`
- VideoUrl string `gorm:"column:video_url"` //`description:"音频文件URL"`
- VideoName string `gorm:"column:video_name"` //`description:"音频文件名称"`
- VideoPlaySeconds string `gorm:"column:video_play_seconds"` //`description:"音频播放时长"`
- }
- // GetReportChapterVideoList 获取报告章节音频列表
- func GetReportChapterVideoList(reportId int) (list []*ReportChapterVideoList, err error) {
- 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 = global.DmSQL["rddp"].Raw(sql, reportId).Find(&list).Error
- return
- }
- // GetReportChapterVideoListByReportIds 根据报告ID集合获取报告章节音频列表
- func GetReportChapterVideoListByReportIds(reportIds []int) (list []*ReportChapterVideoList, err error) {
- if len(reportIds) == 0 {
- return
- }
- 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 = global.DmSQL["rddp"].Raw(sql, reportIds).Find(&list).Error
- return
- }
- // GetReportChapterVideoListByChapterIds 根据章节ID集合获取报告章节音频列表
- func GetReportChapterVideoListByChapterIds(chapterIds []int) (list []*ReportChapterVideoList, err error) {
- if len(chapterIds) == 0 {
- return
- }
- 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 = global.DmSQL["rddp"].Raw(sql, chapterIds).Find(&list).Error
- return
- }
- // PublishReportChapterReq 发布报告章节请求体
- type PublishReportChapterReq struct {
- ReportChapterId int `description:"报告章节ID"`
- PublishReport int `description:"是否同时发布报告"`
- }
- // 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) {
- sql := ` SELECT report_chapter_id,report_id,title FROM report_chapter WHERE report_id = ? AND publish_state = 1 ORDER BY sort ASC`
- err = global.DmSQL["rddp"].Raw(sql, reportId).Find(&list).Error
- return
- }
- // GetChapterListByChapterIds 根据ReportId获取章节列表
- func GetChapterListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
- if len(chapterIds) == 0 {
- return
- }
- sql := ` SELECT * FROM report_chapter WHERE report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) ORDER BY sort ASC`
- err = global.DmSQL["rddp"].Raw(sql, chapterIds).Find(&list).Error
- return
- }
- // UpdateReportChapterTypeNameByTypeId 更新章节类型名称
- func UpdateReportChapterTypeNameByTypeId(typeId int, typeName string) (err error) {
- sql := `UPDATE report_chapter SET type_name = ? WHERE type_id = ?`
- err = global.DmSQL["rddp"].Exec(sql, typeName, typeId).Error
- return
- }
- // CountReportChapterByTypeId 通过章节类型ID获取章节数
- func CountReportChapterByTypeId(typeId int) (count int, err error) {
- sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE type_id = ?`
- err = global.DmSQL["rddp"].Raw(sql, typeId).Scan(&count).Error
- 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) {
- sql := ` SELECT report_chapter_id FROM report_chapter
- WHERE report_id = ?
- ORDER BY report_chapter_id ASC `
- err = global.DmSQL["rddp"].Raw(sql, reportId).Scan(&list).Error
- return
- }
- // ReportChapterMoveReq
- // @Description: 报告章节移动请求
- type ReportChapterMoveReq struct {
- ReportChapterId 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) {
- sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ?`
- err = global.DmSQL["rddp"].Raw(sql, reportChapterId).First(&item).Error
- 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) {
- 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 = global.DmSQL["rddp"].Exec(sql, pars...).Error
- 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) {
- sql := ` SELECT * FROM report_chapter WHERE 1 = 1 AND report_id = ? ORDER BY sort ASC, report_chapter_id ASC LIMIT 1`
- err = global.DmSQL["rddp"].Raw(sql, reportId).First(&item).Error
- 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) {
- sql := `SELECT COALESCE(MAX(sort), 0) AS sort FROM report_chapter WHERE report_id = ?`
- err = global.DmSQL["rddp"].Raw(sql, reportId).Scan(&maxSort).Error
- 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) {
- err = global.DmSQL["rddp"].Select(cols).Updates(chapterChapterInfo).Error
- return
- }
- // DelReportChapterReq
- // @Description: 删除报告章节请求体
- type DelReportChapterReq struct {
- ReportChapterId int `description:"报告章节ID"`
- }
- // 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) {
- sql := ` SELECT COUNT(1) AS count FROM report_chapter WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
- return
- }
|