report_chapter.go 23 KB

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