report_chapter.go 26 KB

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