report_chapter.go 12 KB

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