report_chapter.go 12 KB

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