report_chapter.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. package models
  2. import (
  3. "eta/eta_mobile/models/report"
  4. "eta/eta_mobile/utils"
  5. "github.com/beego/beego/v2/client/orm"
  6. "time"
  7. )
  8. // ReportChapter 报告章节
  9. type ReportChapter struct {
  10. ReportChapterId int `orm:"column(report_chapter_id);pk" description:"报告章节ID"`
  11. ReportId int `description:"报告ID"`
  12. ReportType string `description:"报告类型 day-晨报 week-周报"`
  13. ClassifyIdFirst int `description:"一级分类id"`
  14. ClassifyNameFirst string `description:"一级分类名称"`
  15. TypeId int `description:"品种ID"`
  16. TypeName string `description:"品种名称"`
  17. Title string `description:"标题"`
  18. Abstract string `description:"摘要"`
  19. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  20. Author string `description:"作者"`
  21. Content string `description:"内容"`
  22. ContentSub string `description:"内容前两个章节"`
  23. Stage int `description:"期数"`
  24. Trend string `description:"趋势观点"`
  25. Sort int `description:"排序: 数值越小越靠前"`
  26. IsEdit int `description:"是否已编辑 0-待编辑 1-已编辑"`
  27. PublishState int `description:"发布状态 1-待发布,2-已发布"`
  28. PublishTime time.Time `description:"发布时间"`
  29. VideoUrl string `description:"音频文件URL"`
  30. VideoName string `description:"音频文件名称"`
  31. VideoPlaySeconds string `description:"音频播放时长"`
  32. VideoSize string `description:"音频文件大小,单位M"`
  33. VideoKind int `description:"音频生成方式:1,手动上传,2:自动生成"`
  34. CreateTime string `description:"创建时间"`
  35. ModifyTime time.Time `description:"修改时间"`
  36. OriginalVideoUrl string `description:"原始音频文件URL"`
  37. ContentStruct string `description:"内容组件"`
  38. LastModifyAdminId int `description:"最后更新人ID"`
  39. LastModifyAdminName string `description:"最后更新人姓名"`
  40. ContentModifyTime time.Time `description:"内容更新时间"`
  41. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  42. ReportCreateTime time.Time `description:"报告时间创建时间"`
  43. VoiceGenerateType int `description:"音频生成方式,0:系统生成,1:人工上传"`
  44. }
  45. // ReportChapterItem 报告章节详情
  46. type ReportChapterItem struct {
  47. ReportChapterId int `orm:"column(report_chapter_id);pk" description:"报告章节ID"`
  48. ReportId int `description:"报告ID"`
  49. ReportType string `description:"报告类型 day-晨报 week-周报"`
  50. ClassifyIdFirst int `description:"一级分类id"`
  51. ClassifyNameFirst string `description:"一级分类名称"`
  52. TypeId int `description:"品种ID"`
  53. TypeName string `description:"品种名称"`
  54. Title string `description:"标题"`
  55. Abstract string `description:"摘要"`
  56. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  57. Author string `description:"作者"`
  58. Content string `description:"内容"`
  59. ContentSub string `description:"内容前两个章节"`
  60. Stage int `description:"期数"`
  61. Trend string `description:"趋势观点"`
  62. Sort int `description:"排序: 数值越小越靠前"`
  63. IsEdit int `description:"是否已编辑 0-待编辑 1-已编辑"`
  64. PublishState int `description:"发布状态 1-待发布,2-已发布"`
  65. PublishTime string `description:"发布时间"`
  66. VideoUrl string `description:"音频文件URL"`
  67. VideoName string `description:"音频文件名称"`
  68. VideoPlaySeconds string `description:"音频播放时长"`
  69. VideoSize string `description:"音频文件大小,单位M"`
  70. VideoKind int `description:"音频生成方式:1,手动上传,2:自动生成"`
  71. CreateTime string `description:"创建时间"`
  72. ModifyTime string `description:"修改时间"`
  73. OriginalVideoUrl string `description:"原始音频文件URL"`
  74. ContentStruct string `description:"内容组件"`
  75. LastModifyAdminId int `description:"最后更新人ID"`
  76. LastModifyAdminName string `description:"最后更新人姓名"`
  77. ContentModifyTime string `description:"内容更新时间"`
  78. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  79. ReportCreateTime string `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. o := orm.NewOrmUsingDB("rddp")
  128. sql := ` SELECT * FROM report_chapter WHERE report_id = ? ORDER BY sort ASC`
  129. _, err = o.Raw(sql, reportId).QueryRows(&list)
  130. return
  131. }
  132. // GetPublishedChapterListByReportId 根据ReportId获取已发布章节列表
  133. func GetPublishedChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
  134. o := orm.NewOrmUsingDB("rddp")
  135. sql := ` SELECT * FROM report_chapter WHERE report_id = ? AND publish_state = 2 ORDER BY sort ASC`
  136. _, err = o.Raw(sql, reportId).QueryRows(&list)
  137. return
  138. }
  139. // AddReportChapterReq
  140. // @Description: 新增报告章节请求体
  141. type AddReportChapterReq struct {
  142. ReportId int `description:"报告ID"`
  143. Title string `description:"标题"`
  144. PermissionIdList []int `description:"报告关联的品种权限"`
  145. AdminIdList []int `description:"授权的编辑人id列表"`
  146. }
  147. // EditReportChapterReq 编辑报告章节请求体
  148. type EditReportChapterReq struct {
  149. ReportChapterId int `description:"报告章节ID"`
  150. Title string `description:"标题"`
  151. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  152. Author string `description:"作者"`
  153. Content string `description:"内容"`
  154. TickerList []EditTickList `description:"指标信息"`
  155. CreateTime string `description:"发布时间"`
  156. VideoUrl string `description:"音频文件URL"`
  157. VideoName string `description:"音频文件名称"`
  158. VideoPlaySeconds string `description:"音频播放时长"`
  159. VideoSize string `description:"音频文件大小,单位M"`
  160. // 以下是智能研报相关
  161. ContentStruct string `description:"内容组件"`
  162. HeadImg string `description:"报告头图地址"`
  163. EndImg string `description:"报告尾图地址"`
  164. CanvasColor string `description:"画布颜色"`
  165. HeadResourceId int `description:"版头资源ID"`
  166. EndResourceId int `description:"版尾资源ID"`
  167. }
  168. type EditTickList struct {
  169. Label string
  170. Ticker string
  171. Sort int
  172. }
  173. // GetReportChapterInfoById 根据主键获取报告章节
  174. func GetReportChapterInfoById(reportChapterId int) (item *ReportChapter, err error) {
  175. o := orm.NewOrmUsingDB("rddp")
  176. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ? `
  177. err = o.Raw(sql, reportChapterId).QueryRow(&item)
  178. return
  179. }
  180. // GetReportChapterItemById
  181. // @Description: 根据主键获取报告章节(时间格式为字符串的数据)
  182. // @author: Roc
  183. // @datetime 2024-06-27 14:10:29
  184. // @param reportChapterId int
  185. // @return item *ReportChapterItem
  186. // @return err error
  187. func GetReportChapterItemById(reportChapterId int) (item *ReportChapterItem, err error) {
  188. o := orm.NewOrmUsingDB("rddp")
  189. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ? `
  190. err = o.Raw(sql, reportChapterId).QueryRow(&item)
  191. return
  192. }
  193. // GetLastPublishedReportChapter 获取上一篇已发表的晨周报章节
  194. func GetLastPublishedReportChapter(typeId int, reportType string) (item *ReportChapter, err error) {
  195. o := orm.NewOrmUsingDB("rddp")
  196. sql := ` SELECT * FROM report_chapter WHERE publish_state = 2 AND type_id = ? AND report_type = ? ORDER BY report_chapter_id DESC limit 1 `
  197. err = o.Raw(sql, typeId, reportType).QueryRow(&item)
  198. return
  199. }
  200. // Add
  201. // @Description: 新增章节报告
  202. // @author: Roc
  203. // @receiver chapterInfo
  204. // @datetime 2024-06-04 15:14:41
  205. // @return err error
  206. func (chapterChapterInfo *ReportChapter) Add() (err error) {
  207. o := orm.NewOrmUsingDB("rddp")
  208. lastId, err := o.Insert(chapterChapterInfo)
  209. if err != nil {
  210. return
  211. }
  212. chapterChapterInfo.ReportChapterId = int(lastId)
  213. return
  214. }
  215. // UpdateChapter 更新报表章节
  216. func (chapterChapterInfo *ReportChapter) UpdateChapter(cols []string) (err error) {
  217. o := orm.NewOrmUsingDB("rddp")
  218. _, err = o.Update(chapterChapterInfo, cols...)
  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 := orm.NewOrmUsingDB("rddp")
  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).QueryRows(&list)
  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 := orm.NewOrmUsingDB("rddp")
  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).QueryRows(&list)
  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 := orm.NewOrmUsingDB("rddp")
  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).QueryRows(&list)
  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 := orm.NewOrmUsingDB("rddp")
  327. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 2 `
  328. err = o.Raw(sql, reportId).QueryRow(&count)
  329. return
  330. }
  331. // CountUnPublishedChapterNum
  332. // @Description: 获取报告未发布的章节数
  333. // @author: Roc
  334. // @datetime 2024-06-14 15:59:23
  335. // @param reportId int
  336. // @return count int
  337. // @return err error
  338. func CountUnPublishedChapterNum(reportId int) (count int, err error) {
  339. o := orm.NewOrmUsingDB("rddp")
  340. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 1 `
  341. err = o.Raw(sql, reportId).QueryRow(&count)
  342. return
  343. }
  344. // GetUnPublishedChapterList
  345. // @Description: 获取报告未发布的章节列表
  346. // @author: Roc
  347. // @datetime 2024-06-14 15:59:23
  348. // @param reportId int
  349. // @return list []*ReportChapter
  350. // @return err error
  351. func GetUnPublishedChapterList(reportId int) (list []*ReportChapter, err error) {
  352. o := orm.NewOrmUsingDB("rddp")
  353. sql := ` SELECT report_chapter_id,report_id,title FROM report_chapter WHERE report_id = ? AND publish_state = 1 ORDER BY sort ASC`
  354. _, err = o.Raw(sql, reportId).QueryRows(&list)
  355. return
  356. }
  357. // GetChapterListByChapterIds 根据ReportId获取章节列表
  358. func GetChapterListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
  359. if len(chapterIds) == 0 {
  360. return
  361. }
  362. o := orm.NewOrmUsingDB("rddp")
  363. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) ORDER BY sort ASC`
  364. _, err = o.Raw(sql, chapterIds).QueryRows(&list)
  365. return
  366. }
  367. // GetChapterSimpleListByChapterIds 根据章节ID获取章节列表
  368. func GetChapterSimpleListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
  369. if len(chapterIds) == 0 {
  370. return
  371. }
  372. o := orm.NewOrmUsingDB("rddp")
  373. 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`
  374. _, err = o.Raw(sql, chapterIds).QueryRows(&list)
  375. return
  376. }
  377. // GetChapterSimpleListByReportIds 根据ReportId获取章节列表
  378. func GetChapterSimpleListByReportIds(reportIds []int) (list []*ReportChapter, err error) {
  379. if len(reportIds) == 0 {
  380. return
  381. }
  382. o := orm.NewOrmUsingDB("rddp")
  383. 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`
  384. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  385. return
  386. }
  387. // UpdateReportChapterTypeNameByTypeId 更新章节类型名称
  388. func UpdateReportChapterTypeNameByTypeId(typeId int, typeName string) (err error) {
  389. o := orm.NewOrmUsingDB("rddp")
  390. sql := `UPDATE report_chapter SET type_name = ? WHERE type_id = ?`
  391. _, err = o.Raw(sql, typeName, typeId).Exec()
  392. return
  393. }
  394. // CountReportChapterByTypeId 通过章节类型ID获取章节数
  395. func CountReportChapterByTypeId(typeId int) (count int, err error) {
  396. o := orm.NewOrmUsingDB("rddp")
  397. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE type_id = ?`
  398. err = o.Raw(sql, typeId).QueryRow(&count)
  399. return
  400. }
  401. // AddReportChapter
  402. // @Description: 待添加的报告章节
  403. type AddReportChapter struct {
  404. ReportChapter *ReportChapter
  405. GrantList []*report.ReportChapterGrant
  406. GrantPermissionList []*report.ReportChapterPermissionMapping
  407. }
  408. // EditReportChapterBaseInfoAndPermissionReq
  409. // @Description: 编辑报告章节的基础信息请求
  410. type EditReportChapterBaseInfoAndPermissionReq struct {
  411. ReportChapterId int `description:"报告章节ID"`
  412. Title string `description:"标题"`
  413. PermissionIdList []int `description:"报告关联的品种权限"`
  414. AdminIdList []int `description:"授权的编辑人id列表"`
  415. }
  416. // GetReportChapterIdList
  417. // @Description: 获取报告的所有章节id列表
  418. // @author: Roc
  419. // @datetime 2024-06-05 11:09:40
  420. // @param reportId int
  421. // @return list []int
  422. // @return err error
  423. func GetReportChapterIdList(reportId int) (list []int, err error) {
  424. o := orm.NewOrmUsingDB("rddp")
  425. sql := ` SELECT report_chapter_id FROM report_chapter
  426. WHERE report_id = ?
  427. ORDER BY report_chapter_id ASC `
  428. _, err = o.Raw(sql, reportId).QueryRows(&list)
  429. return
  430. }
  431. // ReportChapterMoveReq
  432. // @Description: 报告章节移动请求
  433. type ReportChapterMoveReq struct {
  434. ReportChapterId int `description:"报告章节id"`
  435. // ParentChartPermissionId int `description:"父级品种id"`
  436. PrevReportChapterId int `description:"上一个兄弟节点报告章节id"`
  437. NextReportChapterId int `description:"下一个兄弟节点报告章节id"`
  438. }
  439. // GetReportChapterById
  440. // @Description: 获取具体章节
  441. // @author: Roc
  442. // @receiver r
  443. // @datetime 2024-06-06 09:32:40
  444. // @param reportChapterId int
  445. // @return item *ReportChapter
  446. // @return err error
  447. func (chapterChapterInfo *ReportChapter) GetReportChapterById(reportChapterId int) (item *ReportChapter, err error) {
  448. o := orm.NewOrmUsingDB("rddp")
  449. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ?`
  450. err = o.Raw(sql, reportChapterId).QueryRow(&item)
  451. return
  452. }
  453. // UpdateReportChapterSortByReportId
  454. // @Description: 根据父类id更新排序
  455. // @author: Roc
  456. // @receiver chapterChapterInfo
  457. // @datetime 2024-06-06 09:39:28
  458. // @param reportId int
  459. // @param reportChapterId int
  460. // @param nowSort int
  461. // @param updateSort string
  462. // @return err error
  463. func (chapterChapterInfo *ReportChapter) UpdateReportChapterSortByReportId(reportId, reportChapterId, nowSort int, updateSort string) (err error) {
  464. o := orm.NewOrmUsingDB("rddp")
  465. pars := make([]interface{}, 0)
  466. sql := ` update report_chapter set sort = ` + updateSort + ` WHERE report_id = ? AND sort > ?`
  467. pars = append(pars, reportId, nowSort)
  468. if reportChapterId > 0 {
  469. sql += ` or ( report_chapter_id > ? and sort = ? )`
  470. pars = append(pars, reportChapterId, nowSort)
  471. }
  472. _, err = o.Raw(sql, pars).Exec()
  473. return
  474. }
  475. // GetFirstReportChapterByReportId
  476. // @Description: 获取当前报告下,且排序数相同 的排序第一条的数据
  477. // @author: Roc
  478. // @receiver chapterChapterInfo
  479. // @datetime 2024-06-06 09:45:32
  480. // @param reportId int
  481. // @return item *ReportChapter
  482. // @return err error
  483. func (chapterChapterInfo *ReportChapter) GetFirstReportChapterByReportId(reportId int) (item *ReportChapter, err error) {
  484. o := orm.NewOrmUsingDB("rddp")
  485. sql := ` SELECT * FROM report_chapter WHERE 1 = 1 AND report_id = ? ORDER BY sort ASC, report_chapter_id ASC LIMIT 1`
  486. err = o.Raw(sql, reportId).QueryRow(&item)
  487. return
  488. }
  489. // GetMaxSortByReportId
  490. // @Description: 获取最大的排序值
  491. // @author: Roc
  492. // @receiver chapterChapterInfo
  493. // @datetime 2024-06-06 09:44:13
  494. // @param reportId int
  495. // @return maxSort int
  496. // @return err error
  497. func (chapterChapterInfo *ReportChapter) GetMaxSortByReportId(reportId int) (maxSort int, err error) {
  498. o := orm.NewOrmUsingDB("rddp")
  499. sql := `SELECT max(sort) AS sort FROM report_chapter WHERE report_id = ?`
  500. err = o.Raw(sql, reportId).QueryRow(&maxSort)
  501. return
  502. }
  503. // Update
  504. // @Description: 数据变更
  505. // @author: Roc
  506. // @receiver chapterChapterInfo
  507. // @datetime 2024-06-06 09:47:46
  508. // @param cols []string
  509. // @return err error
  510. func (chapterChapterInfo *ReportChapter) Update(cols []string) (err error) {
  511. o := orm.NewOrmUsingDB("rddp")
  512. _, err = o.Update(chapterChapterInfo, cols...)
  513. return
  514. }
  515. // DelReportChapterReq
  516. // @Description: 删除报告章节请求体
  517. type DelReportChapterReq struct {
  518. ReportChapterId int `description:"报告章节ID"`
  519. }
  520. // GetAllReportChapter 获取所有的报告章节
  521. func GetAllReportChapter() (items []*ReportChapter, err error) {
  522. o := orm.NewOrmUsingDB("rddp")
  523. sql := ` SELECT * FROM report_chapter ORDER BY report_chapter_id asc `
  524. _, err = o.Raw(sql).QueryRows(&items)
  525. return
  526. }
  527. // GetCountReportChapterByCondition
  528. // @Description: 根据条件获取章节数量
  529. // @author: Roc
  530. // @datetime 2024-07-15 15:37:50
  531. // @param condition string
  532. // @param pars []interface{}
  533. // @return count int
  534. // @return err error
  535. func GetCountReportChapterByCondition(condition string, pars []interface{}) (count int, err error) {
  536. o := orm.NewOrmUsingDB("rddp")
  537. sql := ` SELECT COUNT(1) AS count FROM report_chapter WHERE 1=1 `
  538. if condition != "" {
  539. sql += condition
  540. }
  541. err = o.Raw(sql, pars).QueryRow(&count)
  542. return
  543. }