package models import ( "fmt" "github.com/beego/beego/v2/client/orm" "hongze/hongze_task/utils" "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 time.Time `description:"修改时间"` State int `description:"1:未发布,2:已发布"` PublishTime time.Time `description:"发布时间"` Stage int `description:"期数"` MsgIsSend int `description:"消息是否已发送,0:否,1:是"` Content string `description:"内容"` VideoUrl string `description:"音频文件URL"` VideoName string `description:"音频文件名称"` VideoPlaySeconds string `description:"音频播放时长"` ContentSub string `description:"内容前两个章节"` HasChapter int `description:"是否有章节 0-否 1-是"` ChapterType string `description:"章节类型 day-晨报 week-周报"` OldReportId int `description:"research_report表ID(后续一两个版本过渡需要,之后可移除)"` PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"` } func GetReportById(reportId int) (item *ReportDetail, err error) { o := orm.NewOrmUsingDB("rddp") sql := `SELECT * FROM report WHERE id=?` err = o.Raw(sql, reportId).QueryRow(&item) return } func GetReport() (items []*Report, err error) { sql := `SELECT * FROM report ORDER BY id ASC ` o := orm.NewOrmUsingDB("rddp") _, err = o.Raw(sql).QueryRows(&items) return } func ModifyReportContentSub(id int, contentSub string) (err error) { sql := `UPDATE report SET content_sub=? WHERE id=? ` o := orm.NewOrmUsingDB("rddp") _, err = o.Raw(sql, contentSub, id).Exec() return } func GetReportLimit() (items []*Report, err error) { sql := `SELECT * FROM report WHERE state=2 ORDER BY id DESC LIMIT 50 ` o := orm.NewOrmUsingDB("rddp") _, err = o.Raw(sql).QueryRows(&items) return } func EditReportContent(reportId int, content, contentSub string) (err error) { o := orm.NewOrmUsingDB("rddp") sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? ` _, err = o.Raw(sql, content, contentSub, reportId).Exec() return } // 删除报告日志记录-保留3个月 func DeleteReportSaveLog() { startDateTime := time.Now().AddDate(0, -3, 0).Format(utils.FormatDateTime) fmt.Println(startDateTime) } func EditReportContentHtml(reportId int, content string) (err error) { o := orm.NewOrmUsingDB("rddp") sql := ` UPDATE report SET content=?,modify_time=NOW() WHERE id=? ` _, err = o.Raw(sql, content, reportId).Exec() return } // GetPrePublishedReports 获取定时发布时间为当前时间的未发布的报告列表 func GetPrePublishedReports(startTime, endTime, afterDate string) (list []*Report, err error) { o := orm.NewOrmUsingDB("rddp") 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).QueryRows(&list) return } // PublishReportById 发布报告 func PublishReportById(reportId int, publishTime time.Time) (err error) { o := orm.NewOrmUsingDB("rddp") sql := `UPDATE report SET state = 2, publish_time = ?, modify_time = NOW() WHERE id = ? ` _, err = o.Raw(sql, publishTime, reportId).Exec() return } type ReportDetail 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:已发布"` PublishTime string `description:"发布时间"` Stage int `description:"期数"` MsgIsSend int `description:"消息是否已发送,0:否,1:是"` Content string `description:"内容"` VideoUrl string `description:"音频文件URL"` VideoName string `description:"音频文件名称"` VideoPlaySeconds string `description:"音频播放时长"` ContentSub string `description:"内容前两个章节"` ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"` HasChapter int `description:"是否有章节 0-否 1-是"` ChapterType string `description:"章节类型 day-晨报 week-周报"` OldReportId int `description:"research_report表ID(后续一两个版本过渡需要,之后可移除)"` PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"` } func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) { o := orm.NewOrmUsingDB("rddp") sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? ` _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec() return } // 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"` } // 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 } type ReportChapterTypePermission struct { Id int `orm:"column(id);pk" description:"主键ID"` ReportChapterTypeId int `description:"报告章节类型ID"` ReportChapterTypeName string `description:"章节名称"` ChartPermissionId int `description:"大分类ID"` PermissionName string `description:"权限名称"` ResearchType string `description:"研报类型"` CreatedTime time.Time `description:"创建时间"` } // GetChapterTypePermissionByTypeIdAndResearchType 根据章节类型ID及研报类型获取章节类型权限列表 func GetChapterTypePermissionByTypeIdAndResearchType(typeId int, researchType string) (list []*ReportChapterTypePermission, err error) { o := orm.NewOrm() sql := ` SELECT * FROM report_chapter_type_permission WHERE report_chapter_type_id = ? AND research_type = ? ORDER BY chart_permission_id ASC ` _, err = o.Raw(sql, typeId, researchType).QueryRows(&list) 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:"二级分类名称"` Categories string `description:"关联的品种名称(包括品种别名)"` StageStr string `description:"报告期数"` } type ChartPermissionMappingIdName struct { PermissionId int PermissionName string } func GetChartPermissionNameFromMappingByKeyword(keyword string, source string) (list []*ChartPermissionMappingIdName, err error) { o := orm.NewOrm() 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.key_word = ? " _, err = o.Raw(sql, source, keyword).QueryRows(&list) return } func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) { o := orm.NewOrmUsingDB("rddp") sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? ` _, err = o.Raw(sql1, reportId).Exec() 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.Raw(sql2, reportId).Exec() return } func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) { o := orm.NewOrmUsingDB("rddp") sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? ` _, err = o.Raw(sql1, reportId).Exec() 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.Raw(sql2, reportId).Exec() return } func ModifyReportMsgIsSend(reportId int) (err error) { o := orm.NewOrmUsingDB("rddp") sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? and msg_is_send=0` _, err = o.Raw(sql, reportId).Exec() return }