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. }
  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. o := orm.NewOrmUsingDB("rddp")
  123. to, err := o.Begin()
  124. if err != nil {
  125. return
  126. }
  127. defer func() {
  128. if err != nil {
  129. _ = to.Rollback()
  130. } else {
  131. _ = to.Commit()
  132. }
  133. }()
  134. // 更新章节
  135. if err = chapterInfo.UpdateChapter(updateCols); err != nil {
  136. return
  137. }
  138. // 清空并新增章节ticker
  139. if err = ClearReportChapterTicker(chapterInfo.ReportChapterId); err != nil {
  140. return
  141. }
  142. tickerLen := len(tickerList)
  143. if tickerLen > 0 {
  144. for i := 0; i < tickerLen; i++ {
  145. _, tmpErr := InsertChapterTicker(tickerList[i])
  146. if tmpErr != nil {
  147. return
  148. }
  149. }
  150. }
  151. return
  152. }
  153. // ReportChapterVideoList 报告章节音频列表
  154. type ReportChapterVideoList struct {
  155. ReportId int `description:"报告ID"`
  156. ReportChapterId int `description:"报告章节ID"`
  157. VideoUrl string `description:"音频文件URL"`
  158. VideoName string `description:"音频文件名称"`
  159. VideoPlaySeconds string `description:"音频播放时长"`
  160. }
  161. // GetReportChapterVideoList 获取报告章节音频列表
  162. func GetReportChapterVideoList(reportId int) (list []*ReportChapterVideoList, err error) {
  163. o := orm.NewOrmUsingDB("rddp")
  164. sql := ` SELECT
  165. report_id,
  166. report_chapter_id,
  167. video_url,
  168. video_name,
  169. video_play_seconds
  170. FROM
  171. report_chapter
  172. WHERE
  173. report_id = ? AND publish_state = 2 AND video_url != ""
  174. ORDER BY
  175. report_chapter_id ASC `
  176. _, err = o.Raw(sql, reportId).QueryRows(&list)
  177. return
  178. }
  179. // GetReportChapterVideoListByReportIds 根据报告ID集合获取报告章节音频列表
  180. func GetReportChapterVideoListByReportIds(reportIds []string) (list []*ReportChapterVideoList, err error) {
  181. if len(reportIds) == 0 {
  182. return
  183. }
  184. o := orm.NewOrmUsingDB("rddp")
  185. sql := ` SELECT
  186. report_id,
  187. report_chapter_id,
  188. video_url,
  189. video_name,
  190. video_play_seconds
  191. FROM
  192. report_chapter
  193. WHERE
  194. report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `) AND publish_state = 2 AND video_url != ""
  195. ORDER BY
  196. report_chapter_id ASC `
  197. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  198. return
  199. }
  200. // GetReportChapterVideoListByChapterIds 根据章节ID集合获取报告章节音频列表
  201. func GetReportChapterVideoListByChapterIds(chapterIds string) (list []*ReportChapterVideoList, err error) {
  202. o := orm.NewOrmUsingDB("rddp")
  203. sql := ` SELECT
  204. report_id,
  205. report_chapter_id,
  206. video_url,
  207. video_name,
  208. video_play_seconds
  209. FROM
  210. report_chapter
  211. WHERE
  212. report_chapter_id IN (` + chapterIds + `) AND publish_state = 2
  213. ORDER BY
  214. report_chapter_id ASC `
  215. _, err = o.Raw(sql).QueryRows(&list)
  216. return
  217. }
  218. // PublishReportChapterReq 发布报告章节请求体
  219. type PublishReportChapterReq struct {
  220. ReportChapterId int `description:"报告章节ID"`
  221. Title string `description:"标题"`
  222. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  223. Author string `description:"作者"`
  224. Content string `description:"内容"`
  225. TickerList []EditTickList `description:"指标信息"`
  226. CreateTime string `description:"发布时间"`
  227. PublishReport int `description:"是否同时发布报告"`
  228. VideoUrl string `description:"音频文件URL"`
  229. VideoName string `description:"音频文件名称"`
  230. VideoPlaySeconds string `description:"音频播放时长"`
  231. VideoSize string `description:"音频文件大小,单位M"`
  232. }
  233. // CountPublishedChapterNum 获取报告已发布的章节数
  234. func CountPublishedChapterNum(reportId int) (count int, err error) {
  235. o := orm.NewOrmUsingDB("rddp")
  236. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 2 `
  237. err = o.Raw(sql, reportId).QueryRow(&count)
  238. return
  239. }
  240. // GetChapterListByReportId 根据ReportId获取章节列表
  241. func GetChapterListByChapterIds(chapterIds string) (list []*ReportChapter, err error) {
  242. o := orm.NewOrmUsingDB("rddp")
  243. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id IN (` + chapterIds + `) ORDER BY sort ASC`
  244. _, err = o.Raw(sql).QueryRows(&list)
  245. return
  246. }
  247. // GetChapterSimpleListByChapterIds 根据章节ID获取章节列表
  248. func GetChapterSimpleListByChapterIds(chapterIds string) (list []*ReportChapter, err error) {
  249. o := orm.NewOrmUsingDB("rddp")
  250. 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`
  251. _, err = o.Raw(sql).QueryRows(&list)
  252. return
  253. }
  254. // GetChapterSimpleListByReportIds 根据ReportId获取章节列表
  255. func GetChapterSimpleListByReportIds(reportIds string) (list []*ReportChapter, err error) {
  256. o := orm.NewOrmUsingDB("rddp")
  257. 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`
  258. _, err = o.Raw(sql).QueryRows(&list)
  259. return
  260. }
  261. // UpdateReportChapterTypeNameByTypeId 更新章节类型名称
  262. func UpdateReportChapterTypeNameByTypeId(typeId int, typeName string) (err error) {
  263. o := orm.NewOrmUsingDB("rddp")
  264. sql := `UPDATE report_chapter SET type_name = ? WHERE type_id = ?`
  265. _, err = o.Raw(sql, typeName, typeId).Exec()
  266. return
  267. }
  268. // CountReportChapterByTypeId 通过章节类型ID获取章节数
  269. func CountReportChapterByTypeId(typeId int) (count int, err error) {
  270. o := orm.NewOrmUsingDB("rddp")
  271. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE type_id = ?`
  272. err = o.Raw(sql, typeId).QueryRow(&count)
  273. return
  274. }