report_chapter.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. package models
  2. import (
  3. "eta/eta_api/models/report"
  4. "eta/eta_api/utils"
  5. "github.com/beego/beego/v2/client/orm"
  6. "time"
  7. )
  8. // ReportChapter 报告章节
  9. type ReportChapter struct {
  10. ReportChapterId int `orm:"column(report_chapter_id);pk" description:"报告章节ID"`
  11. ReportId int `description:"报告ID"`
  12. ReportType string `description:"报告类型 day-晨报 week-周报"`
  13. ClassifyIdFirst int `description:"一级分类id"`
  14. ClassifyNameFirst string `description:"一级分类名称"`
  15. TypeId int `description:"品种ID"`
  16. TypeName string `description:"品种名称"`
  17. Title string `description:"标题"`
  18. Abstract string `description:"摘要"`
  19. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  20. Author string `description:"作者"`
  21. Content string `description:"内容"`
  22. ContentSub string `description:"内容前两个章节"`
  23. Stage int `description:"期数"`
  24. Trend string `description:"趋势观点"`
  25. Sort int `description:"排序: 数值越小越靠前"`
  26. IsEdit int `description:"是否已编辑 0-待编辑 1-已编辑"`
  27. PublishState int `description:"发布状态 1-待发布,2-已发布"`
  28. PublishTime time.Time `description:"发布时间"`
  29. VideoUrl string `description:"音频文件URL"`
  30. VideoName string `description:"音频文件名称"`
  31. VideoPlaySeconds string `description:"音频播放时长"`
  32. VideoSize string `description:"音频文件大小,单位M"`
  33. VideoKind int `description:"音频生成方式:1,手动上传,2:自动生成"`
  34. CreateTime string `description:"创建时间"`
  35. ModifyTime time.Time `description:"修改时间"`
  36. OriginalVideoUrl string `description:"原始音频文件URL"`
  37. ClassifyIdSecond int `description:"二级分类id"`
  38. ClassifyNameSecond string `description:"二级分类名称"`
  39. ClassifyIdThird int `description:"三级分类id"`
  40. ClassifyNameThird string `description:"三级分类名称"`
  41. ContentStruct string `description:"内容组件"`
  42. LastModifyAdminId int `description:"最后更新人ID"`
  43. LastModifyAdminName string `description:"最后更新人姓名"`
  44. ContentModifyTime time.Time `description:"内容更新时间"`
  45. CanvasColor string `description:"画布颜色"`
  46. HeadResourceId int `description:"版头资源ID"`
  47. EndResourceId int `description:"版尾资源ID"`
  48. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  49. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  50. ReportCreateTime time.Time `description:"报告时间创建时间"`
  51. }
  52. type ReportChapterResp struct {
  53. ReportChapterId int `description:"报告章节ID"`
  54. ReportId int `description:"报告ID"`
  55. ReportType string `description:"报告类型 day-晨报 week-周报"`
  56. TypeId int `description:"品种ID"`
  57. TypeName string `description:"品种名称"`
  58. TypeEditImg string `description:"后台编辑时的图片"`
  59. Title string `description:"标题"`
  60. Abstract string `description:"摘要"`
  61. Author string `description:"作者"`
  62. Content string `description:"内容"`
  63. ContentSub string `description:"内容前两个章节"`
  64. Stage int `description:"期数"`
  65. Trend string `description:"趋势观点"`
  66. Sort int `description:"排序: 数值越小越靠前"`
  67. IsEdit int `description:"是否已编辑 0-待编辑 1-已编辑"`
  68. PublishState int `description:"发布状态 1-待发布,2-已发布"`
  69. VideoUrl string `description:"音频文件URL"`
  70. VideoName string `description:"音频文件名称"`
  71. VideoPlaySeconds string `description:"音频播放时长"`
  72. VideoSize string `description:"音频文件大小,单位M"`
  73. VideoKind int `description:"音频生成方式:1,手动上传,2:自动生成"`
  74. PublishTime string `description:"发布时间"`
  75. CreateTime string `description:"创建时间"`
  76. ModifyTime string `description:"修改时间"`
  77. }
  78. // GetChapterListByReportId 根据ReportId获取章节列表
  79. func GetChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
  80. o := orm.NewOrmUsingDB("rddp")
  81. sql := ` SELECT * FROM report_chapter WHERE report_id = ? ORDER BY sort ASC`
  82. _, err = o.Raw(sql, reportId).QueryRows(&list)
  83. return
  84. }
  85. // GetPublishedChapterListByReportId 根据ReportId获取已发布章节列表
  86. func GetPublishedChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
  87. o := orm.NewOrmUsingDB("rddp")
  88. sql := ` SELECT * FROM report_chapter WHERE report_id = ? AND publish_state = 2 ORDER BY sort ASC`
  89. _, err = o.Raw(sql, reportId).QueryRows(&list)
  90. return
  91. }
  92. // AddReportChapterReq
  93. // @Description: 新增报告章节请求体
  94. type AddReportChapterReq struct {
  95. ReportId int `description:"报告章节ID"`
  96. Title string `description:"标题"`
  97. Author string `description:"作者"`
  98. Content string `description:"内容"`
  99. CreateTime string `description:"发布时间"`
  100. // 以下是智能研报相关
  101. ContentStruct string `description:"内容组件"`
  102. HeadImg string `description:"报告头图地址"`
  103. EndImg string `description:"报告尾图地址"`
  104. CanvasColor string `description:"画布颜色"`
  105. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  106. HeadResourceId int `description:"版头资源ID"`
  107. EndResourceId int `description:"版尾资源ID"`
  108. }
  109. // EditReportChapterReq 编辑报告章节请求体
  110. type EditReportChapterReq struct {
  111. ReportChapterId int `description:"报告章节ID"`
  112. Title string `description:"标题"`
  113. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  114. Author string `description:"作者"`
  115. Content string `description:"内容"`
  116. TickerList []EditTickList `description:"指标信息"`
  117. CreateTime string `description:"发布时间"`
  118. VideoUrl string `description:"音频文件URL"`
  119. VideoName string `description:"音频文件名称"`
  120. VideoPlaySeconds string `description:"音频播放时长"`
  121. VideoSize string `description:"音频文件大小,单位M"`
  122. // 以下是智能研报相关
  123. ContentStruct string `description:"内容组件"`
  124. HeadImg string `description:"报告头图地址"`
  125. EndImg string `description:"报告尾图地址"`
  126. CanvasColor string `description:"画布颜色"`
  127. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  128. HeadResourceId int `description:"版头资源ID"`
  129. EndResourceId int `description:"版尾资源ID"`
  130. }
  131. type EditTickList struct {
  132. Label string
  133. Ticker string
  134. Sort int
  135. }
  136. // GetReportChapterInfoById 根据主键获取报告章节
  137. func GetReportChapterInfoById(reportChapterId int) (item *ReportChapter, err error) {
  138. o := orm.NewOrmUsingDB("rddp")
  139. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ? `
  140. err = o.Raw(sql, reportChapterId).QueryRow(&item)
  141. return
  142. }
  143. // GetLastPublishedReportChapter 获取上一篇已发表的晨周报章节
  144. func GetLastPublishedReportChapter(typeId int, reportType string) (item *ReportChapter, err error) {
  145. o := orm.NewOrmUsingDB("rddp")
  146. sql := ` SELECT * FROM report_chapter WHERE publish_state = 2 AND type_id = ? AND report_type = ? ORDER BY report_chapter_id DESC limit 1 `
  147. err = o.Raw(sql, typeId, reportType).QueryRow(&item)
  148. return
  149. }
  150. // Add
  151. // @Description: 新增章节报告
  152. // @author: Roc
  153. // @receiver chapterInfo
  154. // @datetime 2024-06-04 15:14:41
  155. // @return err error
  156. func (chapterInfo *ReportChapter) Add() (err error) {
  157. o := orm.NewOrmUsingDB("rddp")
  158. lastId, err := o.Insert(chapterInfo)
  159. if err != nil {
  160. return
  161. }
  162. chapterInfo.ReportChapterId = int(lastId)
  163. return
  164. }
  165. // UpdateChapter 更新报表章节
  166. func (chapterInfo *ReportChapter) UpdateChapter(cols []string) (err error) {
  167. o := orm.NewOrmUsingDB("rddp")
  168. _, err = o.Update(chapterInfo, cols...)
  169. return
  170. }
  171. // EditChapterTrendTagReq 编辑章节趋势标签请求体
  172. type EditChapterTrendTagReq struct {
  173. ReportChapterId int `description:"章节ID"`
  174. Trend string `description:"趋势"`
  175. }
  176. // UpdateChapterAndTicker 更新章节及ticker
  177. func UpdateChapterAndTicker(chapterInfo *ReportChapter, updateCols []string, tickerList []*ReportChapterTicker) (err error) {
  178. // 更新章节
  179. if err = chapterInfo.UpdateChapter(updateCols); err != nil {
  180. return
  181. }
  182. // 清空并新增章节ticker
  183. if err = ClearReportChapterTicker(chapterInfo.ReportChapterId); err != nil {
  184. return
  185. }
  186. tickerLen := len(tickerList)
  187. if tickerLen > 0 {
  188. for i := 0; i < tickerLen; i++ {
  189. _, tmpErr := InsertChapterTicker(tickerList[i])
  190. if tmpErr != nil {
  191. return
  192. }
  193. }
  194. }
  195. return
  196. }
  197. // ReportChapterVideoList 报告章节音频列表
  198. type ReportChapterVideoList struct {
  199. ReportId int `description:"报告ID"`
  200. ReportChapterId int `description:"报告章节ID"`
  201. VideoUrl string `description:"音频文件URL"`
  202. VideoName string `description:"音频文件名称"`
  203. VideoPlaySeconds string `description:"音频播放时长"`
  204. }
  205. // GetReportChapterVideoList 获取报告章节音频列表
  206. func GetReportChapterVideoList(reportId int) (list []*ReportChapterVideoList, err error) {
  207. o := orm.NewOrmUsingDB("rddp")
  208. sql := ` SELECT
  209. report_id,
  210. report_chapter_id,
  211. video_url,
  212. video_name,
  213. video_play_seconds
  214. FROM
  215. report_chapter
  216. WHERE
  217. report_id = ? AND publish_state = 2 AND video_url != ""
  218. ORDER BY
  219. report_chapter_id ASC `
  220. _, err = o.Raw(sql, reportId).QueryRows(&list)
  221. return
  222. }
  223. // GetReportChapterVideoListByReportIds 根据报告ID集合获取报告章节音频列表
  224. func GetReportChapterVideoListByReportIds(reportIds []string) (list []*ReportChapterVideoList, err error) {
  225. if len(reportIds) == 0 {
  226. return
  227. }
  228. o := orm.NewOrmUsingDB("rddp")
  229. sql := ` SELECT
  230. report_id,
  231. report_chapter_id,
  232. video_url,
  233. video_name,
  234. video_play_seconds
  235. FROM
  236. report_chapter
  237. WHERE
  238. report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `) AND publish_state = 2 AND video_url != ""
  239. ORDER BY
  240. report_chapter_id ASC `
  241. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  242. return
  243. }
  244. // GetReportChapterVideoListByChapterIds 根据章节ID集合获取报告章节音频列表
  245. func GetReportChapterVideoListByChapterIds(chapterIds []int) (list []*ReportChapterVideoList, err error) {
  246. if len(chapterIds) == 0 {
  247. return
  248. }
  249. o := orm.NewOrmUsingDB("rddp")
  250. sql := ` SELECT
  251. report_id,
  252. report_chapter_id,
  253. video_url,
  254. video_name,
  255. video_play_seconds
  256. FROM
  257. report_chapter
  258. WHERE
  259. report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) AND publish_state = 2
  260. ORDER BY
  261. report_chapter_id ASC `
  262. _, err = o.Raw(sql, chapterIds).QueryRows(&list)
  263. return
  264. }
  265. // PublishReportChapterReq 发布报告章节请求体
  266. type PublishReportChapterReq struct {
  267. ReportChapterId int `description:"报告章节ID"`
  268. Title string `description:"标题"`
  269. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  270. Author string `description:"作者"`
  271. Content string `description:"内容"`
  272. TickerList []EditTickList `description:"指标信息"`
  273. CreateTime string `description:"发布时间"`
  274. PublishReport int `description:"是否同时发布报告"`
  275. VideoUrl string `description:"音频文件URL"`
  276. VideoName string `description:"音频文件名称"`
  277. VideoPlaySeconds string `description:"音频播放时长"`
  278. VideoSize string `description:"音频文件大小,单位M"`
  279. }
  280. // CountPublishedChapterNum 获取报告已发布的章节数
  281. func CountPublishedChapterNum(reportId int) (count int, err error) {
  282. o := orm.NewOrmUsingDB("rddp")
  283. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 2 `
  284. err = o.Raw(sql, reportId).QueryRow(&count)
  285. return
  286. }
  287. // GetChapterListByChapterIds 根据ReportId获取章节列表
  288. func GetChapterListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
  289. if len(chapterIds) == 0 {
  290. return
  291. }
  292. o := orm.NewOrmUsingDB("rddp")
  293. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) ORDER BY sort ASC`
  294. _, err = o.Raw(sql, chapterIds).QueryRows(&list)
  295. return
  296. }
  297. // GetChapterSimpleListByChapterIds 根据章节ID获取章节列表
  298. func GetChapterSimpleListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
  299. if len(chapterIds) == 0 {
  300. return
  301. }
  302. o := orm.NewOrmUsingDB("rddp")
  303. 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`
  304. _, err = o.Raw(sql, chapterIds).QueryRows(&list)
  305. return
  306. }
  307. // GetChapterSimpleListByReportIds 根据ReportId获取章节列表
  308. func GetChapterSimpleListByReportIds(reportIds []int) (list []*ReportChapter, err error) {
  309. if len(reportIds) == 0 {
  310. return
  311. }
  312. o := orm.NewOrmUsingDB("rddp")
  313. 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`
  314. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  315. return
  316. }
  317. // UpdateReportChapterTypeNameByTypeId 更新章节类型名称
  318. func UpdateReportChapterTypeNameByTypeId(typeId int, typeName string) (err error) {
  319. o := orm.NewOrmUsingDB("rddp")
  320. sql := `UPDATE report_chapter SET type_name = ? WHERE type_id = ?`
  321. _, err = o.Raw(sql, typeName, typeId).Exec()
  322. return
  323. }
  324. // CountReportChapterByTypeId 通过章节类型ID获取章节数
  325. func CountReportChapterByTypeId(typeId int) (count int, err error) {
  326. o := orm.NewOrmUsingDB("rddp")
  327. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE type_id = ?`
  328. err = o.Raw(sql, typeId).QueryRow(&count)
  329. return
  330. }
  331. // AddReportChapter
  332. // @Description: 待添加的报告章节
  333. type AddReportChapter struct {
  334. ReportChapter *ReportChapter
  335. GrantList []*report.ReportChapterGrant
  336. }
  337. // EditReportChapterBaseInfoAndPermissionReq
  338. // @Description: 编辑报告章节的基础信息请求
  339. type EditReportChapterBaseInfoAndPermissionReq struct {
  340. ReportChapterId int `description:"报告章节ID"`
  341. Title string `description:"标题"`
  342. PermissionIdList []int `description:"报告关联的品种权限"`
  343. AdminIdList []int `description:"授权的编辑人id列表"`
  344. }
  345. // GetReportChapterIdList
  346. // @Description: 获取报告的所有章节id列表
  347. // @author: Roc
  348. // @datetime 2024-06-05 11:09:40
  349. // @param reportId int
  350. // @return list []int
  351. // @return err error
  352. func GetReportChapterIdList(reportId int) (list []int, err error) {
  353. o := orm.NewOrmUsingDB("rddp")
  354. sql := ` SELECT report_chapter_id FROM report_chapter
  355. WHERE report_id = ?
  356. ORDER BY report_chapter_id ASC `
  357. _, err = o.Raw(sql, reportId).QueryRows(&list)
  358. return
  359. }