report_chapter.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. PublishReport int `description:"是否同时发布报告"`
  273. }
  274. // CountPublishedChapterNum 获取报告已发布的章节数
  275. func CountPublishedChapterNum(reportId int) (count int, err error) {
  276. o := orm.NewOrmUsingDB("rddp")
  277. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 2 `
  278. err = o.Raw(sql, reportId).QueryRow(&count)
  279. return
  280. }
  281. // CountUnPublishedChapterNum
  282. // @Description: 获取报告未发布的章节数
  283. // @author: Roc
  284. // @datetime 2024-06-14 15:59:23
  285. // @param reportId int
  286. // @return count int
  287. // @return err error
  288. func CountUnPublishedChapterNum(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 = 1 `
  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. }