package models import ( "eta_gn/eta_api/global" "eta_gn/eta_api/models/report" "eta_gn/eta_api/utils" "time" ) 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:人工上传"` } 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:"报告时间创建时间"` } 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) { sql := ` SELECT * FROM report_chapter WHERE report_id = ? ORDER BY sort ASC` err = global.DmSQL["rddp"].Raw(sql, reportId).Find(&list).Error return } 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 } 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) { sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ? ` err = global.DmSQL["rddp"].Raw(sql, reportChapterId).First(&item).Error return } 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 } func (chapterChapterInfo *ReportChapter) Add() (err error) { err = global.DmSQL["rddp"].Create(chapterChapterInfo).Error return } func (chapterChapterInfo *ReportChapter) UpdateChapter(cols []string) (err error) { err = global.DmSQL["rddp"].Select(cols).Updates(chapterChapterInfo).Error 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 `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:"音频播放时长"` } 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 } 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 } 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 } type PublishReportChapterReq struct { ReportChapterId int `description:"报告章节ID"` PublishReport int `description:"是否同时发布报告"` } 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 } 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 } 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 } 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 } 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) { 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 } 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) { sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ?` err = global.DmSQL["rddp"].Raw(sql, reportChapterId).First(&item).Error return } 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 } 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 } 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 } func (chapterChapterInfo *ReportChapter) Update(cols []string) (err error) { err = global.DmSQL["rddp"].Select(cols).Updates(chapterChapterInfo).Error return } type DelReportChapterReq struct { ReportChapterId int `description:"报告章节ID"` } 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 }