report.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. package models
  2. import (
  3. "eta/eta_task/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  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. 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 GetReportById(reportId int) (item *ReportDetail, err error) {
  41. o := orm.NewOrmUsingDB("rddp")
  42. sql := `SELECT * FROM report WHERE id=?`
  43. err = o.Raw(sql, reportId).QueryRow(&item)
  44. return
  45. }
  46. func GetReport() (items []*Report, err error) {
  47. sql := `SELECT * FROM report ORDER BY id ASC `
  48. o := orm.NewOrmUsingDB("rddp")
  49. _, err = o.Raw(sql).QueryRows(&items)
  50. return
  51. }
  52. func ModifyReportContentSub(id int, contentSub string) (err error) {
  53. sql := `UPDATE report SET content_sub=? WHERE id=? `
  54. o := orm.NewOrmUsingDB("rddp")
  55. _, err = o.Raw(sql, contentSub, id).Exec()
  56. return
  57. }
  58. func GetReportLimit() (items []*Report, err error) {
  59. sql := `SELECT * FROM report WHERE state=2 ORDER BY id DESC LIMIT 50 `
  60. o := orm.NewOrmUsingDB("rddp")
  61. _, err = o.Raw(sql).QueryRows(&items)
  62. return
  63. }
  64. func EditReportContent(reportId int, content, contentSub string) (err error) {
  65. o := orm.NewOrmUsingDB("rddp")
  66. sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  67. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  68. return
  69. }
  70. // 删除报告日志记录-保留3个月
  71. func DeleteReportSaveLog() {
  72. startDateTime := time.Now().AddDate(0, -3, 0).Format(utils.FormatDateTime)
  73. fmt.Println(startDateTime)
  74. }
  75. func EditReportContentHtml(reportId int, content string) (err error) {
  76. o := orm.NewOrmUsingDB("rddp")
  77. sql := ` UPDATE report SET content=?,modify_time=NOW() WHERE id=? `
  78. _, err = o.Raw(sql, content, reportId).Exec()
  79. return
  80. }
  81. // GetPrePublishedReports 获取定时发布时间为当前时间的未发布的报告列表
  82. func GetPrePublishedReports(startTime, endTime, afterDate string) (list []*Report, err error) {
  83. o := orm.NewOrmUsingDB("rddp")
  84. sql := `SELECT * FROM report WHERE state = 1 and pre_publish_time >= ? and pre_publish_time <=? and modify_time >= ?`
  85. _, err = o.Raw(sql, startTime, endTime, afterDate).QueryRows(&list)
  86. return
  87. }
  88. // PublishReportById 发布报告
  89. func PublishReportById(reportId int, publishTime time.Time) (err error) {
  90. o := orm.NewOrmUsingDB("rddp")
  91. sql := `UPDATE report SET state = 2, publish_time = ?, modify_time = NOW() WHERE id = ? `
  92. _, err = o.Raw(sql, publishTime, reportId).Exec()
  93. return
  94. }
  95. type ReportDetail struct {
  96. Id int `orm:"column(id)" description:"报告Id"`
  97. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  98. ClassifyIdFirst int `description:"一级分类id"`
  99. ClassifyNameFirst string `description:"一级分类名称"`
  100. ClassifyIdSecond int `description:"二级分类id"`
  101. ClassifyNameSecond string `description:"二级分类名称"`
  102. Title string `description:"标题"`
  103. Abstract string `description:"摘要"`
  104. Author string `description:"作者"`
  105. Frequency string `description:"频度"`
  106. CreateTime string `description:"创建时间"`
  107. ModifyTime string `description:"修改时间"`
  108. State int `description:"1:未发布,2:已发布"`
  109. PublishTime string `description:"发布时间"`
  110. Stage int `description:"期数"`
  111. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  112. Content string `description:"内容"`
  113. VideoUrl string `description:"音频文件URL"`
  114. VideoName string `description:"音频文件名称"`
  115. VideoPlaySeconds string `description:"音频播放时长"`
  116. ContentSub string `description:"内容前两个章节"`
  117. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  118. HasChapter int `description:"是否有章节 0-否 1-是"`
  119. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  120. OldReportId int `description:"research_report表ID(后续一两个版本过渡需要,之后可移除)"`
  121. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  122. }
  123. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  124. o := orm.NewOrmUsingDB("rddp")
  125. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  126. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  127. return
  128. }
  129. // ModifyReportVideoByNoVideo
  130. // @Description: 修改无音频的报告音频信息
  131. // @author: Roc
  132. // @datetime 2024-07-25 18:03:05
  133. // @param reportId int
  134. // @param videoUrl string
  135. // @param videoName string
  136. // @param videoSize string
  137. // @param playSeconds float64
  138. // @return err error
  139. func ModifyReportVideoByNoVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  140. o := orm.NewOrmUsingDB("rddp")
  141. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? AND video_url=""`
  142. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  143. return
  144. }
  145. type ReportChapterTypePermission struct {
  146. Id int `orm:"column(id);pk" description:"主键ID"`
  147. ReportChapterTypeId int `description:"报告章节类型ID"`
  148. ReportChapterTypeName string `description:"章节名称"`
  149. ChartPermissionId int `description:"大分类ID"`
  150. PermissionName string `description:"权限名称"`
  151. ResearchType string `description:"研报类型"`
  152. CreatedTime time.Time `description:"创建时间"`
  153. }
  154. // GetChapterTypePermissionByTypeIdAndResearchType 根据章节类型ID及研报类型获取章节类型权限列表
  155. func GetChapterTypePermissionByTypeIdAndResearchType(typeId int, researchType string) (list []*ReportChapterTypePermission, err error) {
  156. o := orm.NewOrm()
  157. sql := ` SELECT * FROM report_chapter_type_permission WHERE report_chapter_type_id = ? AND research_type = ? ORDER BY chart_permission_id ASC `
  158. _, err = o.Raw(sql, typeId, researchType).QueryRows(&list)
  159. return
  160. }
  161. type ElasticReportDetail struct {
  162. ReportId int `description:"报告ID"`
  163. ReportChapterId int `description:"报告章节ID"`
  164. Title string `description:"标题"`
  165. Abstract string `description:"摘要"`
  166. BodyContent string `description:"内容"`
  167. PublishTime string `description:"发布时间"`
  168. PublishState int `description:"发布状态 1-未发布 2-已发布"`
  169. Author string `description:"作者"`
  170. ClassifyIdFirst int `description:"一级分类ID"`
  171. ClassifyNameFirst string `description:"一级分类名称"`
  172. ClassifyIdSecond int `description:"二级分类ID"`
  173. ClassifyNameSecond string `description:"二级分类名称"`
  174. ClassifyId int `description:"最小单元的分类ID"`
  175. ClassifyName string `description:"最小单元的分类名称"`
  176. Categories string `description:"关联的品种名称(包括品种别名)"`
  177. StageStr string `description:"报告期数"`
  178. }
  179. type ChartPermissionMappingIdName struct {
  180. PermissionId int
  181. PermissionName string
  182. }
  183. func GetChartPermissionNameFromMappingByKeyword(source string, classifyId int) (list []*ChartPermissionMappingIdName, err error) {
  184. o := orm.NewOrmUsingDB("rddp")
  185. 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 = ? "
  186. _, err = o.Raw(sql, source, classifyId).QueryRows(&list)
  187. return
  188. }
  189. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  190. o := orm.NewOrmUsingDB("rddp")
  191. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  192. _, err = o.Raw(sql1, reportId).Exec()
  193. if err != nil {
  194. return
  195. }
  196. //修改音频标题
  197. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  198. _, err = o.Raw(sql2, reportId).Exec()
  199. return
  200. }
  201. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  202. o := orm.NewOrmUsingDB("rddp")
  203. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  204. _, err = o.Raw(sql1, reportId).Exec()
  205. if err != nil {
  206. return
  207. }
  208. //修改音频标题
  209. 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)`
  210. _, err = o.Raw(sql2, reportId).Exec()
  211. return
  212. }
  213. func ModifyReportMsgIsSend(reportId int) (err error) {
  214. o := orm.NewOrmUsingDB("rddp")
  215. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? and msg_is_send=0`
  216. _, err = o.Raw(sql, reportId).Exec()
  217. return
  218. }
  219. // ClearReportSaveLog 清理报告保存日志
  220. func ClearReportSaveLog(date string) (err error) {
  221. o := orm.NewOrmUsingDB("rddp")
  222. sql := `DELETE FROM report_save_log WHERE create_time <= ?`
  223. _, err = o.Raw(sql, date).Exec()
  224. return
  225. }
  226. // PublishReportAndChapter 发布报告及章节
  227. func PublishReportAndChapter(reportInfo *Report, isPublishReport bool, cols []string) (err error) {
  228. o := orm.NewOrmUsingDB("rddp")
  229. to, err := o.Begin()
  230. if err != nil {
  231. return
  232. }
  233. defer func() {
  234. if err != nil {
  235. _ = to.Rollback()
  236. } else {
  237. _ = to.Commit()
  238. }
  239. }()
  240. // 更新报告
  241. if isPublishReport {
  242. _, err = to.Update(reportInfo, cols...)
  243. if err != nil {
  244. return
  245. }
  246. }
  247. // 发布该报告的所有章节
  248. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? `
  249. _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id).Exec()
  250. // 发布章节
  251. //if len(publishIds) > 0 {
  252. // sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
  253. // _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
  254. //}
  255. //if len(unPublishIds) > 0 {
  256. // 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)) + `) `
  257. // _, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
  258. //}
  259. return
  260. }