123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- package yb
- import (
- "encoding/json"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_mobile_admin/controllers"
- ybRequest "hongze/hongze_mobile_admin/models/request/yb"
- "hongze/hongze_mobile_admin/services/yb"
- "hongze/hongze_mobile_admin/utils"
- )
- type CommunityQuestionController struct {
- controllers.BaseAuth
- }
- // QuestionList
- // @Title 获取问答列表
- // @Description 获取问答列表
- // @Param CommunityQuestionId query int false "问答的id,如果传入了问答的id,那么其他条件就默认过滤掉了"
- // @Param ReplyStatus query int false "提问状态 1-待分配 2-待回答 3-已回答"
- // @Param ReplierIds query string false "回复人ID,多个用英文逗号分割"
- // @Param Keyword query string false "关键字搜索"
- // @Success 200 {object} response.CommunityQuestionListResp
- // @router /community/question/list [get]
- func (c *CommunityQuestionController) QuestionList() {
- sysUser := c.AdminWx
- // 权限校验
- msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
- if err != nil {
- c.FailWithMessage(msg, err.Error())
- return
- }
- condition := ""
- pars := make([]interface{}, 0)
- //问答id
- communityQuestionId, _ := c.GetInt("CommunityQuestionId", 0)
- //如果有传入特定的问答id,那么就不用考虑其他状态了
- if communityQuestionId > 0 {
- condition += ` AND q.community_question_id = ? `
- pars = append(pars, communityQuestionId)
- } else {
- //提问状态
- replyStatus, _ := c.GetInt("ReplyStatus", 0)
- if replyStatus > 0 {
- condition += ` AND q.reply_status = ? `
- pars = append(pars, replyStatus)
- }
- //回复人ID
- replierIds := c.GetString("ReplierIds", "")
- if replierIds != "" {
- condition += ` AND q.replier_admin_id IN (` + replierIds + `)`
- }
- //关键字
- keyword := c.GetString("Keyword", "")
- if keyword != "" {
- condition += ` AND q.question_content like "%` + keyword + `%"`
- }
- }
- var startSize int
- pageSize, _ := c.GetInt("PageSize")
- currentIndex, _ := c.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- total, resp, err := yb.GetQuestionList(condition, pars, startSize, pageSize)
- if err != nil {
- c.FailWithMessage("获取问答列表失败", "QuestionList ErrMsg:"+err.Error())
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- c.OkDetailed(resp, "获取成功")
- }
- // QuestionDistribute
- // @Title 分配回复人
- // @Description 获取问答列表
- // @Param ReplyStatus query int false "提问状态 1-待分配 2-待回答 3-已回答"
- // @Param ReplierIds query string false "回复人ID,多个用英文逗号分割"
- // @Success 200 string "操作成功"
- // @router /community/question/distribute [post]
- func (c *CommunityQuestionController) QuestionDistribute() {
- sysUser := c.AdminWx
- // 权限校验
- msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
- if err != nil {
- c.FailWithMessage(msg, err.Error())
- return
- }
- var req ybRequest.QuestionDistributeReq
- if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
- c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
- errMsg, err := yb.DistributeQuestion(req.QuestionId, req.AdminId, req.ResearchGroupFirstId, req.ResearchGroupSecondId, sysUser.AdminId)
- if err != nil {
- c.FailWithMessage(errMsg, "DistributeQuestion,Err:"+err.Error())
- return
- }
- // 模板消息提醒研究员
- go yb.SendMsgToReplier(req.QuestionId)
- c.OkWithMessage(errMsg)
- }
- // QuestionDelete
- // @Title 删除提问
- // @Description 删除提问
- // @Param QuestionId query int false "问题ID"
- // @Success 200 string "操作成功"
- // @router /community/question/delete [post]
- func (c *CommunityQuestionController) QuestionDelete() {
- sysUser := c.AdminWx
- // 权限校验
- msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
- if err != nil {
- c.FailWithMessage(msg, err.Error())
- return
- }
- var req ybRequest.QuestionDeleteReq
- if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
- c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
- if err := yb.SoftDeleteQuestion(req.QuestionId); err != nil {
- c.FailWithMessage("删除提问失败", "DeleteQuestion,Err:"+err.Error())
- return
- }
- c.OkWithMessage("删除成功")
- }
- // SendDistributeTemplateMsg
- // @Title 推送模板消息给回复人
- // @Description 推送模板消息给回复人
- // @Param QuestionId query int false "问题ID"
- // @Success 200 string "操作成功"
- // @router /community/question/send_template_msg [post]
- func (c *CommunityQuestionController) SendDistributeTemplateMsg() {
- sysUser := c.AdminWx
- // 权限校验
- msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
- if err != nil {
- c.FailWithMessage(msg, err.Error())
- return
- }
- var req ybRequest.QuestionMsgSendReq
- if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
- c.FailWithMessage("参数解析异常!", "SendDistributeTemplateMsg,参数解析失败,Err:"+err.Error())
- return
- }
- errMsg, err := yb.SendMsgToReplier(req.QuestionId)
- if err != nil {
- c.FailWithMessage(errMsg, "SendDistributeTemplateMsg,Err:"+err.Error())
- return
- }
- c.OkWithMessage("推送成功")
- }
- // QuestionEdit
- // @Title 编辑问题
- // @Description 编辑问题
- // @Param QuestionId query int true "问题ID"
- // @Param QuestionContent query string true "问题内容"
- // @Success 200 string "操作成功"
- // @router /community/question/edit [post]
- func (c *CommunityQuestionController) QuestionEdit() {
- sysUser := c.AdminWx
- // 权限校验
- msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
- if err != nil {
- c.FailWithMessage(msg, err.Error())
- return
- }
- var req ybRequest.QuestionEditReq
- if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
- c.FailWithMessage("参数解析异常!", "QuestionEdit,参数解析失败,Err:"+err.Error())
- return
- }
- if req.QuestionId <= 0 {
- c.FailWithMessage("问题ID有误", "问题ID有误")
- return
- }
- if req.QuestionContent == "" {
- c.FailWithMessage("内容不可为空", "内容不可为空")
- return
- }
- contentRune := []rune(req.QuestionContent)
- if len(contentRune) > 28 {
- c.FailWithMessage("问题字数不可超过28个字符", "问题字数不可超过28个字符")
- return
- }
- errMsg, err := yb.EditQuestion(req.QuestionId, req.QuestionContent)
- if err != nil {
- c.FailWithMessage(errMsg, "QuestionEdit ErrMsg:"+err.Error())
- return
- }
- c.OkWithMessage("修改成功")
- }
- // UserInfo
- // @Title 获取提问者基本信息
- // @Description 获取提问者基本信息
- // @Param UserId query int false "用户ID"
- // @Success 200 {object} response.CommunityQuestionListResp
- // @router /community/question/user [get]
- func (c *CommunityQuestionController) UserInfo() {
- questionId, _ := c.GetInt("QuestionId")
- if questionId <= 0 {
- c.FailWithMessage("请输入正确的提问ID", "请输入正确的提问ID")
- return
- }
- resp, err := yb.GetQuestionCompanyUser(questionId)
- if err != nil {
- c.FailWithMessage("用户不存在或者查询出错", "UserInfo ErrMsg:"+err.Error())
- return
- }
- c.OkDetailed(resp, "获取成功")
- return
- }
|