report_chapter.go 20 KB

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