report_chapter.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. package models
  2. import (
  3. "eta/eta_api/models/report"
  4. "eta/eta_api/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(chapterInfo *ReportChapter, updateCols []string, tickerList []*ReportChapterTicker) (err error) {
  227. // 更新章节
  228. if err = chapterInfo.UpdateChapter(updateCols); err != nil {
  229. return
  230. }
  231. // 清空并新增章节ticker
  232. if err = ClearReportChapterTicker(chapterInfo.ReportChapterId); err != nil {
  233. return
  234. }
  235. tickerLen := len(tickerList)
  236. if tickerLen > 0 {
  237. for i := 0; i < tickerLen; i++ {
  238. _, tmpErr := InsertChapterTicker(tickerList[i])
  239. if tmpErr != nil {
  240. return
  241. }
  242. }
  243. }
  244. return
  245. }
  246. // ReportChapterVideoList 报告章节音频列表
  247. type ReportChapterVideoList struct {
  248. ReportId int `description:"报告ID"`
  249. ReportChapterId int `description:"报告章节ID"`
  250. VideoUrl string `description:"音频文件URL"`
  251. VideoName string `description:"音频文件名称"`
  252. VideoPlaySeconds string `description:"音频播放时长"`
  253. }
  254. // GetReportChapterVideoList 获取报告章节音频列表
  255. func GetReportChapterVideoList(reportId int) (list []*ReportChapterVideoList, err error) {
  256. o := orm.NewOrmUsingDB("rddp")
  257. sql := ` SELECT
  258. report_id,
  259. report_chapter_id,
  260. video_url,
  261. video_name,
  262. video_play_seconds
  263. FROM
  264. report_chapter
  265. WHERE
  266. report_id = ? AND publish_state = 2 AND video_url != ""
  267. ORDER BY
  268. report_chapter_id ASC `
  269. _, err = o.Raw(sql, reportId).QueryRows(&list)
  270. return
  271. }
  272. // GetReportChapterVideoListByReportIds 根据报告ID集合获取报告章节音频列表
  273. func GetReportChapterVideoListByReportIds(reportIds []string) (list []*ReportChapterVideoList, err error) {
  274. if len(reportIds) == 0 {
  275. return
  276. }
  277. o := orm.NewOrmUsingDB("rddp")
  278. sql := ` SELECT
  279. report_id,
  280. report_chapter_id,
  281. video_url,
  282. video_name,
  283. video_play_seconds
  284. FROM
  285. report_chapter
  286. WHERE
  287. report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `) AND publish_state = 2 AND video_url != ""
  288. ORDER BY
  289. report_chapter_id ASC `
  290. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  291. return
  292. }
  293. // GetReportChapterVideoListByChapterIds 根据章节ID集合获取报告章节音频列表
  294. func GetReportChapterVideoListByChapterIds(chapterIds []int) (list []*ReportChapterVideoList, err error) {
  295. if len(chapterIds) == 0 {
  296. return
  297. }
  298. o := orm.NewOrmUsingDB("rddp")
  299. sql := ` SELECT
  300. report_id,
  301. report_chapter_id,
  302. video_url,
  303. video_name,
  304. video_play_seconds
  305. FROM
  306. report_chapter
  307. WHERE
  308. report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) AND publish_state = 2
  309. ORDER BY
  310. report_chapter_id ASC `
  311. _, err = o.Raw(sql, chapterIds).QueryRows(&list)
  312. return
  313. }
  314. // PublishReportChapterReq 发布报告章节请求体
  315. type PublishReportChapterReq struct {
  316. ReportChapterId int `description:"报告章节ID"`
  317. PublishReport int `description:"是否同时发布报告"`
  318. }
  319. // CountPublishedChapterNum 获取报告已发布的章节数
  320. func CountPublishedChapterNum(reportId int) (count int, err error) {
  321. o := orm.NewOrmUsingDB("rddp")
  322. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 2 `
  323. err = o.Raw(sql, reportId).QueryRow(&count)
  324. return
  325. }
  326. // CountUnPublishedChapterNum
  327. // @Description: 获取报告未发布的章节数
  328. // @author: Roc
  329. // @datetime 2024-06-14 15:59:23
  330. // @param reportId int
  331. // @return count int
  332. // @return err error
  333. func CountUnPublishedChapterNum(reportId int) (count int, err error) {
  334. o := orm.NewOrmUsingDB("rddp")
  335. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 1 `
  336. err = o.Raw(sql, reportId).QueryRow(&count)
  337. return
  338. }
  339. // GetUnPublishedChapterList
  340. // @Description: 获取报告未发布的章节列表
  341. // @author: Roc
  342. // @datetime 2024-06-14 15:59:23
  343. // @param reportId int
  344. // @return list []*ReportChapter
  345. // @return err error
  346. func GetUnPublishedChapterList(reportId int) (list []*ReportChapter, err error) {
  347. o := orm.NewOrmUsingDB("rddp")
  348. sql := ` SELECT report_chapter_id,report_id,title FROM report_chapter WHERE report_id = ? AND publish_state = 1 ORDER BY sort ASC`
  349. _, err = o.Raw(sql, reportId).QueryRows(&list)
  350. return
  351. }
  352. // GetChapterListByChapterIds 根据ReportId获取章节列表
  353. func GetChapterListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
  354. if len(chapterIds) == 0 {
  355. return
  356. }
  357. o := orm.NewOrmUsingDB("rddp")
  358. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) ORDER BY sort ASC`
  359. _, err = o.Raw(sql, chapterIds).QueryRows(&list)
  360. return
  361. }
  362. // GetChapterSimpleListByChapterIds 根据章节ID获取章节列表
  363. func GetChapterSimpleListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
  364. if len(chapterIds) == 0 {
  365. return
  366. }
  367. o := orm.NewOrmUsingDB("rddp")
  368. 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`
  369. _, err = o.Raw(sql, chapterIds).QueryRows(&list)
  370. return
  371. }
  372. // GetChapterSimpleListByReportIds 根据ReportId获取章节列表
  373. func GetChapterSimpleListByReportIds(reportIds []int) (list []*ReportChapter, err error) {
  374. if len(reportIds) == 0 {
  375. return
  376. }
  377. o := orm.NewOrmUsingDB("rddp")
  378. 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`
  379. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  380. return
  381. }
  382. // UpdateReportChapterTypeNameByTypeId 更新章节类型名称
  383. func UpdateReportChapterTypeNameByTypeId(typeId int, typeName string) (err error) {
  384. o := orm.NewOrmUsingDB("rddp")
  385. sql := `UPDATE report_chapter SET type_name = ? WHERE type_id = ?`
  386. _, err = o.Raw(sql, typeName, typeId).Exec()
  387. return
  388. }
  389. // CountReportChapterByTypeId 通过章节类型ID获取章节数
  390. func CountReportChapterByTypeId(typeId int) (count int, err error) {
  391. o := orm.NewOrmUsingDB("rddp")
  392. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE type_id = ?`
  393. err = o.Raw(sql, typeId).QueryRow(&count)
  394. return
  395. }
  396. // AddReportChapter
  397. // @Description: 待添加的报告章节
  398. type AddReportChapter struct {
  399. ReportChapter *ReportChapter
  400. GrantList []*report.ReportChapterGrant
  401. GrantPermissionList []*report.ReportChapterPermissionMapping
  402. }
  403. // EditReportChapterBaseInfoAndPermissionReq
  404. // @Description: 编辑报告章节的基础信息请求
  405. type EditReportChapterBaseInfoAndPermissionReq struct {
  406. ReportChapterId int `description:"报告章节ID"`
  407. Title string `description:"标题"`
  408. PermissionIdList []int `description:"报告关联的品种权限"`
  409. AdminIdList []int `description:"授权的编辑人id列表"`
  410. }
  411. // GetReportChapterIdList
  412. // @Description: 获取报告的所有章节id列表
  413. // @author: Roc
  414. // @datetime 2024-06-05 11:09:40
  415. // @param reportId int
  416. // @return list []int
  417. // @return err error
  418. func GetReportChapterIdList(reportId int) (list []int, err error) {
  419. o := orm.NewOrmUsingDB("rddp")
  420. sql := ` SELECT report_chapter_id FROM report_chapter
  421. WHERE report_id = ?
  422. ORDER BY report_chapter_id ASC `
  423. _, err = o.Raw(sql, reportId).QueryRows(&list)
  424. return
  425. }
  426. // ReportChapterMoveReq
  427. // @Description: 报告章节移动请求
  428. type ReportChapterMoveReq struct {
  429. ReportChapterId int `description:"报告章节id"`
  430. // ParentChartPermissionId int `description:"父级品种id"`
  431. PrevReportChapterId int `description:"上一个兄弟节点报告章节id"`
  432. NextReportChapterId int `description:"下一个兄弟节点报告章节id"`
  433. }
  434. // GetReportChapterById
  435. // @Description: 获取具体章节
  436. // @author: Roc
  437. // @receiver r
  438. // @datetime 2024-06-06 09:32:40
  439. // @param reportChapterId int
  440. // @return item *ReportChapter
  441. // @return err error
  442. func (chapterChapterInfo *ReportChapter) GetReportChapterById(reportChapterId int) (item *ReportChapter, err error) {
  443. o := orm.NewOrmUsingDB("rddp")
  444. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ?`
  445. err = o.Raw(sql, reportChapterId).QueryRow(&item)
  446. return
  447. }
  448. // UpdateReportChapterSortByReportId
  449. // @Description: 根据父类id更新排序
  450. // @author: Roc
  451. // @receiver chapterChapterInfo
  452. // @datetime 2024-06-06 09:39:28
  453. // @param reportId int
  454. // @param reportChapterId int
  455. // @param nowSort int
  456. // @param updateSort string
  457. // @return err error
  458. func (chapterChapterInfo *ReportChapter) UpdateReportChapterSortByReportId(reportId, reportChapterId, nowSort int, updateSort string) (err error) {
  459. o := orm.NewOrmUsingDB("rddp")
  460. pars := make([]interface{}, 0)
  461. sql := ` update report_chapter set sort = ` + updateSort + ` WHERE report_id = ? AND sort > ?`
  462. pars = append(pars, reportId, nowSort)
  463. if reportChapterId > 0 {
  464. sql += ` or ( report_chapter_id > ? and sort = ? )`
  465. pars = append(pars, reportChapterId, nowSort)
  466. }
  467. _, err = o.Raw(sql, pars).Exec()
  468. return
  469. }
  470. // GetFirstReportChapterByReportId
  471. // @Description: 获取当前报告下,且排序数相同 的排序第一条的数据
  472. // @author: Roc
  473. // @receiver chapterChapterInfo
  474. // @datetime 2024-06-06 09:45:32
  475. // @param reportId int
  476. // @return item *ReportChapter
  477. // @return err error
  478. func (chapterChapterInfo *ReportChapter) GetFirstReportChapterByReportId(reportId int) (item *ReportChapter, err error) {
  479. o := orm.NewOrmUsingDB("rddp")
  480. sql := ` SELECT * FROM report_chapter WHERE 1 = 1 AND report_id = ? ORDER BY sort ASC, report_chapter_id ASC LIMIT 1`
  481. err = o.Raw(sql, reportId).QueryRow(&item)
  482. return
  483. }
  484. // GetMaxSortByReportId
  485. // @Description: 获取最大的排序值
  486. // @author: Roc
  487. // @receiver chapterChapterInfo
  488. // @datetime 2024-06-06 09:44:13
  489. // @param reportId int
  490. // @return maxSort int
  491. // @return err error
  492. func (chapterChapterInfo *ReportChapter) GetMaxSortByReportId(reportId int) (maxSort int, err error) {
  493. o := orm.NewOrmUsingDB("rddp")
  494. sql := `SELECT max(sort) AS sort FROM report_chapter WHERE report_id = ?`
  495. err = o.Raw(sql, reportId).QueryRow(&maxSort)
  496. return
  497. }
  498. // Update
  499. // @Description: 数据变更
  500. // @author: Roc
  501. // @receiver chapterChapterInfo
  502. // @datetime 2024-06-06 09:47:46
  503. // @param cols []string
  504. // @return err error
  505. func (chapterChapterInfo *ReportChapter) Update(cols []string) (err error) {
  506. o := orm.NewOrmUsingDB("rddp")
  507. _, err = o.Update(chapterChapterInfo, cols...)
  508. return
  509. }
  510. // DelReportChapterReq
  511. // @Description: 删除报告章节请求体
  512. type DelReportChapterReq struct {
  513. ReportChapterId int `description:"报告章节ID"`
  514. }
  515. // GetAllReportChapter 获取所有的报告章节
  516. func GetAllReportChapter() (items []*ReportChapter, err error) {
  517. o := orm.NewOrmUsingDB("rddp")
  518. sql := ` SELECT * FROM report_chapter ORDER BY report_chapter_id asc `
  519. _, err = o.Raw(sql).QueryRows(&items)
  520. return
  521. }