query.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package report_chapter
  2. import (
  3. "hongze/hongze_yb/global"
  4. "hongze/hongze_yb/utils"
  5. )
  6. func GetLatestChaptersByTypeIdsAndClass(typeIds []int, classifyNameFirst string) (list []*ReportChapter, err error) {
  7. sql := `SELECT
  8. DISTINCT report_id
  9. FROM
  10. report_chapter
  11. WHERE
  12. type_id IN (?)
  13. AND publish_state = 2
  14. AND is_edit = 1
  15. AND report_type = ?
  16. ORDER BY
  17. publish_time desc, report_chapter_id desc limit 30
  18. `
  19. err = global.MYSQL["rddp"].Model(ReportChapter{}).Raw(sql, typeIds, classifyNameFirst).Scan(&list).Error
  20. return
  21. }
  22. // GetListByReportId 根据报告ID获取章节列表
  23. func GetListByReportId(reportId int, classifyNameFirst string) (list []*ReportChapter, err error) {
  24. var where string
  25. if classifyNameFirst == "周报"{
  26. where = "report_id = ? AND is_edit = 1 AND publish_state = 2"
  27. }else{
  28. where = "report_id = ? AND publish_state = 2"
  29. }
  30. err = global.MYSQL["rddp"].Model(ReportChapter{}).
  31. Select("report_chapter_id, report_id, type_id, type_name, abstract, title, author, publish_time, trend").
  32. Where(where, reportId).
  33. Order("sort asc, report_chapter_id asc").
  34. Scan(&list).Error
  35. return
  36. }
  37. // GetListByReportIdTypeIds 根据报告ID、章节类型ID获取章节列表
  38. func GetListByReportIdTypeIds(reportId int, typeIds []int, classifyNameFirst string) (list []*ReportChapter, err error) {
  39. var where string
  40. if classifyNameFirst == "周报"{
  41. where = "report_id = ? AND type_id in (?) AND is_edit = 1 AND publish_state = 2 "
  42. }else{
  43. where = "report_id = ? AND type_id in (?) AND publish_state = 2 "
  44. }
  45. err = global.MYSQL["rddp"].Model(ReportChapter{}).
  46. Select("report_chapter_id, report_id, type_id, type_name, abstract, title, author, publish_time").
  47. Where(where, reportId, typeIds).
  48. Order("sort asc, report_chapter_id asc").
  49. Scan(&list).Error
  50. return
  51. }
  52. // GetContentById 根据ID获取章节详情
  53. func GetContentById(id int, typeIds []int) (info *ReportChapter, err error) {
  54. err = global.MYSQL["rddp"].Model(ReportChapter{}).Select("report_chapter_id, report_id, is_edit, classify_name_first, classify_id_first, content, trend, type_id, type_name, abstract, title, author, stage, publish_time, content, content_sub, video_url, video_name, video_play_seconds, video_size").
  55. Where("report_chapter_id = ? and type_id in (?) AND publish_state = 2 ", id, typeIds).
  56. First(&info).Error
  57. if err == utils.ErrNoRow {
  58. err = nil
  59. }
  60. return
  61. }
  62. // GetReportIdsByTypeIdsAndClass 根据章节ID获取报告ID
  63. func GetReportIdsByTypeIdsAndClass(typeIds []int, classifyNameFirst string) (reportIds []int, err error) {
  64. var list []*ReportChapter
  65. err = global.MYSQL["rddp"].Model(ReportChapter{}).Select("DISTINCT report_id").Where("type_id in (?) and publish_state = 2 AND is_edit = 1 AND classify_name_first= ? ", typeIds, classifyNameFirst).Scan(&list).Error
  66. if err != nil {
  67. return
  68. }
  69. for _, v := range list {
  70. reportIds = append(reportIds, v.ReportId)
  71. }
  72. return
  73. }
  74. // GetTypeIdById 根据ID获取章节类型
  75. func GetTypeIdById(id int) (info *ReportChapter, err error) {
  76. err = global.MYSQL["rddp"].Model(ReportChapter{}).Select("report_chapter_id, type_id").
  77. Where("report_chapter_id = ? AND publish_state = 2 ", id).
  78. First(&info).Error
  79. if err == utils.ErrNoRow {
  80. err = nil
  81. }
  82. return
  83. }
  84. // GetByTypeIdsAndReportIds 根据章节ID和ReportIds查询报告
  85. func GetByTypeIdsAndReportIds(typeIds []int, reportIds []int, classifyNameFirst string) (list []*ReportChapter, err error) {
  86. var where string
  87. if classifyNameFirst == "周报"{
  88. where = "report_id in (?) AND type_id in (?) AND is_edit = 1 AND publish_state = 2 "
  89. }else{
  90. where = "report_id in (?) AND type_id in (?) AND publish_state = 2 "
  91. }
  92. err = global.MYSQL["rddp"].Model(ReportChapter{}).
  93. Select("report_id, type_id, report_chapter_id, classify_name_first, classify_id_first, video_url, video_name, video_play_seconds, video_size, sort").
  94. Where(where, reportIds, typeIds).
  95. Order("sort asc, report_chapter_id asc").
  96. Scan(&list).Error
  97. if err != nil {
  98. return
  99. }
  100. for _, v := range list {
  101. reportIds = append(reportIds, v.ReportId)
  102. }
  103. return
  104. }