report_chapter.go 19 KB

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