123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- package models
- import (
- "eta_gn/eta_task/utils"
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "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是"`
- AdminId int
- AdminName string `description:"系统用户名称"`
- ClassifyIdThird int `description:"三级分类id"`
- ClassifyNameThird string `description:"三级分类名称"`
- }
- 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
- }
- 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:"二级分类名称"`
- 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 := orm.NewOrmUsingDB("rddp")
- 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 = ? "
- _, err = o.Raw(sql, source, classifyId).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
- }
- // ClearReportSaveLog 清理报告保存日志
- func ClearReportSaveLog(date string) (err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `DELETE FROM report_save_log WHERE create_time <= ?`
- _, err = o.Raw(sql, date).Exec()
- return
- }
- // PublishReportAndChapter 发布报告及章节
- func PublishReportAndChapter(reportInfo *Report, isPublishReport bool, cols []string) (err error) {
- o := orm.NewOrmUsingDB("rddp")
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- // 更新报告
- if isPublishReport {
- _, err = to.Update(reportInfo, cols...)
- if err != nil {
- return
- }
- }
- // 发布该报告的所有章节
- sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? `
- _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id).Exec()
- // 发布章节
- //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).Exec()
- //}
- //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).Exec()
- //}
- return
- }
|