yb_community_question_comment.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // YbCommunityQuestionComment 研报问答社区 用户留言表
  7. type YbCommunityQuestionComment struct {
  8. CommunityQuestionCommentId uint64 `orm:"column(community_question_comment_id);pk;" description:"留言ID"`
  9. CommunityQuestionId int `orm:"column(community_question_id)" description:"社区问答id"`
  10. UserId uint64 `orm:"column(user_id)" description:"用户id"`
  11. RealName string `orm:"column(real_name)" description:"用户当时昵称"`
  12. Content string `orm:"column(content)" description:"留言内容"`
  13. ReplyCommentId uint64 `orm:"column(reply_comment_id)" description:"回复的留言ID"`
  14. IsTop int8 `orm:"column(is_top)" description:"是否置顶(0-未置顶,1-置顶)"`
  15. IsHot int8 `orm:"column(is_hot)" description:"是否设置精选(0-未设置,1-已设置)"`
  16. HotTopTime time.Time `orm:"column(hot_top_time)" description:"设置精选或者设置置顶的时间"`
  17. Type int8 `orm:"column(type)" description:"留言类型 1-评论 2-回复"`
  18. Enabled int8 `orm:"column(enabled)" description:"是否有效, 0-无效留言 1-有效留言"`
  19. IsShowName int8 `orm:"column(is_show_name)" description:"是否匿名 0-匿名,1-不匿名"`
  20. SourceAgent int `orm:"column(source_agent)" description:"留言入口来源,1:小程序,2:小程序pc, 4:web pc"`
  21. TopTime time.Time `orm:"column(top_time)" description:"设置置顶的时间"`
  22. HotTime time.Time `orm:"column(hot_time)" description:"设置精选的时间"`
  23. ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
  24. CreateTime time.Time `orm:"column(create_time)" description:"创建时间"`
  25. Source int `orm:"column(source)" description:"来源:1-问答社区; 2-视频社区"`
  26. }
  27. // GetQuestionCommentById 主键获取提问评论
  28. func GetQuestionCommentById(questionId int) (item *YbCommunityQuestionComment, err error) {
  29. o := orm.NewOrm()
  30. sql := `SELECT * FROM yb_community_question_comment WHERE community_question_comment_id = ? AND enabled = 1 LIMIT 1`
  31. err = o.Raw(sql, questionId).QueryRow(&item)
  32. return
  33. }
  34. //Update 更新评论信息
  35. func (item *YbCommunityQuestionComment) Update(cols []string) (err error) {
  36. o := orm.NewOrm()
  37. _, err = o.Update(item, cols...)
  38. return
  39. }
  40. //删除数据
  41. func (item *YbCommunityQuestionComment) Delete() (err error) {
  42. o := orm.NewOrm()
  43. sql := ` DELETE FROM yb_community_question_comment WHERE community_question_comment_id = ?`
  44. _, err = o.Raw(sql, item.CommunityQuestionCommentId).Exec()
  45. return
  46. }
  47. // YbCommunityQuestionCommentAndQuestion 研报问答社区和信息
  48. type YbCommunityQuestionCommentAndQuestion struct {
  49. CommunityQuestionCommentId uint64 `orm:"column(community_question_comment_id);pk;" description:"留言ID"`
  50. CommunityQuestionId int `orm:"column(community_question_id)" description:"社区问答id"`
  51. UserId uint64 `orm:"column(user_id)" description:"用户id"`
  52. NickName string `description:"用户名称"`
  53. RealName string `description:"用户真实姓名"`
  54. CompanyId int `description:"客户id"`
  55. CompanyName string `description:"客户名称"`
  56. CompanyFiccStatus string `description:"客户ficc状态"`
  57. Content string `orm:"column(content)" description:"留言内容"`
  58. ReplyCommentId uint64 `orm:"column(reply_comment_id)" description:"回复的留言ID" json:"-"`
  59. IsTop int8 `orm:"column(is_top)" description:"是否置顶(0-未置顶,1-置顶)" json:"-"`
  60. IsHot int8 `orm:"column(is_hot)" description:"是否设置精选(0-未设置,1-已设置)"`
  61. HotTopTime time.Time `orm:"column(hot_top_time)" description:"设置精选或者设置置顶的时间"`
  62. Type int8 `orm:"column(type)" description:"留言类型 1-评论 2-回复" json:"-"`
  63. Enabled int8 `orm:"column(enabled)" description:"是否有效, 0-无效留言 1-有效留言" json:"-"`
  64. IsShowName int8 `orm:"column(is_show_name)" description:"是否匿名 0-匿名,1-不匿名"`
  65. SourceAgent int `orm:"column(source_agent)" description:"留言入口来源,1:小程序,2:小程序pc, 4:web pc"`
  66. TopTime time.Time `orm:"column(top_time)" description:"设置置顶的时间"`
  67. HotTime time.Time `orm:"column(hot_time)" description:"设置精选的时间"`
  68. ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
  69. CreateTime string `orm:"column(create_time)" description:"创建时间"`
  70. QuestionContent string `description:"问题内容"`
  71. }
  72. // GetCommunityQuestionCommentList 获取问答列表
  73. func GetCommunityQuestionCommentList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*YbCommunityQuestionCommentAndQuestion, err error) {
  74. o := orm.NewOrm()
  75. //汇总数据
  76. totalSQl := `SELECT COUNT(1) total FROM yb_community_question_comment a join yb_community_question b on a.community_question_id = b.community_question_id WHERE a.enabled = 1 AND a.type = 1 AND b.is_deleted=0 `
  77. totalSQl += condition
  78. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  79. return
  80. }
  81. // 列表数据
  82. sql := `SELECT a.*,b.question_content FROM yb_community_question_comment a join yb_community_question b on a.community_question_id = b.community_question_id WHERE a.enabled = 1 AND a.type = 1 AND b.is_deleted=0 `
  83. sql += condition
  84. sql += ` ORDER BY a.create_time DESC LIMIT ?,?`
  85. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  86. return
  87. }
  88. // GetCommunityQuestionCommentListByIds 根据问答评论id获取列表数据
  89. func GetCommunityQuestionCommentListByIds(CommunityQuestionCommentIds string) (list []*YbCommunityQuestionComment, err error) {
  90. o := orm.NewOrm()
  91. // 列表数据
  92. sql := `SELECT q.* FROM yb_community_question_comment q WHERE q.enabled = 1 AND community_question_comment_id in (` + CommunityQuestionCommentIds + `)`
  93. _, err = o.Raw(sql).QueryRows(&list)
  94. return
  95. }