query.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package report_chapter
  2. import (
  3. "hongze/hongze_yb/global"
  4. "hongze/hongze_yb/utils"
  5. )
  6. func GetLatestChapterByTypeIdsAndClass(typeIds []int, classifyNameFirst string) (reportChapter *ReportChapter, err error) {
  7. sql := `SELECT
  8. max( publish_time ) as publish_time,
  9. classify_id_first,
  10. classify_name_first,
  11. title,
  12. type_id,
  13. type_name,
  14. report_chapter_id
  15. FROM
  16. report_chapter
  17. WHERE
  18. type_id IN (?)
  19. AND publish_state = 2
  20. AND is_edit = 1
  21. AND classify_name_first = ?
  22. ORDER BY
  23. publish_time desc`
  24. err = global.MYSQL["rddp"].Model(ReportChapter{}).Raw(sql, typeIds, classifyNameFirst).First(&reportChapter).Error
  25. return
  26. }
  27. // GetListByReportId 根据报告ID获取章节列表
  28. func GetListByReportId(reportId int, classifyNameFirst string) (list []*ReportChapter, err error) {
  29. var where string
  30. if classifyNameFirst == "周报"{
  31. where = "report_id = ? AND is_edit = 1 AND publish_state = 2"
  32. }else{
  33. where = "report_id = ? AND publish_state = 2"
  34. }
  35. err = global.MYSQL["rddp"].Model(ReportChapter{}).
  36. Select("report_chapter_id, report_id, type_id, type_name, abstract, title, author, publish_time").
  37. Where(where, reportId).
  38. Order("sort asc, report_chapter_id asc").
  39. Scan(&list).Error
  40. return
  41. }
  42. // GetListByReportIdTypeIds 根据报告ID、章节类型ID获取章节列表
  43. func GetListByReportIdTypeIds(reportId int, typeIds []int, classifyNameFirst string) (list []*ReportChapter, err error) {
  44. var where string
  45. if classifyNameFirst == "周报"{
  46. where = "report_id = ? AND type_id in (?) AND is_edit = 1 AND publish_state = 2 "
  47. }else{
  48. where = "report_id = ? AND type_id in (?) AND publish_state = 2 "
  49. }
  50. err = global.MYSQL["rddp"].Model(ReportChapter{}).
  51. Select("report_chapter_id, report_id, type_id, type_name, abstract, title, author, publish_time").
  52. Where(where, reportId, typeIds).
  53. Order("sort asc, report_chapter_id asc").
  54. Scan(&list).Error
  55. return
  56. }
  57. // GetContentById 根据ID获取章节详情
  58. func GetContentById(id int, typeIds []int) (info *ReportChapter, err error) {
  59. err = global.MYSQL["rddp"].Model(ReportChapter{}).Select("report_chapter_id, report_id, is_edit, content, trend, type_id, type_name, abstract, title, author, publish_time, content, content_sub, video_url, video_name, video_play_seconds, video_size").
  60. Where("report_chapter_id = ? and type_id in (?) AND publish_state = 2 ", id, typeIds).
  61. First(&info).Error
  62. if err == utils.ErrNoRow {
  63. err = nil
  64. }
  65. return
  66. }
  67. // GetReportIdsByTypeIdsAndClass 根据章节ID获取报告ID
  68. func GetReportIdsByTypeIdsAndClass(typeIds []int, classifyNameFirst string) (reportIds []int, err error) {
  69. var list []*ReportChapter
  70. 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
  71. if err != nil {
  72. return
  73. }
  74. for _, v := range list {
  75. reportIds = append(reportIds, v.ReportId)
  76. }
  77. return
  78. }