report_chapter.go 19 KB

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