query.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package yb_community_question_comment
  2. import (
  3. "hongze/hongze_yb/global"
  4. "hongze/hongze_yb/utils"
  5. )
  6. // GetByCommunityQuestionCommentId 根据留言ID,查询留言
  7. func GetByCommunityQuestionCommentId(communityQuestionCommentId uint64) (item *YbCommunityQuestionComment, err error) {
  8. err = global.DEFAULT_MYSQL.Where("community_question_comment_id = ? ", communityQuestionCommentId).First(&item).Error
  9. if err == utils.ErrNoRow {
  10. err = nil
  11. }
  12. return
  13. }
  14. // GetListByUserIdReportId 获取用户的留言列表
  15. func GetListByUserIdReportId(userId uint64, reportId, reportChapterId int) (list []*YbCommunityQuestionComment, err error) {
  16. err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
  17. Where("user_id = ? and report_id = ? and report_chapter_id = ? and enabled = 1 ", userId, reportId, reportChapterId).
  18. Order("create_time desc, comment_id desc").
  19. Scan(&list).Error
  20. if err == utils.ErrNoRow {
  21. err = nil
  22. }
  23. return
  24. }
  25. // GetListByUserIdOldReportId 获取用户的留言列表
  26. func GetListByUserIdOldReportId(userId uint64, oldReportId, oldReportChapterId int) (list []*YbCommunityQuestionComment, err error) {
  27. err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
  28. Where("user_id = ? and old_report_id = ? and old_report_chapter_id = ? and enabled = 1 ", userId, oldReportId, oldReportChapterId).
  29. Order("create_time desc, comment_id desc").
  30. Scan(&list).Error
  31. if err == utils.ErrNoRow {
  32. err = nil
  33. }
  34. return
  35. }
  36. // GetHotListByReportId 获取报告的精选留言列表
  37. func GetHotListByReportId(reportId, reportChapterId int, offset, limit int) (list []*YbCommunityQuestionComment, err error) {
  38. err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
  39. Where("report_id = ? and report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId, reportChapterId).
  40. Order("is_top desc, hot_top_time desc, comment_id desc").
  41. Offset(offset).
  42. Limit(limit).
  43. Scan(&list).Error
  44. return
  45. }
  46. // GetHotListTotalByReportId 获取精选留言总条数
  47. func GetHotListTotalByReportId(reportId, reportChapterId int) (total int64, err error) {
  48. err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
  49. Where("report_id = ? and report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId, reportChapterId).
  50. Count(&total).Error
  51. return
  52. }
  53. // GetHotListByOldReportId 获取老报告的精选留言列表
  54. func GetHotListByOldReportId(oldReportId, oldReportChapterId int, offset, limit int) (list []*YbCommunityQuestionComment, err error) {
  55. err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
  56. Where("old_report_id = ? and old_report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", oldReportId, oldReportChapterId).
  57. Order("is_top desc, hot_top_time desc, comment_id desc").
  58. Offset(offset).
  59. Limit(limit).
  60. Scan(&list).Error
  61. return
  62. }
  63. // GetHotListTotalByOldReportId 获取老报告的精选留言总条数
  64. func GetHotListTotalByOldReportId(oldReportId, oldReportChapterId int) (total int64, err error) {
  65. err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
  66. Where("old_report_id = ? and old_report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", oldReportId, oldReportChapterId).
  67. Count(&total).Error
  68. return
  69. }
  70. // GetReplyListByReplyCommentId 获取报告的精选留言的回复列表
  71. func GetReplyListByReplyCommentId(replyCommentIds []uint64) (list []*YbCommunityQuestionComment, err error) {
  72. err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
  73. Where("enabled = 1 and type = 2 and reply_comment_id in ?", replyCommentIds).
  74. Order("comment_id asc").
  75. Scan(&list).Error
  76. return
  77. }
  78. type SimpleYbCommunityQuestionComment struct {
  79. CommunityQuestionCommentID uint64 `gorm:"primaryKey;column:community_question_comment_id;type:bigint(20) unsigned;not null" json:"-"`
  80. UserID uint64 `gorm:"column:user_id;type:bigint(20) unsigned;not null;default:0" json:"userId"` // 用户id
  81. Type int8 `gorm:"column:type;type:tinyint(1);not null;default:1" json:"type"` // 留言类型 1-评论 2-回复
  82. Enabled int8 `gorm:"column:enabled;type:tinyint(1);not null;default:1" json:"enabled"` // 是否有效, 0-无效留言 1-有效留言
  83. }
  84. // GetSimpleByCommentId 根据留言ID,查询留言
  85. func GetSimpleByCommentId(commentId uint64) (item *SimpleYbCommunityQuestionComment, err error) {
  86. err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
  87. Select("community_question_comment_id, user_id, type, enabled").
  88. Where("comment_id = ?", commentId).First(&item).Error
  89. if err == utils.ErrNoRow {
  90. err = nil
  91. }
  92. return
  93. }
  94. // GetMyLatestComment 获取用户最新的留言
  95. func GetMyLatestComment(userId uint64) (item *YbCommunityQuestionComment, err error) {
  96. err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
  97. Select("comment_id, user_id, type, enabled, is_show_name").
  98. Where("user_id = ? and type=1", userId).Order("comment_id desc").First(&item).Error
  99. return
  100. }