report_chapter.go 24 KB

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