report_chapter.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. package models
  2. import (
  3. sql2 "database/sql"
  4. "eta/eta_api/global"
  5. "eta/eta_api/models/report"
  6. "eta/eta_api/utils"
  7. "gorm.io/gorm"
  8. "time"
  9. )
  10. // ReportChapter 报告章节
  11. type ReportChapter struct {
  12. ReportChapterId int `gorm:"column:report_chapter_id;primaryKey;autoIncrement" description:"报告章节ID"`
  13. ReportId int `description:"报告ID"`
  14. ReportType string `description:"报告类型 day-晨报 week-周报"`
  15. ClassifyIdFirst int `description:"一级分类id"`
  16. ClassifyNameFirst string `description:"一级分类名称"`
  17. TypeId int `description:"品种ID"`
  18. TypeName string `description:"品种名称"`
  19. Title string `description:"标题"`
  20. Abstract string `description:"摘要"`
  21. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  22. Author string `description:"作者"`
  23. Content string `description:"内容"`
  24. ContentSub string `description:"内容前两个章节"`
  25. Stage int `description:"期数"`
  26. Trend string `description:"趋势观点"`
  27. Sort int `description:"排序: 数值越小越靠前"`
  28. IsEdit int `description:"是否已编辑 0-待编辑 1-已编辑"`
  29. PublishState int `description:"发布状态 1-待发布,2-已发布"`
  30. PublishTime time.Time `description:"发布时间"`
  31. VideoUrl string `description:"音频文件URL"`
  32. VideoName string `description:"音频文件名称"`
  33. VideoPlaySeconds string `description:"音频播放时长"`
  34. VideoSize string `description:"音频文件大小,单位M"`
  35. VideoKind int `description:"音频生成方式:1,手动上传,2:自动生成"`
  36. CreateTime string `description:"创建时间"`
  37. ModifyTime time.Time `description:"修改时间"`
  38. OriginalVideoUrl string `description:"原始音频文件URL"`
  39. ContentStruct string `description:"内容组件"`
  40. LastModifyAdminId int `description:"最后更新人ID"`
  41. LastModifyAdminName string `description:"最后更新人姓名"`
  42. ContentModifyTime time.Time `description:"内容更新时间"`
  43. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  44. ReportCreateTime time.Time `description:"报告时间创建时间"`
  45. VoiceGenerateType int `description:"音频生成方式,0:系统生成,1:人工上传"`
  46. }
  47. // AfterFind 在该模型上设置钩子函数,把日期转成正确的string,所以查询函数只能用Find函数,First或者Scan是不会触发该函数的来获取数据
  48. func (m *ReportChapter) AfterFind(db *gorm.DB) (err error) {
  49. m.CreateTime = utils.GormDateStrToDateTimeStr(m.CreateTime)
  50. return
  51. }
  52. // ConvDateTimeStr
  53. // @Description: ConvDateTimeStr
  54. // @author: Roc
  55. // @receiver m
  56. // @datetime 2025-02-13 09:54:02
  57. // @return err error
  58. func (m *ReportChapter) ConvDateTimeStr() {
  59. m.CreateTime = utils.GormDateStrToDateTimeStr(m.CreateTime)
  60. return
  61. }
  62. // ReportChapterItem 报告章节详情
  63. type ReportChapterItem struct {
  64. ReportChapterId int `gorm:"column:report_chapter_id;primaryKey;autoIncrement" description:"报告章节ID"`
  65. ReportId int `description:"报告ID"`
  66. ReportType string `description:"报告类型 day-晨报 week-周报"`
  67. ClassifyIdFirst int `description:"一级分类id"`
  68. ClassifyNameFirst string `description:"一级分类名称"`
  69. TypeId int `description:"品种ID"`
  70. TypeName string `description:"品种名称"`
  71. Title string `description:"标题"`
  72. Abstract string `description:"摘要"`
  73. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  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. PublishTime string `description:"发布时间"`
  83. VideoUrl string `description:"音频文件URL"`
  84. VideoName string `description:"音频文件名称"`
  85. VideoPlaySeconds string `description:"音频播放时长"`
  86. VideoSize string `description:"音频文件大小,单位M"`
  87. VideoKind int `description:"音频生成方式:1,手动上传,2:自动生成"`
  88. CreateTime string `description:"创建时间"`
  89. ModifyTime string `description:"修改时间"`
  90. OriginalVideoUrl string `description:"原始音频文件URL"`
  91. ContentStruct string `description:"内容组件"`
  92. LastModifyAdminId int `description:"最后更新人ID"`
  93. LastModifyAdminName string `description:"最后更新人姓名"`
  94. ContentModifyTime string `description:"内容更新时间"`
  95. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  96. ReportCreateTime string `description:"报告时间创建时间"`
  97. }
  98. // AfterFind 在该模型上设置钩子函数,把日期转成正确的string,所以查询函数只能用Find函数,First或者Scan是不会触发该函数的来获取数据
  99. func (m *ReportChapterItem) AfterFind(db *gorm.DB) (err error) {
  100. m.CreateTime = utils.GormDateStrToDateTimeStr(m.CreateTime)
  101. m.ModifyTime = utils.GormDateStrToDateTimeStr(m.ModifyTime)
  102. m.PublishTime = utils.GormDateStrToDateTimeStr(m.PublishTime)
  103. m.ContentModifyTime = utils.GormDateStrToDateTimeStr(m.ContentModifyTime)
  104. m.ReportCreateTime = utils.GormDateStrToDateTimeStr(m.ReportCreateTime)
  105. return
  106. }
  107. // ConvDateTimeStr
  108. // @Description: ConvDateTimeStr
  109. // @author: Roc
  110. // @receiver m
  111. // @datetime 2025-02-13 09:54:02
  112. // @return err error
  113. func (m *ReportChapterItem) ConvDateTimeStr() {
  114. m.CreateTime = utils.GormDateStrToDateTimeStr(m.CreateTime)
  115. m.ModifyTime = utils.GormDateStrToDateTimeStr(m.ModifyTime)
  116. m.PublishTime = utils.GormDateStrToDateTimeStr(m.PublishTime)
  117. m.ContentModifyTime = utils.GormDateStrToDateTimeStr(m.ContentModifyTime)
  118. m.ReportCreateTime = utils.GormDateStrToDateTimeStr(m.ReportCreateTime)
  119. return
  120. }
  121. // ReportChapterItemResp
  122. // @Description: 章节详情(带有一些额外的数据)
  123. type ReportChapterItemResp struct {
  124. ReportChapterItem
  125. GrandAdminIdList []int `description:"授权的用户id列表"`
  126. PermissionIdList []int `description:"关联的品种id列表"`
  127. CanEdit bool `description:"是否可编辑"`
  128. Editor string `description:"编辑人"`
  129. HeadImg string `description:"报告头图地址"`
  130. EndImg string `description:"报告尾图地址"`
  131. HeadStyle string `description:"版头样式"`
  132. EndStyle string `description:"版尾样式"`
  133. }
  134. type ReportChapterResp struct {
  135. ReportChapterId int `description:"报告章节ID"`
  136. ReportId int `description:"报告ID"`
  137. ReportType string `description:"报告类型 day-晨报 week-周报"`
  138. TypeId int `description:"品种ID"`
  139. TypeName string `description:"品种名称"`
  140. TypeEditImg string `description:"后台编辑时的图片"`
  141. Title string `description:"标题"`
  142. Abstract string `description:"摘要"`
  143. Author string `description:"作者"`
  144. Content string `description:"内容"`
  145. ContentSub string `description:"内容前两个章节"`
  146. Stage int `description:"期数"`
  147. Trend string `description:"趋势观点"`
  148. Sort int `description:"排序: 数值越小越靠前"`
  149. IsEdit int `description:"是否已编辑 0-待编辑 1-已编辑"`
  150. PublishState int `description:"发布状态 1-待发布,2-已发布"`
  151. VideoUrl string `description:"音频文件URL"`
  152. VideoName string `description:"音频文件名称"`
  153. VideoPlaySeconds string `description:"音频播放时长"`
  154. VideoSize string `description:"音频文件大小,单位M"`
  155. VideoKind int `description:"音频生成方式:1,手动上传,2:自动生成"`
  156. PublishTime string `description:"发布时间"`
  157. CreateTime string `description:"创建时间"`
  158. ModifyTime string `description:"修改时间"`
  159. GrandAdminIdList []int `description:"授权的用户id列表"`
  160. PermissionIdList []int `description:"关联的品种id列表"`
  161. CanEdit bool `description:"是否可编辑"`
  162. Editor string `description:"编辑人"`
  163. IsAuth bool `description:"是否有权限"`
  164. }
  165. // GetChapterListByReportId 根据ReportId获取章节列表
  166. func GetChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
  167. o := global.DbMap[utils.DbNameReport]
  168. sql := ` SELECT * FROM report_chapter WHERE report_id = ? ORDER BY sort ASC`
  169. err = o.Raw(sql, reportId).Find(&list).Error
  170. return
  171. }
  172. // GetPublishedChapterListByReportId 根据ReportId获取已发布章节列表
  173. func GetPublishedChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
  174. o := global.DbMap[utils.DbNameReport]
  175. sql := ` SELECT * FROM report_chapter WHERE report_id = ? AND publish_state = 2 ORDER BY sort ASC`
  176. err = o.Raw(sql, reportId).Find(&list).Error
  177. return
  178. }
  179. // AddReportChapterReq
  180. // @Description: 新增报告章节请求体
  181. type AddReportChapterReq struct {
  182. ReportId int `description:"报告ID"`
  183. Title string `description:"标题"`
  184. PermissionIdList []int `description:"报告关联的品种权限"`
  185. AdminIdList []int `description:"授权的编辑人id列表"`
  186. }
  187. // EditReportChapterReq 编辑报告章节请求体
  188. type EditReportChapterReq struct {
  189. ReportChapterId int `description:"报告章节ID"`
  190. Title string `description:"标题"`
  191. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  192. Author string `description:"作者"`
  193. Content string `description:"内容"`
  194. TickerList []EditTickList `description:"指标信息"`
  195. CreateTime string `description:"发布时间"`
  196. VideoUrl string `description:"音频文件URL"`
  197. VideoName string `description:"音频文件名称"`
  198. VideoPlaySeconds string `description:"音频播放时长"`
  199. VideoSize string `description:"音频文件大小,单位M"`
  200. // 以下是智能研报相关
  201. ContentStruct string `description:"内容组件"`
  202. HeadImg string `description:"报告头图地址"`
  203. EndImg string `description:"报告尾图地址"`
  204. CanvasColor string `description:"画布颜色"`
  205. HeadResourceId int `description:"版头资源ID"`
  206. EndResourceId int `description:"版尾资源ID"`
  207. }
  208. type EditTickList struct {
  209. Label string
  210. Ticker string
  211. Sort int
  212. }
  213. // GetReportChapterInfoById 根据主键获取报告章节
  214. func GetReportChapterInfoById(reportChapterId int) (item *ReportChapter, err error) {
  215. o := global.DbMap[utils.DbNameReport]
  216. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ? `
  217. err = o.Raw(sql, reportChapterId).First(&item).Error
  218. if err != nil {
  219. return
  220. }
  221. item.ConvDateTimeStr()
  222. return
  223. }
  224. // GetReportChapterItemById
  225. // @Description: 根据主键获取报告章节(时间格式为字符串的数据)
  226. // @author: Roc
  227. // @datetime 2024-06-27 14:10:29
  228. // @param reportChapterId int
  229. // @return item *ReportChapterItem
  230. // @return err error
  231. func GetReportChapterItemById(reportChapterId int) (item *ReportChapterItem, err error) {
  232. o := global.DbMap[utils.DbNameReport]
  233. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ? `
  234. err = o.Raw(sql, reportChapterId).First(&item).Error
  235. if err != nil {
  236. return
  237. }
  238. item.ConvDateTimeStr()
  239. return
  240. }
  241. // GetLastPublishedReportChapter 获取上一篇已发表的晨周报章节
  242. func GetLastPublishedReportChapter(typeId int, reportType string) (item *ReportChapter, err error) {
  243. o := global.DbMap[utils.DbNameReport]
  244. sql := ` SELECT * FROM report_chapter WHERE publish_state = 2 AND type_id = ? AND report_type = ? ORDER BY report_chapter_id DESC limit 1 `
  245. err = o.Raw(sql, typeId, reportType).First(&item).Error
  246. if err != nil {
  247. return
  248. }
  249. item.ConvDateTimeStr()
  250. return
  251. }
  252. // Add
  253. // @Description: 新增章节报告
  254. // @author: Roc
  255. // @receiver chapterInfo
  256. // @datetime 2024-06-04 15:14:41
  257. // @return err error
  258. func (chapterChapterInfo *ReportChapter) Add() (err error) {
  259. o := global.DbMap[utils.DbNameReport]
  260. err = o.Create(chapterChapterInfo).Error
  261. if err != nil {
  262. return
  263. }
  264. return
  265. }
  266. // UpdateChapter 更新报表章节
  267. func (chapterChapterInfo *ReportChapter) UpdateChapter(cols []string) (err error) {
  268. o := global.DbMap[utils.DbNameReport]
  269. err = o.Select(cols).Updates(chapterChapterInfo).Error
  270. return
  271. }
  272. // EditChapterTrendTagReq 编辑章节趋势标签请求体
  273. type EditChapterTrendTagReq struct {
  274. ReportChapterId int `description:"章节ID"`
  275. Trend string `description:"趋势"`
  276. }
  277. // UpdateChapterAndTicker 更新章节及ticker
  278. func UpdateChapterAndTicker(reportInfo *Report, chapterInfo *ReportChapter, updateCols []string, tickerList []*ReportChapterTicker) (err error) {
  279. // 更新报告的最近编辑人信息
  280. if err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"}); err != nil {
  281. return
  282. }
  283. // 更新章节
  284. if err = chapterInfo.UpdateChapter(updateCols); err != nil {
  285. return
  286. }
  287. // 清空并新增章节ticker
  288. if err = ClearReportChapterTicker(chapterInfo.ReportChapterId); err != nil {
  289. return
  290. }
  291. tickerLen := len(tickerList)
  292. if tickerLen > 0 {
  293. for i := 0; i < tickerLen; i++ {
  294. _, tmpErr := InsertChapterTicker(tickerList[i])
  295. if tmpErr != nil {
  296. return
  297. }
  298. }
  299. }
  300. return
  301. }
  302. // ReportChapterVideoList 报告章节音频列表
  303. type ReportChapterVideoList struct {
  304. ReportId int `description:"报告ID"`
  305. ReportChapterId int `description:"报告章节ID"`
  306. VideoUrl string `description:"音频文件URL"`
  307. VideoName string `description:"音频文件名称"`
  308. VideoPlaySeconds string `description:"音频播放时长"`
  309. }
  310. // GetReportChapterVideoList 获取报告章节音频列表
  311. func GetReportChapterVideoList(reportId int) (list []*ReportChapterVideoList, err error) {
  312. o := global.DbMap[utils.DbNameReport]
  313. sql := ` SELECT
  314. report_id,
  315. report_chapter_id,
  316. video_url,
  317. video_name,
  318. video_play_seconds
  319. FROM
  320. report_chapter
  321. WHERE
  322. report_id = ? AND publish_state = 2 AND video_url != ''
  323. ORDER BY
  324. report_chapter_id ASC `
  325. err = o.Raw(sql, reportId).Find(&list).Error
  326. return
  327. }
  328. // GetReportChapterVideoListByReportIds 根据报告ID集合获取报告章节音频列表
  329. func GetReportChapterVideoListByReportIds(reportIds []int) (list []*ReportChapterVideoList, err error) {
  330. if len(reportIds) == 0 {
  331. return
  332. }
  333. o := global.DbMap[utils.DbNameReport]
  334. sql := ` SELECT
  335. report_id,
  336. report_chapter_id,
  337. video_url,
  338. video_name,
  339. video_play_seconds
  340. FROM
  341. report_chapter
  342. WHERE
  343. report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `) AND publish_state = 2 AND video_url != ''
  344. ORDER BY
  345. report_chapter_id ASC `
  346. err = o.Raw(sql, reportIds).Find(&list).Error
  347. return
  348. }
  349. // GetReportChapterVideoListByChapterIds 根据章节ID集合获取报告章节音频列表
  350. func GetReportChapterVideoListByChapterIds(chapterIds []int) (list []*ReportChapterVideoList, err error) {
  351. if len(chapterIds) == 0 {
  352. return
  353. }
  354. o := global.DbMap[utils.DbNameReport]
  355. sql := ` SELECT
  356. report_id,
  357. report_chapter_id,
  358. video_url,
  359. video_name,
  360. video_play_seconds
  361. FROM
  362. report_chapter
  363. WHERE
  364. report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) AND publish_state = 2
  365. ORDER BY
  366. report_chapter_id ASC `
  367. err = o.Raw(sql, chapterIds).Find(&list).Error
  368. return
  369. }
  370. // PublishReportChapterReq 发布报告章节请求体
  371. type PublishReportChapterReq struct {
  372. ReportChapterId int `description:"报告章节ID"`
  373. PublishReport int `description:"是否同时发布报告"`
  374. }
  375. // CountPublishedChapterNum 获取报告已发布的章节数
  376. func CountPublishedChapterNum(reportId int) (count int, err error) {
  377. o := global.DbMap[utils.DbNameReport]
  378. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 2 `
  379. var countNull sql2.NullInt64
  380. err = o.Raw(sql, reportId).Scan(&countNull).Error
  381. if err != nil {
  382. return
  383. }
  384. if countNull.Valid {
  385. count = int(countNull.Int64)
  386. }
  387. return
  388. }
  389. // CountUnPublishedChapterNum
  390. // @Description: 获取报告未发布的章节数
  391. // @author: Roc
  392. // @datetime 2024-06-14 15:59:23
  393. // @param reportId int
  394. // @return count int
  395. // @return err error
  396. //func CountUnPublishedChapterNum(reportId int) (count int, err error) {
  397. // o := global.DbMap[utils.DbNameReport]
  398. // sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 1 `
  399. // err = o.Raw(sql, reportId).First(&count)
  400. //
  401. // return
  402. //}
  403. // GetUnPublishedChapterList
  404. // @Description: 获取报告未发布的章节列表
  405. // @author: Roc
  406. // @datetime 2024-06-14 15:59:23
  407. // @param reportId int
  408. // @return list []*ReportChapter
  409. // @return err error
  410. func GetUnPublishedChapterList(reportId int) (list []*ReportChapter, err error) {
  411. o := global.DbMap[utils.DbNameReport]
  412. sql := ` SELECT report_chapter_id,report_id,title FROM report_chapter WHERE report_id = ? AND publish_state = 1 ORDER BY sort ASC`
  413. err = o.Raw(sql, reportId).Find(&list).Error
  414. return
  415. }
  416. // GetChapterListByChapterIds 根据ReportId获取章节列表
  417. func GetChapterListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
  418. if len(chapterIds) == 0 {
  419. return
  420. }
  421. o := global.DbMap[utils.DbNameReport]
  422. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) ORDER BY sort ASC`
  423. err = o.Raw(sql, chapterIds).Find(&list).Error
  424. return
  425. }
  426. // GetChapterSimpleListByChapterIds 根据章节ID获取章节列表
  427. //func GetChapterSimpleListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
  428. // if len(chapterIds) == 0 {
  429. // return
  430. // }
  431. // o := global.DbMap[utils.DbNameReport]
  432. // 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`
  433. // err = o.Raw(sql, chapterIds).Find(&list)
  434. // return
  435. //}
  436. // GetChapterSimpleListByReportIds 根据ReportId获取章节列表
  437. //func GetChapterSimpleListByReportIds(reportIds []int) (list []*ReportChapter, err error) {
  438. // if len(reportIds) == 0 {
  439. // return
  440. // }
  441. // o := global.DbMap[utils.DbNameReport]
  442. // 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`
  443. // err = o.Raw(sql, reportIds).Find(&list)
  444. // return
  445. //}
  446. // UpdateReportChapterTypeNameByTypeId 更新章节类型名称
  447. func UpdateReportChapterTypeNameByTypeId(typeId int, typeName string) (err error) {
  448. o := global.DbMap[utils.DbNameReport]
  449. sql := `UPDATE report_chapter SET type_name = ? WHERE type_id = ?`
  450. err = o.Raw(sql, typeName, typeId).Error
  451. return
  452. }
  453. // CountReportChapterByTypeId 通过章节类型ID获取章节数
  454. func CountReportChapterByTypeId(typeId int) (count int, err error) {
  455. o := global.DbMap[utils.DbNameReport]
  456. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE type_id = ?`
  457. err = o.Raw(sql, typeId).First(&count).Error
  458. return
  459. }
  460. // AddReportChapter
  461. // @Description: 待添加的报告章节
  462. type AddReportChapter struct {
  463. ReportChapter *ReportChapter
  464. GrantList []*report.ReportChapterGrant
  465. GrantPermissionList []*report.ReportChapterPermissionMapping
  466. }
  467. // EditReportChapterBaseInfoAndPermissionReq
  468. // @Description: 编辑报告章节的基础信息请求
  469. type EditReportChapterBaseInfoAndPermissionReq struct {
  470. ReportChapterId int `description:"报告章节ID"`
  471. Title string `description:"标题"`
  472. PermissionIdList []int `description:"报告关联的品种权限"`
  473. AdminIdList []int `description:"授权的编辑人id列表"`
  474. }
  475. // GetReportChapterIdList
  476. // @Description: 获取报告的所有章节id列表
  477. // @author: Roc
  478. // @datetime 2024-06-05 11:09:40
  479. // @param reportId int
  480. // @return list []int
  481. // @return err error
  482. func GetReportChapterIdList(reportId int) (list []int, err error) {
  483. o := global.DbMap[utils.DbNameReport]
  484. sql := ` SELECT report_chapter_id FROM report_chapter
  485. WHERE report_id = ?
  486. ORDER BY report_chapter_id ASC `
  487. err = o.Raw(sql, reportId).Find(&list).Error
  488. return
  489. }
  490. // ReportChapterMoveReq
  491. // @Description: 报告章节移动请求
  492. type ReportChapterMoveReq struct {
  493. ReportChapterId int `description:"报告章节id"`
  494. // ParentChartPermissionId int `description:"父级品种id"`
  495. PrevReportChapterId int `description:"上一个兄弟节点报告章节id"`
  496. NextReportChapterId int `description:"下一个兄弟节点报告章节id"`
  497. }
  498. // GetReportChapterById
  499. // @Description: 获取具体章节
  500. // @author: Roc
  501. // @receiver r
  502. // @datetime 2024-06-06 09:32:40
  503. // @param reportChapterId int
  504. // @return item *ReportChapter
  505. // @return err error
  506. func (chapterChapterInfo *ReportChapter) GetReportChapterById(reportChapterId int) (item *ReportChapter, err error) {
  507. o := global.DbMap[utils.DbNameReport]
  508. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ?`
  509. err = o.Raw(sql, reportChapterId).First(&item).Error
  510. if err != nil {
  511. return
  512. }
  513. item.ConvDateTimeStr()
  514. return
  515. }
  516. // UpdateReportChapterSortByReportId
  517. // @Description: 根据父类id更新排序
  518. // @author: Roc
  519. // @receiver chapterChapterInfo
  520. // @datetime 2024-06-06 09:39:28
  521. // @param reportId int
  522. // @param reportChapterId int
  523. // @param nowSort int
  524. // @param updateSort string
  525. // @return err error
  526. func (chapterChapterInfo *ReportChapter) UpdateReportChapterSortByReportId(reportId, reportChapterId, nowSort int, updateSort string) (err error) {
  527. o := global.DbMap[utils.DbNameReport]
  528. pars := make([]interface{}, 0)
  529. sql := ` update report_chapter set sort = ` + updateSort + ` WHERE report_id = ? AND sort > ?`
  530. pars = append(pars, reportId, nowSort)
  531. if reportChapterId > 0 {
  532. sql += ` or ( report_chapter_id > ? and sort = ? )`
  533. pars = append(pars, reportChapterId, nowSort)
  534. }
  535. err = o.Exec(sql, pars...).Error
  536. return
  537. }
  538. // GetFirstReportChapterByReportId
  539. // @Description: 获取当前报告下,且排序数相同 的排序第一条的数据
  540. // @author: Roc
  541. // @receiver chapterChapterInfo
  542. // @datetime 2024-06-06 09:45:32
  543. // @param reportId int
  544. // @return item *ReportChapter
  545. // @return err error
  546. func (chapterChapterInfo *ReportChapter) GetFirstReportChapterByReportId(reportId int) (item *ReportChapter, err error) {
  547. o := global.DbMap[utils.DbNameReport]
  548. sql := ` SELECT * FROM report_chapter WHERE 1 = 1 AND report_id = ? ORDER BY sort ASC, report_chapter_id ASC LIMIT 1`
  549. err = o.Raw(sql, reportId).First(&item).Error
  550. if err != nil {
  551. return
  552. }
  553. item.ConvDateTimeStr()
  554. return
  555. }
  556. // GetMaxSortByReportId
  557. // @Description: 获取最大的排序值
  558. // @author: Roc
  559. // @receiver chapterChapterInfo
  560. // @datetime 2024-06-06 09:44:13
  561. // @param reportId int
  562. // @return maxSort int
  563. // @return err error
  564. func (chapterChapterInfo *ReportChapter) GetMaxSortByReportId(reportId int) (maxSort int, err error) {
  565. o := global.DbMap[utils.DbNameReport]
  566. sql := `SELECT max(sort) AS sort FROM report_chapter WHERE report_id = ?`
  567. var maxNull sql2.NullInt64
  568. err = o.Raw(sql, reportId).Scan(&maxNull).Error
  569. if err != nil {
  570. return
  571. }
  572. if maxNull.Valid {
  573. maxSort = int(maxNull.Int64)
  574. }
  575. return
  576. }
  577. // Update
  578. // @Description: 数据变更
  579. // @author: Roc
  580. // @receiver chapterChapterInfo
  581. // @datetime 2024-06-06 09:47:46
  582. // @param cols []string
  583. // @return err error
  584. func (chapterChapterInfo *ReportChapter) Update(cols []string) (err error) {
  585. o := global.DbMap[utils.DbNameReport]
  586. err = o.Select(cols).Updates(chapterChapterInfo).Error
  587. return
  588. }
  589. // DelReportChapterReq
  590. // @Description: 删除报告章节请求体
  591. type DelReportChapterReq struct {
  592. ReportChapterId int `description:"报告章节ID"`
  593. }
  594. // GetAllReportChapter 获取所有的报告章节
  595. func GetAllReportChapter() (items []*ReportChapter, err error) {
  596. o := global.DbMap[utils.DbNameReport]
  597. sql := ` SELECT * FROM report_chapter ORDER BY report_chapter_id asc `
  598. err = o.Raw(sql).Find(&items).Error
  599. return
  600. }
  601. // GetCountReportChapterByCondition
  602. // @Description: 根据条件获取章节数量
  603. // @author: Roc
  604. // @datetime 2024-07-15 15:37:50
  605. // @param condition string
  606. // @param pars []interface{}
  607. // @return count int
  608. // @return err error
  609. func GetCountReportChapterByCondition(condition string, pars []interface{}) (count int, err error) {
  610. o := global.DbMap[utils.DbNameReport]
  611. sql := ` SELECT COUNT(1) AS count FROM report_chapter WHERE 1=1 `
  612. if condition != "" {
  613. sql += condition
  614. }
  615. var countNull sql2.NullInt64
  616. err = o.Raw(sql, pars...).Scan(&countNull).Error
  617. if err != nil {
  618. return
  619. }
  620. if countNull.Valid {
  621. count = int(countNull.Int64)
  622. }
  623. return
  624. }
  625. // GetNewestPreReportChapterByClassifyIdAndTypeId 获取分类下往期中最新发布的系统章节
  626. func GetNewestPreReportChapterByClassifyIdAndTypeId(classifyId, typeId int) (item *ReportChapter, err error) {
  627. o := global.DbMap[utils.DbNameReport]
  628. sql := `SELECT a.* FROM report_chapter AS a JOIN report AS b ON a.report_id = b.id WHERE a.classify_id_first = ? AND a.type_id = ? AND a.publish_state = 2 AND b.state IN (2,6) ORDER BY a.publish_time DESC LIMIT 1`
  629. err = o.Raw(sql, classifyId, typeId).First(&item).Error
  630. if err != nil {
  631. return
  632. }
  633. item.ConvDateTimeStr()
  634. return
  635. }