report_chapter.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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. ContentStruct string `description:"内容组件"`
  38. LastModifyAdminId int `description:"最后更新人ID"`
  39. LastModifyAdminName string `description:"最后更新人姓名"`
  40. ContentModifyTime time.Time `description:"内容更新时间"`
  41. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  42. ReportCreateTime time.Time `description:"报告时间创建时间"`
  43. }
  44. // ReportChapterItem
  45. // @Description: 章节详情(带有一些额外的数据)
  46. type ReportChapterItem struct {
  47. ReportChapter
  48. GrandAdminIdList []int `description:"授权的用户id列表"`
  49. PermissionIdList []int `description:"关联的品种id列表"`
  50. CanEdit bool `description:"是否可编辑"`
  51. Editor string `description:"编辑人"`
  52. HeadImg string `description:"报告头图地址"`
  53. EndImg string `description:"报告尾图地址"`
  54. HeadStyle string `description:"版头样式"`
  55. EndStyle string `description:"版尾样式"`
  56. }
  57. type ReportChapterResp struct {
  58. ReportChapterId int `description:"报告章节ID"`
  59. ReportId int `description:"报告ID"`
  60. ReportType string `description:"报告类型 day-晨报 week-周报"`
  61. TypeId int `description:"品种ID"`
  62. TypeName string `description:"品种名称"`
  63. TypeEditImg string `description:"后台编辑时的图片"`
  64. Title string `description:"标题"`
  65. Abstract string `description:"摘要"`
  66. Author string `description:"作者"`
  67. Content string `description:"内容"`
  68. ContentSub string `description:"内容前两个章节"`
  69. Stage int `description:"期数"`
  70. Trend string `description:"趋势观点"`
  71. Sort int `description:"排序: 数值越小越靠前"`
  72. IsEdit int `description:"是否已编辑 0-待编辑 1-已编辑"`
  73. PublishState int `description:"发布状态 1-待发布,2-已发布"`
  74. VideoUrl string `description:"音频文件URL"`
  75. VideoName string `description:"音频文件名称"`
  76. VideoPlaySeconds string `description:"音频播放时长"`
  77. VideoSize string `description:"音频文件大小,单位M"`
  78. VideoKind int `description:"音频生成方式:1,手动上传,2:自动生成"`
  79. PublishTime string `description:"发布时间"`
  80. CreateTime string `description:"创建时间"`
  81. ModifyTime string `description:"修改时间"`
  82. GrandAdminIdList []int `description:"授权的用户id列表"`
  83. PermissionIdList []int `description:"关联的品种id列表"`
  84. CanEdit bool `description:"是否可编辑"`
  85. Editor string `description:"编辑人"`
  86. IsAuth bool `description:"是否有权限"`
  87. }
  88. // GetChapterListByReportId 根据ReportId获取章节列表
  89. func GetChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
  90. o := orm.NewOrmUsingDB("rddp")
  91. sql := ` SELECT * FROM report_chapter WHERE report_id = ? ORDER BY sort ASC`
  92. _, err = o.Raw(sql, reportId).QueryRows(&list)
  93. return
  94. }
  95. // GetPublishedChapterListByReportId 根据ReportId获取已发布章节列表
  96. func GetPublishedChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
  97. o := orm.NewOrmUsingDB("rddp")
  98. sql := ` SELECT * FROM report_chapter WHERE report_id = ? AND publish_state = 2 ORDER BY sort ASC`
  99. _, err = o.Raw(sql, reportId).QueryRows(&list)
  100. return
  101. }
  102. // AddReportChapterReq
  103. // @Description: 新增报告章节请求体
  104. type AddReportChapterReq struct {
  105. ReportId int `description:"报告ID"`
  106. Title string `description:"标题"`
  107. PermissionIdList []int `description:"报告关联的品种权限"`
  108. AdminIdList []int `description:"授权的编辑人id列表"`
  109. }
  110. // EditReportChapterReq 编辑报告章节请求体
  111. type EditReportChapterReq struct {
  112. ReportChapterId int `description:"报告章节ID"`
  113. Title string `description:"标题"`
  114. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  115. Author string `description:"作者"`
  116. Content string `description:"内容"`
  117. TickerList []EditTickList `description:"指标信息"`
  118. CreateTime string `description:"发布时间"`
  119. VideoUrl string `description:"音频文件URL"`
  120. VideoName string `description:"音频文件名称"`
  121. VideoPlaySeconds string `description:"音频播放时长"`
  122. VideoSize string `description:"音频文件大小,单位M"`
  123. // 以下是智能研报相关
  124. ContentStruct string `description:"内容组件"`
  125. HeadImg string `description:"报告头图地址"`
  126. EndImg string `description:"报告尾图地址"`
  127. CanvasColor string `description:"画布颜色"`
  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 (chapterChapterInfo *ReportChapter) Add() (err error) {
  157. o := orm.NewOrmUsingDB("rddp")
  158. lastId, err := o.Insert(chapterChapterInfo)
  159. if err != nil {
  160. return
  161. }
  162. chapterChapterInfo.ReportChapterId = int(lastId)
  163. return
  164. }
  165. // UpdateChapter 更新报表章节
  166. func (chapterChapterInfo *ReportChapter) UpdateChapter(cols []string) (err error) {
  167. o := orm.NewOrmUsingDB("rddp")
  168. _, err = o.Update(chapterChapterInfo, 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. PublishReport int `description:"是否同时发布报告"`
  269. }
  270. // CountPublishedChapterNum 获取报告已发布的章节数
  271. func CountPublishedChapterNum(reportId int) (count int, err error) {
  272. o := orm.NewOrmUsingDB("rddp")
  273. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 2 `
  274. err = o.Raw(sql, reportId).QueryRow(&count)
  275. return
  276. }
  277. // CountUnPublishedChapterNum
  278. // @Description: 获取报告未发布的章节数
  279. // @author: Roc
  280. // @datetime 2024-06-14 15:59:23
  281. // @param reportId int
  282. // @return count int
  283. // @return err error
  284. func CountUnPublishedChapterNum(reportId int) (count int, err error) {
  285. o := orm.NewOrmUsingDB("rddp")
  286. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 1 `
  287. err = o.Raw(sql, reportId).QueryRow(&count)
  288. return
  289. }
  290. // GetUnPublishedChapterList
  291. // @Description: 获取报告未发布的章节列表
  292. // @author: Roc
  293. // @datetime 2024-06-14 15:59:23
  294. // @param reportId int
  295. // @return list []*ReportChapter
  296. // @return err error
  297. func GetUnPublishedChapterList(reportId int) (list []*ReportChapter, err error) {
  298. o := orm.NewOrmUsingDB("rddp")
  299. sql := ` SELECT report_chapter_id,report_id,title FROM report_chapter WHERE report_id = ? AND publish_state = 1 ORDER BY sort ASC`
  300. _, err = o.Raw(sql, reportId).QueryRows(&list)
  301. return
  302. }
  303. // GetChapterListByChapterIds 根据ReportId获取章节列表
  304. func GetChapterListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
  305. if len(chapterIds) == 0 {
  306. return
  307. }
  308. o := orm.NewOrmUsingDB("rddp")
  309. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) ORDER BY sort ASC`
  310. _, err = o.Raw(sql, chapterIds).QueryRows(&list)
  311. return
  312. }
  313. // GetChapterSimpleListByChapterIds 根据章节ID获取章节列表
  314. func GetChapterSimpleListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
  315. if len(chapterIds) == 0 {
  316. return
  317. }
  318. o := orm.NewOrmUsingDB("rddp")
  319. 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`
  320. _, err = o.Raw(sql, chapterIds).QueryRows(&list)
  321. return
  322. }
  323. // GetChapterSimpleListByReportIds 根据ReportId获取章节列表
  324. func GetChapterSimpleListByReportIds(reportIds []int) (list []*ReportChapter, err error) {
  325. if len(reportIds) == 0 {
  326. return
  327. }
  328. o := orm.NewOrmUsingDB("rddp")
  329. 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`
  330. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  331. return
  332. }
  333. // UpdateReportChapterTypeNameByTypeId 更新章节类型名称
  334. func UpdateReportChapterTypeNameByTypeId(typeId int, typeName string) (err error) {
  335. o := orm.NewOrmUsingDB("rddp")
  336. sql := `UPDATE report_chapter SET type_name = ? WHERE type_id = ?`
  337. _, err = o.Raw(sql, typeName, typeId).Exec()
  338. return
  339. }
  340. // CountReportChapterByTypeId 通过章节类型ID获取章节数
  341. func CountReportChapterByTypeId(typeId int) (count int, err error) {
  342. o := orm.NewOrmUsingDB("rddp")
  343. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE type_id = ?`
  344. err = o.Raw(sql, typeId).QueryRow(&count)
  345. return
  346. }
  347. // AddReportChapter
  348. // @Description: 待添加的报告章节
  349. type AddReportChapter struct {
  350. ReportChapter *ReportChapter
  351. GrantList []*report.ReportChapterGrant
  352. }
  353. // EditReportChapterBaseInfoAndPermissionReq
  354. // @Description: 编辑报告章节的基础信息请求
  355. type EditReportChapterBaseInfoAndPermissionReq struct {
  356. ReportChapterId int `description:"报告章节ID"`
  357. Title string `description:"标题"`
  358. PermissionIdList []int `description:"报告关联的品种权限"`
  359. AdminIdList []int `description:"授权的编辑人id列表"`
  360. }
  361. // GetReportChapterIdList
  362. // @Description: 获取报告的所有章节id列表
  363. // @author: Roc
  364. // @datetime 2024-06-05 11:09:40
  365. // @param reportId int
  366. // @return list []int
  367. // @return err error
  368. func GetReportChapterIdList(reportId int) (list []int, err error) {
  369. o := orm.NewOrmUsingDB("rddp")
  370. sql := ` SELECT report_chapter_id FROM report_chapter
  371. WHERE report_id = ?
  372. ORDER BY report_chapter_id ASC `
  373. _, err = o.Raw(sql, reportId).QueryRows(&list)
  374. return
  375. }
  376. // ReportChapterMoveReq
  377. // @Description: 报告章节移动请求
  378. type ReportChapterMoveReq struct {
  379. ReportChapterId int `description:"报告章节id"`
  380. // ParentChartPermissionId int `description:"父级品种id"`
  381. PrevReportChapterId int `description:"上一个兄弟节点报告章节id"`
  382. NextReportChapterId int `description:"下一个兄弟节点报告章节id"`
  383. }
  384. // GetReportChapterById
  385. // @Description: 获取具体章节
  386. // @author: Roc
  387. // @receiver r
  388. // @datetime 2024-06-06 09:32:40
  389. // @param reportChapterId int
  390. // @return item *ReportChapter
  391. // @return err error
  392. func (chapterChapterInfo *ReportChapter) GetReportChapterById(reportChapterId int) (item *ReportChapter, err error) {
  393. o := orm.NewOrmUsingDB("rddp")
  394. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ?`
  395. err = o.Raw(sql, reportChapterId).QueryRow(&item)
  396. return
  397. }
  398. // UpdateReportChapterSortByReportId
  399. // @Description: 根据父类id更新排序
  400. // @author: Roc
  401. // @receiver chapterChapterInfo
  402. // @datetime 2024-06-06 09:39:28
  403. // @param reportId int
  404. // @param reportChapterId int
  405. // @param nowSort int
  406. // @param updateSort string
  407. // @return err error
  408. func (chapterChapterInfo *ReportChapter) UpdateReportChapterSortByReportId(reportId, reportChapterId, nowSort int, updateSort string) (err error) {
  409. o := orm.NewOrmUsingDB("rddp")
  410. pars := make([]interface{}, 0)
  411. sql := ` update report_chapter set sort = ` + updateSort + ` WHERE report_id = ? AND sort > ?`
  412. pars = append(pars, reportId, nowSort)
  413. if reportChapterId > 0 {
  414. sql += ` or ( report_chapter_id > ? and sort = ? )`
  415. pars = append(pars, reportChapterId, nowSort)
  416. }
  417. _, err = o.Raw(sql, pars).Exec()
  418. return
  419. }
  420. // GetFirstReportChapterByReportId
  421. // @Description: 获取当前报告下,且排序数相同 的排序第一条的数据
  422. // @author: Roc
  423. // @receiver chapterChapterInfo
  424. // @datetime 2024-06-06 09:45:32
  425. // @param reportId int
  426. // @return item *ReportChapter
  427. // @return err error
  428. func (chapterChapterInfo *ReportChapter) GetFirstReportChapterByReportId(reportId int) (item *ReportChapter, err error) {
  429. o := orm.NewOrmUsingDB("rddp")
  430. sql := ` SELECT * FROM report_chapter WHERE 1 = 1 AND report_id = ? ORDER BY sort ASC, report_chapter_id ASC LIMIT 1`
  431. err = o.Raw(sql, reportId).QueryRow(&item)
  432. return
  433. }
  434. // GetMaxSortByReportId
  435. // @Description: 获取最大的排序值
  436. // @author: Roc
  437. // @receiver chapterChapterInfo
  438. // @datetime 2024-06-06 09:44:13
  439. // @param reportId int
  440. // @return maxSort int
  441. // @return err error
  442. func (chapterChapterInfo *ReportChapter) GetMaxSortByReportId(reportId int) (maxSort int, err error) {
  443. o := orm.NewOrmUsingDB("rddp")
  444. sql := `SELECT max(sort) AS sort FROM report_chapter WHERE report_id = ?`
  445. err = o.Raw(sql, reportId).QueryRow(&maxSort)
  446. return
  447. }
  448. // Update
  449. // @Description: 数据变更
  450. // @author: Roc
  451. // @receiver chapterChapterInfo
  452. // @datetime 2024-06-06 09:47:46
  453. // @param cols []string
  454. // @return err error
  455. func (chapterChapterInfo *ReportChapter) Update(cols []string) (err error) {
  456. o := orm.NewOrmUsingDB("rddp")
  457. _, err = o.Update(chapterChapterInfo, cols...)
  458. return
  459. }
  460. // DelReportChapterReq
  461. // @Description: 删除报告章节请求体
  462. type DelReportChapterReq struct {
  463. ReportChapterId int `description:"报告章节ID"`
  464. }