report.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. package models
  2. import (
  3. "eta/eta_task/global"
  4. "eta/eta_task/utils"
  5. "gorm.io/gorm"
  6. "time"
  7. )
  8. type Report struct {
  9. Id int `gorm:"column:id;primaryKey;autoIncrement" description:"报告Id"`
  10. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  11. ClassifyIdFirst int `description:"一级分类id"`
  12. ClassifyNameFirst string `description:"一级分类名称"`
  13. ClassifyIdSecond int `description:"二级分类id"`
  14. ClassifyNameSecond string `description:"二级分类名称"`
  15. Title string `description:"标题"`
  16. Abstract string `description:"摘要"`
  17. Author string `description:"作者"`
  18. Frequency string `description:"频度"`
  19. CreateTime string `description:"创建时间"`
  20. ModifyTime time.Time `description:"修改时间"`
  21. State int `description:"1:未发布,2:已发布"`
  22. PublishTime time.Time `description:"发布时间"`
  23. Stage int `description:"期数"`
  24. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  25. Content string `description:"内容"`
  26. VideoUrl string `description:"音频文件URL"`
  27. VideoName string `description:"音频文件名称"`
  28. VideoPlaySeconds string `description:"音频播放时长"`
  29. VideoSize string `description:"音频文件大小,单位M"`
  30. ContentSub string `description:"内容前两个章节"`
  31. HasChapter int `description:"是否有章节 0-否 1-是"`
  32. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  33. OldReportId int `description:"research_report表ID(后续一两个版本过渡需要,之后可移除)"`
  34. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  35. AdminId int
  36. AdminName string `description:"系统用户名称"`
  37. ClassifyIdThird int `description:"三级分类id"`
  38. ClassifyNameThird string `description:"三级分类名称"`
  39. }
  40. func (m *Report) AfterFind(db *gorm.DB) (err error) {
  41. m.CreateTime = utils.GormDateStrToDateTimeStr(m.CreateTime)
  42. return
  43. }
  44. // GetPrePublishedReports 获取定时发布时间为当前时间的未发布的报告列表
  45. func GetPrePublishedReports(startTime, endTime, afterDate string) (list []*Report, err error) {
  46. o := global.DbMap[utils.DbNameReport]
  47. sql := `SELECT * FROM report WHERE state = 1 and pre_publish_time >= ? and pre_publish_time <=? and modify_time >= ?`
  48. err = o.Raw(sql, startTime, endTime, afterDate).Find(&list).Error
  49. return
  50. }
  51. // PublishReportById 发布报告
  52. func PublishReportById(reportId int, publishTime time.Time) (err error) {
  53. o := global.DbMap[utils.DbNameReport]
  54. sql := `UPDATE report SET state = 2, publish_time = ?, modify_time = NOW() WHERE id = ? `
  55. err = o.Exec(sql, publishTime, reportId).Error
  56. return
  57. }
  58. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  59. o := global.DbMap[utils.DbNameReport]
  60. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  61. err = o.Exec(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Error
  62. return
  63. }
  64. // ModifyReportVideoByNoVideo
  65. // @Description: 修改无音频的报告音频信息
  66. // @author: Roc
  67. // @datetime 2024-07-25 18:03:05
  68. // @param reportId int
  69. // @param videoUrl string
  70. // @param videoName string
  71. // @param videoSize string
  72. // @param playSeconds float64
  73. // @return err error
  74. func ModifyReportVideoByNoVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  75. o := global.DbMap[utils.DbNameReport]
  76. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? AND video_url=""`
  77. err = o.Exec(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Error
  78. return
  79. }
  80. type ElasticReportDetail struct {
  81. ReportId int `description:"报告ID"`
  82. ReportChapterId int `description:"报告章节ID"`
  83. Title string `description:"标题"`
  84. Abstract string `description:"摘要"`
  85. BodyContent string `description:"内容"`
  86. PublishTime string `description:"发布时间"`
  87. PublishState int `description:"发布状态 1-未发布 2-已发布"`
  88. Author string `description:"作者"`
  89. ClassifyIdFirst int `description:"一级分类ID"`
  90. ClassifyNameFirst string `description:"一级分类名称"`
  91. ClassifyIdSecond int `description:"二级分类ID"`
  92. ClassifyNameSecond string `description:"二级分类名称"`
  93. ClassifyId int `description:"最小单元的分类ID"`
  94. ClassifyName string `description:"最小单元的分类名称"`
  95. Categories string `description:"关联的品种名称(包括品种别名)"`
  96. StageStr string `description:"报告期数"`
  97. }
  98. type ChartPermissionMappingIdName struct {
  99. PermissionId int
  100. PermissionName string
  101. }
  102. func GetChartPermissionNameFromMappingByKeyword(source string, classifyId int) (list []*ChartPermissionMappingIdName, err error) {
  103. o := global.DbMap[utils.DbNameReport]
  104. 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 = ? "
  105. sql = utils.ReplaceDriverKeywords("", sql)
  106. err = o.Raw(sql, source, classifyId).Find(&list).Error
  107. return
  108. }
  109. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  110. o := global.DbMap[utils.DbNameReport]
  111. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  112. err = o.Exec(sql1, reportId).Error
  113. if err != nil {
  114. return
  115. }
  116. //修改音频标题
  117. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  118. err = o.Exec(sql2, reportId).Error
  119. return
  120. }
  121. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  122. o := global.DbMap[utils.DbNameReport]
  123. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  124. err = o.Exec(sql1, reportId).Error
  125. if err != nil {
  126. return
  127. }
  128. //修改音频标题
  129. 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)`
  130. err = o.Exec(sql2, reportId).Error
  131. return
  132. }
  133. func ModifyReportMsgIsSend(reportId int) (err error) {
  134. o := global.DbMap[utils.DbNameReport]
  135. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? and msg_is_send=0`
  136. err = o.Exec(sql, reportId).Error
  137. return
  138. }
  139. // ClearReportSaveLog 清理报告保存日志
  140. func ClearReportSaveLog(date string) (err error) {
  141. o := global.DbMap[utils.DbNameReport]
  142. sql := `DELETE FROM report_save_log WHERE create_time <= ?`
  143. err = o.Exec(sql, date).Error
  144. return
  145. }
  146. // PublishReportAndChapter 发布报告及章节
  147. func PublishReportAndChapter(reportInfo *Report, isPublishReport bool, cols []string) (err error) {
  148. o := global.DbMap[utils.DbNameReport]
  149. to := o.Begin()
  150. defer func() {
  151. if err != nil {
  152. _ = to.Rollback()
  153. } else {
  154. _ = to.Commit()
  155. }
  156. }()
  157. // 更新报告
  158. if isPublishReport {
  159. err = to.Select(cols).Updates(reportInfo).Error
  160. if err != nil {
  161. return
  162. }
  163. }
  164. // 发布该报告的所有章节
  165. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? `
  166. err = to.Exec(sql, reportInfo.PublishTime, reportInfo.Id).Error
  167. // 发布章节
  168. //if len(publishIds) > 0 {
  169. // sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
  170. // err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Error
  171. //}
  172. //if len(unPublishIds) > 0 {
  173. // 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)) + `) `
  174. // err = to.Raw(sql, reportInfo.Id, unPublishIds).Error
  175. //}
  176. return
  177. }