report_chapter.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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. // ReportChapterItem
  53. // @Description: 章节详情(带有一些额外的数据)
  54. type ReportChapterItem struct {
  55. ReportChapter
  56. GrandAdminIdList []int `description:"授权的用户id列表"`
  57. PermissionIdList []int `description:"关联的品种id列表"`
  58. CanEdit bool `description:"是否可编辑"`
  59. Editor string `description:"编辑人"`
  60. HeadImg string `description:"报告头图地址"`
  61. EndImg string `description:"报告尾图地址"`
  62. HeadStyle string `description:"版头样式"`
  63. EndStyle string `description:"版尾样式"`
  64. }
  65. type ReportChapterResp struct {
  66. ReportChapterId int `description:"报告章节ID"`
  67. ReportId int `description:"报告ID"`
  68. ReportType string `description:"报告类型 day-晨报 week-周报"`
  69. TypeId int `description:"品种ID"`
  70. TypeName string `description:"品种名称"`
  71. TypeEditImg string `description:"后台编辑时的图片"`
  72. Title string `description:"标题"`
  73. Abstract string `description:"摘要"`
  74. Author string `description:"作者"`
  75. Content string `description:"内容"`
  76. ContentSub string `description:"内容前两个章节"`
  77. Stage int `description:"期数"`
  78. Trend string `description:"趋势观点"`
  79. Sort int `description:"排序: 数值越小越靠前"`
  80. IsEdit int `description:"是否已编辑 0-待编辑 1-已编辑"`
  81. PublishState int `description:"发布状态 1-待发布,2-已发布"`
  82. VideoUrl string `description:"音频文件URL"`
  83. VideoName string `description:"音频文件名称"`
  84. VideoPlaySeconds string `description:"音频播放时长"`
  85. VideoSize string `description:"音频文件大小,单位M"`
  86. VideoKind int `description:"音频生成方式:1,手动上传,2:自动生成"`
  87. PublishTime string `description:"发布时间"`
  88. CreateTime string `description:"创建时间"`
  89. ModifyTime string `description:"修改时间"`
  90. GrandAdminIdList []int `description:"授权的用户id列表"`
  91. PermissionIdList []int `description:"关联的品种id列表"`
  92. CanEdit bool `description:"是否可编辑"`
  93. Editor string `description:"编辑人"`
  94. IsAuth bool `description:"是否有权限"`
  95. }
  96. // GetChapterListByReportId 根据ReportId获取章节列表
  97. func GetChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
  98. o := orm.NewOrmUsingDB("rddp")
  99. sql := ` SELECT * FROM report_chapter WHERE report_id = ? ORDER BY sort ASC`
  100. _, err = o.Raw(sql, reportId).QueryRows(&list)
  101. return
  102. }
  103. // GetPublishedChapterListByReportId 根据ReportId获取已发布章节列表
  104. func GetPublishedChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
  105. o := orm.NewOrmUsingDB("rddp")
  106. sql := ` SELECT * FROM report_chapter WHERE report_id = ? AND publish_state = 2 ORDER BY sort ASC`
  107. _, err = o.Raw(sql, reportId).QueryRows(&list)
  108. return
  109. }
  110. // AddReportChapterReq
  111. // @Description: 新增报告章节请求体
  112. type AddReportChapterReq struct {
  113. ReportId int `description:"报告ID"`
  114. Title string `description:"标题"`
  115. PermissionIdList []int `description:"报告关联的品种权限"`
  116. AdminIdList []int `description:"授权的编辑人id列表"`
  117. }
  118. // EditReportChapterReq 编辑报告章节请求体
  119. type EditReportChapterReq struct {
  120. ReportChapterId int `description:"报告章节ID"`
  121. Title string `description:"标题"`
  122. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  123. Author string `description:"作者"`
  124. Content string `description:"内容"`
  125. TickerList []EditTickList `description:"指标信息"`
  126. CreateTime string `description:"发布时间"`
  127. VideoUrl string `description:"音频文件URL"`
  128. VideoName string `description:"音频文件名称"`
  129. VideoPlaySeconds string `description:"音频播放时长"`
  130. VideoSize string `description:"音频文件大小,单位M"`
  131. // 以下是智能研报相关
  132. ContentStruct string `description:"内容组件"`
  133. HeadImg string `description:"报告头图地址"`
  134. EndImg string `description:"报告尾图地址"`
  135. CanvasColor string `description:"画布颜色"`
  136. HeadResourceId int `description:"版头资源ID"`
  137. EndResourceId int `description:"版尾资源ID"`
  138. }
  139. type EditTickList struct {
  140. Label string
  141. Ticker string
  142. Sort int
  143. }
  144. // GetReportChapterInfoById 根据主键获取报告章节
  145. func GetReportChapterInfoById(reportChapterId int) (item *ReportChapter, err error) {
  146. o := orm.NewOrmUsingDB("rddp")
  147. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ? `
  148. err = o.Raw(sql, reportChapterId).QueryRow(&item)
  149. return
  150. }
  151. // GetLastPublishedReportChapter 获取上一篇已发表的晨周报章节
  152. func GetLastPublishedReportChapter(typeId int, reportType string) (item *ReportChapter, err error) {
  153. o := orm.NewOrmUsingDB("rddp")
  154. sql := ` SELECT * FROM report_chapter WHERE publish_state = 2 AND type_id = ? AND report_type = ? ORDER BY report_chapter_id DESC limit 1 `
  155. err = o.Raw(sql, typeId, reportType).QueryRow(&item)
  156. return
  157. }
  158. // Add
  159. // @Description: 新增章节报告
  160. // @author: Roc
  161. // @receiver chapterInfo
  162. // @datetime 2024-06-04 15:14:41
  163. // @return err error
  164. func (chapterChapterInfo *ReportChapter) Add() (err error) {
  165. o := orm.NewOrmUsingDB("rddp")
  166. lastId, err := o.Insert(chapterChapterInfo)
  167. if err != nil {
  168. return
  169. }
  170. chapterChapterInfo.ReportChapterId = int(lastId)
  171. return
  172. }
  173. // UpdateChapter 更新报表章节
  174. func (chapterChapterInfo *ReportChapter) UpdateChapter(cols []string) (err error) {
  175. o := orm.NewOrmUsingDB("rddp")
  176. _, err = o.Update(chapterChapterInfo, cols...)
  177. return
  178. }
  179. // EditChapterTrendTagReq 编辑章节趋势标签请求体
  180. type EditChapterTrendTagReq struct {
  181. ReportChapterId int `description:"章节ID"`
  182. Trend string `description:"趋势"`
  183. }
  184. // UpdateChapterAndTicker 更新章节及ticker
  185. func UpdateChapterAndTicker(chapterInfo *ReportChapter, updateCols []string, tickerList []*ReportChapterTicker) (err error) {
  186. // 更新章节
  187. if err = chapterInfo.UpdateChapter(updateCols); err != nil {
  188. return
  189. }
  190. // 清空并新增章节ticker
  191. if err = ClearReportChapterTicker(chapterInfo.ReportChapterId); err != nil {
  192. return
  193. }
  194. tickerLen := len(tickerList)
  195. if tickerLen > 0 {
  196. for i := 0; i < tickerLen; i++ {
  197. _, tmpErr := InsertChapterTicker(tickerList[i])
  198. if tmpErr != nil {
  199. return
  200. }
  201. }
  202. }
  203. return
  204. }
  205. // ReportChapterVideoList 报告章节音频列表
  206. type ReportChapterVideoList struct {
  207. ReportId int `description:"报告ID"`
  208. ReportChapterId int `description:"报告章节ID"`
  209. VideoUrl string `description:"音频文件URL"`
  210. VideoName string `description:"音频文件名称"`
  211. VideoPlaySeconds string `description:"音频播放时长"`
  212. }
  213. // GetReportChapterVideoList 获取报告章节音频列表
  214. func GetReportChapterVideoList(reportId int) (list []*ReportChapterVideoList, err error) {
  215. o := orm.NewOrmUsingDB("rddp")
  216. sql := ` SELECT
  217. report_id,
  218. report_chapter_id,
  219. video_url,
  220. video_name,
  221. video_play_seconds
  222. FROM
  223. report_chapter
  224. WHERE
  225. report_id = ? AND publish_state = 2 AND video_url != ""
  226. ORDER BY
  227. report_chapter_id ASC `
  228. _, err = o.Raw(sql, reportId).QueryRows(&list)
  229. return
  230. }
  231. // GetReportChapterVideoListByReportIds 根据报告ID集合获取报告章节音频列表
  232. func GetReportChapterVideoListByReportIds(reportIds []string) (list []*ReportChapterVideoList, err error) {
  233. if len(reportIds) == 0 {
  234. return
  235. }
  236. o := orm.NewOrmUsingDB("rddp")
  237. sql := ` SELECT
  238. report_id,
  239. report_chapter_id,
  240. video_url,
  241. video_name,
  242. video_play_seconds
  243. FROM
  244. report_chapter
  245. WHERE
  246. report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `) AND publish_state = 2 AND video_url != ""
  247. ORDER BY
  248. report_chapter_id ASC `
  249. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  250. return
  251. }
  252. // GetReportChapterVideoListByChapterIds 根据章节ID集合获取报告章节音频列表
  253. func GetReportChapterVideoListByChapterIds(chapterIds []int) (list []*ReportChapterVideoList, err error) {
  254. if len(chapterIds) == 0 {
  255. return
  256. }
  257. o := orm.NewOrmUsingDB("rddp")
  258. sql := ` SELECT
  259. report_id,
  260. report_chapter_id,
  261. video_url,
  262. video_name,
  263. video_play_seconds
  264. FROM
  265. report_chapter
  266. WHERE
  267. report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) AND publish_state = 2
  268. ORDER BY
  269. report_chapter_id ASC `
  270. _, err = o.Raw(sql, chapterIds).QueryRows(&list)
  271. return
  272. }
  273. // PublishReportChapterReq 发布报告章节请求体
  274. type PublishReportChapterReq struct {
  275. ReportChapterId int `description:"报告章节ID"`
  276. Title string `description:"标题"`
  277. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  278. Author string `description:"作者"`
  279. Content string `description:"内容"`
  280. TickerList []EditTickList `description:"指标信息"`
  281. CreateTime string `description:"发布时间"`
  282. PublishReport int `description:"是否同时发布报告"`
  283. VideoUrl string `description:"音频文件URL"`
  284. VideoName string `description:"音频文件名称"`
  285. VideoPlaySeconds string `description:"音频播放时长"`
  286. VideoSize string `description:"音频文件大小,单位M"`
  287. }
  288. // CountPublishedChapterNum 获取报告已发布的章节数
  289. func CountPublishedChapterNum(reportId int) (count int, err error) {
  290. o := orm.NewOrmUsingDB("rddp")
  291. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 2 `
  292. err = o.Raw(sql, reportId).QueryRow(&count)
  293. return
  294. }
  295. // GetChapterListByChapterIds 根据ReportId获取章节列表
  296. func GetChapterListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
  297. if len(chapterIds) == 0 {
  298. return
  299. }
  300. o := orm.NewOrmUsingDB("rddp")
  301. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) ORDER BY sort ASC`
  302. _, err = o.Raw(sql, chapterIds).QueryRows(&list)
  303. return
  304. }
  305. // GetChapterSimpleListByChapterIds 根据章节ID获取章节列表
  306. func GetChapterSimpleListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
  307. if len(chapterIds) == 0 {
  308. return
  309. }
  310. o := orm.NewOrmUsingDB("rddp")
  311. 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`
  312. _, err = o.Raw(sql, chapterIds).QueryRows(&list)
  313. return
  314. }
  315. // GetChapterSimpleListByReportIds 根据ReportId获取章节列表
  316. func GetChapterSimpleListByReportIds(reportIds []int) (list []*ReportChapter, err error) {
  317. if len(reportIds) == 0 {
  318. return
  319. }
  320. o := orm.NewOrmUsingDB("rddp")
  321. 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`
  322. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  323. return
  324. }
  325. // UpdateReportChapterTypeNameByTypeId 更新章节类型名称
  326. func UpdateReportChapterTypeNameByTypeId(typeId int, typeName string) (err error) {
  327. o := orm.NewOrmUsingDB("rddp")
  328. sql := `UPDATE report_chapter SET type_name = ? WHERE type_id = ?`
  329. _, err = o.Raw(sql, typeName, typeId).Exec()
  330. return
  331. }
  332. // CountReportChapterByTypeId 通过章节类型ID获取章节数
  333. func CountReportChapterByTypeId(typeId int) (count int, err error) {
  334. o := orm.NewOrmUsingDB("rddp")
  335. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE type_id = ?`
  336. err = o.Raw(sql, typeId).QueryRow(&count)
  337. return
  338. }
  339. // AddReportChapter
  340. // @Description: 待添加的报告章节
  341. type AddReportChapter struct {
  342. ReportChapter *ReportChapter
  343. GrantList []*report.ReportChapterGrant
  344. }
  345. // EditReportChapterBaseInfoAndPermissionReq
  346. // @Description: 编辑报告章节的基础信息请求
  347. type EditReportChapterBaseInfoAndPermissionReq struct {
  348. ReportChapterId int `description:"报告章节ID"`
  349. Title string `description:"标题"`
  350. PermissionIdList []int `description:"报告关联的品种权限"`
  351. AdminIdList []int `description:"授权的编辑人id列表"`
  352. }
  353. // GetReportChapterIdList
  354. // @Description: 获取报告的所有章节id列表
  355. // @author: Roc
  356. // @datetime 2024-06-05 11:09:40
  357. // @param reportId int
  358. // @return list []int
  359. // @return err error
  360. func GetReportChapterIdList(reportId int) (list []int, err error) {
  361. o := orm.NewOrmUsingDB("rddp")
  362. sql := ` SELECT report_chapter_id FROM report_chapter
  363. WHERE report_id = ?
  364. ORDER BY report_chapter_id ASC `
  365. _, err = o.Raw(sql, reportId).QueryRows(&list)
  366. return
  367. }
  368. // ReportChapterMoveReq
  369. // @Description: 报告章节移动请求
  370. type ReportChapterMoveReq struct {
  371. ReportChapterId int `description:"报告章节id"`
  372. // ParentChartPermissionId int `description:"父级品种id"`
  373. PrevReportChapterId int `description:"上一个兄弟节点报告章节id"`
  374. NextReportChapterId int `description:"下一个兄弟节点报告章节id"`
  375. }
  376. // GetReportChapterById
  377. // @Description: 获取具体章节
  378. // @author: Roc
  379. // @receiver r
  380. // @datetime 2024-06-06 09:32:40
  381. // @param reportChapterId int
  382. // @return item *ReportChapter
  383. // @return err error
  384. func (chapterChapterInfo *ReportChapter) GetReportChapterById(reportChapterId int) (item *ReportChapter, err error) {
  385. o := orm.NewOrmUsingDB("rddp")
  386. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ?`
  387. err = o.Raw(sql, reportChapterId).QueryRow(&item)
  388. return
  389. }
  390. // UpdateReportChapterSortByReportId
  391. // @Description: 根据父类id更新排序
  392. // @author: Roc
  393. // @receiver chapterChapterInfo
  394. // @datetime 2024-06-06 09:39:28
  395. // @param reportId int
  396. // @param reportChapterId int
  397. // @param nowSort int
  398. // @param updateSort string
  399. // @return err error
  400. func (chapterChapterInfo *ReportChapter) UpdateReportChapterSortByReportId(reportId, reportChapterId, nowSort int, updateSort string) (err error) {
  401. o := orm.NewOrmUsingDB("rddp")
  402. pars := make([]interface{}, 0)
  403. sql := ` update report_chapter set sort = ` + updateSort + ` WHERE report_id = ? AND sort > ?`
  404. pars = append(pars, reportId, nowSort)
  405. if reportChapterId > 0 {
  406. sql += ` or ( report_chapter_id > ? and sort = ? )`
  407. pars = append(pars, reportChapterId, nowSort)
  408. }
  409. _, err = o.Raw(sql, pars).Exec()
  410. return
  411. }
  412. // GetFirstReportChapterByReportId
  413. // @Description: 获取当前报告下,且排序数相同 的排序第一条的数据
  414. // @author: Roc
  415. // @receiver chapterChapterInfo
  416. // @datetime 2024-06-06 09:45:32
  417. // @param reportId int
  418. // @return item *ReportChapter
  419. // @return err error
  420. func (chapterChapterInfo *ReportChapter) GetFirstReportChapterByReportId(reportId int) (item *ReportChapter, err error) {
  421. o := orm.NewOrmUsingDB("rddp")
  422. sql := ` SELECT * FROM report_chapter WHERE 1 = 1 AND report_id = ? ORDER BY sort ASC, report_chapter_id ASC LIMIT 1`
  423. err = o.Raw(sql, reportId).QueryRow(&item)
  424. return
  425. }
  426. // GetMaxSortByReportId
  427. // @Description: 获取最大的排序值
  428. // @author: Roc
  429. // @receiver chapterChapterInfo
  430. // @datetime 2024-06-06 09:44:13
  431. // @param reportId int
  432. // @return maxSort int
  433. // @return err error
  434. func (chapterChapterInfo *ReportChapter) GetMaxSortByReportId(reportId int) (maxSort int, err error) {
  435. o := orm.NewOrmUsingDB("rddp")
  436. sql := `SELECT max(sort) AS sort FROM report_chapter WHERE report_id = ?`
  437. err = o.Raw(sql, reportId).QueryRow(&maxSort)
  438. return
  439. }
  440. // Update
  441. // @Description: 数据变更
  442. // @author: Roc
  443. // @receiver chapterChapterInfo
  444. // @datetime 2024-06-06 09:47:46
  445. // @param cols []string
  446. // @return err error
  447. func (chapterChapterInfo *ReportChapter) Update(cols []string) (err error) {
  448. o := orm.NewOrmUsingDB("rddp")
  449. _, err = o.Update(chapterChapterInfo, cols...)
  450. return
  451. }
  452. // DelReportChapterReq
  453. // @Description: 删除报告章节请求体
  454. type DelReportChapterReq struct {
  455. ReportChapterId int `description:"报告章节ID"`
  456. }