report.go 8.4 KB

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