report_chapter.go 19 KB

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