report.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hongze_task/utils"
  6. "time"
  7. )
  8. type Report struct {
  9. Id int `orm:"column(id)" 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. ContentSub string `description:"内容前两个章节"`
  30. HasChapter int `description:"是否有章节 0-否 1-是"`
  31. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  32. OldReportId int `description:"research_report表ID(后续一两个版本过渡需要,之后可移除)"`
  33. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  34. }
  35. func GetReportById(reportId int) (item *ReportDetail, err error) {
  36. o := orm.NewOrmUsingDB("rddp")
  37. sql := `SELECT * FROM report WHERE id=?`
  38. err = o.Raw(sql, reportId).QueryRow(&item)
  39. return
  40. }
  41. func GetReport() (items []*Report, err error) {
  42. sql := `SELECT * FROM report ORDER BY id ASC `
  43. o := orm.NewOrmUsingDB("rddp")
  44. _, err = o.Raw(sql).QueryRows(&items)
  45. return
  46. }
  47. func ModifyReportContentSub(id int, contentSub string) (err error) {
  48. sql := `UPDATE report SET content_sub=? WHERE id=? `
  49. o := orm.NewOrmUsingDB("rddp")
  50. _, err = o.Raw(sql, contentSub, id).Exec()
  51. return
  52. }
  53. func GetReportLimit() (items []*Report, err error) {
  54. sql := `SELECT * FROM report WHERE state=2 ORDER BY id DESC LIMIT 50 `
  55. o := orm.NewOrmUsingDB("rddp")
  56. _, err = o.Raw(sql).QueryRows(&items)
  57. return
  58. }
  59. func EditReportContent(reportId int, content, contentSub string) (err error) {
  60. o := orm.NewOrmUsingDB("rddp")
  61. sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  62. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  63. return
  64. }
  65. // 删除报告日志记录-保留3个月
  66. func DeleteReportSaveLog() {
  67. startDateTime := time.Now().AddDate(0, -3, 0).Format(utils.FormatDateTime)
  68. fmt.Println(startDateTime)
  69. }
  70. func EditReportContentHtml(reportId int, content string) (err error) {
  71. o := orm.NewOrmUsingDB("rddp")
  72. sql := ` UPDATE report SET content=?,modify_time=NOW() WHERE id=? `
  73. _, err = o.Raw(sql, content, reportId).Exec()
  74. return
  75. }
  76. // GetPrePublishedReports 获取定时发布时间为当前时间的未发布的报告列表
  77. func GetPrePublishedReports(startTime, endTime, afterDate string) (list []*Report, err error) {
  78. o := orm.NewOrmUsingDB("rddp")
  79. sql := `SELECT * FROM report WHERE state = 1 and pre_publish_time >= ? and pre_publish_time <=? and modify_time >= ?`
  80. _, err = o.Raw(sql, startTime, endTime, afterDate).QueryRows(&list)
  81. return
  82. }
  83. // PublishReportById 发布报告
  84. func PublishReportById(reportId int, publishTime time.Time) (err error) {
  85. o := orm.NewOrmUsingDB("rddp")
  86. sql := `UPDATE report SET state = 2, publish_time = ?, modify_time = NOW() WHERE id = ? `
  87. _, err = o.Raw(sql, publishTime, reportId).Exec()
  88. return
  89. }
  90. type ReportDetail struct {
  91. Id int `orm:"column(id)" description:"报告Id"`
  92. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  93. ClassifyIdFirst int `description:"一级分类id"`
  94. ClassifyNameFirst string `description:"一级分类名称"`
  95. ClassifyIdSecond int `description:"二级分类id"`
  96. ClassifyNameSecond string `description:"二级分类名称"`
  97. Title string `description:"标题"`
  98. Abstract string `description:"摘要"`
  99. Author string `description:"作者"`
  100. Frequency string `description:"频度"`
  101. CreateTime string `description:"创建时间"`
  102. ModifyTime string `description:"修改时间"`
  103. State int `description:"1:未发布,2:已发布"`
  104. PublishTime string `description:"发布时间"`
  105. Stage int `description:"期数"`
  106. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  107. Content string `description:"内容"`
  108. VideoUrl string `description:"音频文件URL"`
  109. VideoName string `description:"音频文件名称"`
  110. VideoPlaySeconds string `description:"音频播放时长"`
  111. ContentSub string `description:"内容前两个章节"`
  112. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  113. HasChapter int `description:"是否有章节 0-否 1-是"`
  114. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  115. OldReportId int `description:"research_report表ID(后续一两个版本过渡需要,之后可移除)"`
  116. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  117. }
  118. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  119. o := orm.NewOrmUsingDB("rddp")
  120. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  121. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  122. return
  123. }
  124. // ReportChapter 报告章节
  125. type ReportChapter struct {
  126. ReportChapterId int `orm:"column(report_chapter_id);pk" description:"报告章节ID"`
  127. ReportId int `description:"报告ID"`
  128. ReportType string `description:"报告类型 day-晨报 week-周报"`
  129. ClassifyIdFirst int `description:"一级分类id"`
  130. ClassifyNameFirst string `description:"一级分类名称"`
  131. TypeId int `description:"品种ID"`
  132. TypeName string `description:"品种名称"`
  133. Title string `description:"标题"`
  134. Abstract string `description:"摘要"`
  135. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  136. Author string `description:"作者"`
  137. Content string `description:"内容"`
  138. ContentSub string `description:"内容前两个章节"`
  139. Stage int `description:"期数"`
  140. Trend string `description:"趋势观点"`
  141. Sort int `description:"排序: 数值越小越靠前"`
  142. IsEdit int `description:"是否已编辑 0-待编辑 1-已编辑"`
  143. PublishState int `description:"发布状态 1-待发布,2-已发布"`
  144. PublishTime time.Time `description:"发布时间"`
  145. VideoUrl string `description:"音频文件URL"`
  146. VideoName string `description:"音频文件名称"`
  147. VideoPlaySeconds string `description:"音频播放时长"`
  148. VideoSize string `description:"音频文件大小,单位M"`
  149. VideoKind int `description:"音频生成方式:1,手动上传,2:自动生成"`
  150. CreateTime string `description:"创建时间"`
  151. ModifyTime time.Time `description:"修改时间"`
  152. OriginalVideoUrl string `description:"原始音频文件URL"`
  153. }
  154. // GetPublishedChapterListByReportId 根据ReportId获取已发布章节列表
  155. func GetPublishedChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
  156. o := orm.NewOrmUsingDB("rddp")
  157. sql := ` SELECT * FROM report_chapter WHERE report_id = ? AND publish_state = 2 ORDER BY sort ASC`
  158. _, err = o.Raw(sql, reportId).QueryRows(&list)
  159. return
  160. }
  161. type ReportChapterTypePermission struct {
  162. Id int `orm:"column(id);pk" description:"主键ID"`
  163. ReportChapterTypeId int `description:"报告章节类型ID"`
  164. ReportChapterTypeName string `description:"章节名称"`
  165. ChartPermissionId int `description:"大分类ID"`
  166. PermissionName string `description:"权限名称"`
  167. ResearchType string `description:"研报类型"`
  168. CreatedTime time.Time `description:"创建时间"`
  169. }
  170. // GetChapterTypePermissionByTypeIdAndResearchType 根据章节类型ID及研报类型获取章节类型权限列表
  171. func GetChapterTypePermissionByTypeIdAndResearchType(typeId int, researchType string) (list []*ReportChapterTypePermission, err error) {
  172. o := orm.NewOrm()
  173. sql := ` SELECT * FROM report_chapter_type_permission WHERE report_chapter_type_id = ? AND research_type = ? ORDER BY chart_permission_id ASC `
  174. _, err = o.Raw(sql, typeId, researchType).QueryRows(&list)
  175. return
  176. }
  177. type ElasticReportDetail struct {
  178. ReportId int `description:"报告ID"`
  179. ReportChapterId int `description:"报告章节ID"`
  180. Title string `description:"标题"`
  181. Abstract string `description:"摘要"`
  182. BodyContent string `description:"内容"`
  183. PublishTime string `description:"发布时间"`
  184. PublishState int `description:"发布状态 1-未发布 2-已发布"`
  185. Author string `description:"作者"`
  186. ClassifyIdFirst int `description:"一级分类ID"`
  187. ClassifyNameFirst string `description:"一级分类名称"`
  188. ClassifyIdSecond int `description:"二级分类ID"`
  189. ClassifyNameSecond string `description:"二级分类名称"`
  190. Categories string `description:"关联的品种名称(包括品种别名)"`
  191. StageStr string `description:"报告期数"`
  192. }
  193. type ChartPermissionMappingIdName struct {
  194. PermissionId int
  195. PermissionName string
  196. }
  197. func GetChartPermissionNameFromMappingByKeyword(keyword string, source string) (list []*ChartPermissionMappingIdName, err error) {
  198. o := orm.NewOrm()
  199. 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 = ? "
  200. _, err = o.Raw(sql, source, keyword).QueryRows(&list)
  201. return
  202. }
  203. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  204. o := orm.NewOrmUsingDB("rddp")
  205. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  206. _, err = o.Raw(sql1, reportId).Exec()
  207. if err != nil {
  208. return
  209. }
  210. //修改音频标题
  211. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  212. _, err = o.Raw(sql2, reportId).Exec()
  213. return
  214. }
  215. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  216. o := orm.NewOrmUsingDB("rddp")
  217. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  218. _, err = o.Raw(sql1, reportId).Exec()
  219. if err != nil {
  220. return
  221. }
  222. //修改音频标题
  223. 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)`
  224. _, err = o.Raw(sql2, reportId).Exec()
  225. return
  226. }
  227. func ModifyReportMsgIsSend(reportId int) (err error) {
  228. o := orm.NewOrmUsingDB("rddp")
  229. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? and msg_is_send=0`
  230. _, err = o.Raw(sql, reportId).Exec()
  231. return
  232. }