report_chapter.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // ReportChapter 报告章节
  7. type ReportChapter struct {
  8. ReportChapterId int `orm:"column(report_chapter_id);pk" description:"报告章节ID"`
  9. ReportId int `description:"报告ID"`
  10. ReportType string `description:"报告类型 day-晨报 week-周报"`
  11. ClassifyIdFirst int `description:"一级分类id"`
  12. ClassifyNameFirst string `description:"一级分类名称"`
  13. TypeId int `description:"品种ID"`
  14. TypeName string `description:"品种名称"`
  15. Title string `description:"标题"`
  16. Abstract string `description:"摘要"`
  17. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  18. Author string `description:"作者"`
  19. Content string `description:"内容"`
  20. ContentSub string `description:"内容前两个章节"`
  21. Stage int `description:"期数"`
  22. Trend string `description:"趋势观点"`
  23. Sort int `description:"排序: 数值越小越靠前"`
  24. IsEdit int `description:"是否已编辑 0-待编辑 1-已编辑"`
  25. PublishState int `description:"发布状态 1-待发布,2-已发布"`
  26. PublishTime time.Time `description:"发布时间"`
  27. VideoUrl string `description:"音频文件URL"`
  28. VideoName string `description:"音频文件名称"`
  29. VideoPlaySeconds string `description:"音频播放时长"`
  30. VideoSize string `description:"音频文件大小,单位M"`
  31. VideoKind int `description:"音频生成方式:1,手动上传,2:自动生成"`
  32. CreateTime string `description:"创建时间"`
  33. ModifyTime time.Time `description:"修改时间"`
  34. OriginalVideoUrl string `description:"原始音频文件URL"`
  35. }
  36. type ReportChapterResp struct {
  37. ReportChapterId int `description:"报告章节ID"`
  38. ReportId int `description:"报告ID"`
  39. ReportType string `description:"报告类型 day-晨报 week-周报"`
  40. TypeId int `description:"品种ID"`
  41. TypeName string `description:"品种名称"`
  42. TypeEditImg string `description:"后台编辑时的图片"`
  43. Title string `description:"标题"`
  44. Abstract string `description:"摘要"`
  45. Author string `description:"作者"`
  46. Content string `description:"内容"`
  47. ContentSub string `description:"内容前两个章节"`
  48. Stage int `description:"期数"`
  49. Trend string `description:"趋势观点"`
  50. Sort int `description:"排序: 数值越小越靠前"`
  51. IsEdit int `description:"是否已编辑 0-待编辑 1-已编辑"`
  52. PublishState int `description:"发布状态 1-待发布,2-已发布"`
  53. VideoUrl string `description:"音频文件URL"`
  54. VideoName string `description:"音频文件名称"`
  55. VideoPlaySeconds string `description:"音频播放时长"`
  56. VideoSize string `description:"音频文件大小,单位M"`
  57. VideoKind int `description:"音频生成方式:1,手动上传,2:自动生成"`
  58. PublishTime string `description:"发布时间"`
  59. CreateTime string `description:"创建时间"`
  60. ModifyTime string `description:"修改时间"`
  61. }
  62. // GetChapterListByReportId 根据ReportId获取章节列表
  63. func GetChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
  64. o := orm.NewOrmUsingDB("rddp")
  65. sql := ` SELECT * FROM report_chapter WHERE report_id = ? ORDER BY sort ASC`
  66. _, err = o.Raw(sql, reportId).QueryRows(&list)
  67. return
  68. }
  69. // GetPublishedChapterListByReportId 根据ReportId获取已发布章节列表
  70. func GetPublishedChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
  71. o := orm.NewOrmUsingDB("rddp")
  72. sql := ` SELECT * FROM report_chapter WHERE report_id = ? AND publish_state = 2 ORDER BY sort ASC`
  73. _, err = o.Raw(sql, reportId).QueryRows(&list)
  74. return
  75. }
  76. // EditReportChapterReq 编辑报告章节请求体
  77. type EditReportChapterReq struct {
  78. ReportChapterId int `description:"报告章节ID"`
  79. Title string `description:"标题"`
  80. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  81. Author string `description:"作者"`
  82. Content string `description:"内容"`
  83. TickerList []EditTickList `description:"指标信息"`
  84. CreateTime string `description:"发布时间"`
  85. VideoUrl string `description:"音频文件URL"`
  86. VideoName string `description:"音频文件名称"`
  87. VideoPlaySeconds string `description:"音频播放时长"`
  88. VideoSize string `description:"音频文件大小,单位M"`
  89. }
  90. type EditTickList struct {
  91. Label string
  92. Ticker string
  93. Sort int
  94. }
  95. // GetReportChapterInfoById 根据主键获取报告章节
  96. func GetReportChapterInfoById(reportChapterId int) (item *ReportChapter, err error) {
  97. o := orm.NewOrmUsingDB("rddp")
  98. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ? `
  99. err = o.Raw(sql, reportChapterId).QueryRow(&item)
  100. return
  101. }
  102. // GetLastPublishedReportChapter 获取上一篇已发表的晨周报章节
  103. func GetLastPublishedReportChapter(typeId int, reportType string) (item *ReportChapter, err error) {
  104. o := orm.NewOrmUsingDB("rddp")
  105. sql := ` SELECT * FROM report_chapter WHERE publish_state = 2 AND type_id = ? AND report_type = ? ORDER BY report_chapter_id DESC limit 1 `
  106. err = o.Raw(sql, typeId, reportType).QueryRow(&item)
  107. return
  108. }
  109. // UpdateChapter 更新报表章节
  110. func (chapterInfo *ReportChapter) UpdateChapter(cols []string) (err error) {
  111. o := orm.NewOrmUsingDB("rddp")
  112. _, err = o.Update(chapterInfo, cols...)
  113. return
  114. }
  115. // EditChapterTrendTagReq 编辑章节趋势标签请求体
  116. type EditChapterTrendTagReq struct {
  117. ReportChapterId int `description:"章节ID"`
  118. Trend string `description:"趋势"`
  119. }
  120. // UpdateChapterAndTicker 更新章节及ticker
  121. func UpdateChapterAndTicker(chapterInfo *ReportChapter, updateCols []string, tickerList []*ReportChapterTicker) (err error) {
  122. // 更新章节
  123. if err = chapterInfo.UpdateChapter(updateCols); err != nil {
  124. return
  125. }
  126. // 清空并新增章节ticker
  127. if err = ClearReportChapterTicker(chapterInfo.ReportChapterId); err != nil {
  128. return
  129. }
  130. tickerLen := len(tickerList)
  131. if tickerLen > 0 {
  132. for i := 0; i < tickerLen; i++ {
  133. _, tmpErr := InsertChapterTicker(tickerList[i])
  134. if tmpErr != nil {
  135. return
  136. }
  137. }
  138. }
  139. return
  140. }
  141. // ReportChapterVideoList 报告章节音频列表
  142. type ReportChapterVideoList struct {
  143. ReportId int `description:"报告ID"`
  144. ReportChapterId int `description:"报告章节ID"`
  145. VideoUrl string `description:"音频文件URL"`
  146. VideoName string `description:"音频文件名称"`
  147. VideoPlaySeconds string `description:"音频播放时长"`
  148. }
  149. // GetReportChapterVideoList 获取报告章节音频列表
  150. func GetReportChapterVideoList(reportId int) (list []*ReportChapterVideoList, err error) {
  151. o := orm.NewOrmUsingDB("rddp")
  152. sql := ` SELECT
  153. report_id,
  154. report_chapter_id,
  155. video_url,
  156. video_name,
  157. video_play_seconds
  158. FROM
  159. report_chapter
  160. WHERE
  161. report_id = ? AND publish_state = 2 AND video_url != ""
  162. ORDER BY
  163. report_chapter_id ASC `
  164. _, err = o.Raw(sql, reportId).QueryRows(&list)
  165. return
  166. }
  167. // GetReportChapterVideoListByReportIds 根据报告ID集合获取报告章节音频列表
  168. func GetReportChapterVideoListByReportIds(reportIds string) (list []*ReportChapterVideoList, err error) {
  169. o := orm.NewOrmUsingDB("rddp")
  170. sql := ` SELECT
  171. report_id,
  172. report_chapter_id,
  173. video_url,
  174. video_name,
  175. video_play_seconds
  176. FROM
  177. report_chapter
  178. WHERE
  179. report_id IN (` + reportIds + `) AND publish_state = 2 AND video_url != ""
  180. ORDER BY
  181. report_chapter_id ASC `
  182. _, err = o.Raw(sql).QueryRows(&list)
  183. return
  184. }
  185. // GetReportChapterVideoListByChapterIds 根据章节ID集合获取报告章节音频列表
  186. func GetReportChapterVideoListByChapterIds(chapterIds string) (list []*ReportChapterVideoList, err error) {
  187. o := orm.NewOrmUsingDB("rddp")
  188. sql := ` SELECT
  189. report_id,
  190. report_chapter_id,
  191. video_url,
  192. video_name,
  193. video_play_seconds
  194. FROM
  195. report_chapter
  196. WHERE
  197. report_chapter_id IN (` + chapterIds + `) AND publish_state = 2
  198. ORDER BY
  199. report_chapter_id ASC `
  200. _, err = o.Raw(sql).QueryRows(&list)
  201. return
  202. }
  203. // PublishReportChapterReq 发布报告章节请求体
  204. type PublishReportChapterReq struct {
  205. ReportChapterId int `description:"报告章节ID"`
  206. Title string `description:"标题"`
  207. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  208. Author string `description:"作者"`
  209. Content string `description:"内容"`
  210. TickerList []EditTickList `description:"指标信息"`
  211. CreateTime string `description:"发布时间"`
  212. PublishReport int `description:"是否同时发布报告"`
  213. VideoUrl string `description:"音频文件URL"`
  214. VideoName string `description:"音频文件名称"`
  215. VideoPlaySeconds string `description:"音频播放时长"`
  216. VideoSize string `description:"音频文件大小,单位M"`
  217. }
  218. // CountPublishedChapterNum 获取报告已发布的章节数
  219. func CountPublishedChapterNum(reportId int) (count int, err error) {
  220. o := orm.NewOrmUsingDB("rddp")
  221. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 2 `
  222. err = o.Raw(sql, reportId).QueryRow(&count)
  223. return
  224. }
  225. // GetChapterListByReportId 根据ReportId获取章节列表
  226. func GetChapterListByChapterIds(chapterIds string) (list []*ReportChapter, err error) {
  227. o := orm.NewOrmUsingDB("rddp")
  228. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id IN (` + chapterIds + `) ORDER BY sort ASC`
  229. _, err = o.Raw(sql).QueryRows(&list)
  230. return
  231. }
  232. // GetChapterSimpleListByChapterIds 根据章节ID获取章节列表
  233. func GetChapterSimpleListByChapterIds(chapterIds string) (list []*ReportChapter, err error) {
  234. o := orm.NewOrmUsingDB("rddp")
  235. sql := ` SELECT report_id, report_chapter_id, title, type_name, create_time, IF(publish_time,publish_time,create_time) as publish_time FROM report_chapter WHERE report_chapter_id IN (` + chapterIds + `) ORDER BY publish_time desc, sort ASC`
  236. _, err = o.Raw(sql).QueryRows(&list)
  237. return
  238. }
  239. // GetChapterSimpleListByReportIds 根据ReportId获取章节列表
  240. func GetChapterSimpleListByReportIds(reportIds string) (list []*ReportChapter, err error) {
  241. o := orm.NewOrmUsingDB("rddp")
  242. sql := ` SELECT report_id, report_chapter_id, title, type_name, create_time, IF(publish_time,publish_time,create_time) as publish_time FROM report_chapter WHERE publish_state = 2 and report_id IN (` + reportIds + `) ORDER BY publish_time desc, sort ASC`
  243. _, err = o.Raw(sql).QueryRows(&list)
  244. return
  245. }
  246. // UpdateReportChapterTypeNameByTypeId 更新章节类型名称
  247. func UpdateReportChapterTypeNameByTypeId(typeId int, typeName string) (err error) {
  248. o := orm.NewOrmUsingDB("rddp")
  249. sql := `UPDATE report_chapter SET type_name = ? WHERE type_id = ?`
  250. _, err = o.Raw(sql, typeName, typeId).Exec()
  251. return
  252. }
  253. // CountReportChapterByTypeId 通过章节类型ID获取章节数
  254. func CountReportChapterByTypeId(typeId int) (count int, err error) {
  255. o := orm.NewOrmUsingDB("rddp")
  256. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE type_id = ?`
  257. err = o.Raw(sql, typeId).QueryRow(&count)
  258. return
  259. }