community_question.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. package yb
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_mobile_admin/controllers"
  6. ybRequest "hongze/hongze_mobile_admin/models/request/yb"
  7. "hongze/hongze_mobile_admin/services/yb"
  8. "hongze/hongze_mobile_admin/utils"
  9. )
  10. type CommunityQuestionController struct {
  11. controllers.BaseAuth
  12. }
  13. // QuestionList
  14. // @Title 获取问答列表
  15. // @Description 获取问答列表
  16. // @Param CommunityQuestionId query int false "问答的id,如果传入了问答的id,那么其他条件就默认过滤掉了"
  17. // @Param ReplyStatus query int false "提问状态 1-待分配 2-待回答 3-已回答"
  18. // @Param ReplierIds query string false "回复人ID,多个用英文逗号分割"
  19. // @Param Keyword query string false "关键字搜索"
  20. // @Success 200 {object} response.CommunityQuestionListResp
  21. // @router /community/question/list [get]
  22. func (c *CommunityQuestionController) QuestionList() {
  23. sysUser := c.AdminWx
  24. // 权限校验
  25. msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
  26. if err != nil {
  27. c.FailWithMessage(msg, err.Error())
  28. return
  29. }
  30. condition := ""
  31. pars := make([]interface{}, 0)
  32. //问答id
  33. communityQuestionId, _ := c.GetInt("CommunityQuestionId", 0)
  34. //如果有传入特定的问答id,那么就不用考虑其他状态了
  35. if communityQuestionId > 0 {
  36. condition += ` AND q.community_question_id = ? `
  37. pars = append(pars, communityQuestionId)
  38. } else {
  39. //提问状态
  40. replyStatus, _ := c.GetInt("ReplyStatus", 0)
  41. if replyStatus > 0 {
  42. condition += ` AND q.reply_status = ? `
  43. pars = append(pars, replyStatus)
  44. }
  45. //回复人ID
  46. replierIds := c.GetString("ReplierIds", "")
  47. if replierIds != "" {
  48. condition += ` AND q.replier_admin_id IN (` + replierIds + `)`
  49. }
  50. //关键字
  51. keyword := c.GetString("Keyword", "")
  52. if keyword != "" {
  53. condition += ` AND q.question_content like "%` + keyword + `%"`
  54. }
  55. }
  56. var startSize int
  57. pageSize, _ := c.GetInt("PageSize")
  58. currentIndex, _ := c.GetInt("CurrentIndex")
  59. if pageSize <= 0 {
  60. pageSize = utils.PageSize20
  61. }
  62. if currentIndex <= 0 {
  63. currentIndex = 1
  64. }
  65. startSize = paging.StartIndex(currentIndex, pageSize)
  66. total, resp, err := yb.GetQuestionList(condition, pars, startSize, pageSize)
  67. if err != nil {
  68. c.FailWithMessage("获取问答列表失败", "QuestionList ErrMsg:"+err.Error())
  69. return
  70. }
  71. page := paging.GetPaging(currentIndex, pageSize, total)
  72. resp.Paging = page
  73. c.OkDetailed(resp, "获取成功")
  74. }
  75. // QuestionDistribute
  76. // @Title 分配回复人
  77. // @Description 获取问答列表
  78. // @Param ReplyStatus query int false "提问状态 1-待分配 2-待回答 3-已回答"
  79. // @Param ReplierIds query string false "回复人ID,多个用英文逗号分割"
  80. // @Success 200 string "操作成功"
  81. // @router /community/question/distribute [post]
  82. func (c *CommunityQuestionController) QuestionDistribute() {
  83. sysUser := c.AdminWx
  84. // 权限校验
  85. msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
  86. if err != nil {
  87. c.FailWithMessage(msg, err.Error())
  88. return
  89. }
  90. var req ybRequest.QuestionDistributeReq
  91. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  92. c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  93. return
  94. }
  95. errMsg, err := yb.DistributeQuestion(req.QuestionId, req.AdminId, req.ResearchGroupFirstId, req.ResearchGroupSecondId, sysUser.AdminId)
  96. if err != nil {
  97. c.FailWithMessage(errMsg, "DistributeQuestion,Err:"+err.Error())
  98. return
  99. }
  100. // 模板消息提醒研究员
  101. go yb.SendMsgToReplier(req.QuestionId)
  102. c.OkWithMessage(errMsg)
  103. }
  104. // QuestionDelete
  105. // @Title 删除提问
  106. // @Description 删除提问
  107. // @Param QuestionId query int false "问题ID"
  108. // @Success 200 string "操作成功"
  109. // @router /community/question/delete [post]
  110. func (c *CommunityQuestionController) QuestionDelete() {
  111. sysUser := c.AdminWx
  112. // 权限校验
  113. msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
  114. if err != nil {
  115. c.FailWithMessage(msg, err.Error())
  116. return
  117. }
  118. var req ybRequest.QuestionDeleteReq
  119. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  120. c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  121. return
  122. }
  123. if err := yb.SoftDeleteQuestion(req.QuestionId); err != nil {
  124. c.FailWithMessage("删除提问失败", "DeleteQuestion,Err:"+err.Error())
  125. return
  126. }
  127. c.OkWithMessage("删除成功")
  128. }
  129. // SendDistributeTemplateMsg
  130. // @Title 推送模板消息给回复人
  131. // @Description 推送模板消息给回复人
  132. // @Param QuestionId query int false "问题ID"
  133. // @Success 200 string "操作成功"
  134. // @router /community/question/send_template_msg [post]
  135. func (c *CommunityQuestionController) SendDistributeTemplateMsg() {
  136. sysUser := c.AdminWx
  137. // 权限校验
  138. msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
  139. if err != nil {
  140. c.FailWithMessage(msg, err.Error())
  141. return
  142. }
  143. var req ybRequest.QuestionMsgSendReq
  144. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  145. c.FailWithMessage("参数解析异常!", "SendDistributeTemplateMsg,参数解析失败,Err:"+err.Error())
  146. return
  147. }
  148. errMsg, err := yb.SendMsgToReplier(req.QuestionId)
  149. if err != nil {
  150. c.FailWithMessage(errMsg, "SendDistributeTemplateMsg,Err:"+err.Error())
  151. return
  152. }
  153. c.OkWithMessage("推送成功")
  154. }
  155. // QuestionEdit
  156. // @Title 编辑问题
  157. // @Description 编辑问题
  158. // @Param QuestionId query int true "问题ID"
  159. // @Param QuestionContent query string true "问题内容"
  160. // @Success 200 string "操作成功"
  161. // @router /community/question/edit [post]
  162. func (c *CommunityQuestionController) QuestionEdit() {
  163. sysUser := c.AdminWx
  164. // 权限校验
  165. msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
  166. if err != nil {
  167. c.FailWithMessage(msg, err.Error())
  168. return
  169. }
  170. var req ybRequest.QuestionEditReq
  171. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  172. c.FailWithMessage("参数解析异常!", "QuestionEdit,参数解析失败,Err:"+err.Error())
  173. return
  174. }
  175. if req.QuestionId <= 0 {
  176. c.FailWithMessage("问题ID有误", "问题ID有误")
  177. return
  178. }
  179. if req.QuestionContent == "" {
  180. c.FailWithMessage("内容不可为空", "内容不可为空")
  181. return
  182. }
  183. contentRune := []rune(req.QuestionContent)
  184. if len(contentRune) > 28 {
  185. c.FailWithMessage("问题字数不可超过28个字符", "问题字数不可超过28个字符")
  186. return
  187. }
  188. errMsg, err := yb.EditQuestion(req.QuestionId, req.QuestionContent)
  189. if err != nil {
  190. c.FailWithMessage(errMsg, "QuestionEdit ErrMsg:"+err.Error())
  191. return
  192. }
  193. c.OkWithMessage("修改成功")
  194. }
  195. // UserInfo
  196. // @Title 获取提问者基本信息
  197. // @Description 获取提问者基本信息
  198. // @Param UserId query int false "用户ID"
  199. // @Success 200 {object} response.CommunityQuestionListResp
  200. // @router /community/question/user [get]
  201. func (c *CommunityQuestionController) UserInfo() {
  202. questionId, _ := c.GetInt("QuestionId")
  203. if questionId <= 0 {
  204. c.FailWithMessage("请输入正确的提问ID", "请输入正确的提问ID")
  205. return
  206. }
  207. resp, err := yb.GetQuestionCompanyUser(questionId)
  208. if err != nil {
  209. c.FailWithMessage("用户不存在或者查询出错", "UserInfo ErrMsg:"+err.Error())
  210. return
  211. }
  212. c.OkDetailed(resp, "获取成功")
  213. return
  214. }