community_question.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/utils"
  5. "time"
  6. )
  7. const (
  8. // 回复状态
  9. ReplyStatusDitribute = 1
  10. ReplyStatusWait = 2
  11. ReplyStatusDone = 3
  12. ReplyStatusStop = 4
  13. )
  14. // CommunityQuestion 问答社区
  15. type CommunityQuestion struct {
  16. CommunityQuestionId int `orm:"column(community_question_id);pk" description:"问题ID"`
  17. UserId int `description:"提问用户ID"`
  18. UserOpenid string `description:"提问用户openid"`
  19. Mobile string `description:"用户手机号"`
  20. RealName string `description:"用户名"`
  21. QuestionContent string `description:"问题描述"`
  22. ReplierUserId int `description:"回复人的user_id"`
  23. ReplierOpenid string `description:"回复人openid"`
  24. ReplierAdminId int `description:"回复人关联的admin_id"`
  25. ReplierRealName string `description:"回复人姓名"`
  26. ReplierAvatar string `description:"回复人头像"`
  27. ResearchGroupFirstId int `description:"回复人研究方向一级分组ID"`
  28. ResearchGroupSecondId int `description:"回复人研究方向二级分组ID"`
  29. ResearchGroupFirstName string `description:"研究方向一级分组名称"`
  30. ResearchGroupSecondName string `description:"研究方向二级分组名称"`
  31. DistributeAdminId int `description:"分配人admin_id"`
  32. DistributeTime time.Time `description:"分配时间"`
  33. VarietyTagId int `description:"标签ID"`
  34. VarietyTagName string `description:"标签名称"`
  35. IsRead int `description:"用户是否已读 0-未读 1-已读"`
  36. ReplierIsRead int `description:"回复人是否已读 0-未读 1-已读"`
  37. ReplyStatus int `description:"状态 1-待分配 2-待回答 3-已回答 4-已终止"`
  38. MsgSendStatus int `description:"消息推送进度 0-待推送 1-已推送回答人 2-已推送提问人"`
  39. ReplyTime time.Time `description:"回复时间"`
  40. CreateTime time.Time `description:"提问时间"`
  41. ModifyTime time.Time `description:"修改时间"`
  42. IsDeleted int `description:"是否已删除 0-否 1-是"`
  43. DeleteTime time.Time `description:"删除时间"`
  44. StopReason string `description:"终止原因"`
  45. }
  46. type CommunityQuestionMore struct {
  47. CommunityQuestion
  48. ClickNum int `description:"点击量"`
  49. UserQaCount int `description:"用户提问数"`
  50. }
  51. func (item *CommunityQuestion) TableName() string {
  52. return "yb_community_question"
  53. }
  54. func (item *CommunityQuestion) Update(cols []string) (err error) {
  55. o := orm.NewOrm()
  56. _, err = o.Update(item, cols...)
  57. return
  58. }
  59. // GetQuestionById 主键获取提问
  60. func GetQuestionById(questionId int) (item *CommunityQuestion, err error) {
  61. o := orm.NewOrm()
  62. sql := `SELECT * FROM yb_community_question WHERE community_question_id = ? AND is_deleted = 0 LIMIT 1`
  63. err = o.Raw(sql, questionId).QueryRow(&item)
  64. return
  65. }
  66. // GetCommunityQuestionList 获取问答列表
  67. func GetCommunityQuestionList(condition string, pars []interface{}, order string, startSize, pageSize int) (total int, list []*CommunityQuestionMore, err error) {
  68. o := orm.NewOrm()
  69. sql := `SELECT
  70. q.*, l.click_num,
  71. c.user_qa_count
  72. FROM
  73. yb_community_question q
  74. LEFT JOIN (
  75. SELECT
  76. count(*) AS click_num,
  77. community_question_id
  78. FROM
  79. yb_community_audio_listen_log
  80. GROUP BY
  81. community_question_id
  82. ) AS l ON q.community_question_id = l.community_question_id
  83. LEFT JOIN (
  84. SELECT
  85. count(*) AS user_qa_count,
  86. user_id
  87. FROM
  88. yb_community_question
  89. GROUP BY
  90. user_id
  91. ) AS c ON q.user_id = c.user_id
  92. WHERE
  93. q.is_deleted = 0 `
  94. sql += condition
  95. if order != "" {
  96. sql += order
  97. } else {
  98. sql += ` ORDER BY q.create_time DESC`
  99. }
  100. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  101. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  102. return
  103. }
  104. sql += ` LIMIT ?,?`
  105. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  106. return
  107. }
  108. type CommunityQuestionCount struct {
  109. ReplyStatus int `json:"reply_status"`
  110. Total int `json:"total"`
  111. }
  112. // GetCommunityQuestionCount 根据状态获取问答数
  113. func GetCommunityQuestionCount() (list []*CommunityQuestionCount, err error) {
  114. o := orm.NewOrm()
  115. sql := `SELECT reply_status, COUNT(1) total FROM yb_community_question WHERE is_deleted = 0 GROUP BY reply_status`
  116. _, err = o.Raw(sql).QueryRows(&list)
  117. return
  118. }
  119. // DeleteQuestion (软)删除问题
  120. func DeleteQuestion(questionId int) (err error) {
  121. o := orm.NewOrm()
  122. sql := `UPDATE yb_community_question SET is_deleted = 1, delete_time = NOW() WHERE community_question_id = ? LIMIT 1`
  123. _, err = o.Raw(sql, questionId).Exec()
  124. return
  125. }
  126. // GetQuestionListByIds 根据IDs获取问答列表
  127. func GetQuestionListByIds(questionIds []int) (list []*CommunityQuestion, err error) {
  128. arrLen := len(questionIds)
  129. if arrLen == 0 {
  130. return
  131. }
  132. o := orm.NewOrm()
  133. sql := `SELECT * FROM yb_community_question WHERE community_question_id IN (` + utils.GetOrmInReplace(arrLen) + `) AND is_deleted = 0`
  134. _, err = o.Raw(sql, questionIds).QueryRows(&list)
  135. return
  136. }
  137. // GetQuestionByIds 根据IDs获取问答列表
  138. func GetQuestionByIds(questionIds []int) (list []*CommunityQuestion, err error) {
  139. arrLen := len(questionIds)
  140. if arrLen == 0 {
  141. return
  142. }
  143. o := orm.NewOrm()
  144. sql := `SELECT * FROM yb_community_question WHERE community_question_id IN (` + utils.GetOrmInReplace(arrLen) + `)`
  145. _, err = o.Raw(sql, questionIds).QueryRows(&list)
  146. return
  147. }
  148. // CommunityQuestionDetail 问答社区详情
  149. type CommunityQuestionDetail struct {
  150. CommunityQuestionId int `description:"问题ID"`
  151. Mobile string `description:"用户手机号"`
  152. RealName string `description:"用户名"`
  153. QuestionContent string `description:"问题描述"`
  154. ResearchGroupFirstName string `description:"研究方向一级分组名称"`
  155. ResearchGroupSecondName string `description:"研究方向二级分组名称"`
  156. VarietyTagName string `description:"标签名称"`
  157. ReplyStatus int `description:"状态 1-待分配 2-待回答 3-已回答 4-已终止"`
  158. MsgSendStatus int `description:"消息推送进度 0-待推送 1-已推送回答人 2-已推送提问人"`
  159. ReplyTime string `description:"回复时间"`
  160. CreateTime string `description:"提问时间"`
  161. StopReason string `description:"终止原因"`
  162. ProcessList []*CommunityQuestionProcessItem
  163. }