report_chapter.go 26 KB

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