123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- package models
- import (
- sql2 "database/sql"
- "errors"
- "eta/eta_task/global"
- "eta/eta_task/utils"
- "gorm.io/gorm"
- "time"
- )
- type Report struct {
- Id int `orm:"column(id)" description:"报告Id"`
- AddType int `description:"新增方式:1:新增报告,2:继承报告"`
- ClassifyIdFirst int `description:"一级分类id"`
- ClassifyNameFirst string `description:"一级分类名称"`
- ClassifyIdSecond int `description:"二级分类id"`
- ClassifyNameSecond string `description:"二级分类名称"`
- Title string `description:"标题"`
- Abstract string `description:"摘要"`
- Author string `description:"作者"`
- Frequency string `description:"频度"`
- CreateTime string `description:"创建时间"`
- ModifyTime string `description:"修改时间"`
- State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
- PublishTime time.Time `description:"发布时间"`
- Stage int `description:"期数"`
- MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
- ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
- Content string `description:"内容"`
- VideoUrl string `description:"音频文件URL"`
- VideoName string `description:"音频文件名称"`
- VideoPlaySeconds string `description:"音频播放时长"`
- VideoSize string `description:"音频文件大小,单位M"`
- ContentSub string `description:"内容前两个章节"`
- ReportCode string `description:"报告唯一编码"`
- ReportVersion int `description:"1:旧版,2:新版"`
- HasChapter int `description:"是否有章节 0-否 1-是"`
- ChapterType string `description:"章节类型 day-晨报 week-周报"`
- OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
- MsgSendTime time.Time `description:"模版消息发送时间"`
- AdminId int `description:"创建者账号"`
- AdminRealName string `description:"创建者姓名"`
- ApproveTime time.Time `description:"审批时间"`
- ApproveId int `description:"审批ID"`
- DetailImgUrl string `description:"报告详情长图地址"`
- DetailPdfUrl string `description:"报告详情PDF地址"`
- DetailImgUrlMobile string `description:"报告详情长图地址-手机端"`
- DetailPdfUrlMobile string `description:"报告详情PDF地址-手机端"`
- ContentStruct string `description:"内容组件"`
- LastModifyAdminId int `description:"最后更新人ID"`
- LastModifyAdminName string `description:"最后更新人姓名"`
- ContentModifyTime time.Time `description:"内容更新时间"`
- Pv int `description:"pv"`
- Uv int `description:"uv"`
- HeadImg string `description:"报告头图地址"`
- EndImg string `description:"报告尾图地址"`
- CanvasColor string `description:"画布颜色"`
- NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
- HeadResourceId int `description:"版头资源ID"`
- EndResourceId int `description:"版尾资源ID"`
- ClassifyIdThird int `description:"三级分类id"`
- ClassifyNameThird string `description:"三级分类名称"`
- CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
- ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
- IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
- ReportCreateTime time.Time `description:"报告时间创建时间"`
- InheritReportId int `description:"待继承的报告ID"`
- VoiceGenerateType int `description:"音频生成方式,0:系统生成,1:人工上传"`
- RaiReportId int `description:"RAI报告ID"`
- FreeLayoutConfig string `description:"'自由布局配置"`
- MiniShow int `description:"是否在C端展示:0-否;1-是"`
- PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
- }
- func (m *Report) AfterFind(db *gorm.DB) (err error) {
- m.CreateTime = utils.GormDateStrToDateTimeStr(m.CreateTime)
- return
- }
- // GetPrePublishedReports 获取定时发布时间为当前时间的未发布的报告列表
- func GetPrePublishedReports(startTime, endTime, afterDate string) (list []*Report, err error) {
- o := global.DbMap[utils.DbNameReport]
- sql := `SELECT * FROM report WHERE state = 1 and pre_publish_time >= ? and pre_publish_time <=? and modify_time >= ?`
- err = o.Raw(sql, startTime, endTime, afterDate).Find(&list).Error
- return
- }
- // PublishReportById 发布报告
- func PublishReportById(reportId int, publishTime time.Time) (err error) {
- o := global.DbMap[utils.DbNameReport]
- sql := `UPDATE report SET state = 2, publish_time = ?, modify_time = NOW() WHERE id = ? `
- err = o.Exec(sql, publishTime, reportId).Error
- return
- }
- func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
- o := global.DbMap[utils.DbNameReport]
- sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
- err = o.Exec(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Error
- return
- }
- // ModifyReportVideoByNoVideo
- // @Description: 修改无音频的报告音频信息
- // @author: Roc
- // @datetime 2024-07-25 18:03:05
- // @param reportId int
- // @param videoUrl string
- // @param videoName string
- // @param videoSize string
- // @param playSeconds float64
- // @return err error
- func ModifyReportVideoByNoVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
- o := global.DbMap[utils.DbNameReport]
- sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? AND video_url=""`
- err = o.Exec(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Error
- return
- }
- type ElasticReportDetail struct {
- ReportId int `description:"报告ID"`
- ReportChapterId int `description:"报告章节ID"`
- Title string `description:"标题"`
- Abstract string `description:"摘要"`
- BodyContent string `description:"内容"`
- PublishTime string `description:"发布时间"`
- PublishState int `description:"发布状态 1-未发布 2-已发布"`
- Author string `description:"作者"`
- ClassifyIdFirst int `description:"一级分类ID"`
- ClassifyNameFirst string `description:"一级分类名称"`
- ClassifyIdSecond int `description:"二级分类ID"`
- ClassifyNameSecond string `description:"二级分类名称"`
- ClassifyId int `description:"最小单元的分类ID"`
- ClassifyName string `description:"最小单元的分类名称"`
- Categories string `description:"关联的品种名称(包括品种别名)"`
- StageStr string `description:"报告期数"`
- }
- type ChartPermissionMappingIdName struct {
- PermissionId int
- PermissionName string
- }
- func GetChartPermissionNameFromMappingByKeyword(source string, classifyId int) (list []*ChartPermissionMappingIdName, err error) {
- o := global.DbMap[utils.DbNameReport]
- sql := " SELECT b.chart_permission_id AS permission_id,b.permission_name FROM chart_permission_search_key_word_mapping AS a INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id WHERE a.from = ? AND a.classify_id = ? "
- sql = utils.ReplaceDriverKeywords("", sql)
- err = o.Raw(sql, source, classifyId).Find(&list).Error
- return
- }
- func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
- o := global.DbMap[utils.DbNameReport]
- sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
- err = o.Exec(sql1, reportId).Error
- if err != nil {
- return
- }
- //修改音频标题
- sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
- err = o.Exec(sql2, reportId).Error
- return
- }
- func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
- o := global.DbMap[utils.DbNameReport]
- sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
- err = o.Exec(sql1, reportId).Error
- if err != nil {
- return
- }
- //修改音频标题
- sql2 := ` UPDATE report_chapter SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE report_id = ? and (video_name !="" and video_name is not null)`
- err = o.Exec(sql2, reportId).Error
- return
- }
- func ModifyReportMsgIsSend(reportId int) (err error) {
- o := global.DbMap[utils.DbNameReport]
- sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? and msg_is_send=0`
- err = o.Exec(sql, reportId).Error
- return
- }
- // ClearReportSaveLog 清理报告保存日志
- func ClearReportSaveLog(date string) (err error) {
- o := global.DbMap[utils.DbNameReport]
- sql := `DELETE FROM report_save_log WHERE create_time <= ?`
- err = o.Exec(sql, date).Error
- return
- }
- // PublishReportAndChapter 发布报告及章节
- func PublishReportAndChapter(reportInfo *Report, isPublishReport bool, cols []string) (err error) {
- o := global.DbMap[utils.DbNameReport]
- to := o.Begin()
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- // 更新报告
- if isPublishReport {
- err = to.Select(cols).Updates(reportInfo).Error
- if err != nil {
- return
- }
- }
- // 发布该报告的所有章节
- sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? `
- err = to.Exec(sql, reportInfo.PublishTime, reportInfo.Id).Error
- // 发布章节
- //if len(publishIds) > 0 {
- // sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
- // err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Error
- //}
- //if len(unPublishIds) > 0 {
- // sql := ` UPDATE report_chapter SET publish_state = 1, publish_time = NULL, is_edit = 0 WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(unPublishIds)) + `) `
- // err = to.Raw(sql, reportInfo.Id, unPublishIds).Error
- //}
- return
- }
- func GetReport(classifyIdFirst int, startTime, endTime string) (item *Report, err error) {
- o := global.DbMap[utils.DbNameReport]
- sql := ` SELECT * FROM report WHERE classify_id_first = ? AND create_time >= ? AND create_time <= ? `
- err = o.Raw(sql, classifyIdFirst, startTime, endTime).Scan(&item).Error
- return item, err
- }
- // @return count int
- // @return err error
- func GetReportStage(classifyIdFirst, classifyIdSecond, classifyIdThird int) (count int, err error) {
- o := global.DbMap[utils.DbNameReport]
- classifyId := classifyIdThird
- if classifyId <= 0 {
- classifyId = classifyIdSecond
- }
- if classifyId <= 0 {
- classifyId = classifyIdFirst
- }
- if classifyId <= 0 {
- err = errors.New("错误的分类id")
- return
- }
- yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
- sql := `SELECT MAX(stage) AS max_stage FROM report WHERE create_time > ? `
- if classifyIdThird > 0 {
- sql += " AND classify_id_third = ? "
- } else if classifyIdSecond > 0 {
- sql += " AND classify_id_second = ? "
- } else {
- sql += " AND classify_id_first = ? "
- }
- var maxNull sql2.NullInt64
- err = o.Raw(sql, yearStart, classifyId).Scan(&maxNull).Error
- if err != nil {
- return
- }
- if maxNull.Valid {
- count = int(maxNull.Int64)
- }
- return
- }
- func AddReport(reportInfo *Report) (err error) {
- o := global.DbMap[utils.DbNameReport]
- err = o.Create(reportInfo).Error
- if err != nil {
- return err
- }
- return
- }
- func ModifyReportContent(reportId int, content string) (err error) {
- o := global.DbMap[utils.DbNameReport]
- sql := `UPDATE report SET content = ?,modify_time = NOW() WHERE id = ?`
- err = o.Exec(sql, content, reportId).Error
- return
- }
|