report_chapter.go 23 KB

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