Parcourir la source

fix:新增评论相关接口

Roc il y a 2 ans
Parent
commit
d6eae48b25

+ 81 - 13
controllers/yb/community_question_comment.go

@@ -1,20 +1,28 @@
 package yb
 
 import (
+	"encoding/json"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"hongze/hongze_mobile_admin/controllers"
+	ybRequest "hongze/hongze_mobile_admin/models/request/yb"
 	ybResponse "hongze/hongze_mobile_admin/models/response/yb"
 	"hongze/hongze_mobile_admin/services/yb"
 	"hongze/hongze_mobile_admin/utils"
 )
 
-// QuestionCommentList
+type CommunityQuestionCommentController struct {
+	controllers.BaseAuth
+}
+
+// List
 // @Title 获取问答评论列表
 // @Description 获取问答评论列表
-// @Param   TopStatus	query	int		false	"提问状态 -1:全部 0-未精选,1-已精选"
+// @Param   CommunityQuestionCommentId	query	int		false	"评论id"
+// @Param   HotStatus	query	int		false	"精选状态 -1:全部 0-未精选,1-已精选"
 // @Param   Keyword	query	string	false	"关键字搜索"
 // @Success 200 {object} yb.CommunityQuestionCommentListResp
 // @router /community/question/comment/list [get]
-func (c *CommunityQuestionController) QuestionCommentList() {
+func (c *CommunityQuestionCommentController) List() {
 	sysUser := c.AdminWx
 
 	// 权限校验
@@ -27,16 +35,23 @@ func (c *CommunityQuestionController) QuestionCommentList() {
 	condition := ""
 	pars := make([]interface{}, 0)
 
-	//精选状态状态
-	topStatus, _ := c.GetInt("TopStatus", 0)
-	if topStatus >= 0 {
-		condition += ` AND a.is_hot = ? `
-		pars = append(pars, topStatus)
-	}
-	//关键字
-	keyword := c.GetString("Keyword", "")
-	if keyword != "" {
-		condition += ` AND a.content like  "%` + keyword + `%"`
+	//问答id
+	communityQuestionCommentId, _ := c.GetInt("CommunityQuestionCommentId", 0)
+	if communityQuestionCommentId > 0 {
+		condition += ` AND a.community_question_comment_id = ? `
+		pars = append(pars, communityQuestionCommentId)
+	} else {
+		//精选状态状态
+		hotStatus, _ := c.GetInt("HotStatus", 0)
+		if hotStatus >= 0 {
+			condition += ` AND a.is_hot = ? `
+			pars = append(pars, hotStatus)
+		}
+		//关键字
+		keyword := c.GetString("Keyword", "")
+		if keyword != "" {
+			condition += ` AND a.content like  "%` + keyword + `%"`
+		}
 	}
 
 	var startSize int
@@ -62,3 +77,56 @@ func (c *CommunityQuestionController) QuestionCommentList() {
 		List:   list,
 	}, "获取成功")
 }
+
+// Delete
+// @Title 删除评论
+// @Description 删除评论
+// @Param   QuestionId	query	int	false	"问题ID"
+// @Success 200 string "操作成功"
+// @router /community/question/comment/delete [post]
+func (c *CommunityQuestionCommentController) Delete() {
+	sysUser := c.AdminWx
+	// 权限校验
+	msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
+	if err != nil {
+		c.FailWithMessage(msg, err.Error())
+		return
+	}
+
+	var req ybRequest.QuestionCommentDeleteReq
+	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
+		c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
+		return
+	}
+	if err, errMsg := yb.SoftDeleteQuestionComment(req.CommunityQuestionCommentId); err != nil {
+		c.FailWithMessage(errMsg, "DeleteQuestion,Err:"+err.Error())
+		return
+	}
+	c.OkWithMessage("删除成功")
+}
+
+// Hot
+// @Title 设置/取消 问题评论精选
+// @Description 设置/取消 问题评论精选
+// @Success 200 string "操作成功"
+// @router /community/question/comment/hot [post]
+func (c *CommunityQuestionCommentController) Hot() {
+	sysUser := c.AdminWx
+	// 权限校验
+	msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
+	if err != nil {
+		c.FailWithMessage(msg, err.Error())
+		return
+	}
+
+	var req ybRequest.QuestionCommentHotReq
+	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
+		c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
+		return
+	}
+	if err, errMsg := yb.SetHotQuestionComment(req.CommunityQuestionCommentId); err != nil {
+		c.FailWithMessage(errMsg, "DeleteQuestion,Err:"+err.Error())
+		return
+	}
+	c.OkWithMessage("操作成功")
+}

+ 11 - 0
models/request/yb/community_question_comment.go

@@ -0,0 +1,11 @@
+package yb
+
+// QuestionCommentDeleteReq 删除问答评论请求
+type QuestionCommentDeleteReq struct {
+	CommunityQuestionCommentId int `description:"问题评论ID"`
+}
+
+// QuestionCommentHotReq 设置/取消 精选问答评论请求
+type QuestionCommentHotReq struct {
+	CommunityQuestionCommentId int `description:"问题评论ID"`
+}

+ 17 - 2
models/tables/yb_community_question_comment/yb_community_question_comment.go

@@ -25,6 +25,21 @@ type YbCommunityQuestionComment struct {
 	CreateTime                 time.Time `orm:"column(create_time)" description:"创建时间"`
 }
 
+// GetQuestionCommentById 主键获取提问评论
+func GetQuestionCommentById(questionId int) (item *YbCommunityQuestionComment, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM yb_community_question_comment WHERE community_question_comment_id = ? AND enabled = 1 LIMIT 1`
+	err = o.Raw(sql, questionId).QueryRow(&item)
+	return
+}
+
+//Update 更新评论信息
+func (item *YbCommunityQuestionComment) Update(cols []string) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(item, cols...)
+	return
+}
+
 // YbCommunityQuestionCommentAndQuestion 研报问答社区和信息
 type YbCommunityQuestionCommentAndQuestion struct {
 	CommunityQuestionCommentId uint64    `orm:"column(community_question_comment_id);pk;" description:"留言ID"`
@@ -51,14 +66,14 @@ func GetCommunityQuestionCommentList(condition string, pars []interface{}, start
 	o := orm.NewOrm()
 
 	//汇总数据
-	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 = 0 and b.is_deleted=0 `
+	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 b.is_deleted=0 `
 	totalSQl += condition
 	if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
 		return
 	}
 
 	// 列表数据
-	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 = 0 and b.is_deleted=0 `
+	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 b.is_deleted=0 `
 	sql += condition
 	sql += ` ORDER BY a.create_time DESC LIMIT ?,?`
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)

+ 20 - 2
routers/commentsRouter.go

@@ -178,9 +178,27 @@ func init() {
             Filters: nil,
             Params: nil})
 
-    beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers/yb:CommunityQuestionController"] = append(beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers/yb:CommunityQuestionController"],
+    beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers/yb:CommunityQuestionCommentController"] = append(beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers/yb:CommunityQuestionCommentController"],
+        beego.ControllerComments{
+            Method: "Delete",
+            Router: `/community/question/comment/delete`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers/yb:CommunityQuestionCommentController"] = append(beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers/yb:CommunityQuestionCommentController"],
         beego.ControllerComments{
-            Method: "QuestionCommentList",
+            Method: "Hot",
+            Router: `/community/question/comment/hot`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers/yb:CommunityQuestionCommentController"] = append(beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers/yb:CommunityQuestionCommentController"],
+        beego.ControllerComments{
+            Method: "List",
             Router: `/community/question/comment/list`,
             AllowHTTPMethods: []string{"get"},
             MethodParams: param.Make(),

+ 1 - 0
routers/router.go

@@ -85,6 +85,7 @@ func init() {
 		web.NSNamespace("/yb",
 			web.NSInclude(
 				&yb.CommunityQuestionController{},
+				&yb.CommunityQuestionCommentController{},
 			),
 		),
 		web.NSNamespace("/taglib",

+ 53 - 0
services/yb/community_question_comment.go

@@ -6,7 +6,9 @@ import (
 	ybResponse "hongze/hongze_mobile_admin/models/response/yb"
 	"hongze/hongze_mobile_admin/models/tables/wx_user"
 	"hongze/hongze_mobile_admin/models/tables/yb_community_question_comment"
+	"hongze/hongze_mobile_admin/utils"
 	"strings"
+	"time"
 )
 
 // GetCommunityQuestionCommentList 问答评论列表
@@ -74,3 +76,54 @@ func GetCommunityQuestionCommentList(condition string, pars []interface{}, start
 	}
 	return
 }
+
+// SoftDeleteQuestionComment 删除问题评论
+func SoftDeleteQuestionComment(questionCommentId int) (err error, errMsg string) {
+	errMsg = `删除成功`
+	questionCommentInfo, err := yb_community_question_comment.GetQuestionCommentById(questionCommentId)
+	if err != nil {
+		errMsg = "查找评论失败"
+		if err.Error() == utils.ErrNoRow() {
+			errMsg = "该评论不存在"
+		}
+		return
+	}
+
+	//标记删除
+	questionCommentInfo.Enabled = 0
+	questionCommentInfo.ModifyTime = time.Now()
+	err = questionCommentInfo.Update([]string{"Enabled", "ModifyTime"})
+	if err != nil {
+		errMsg = "删除提问失败"
+	}
+	return
+}
+
+// SetHotQuestionComment 设置/取消 问题评论精选
+func SetHotQuestionComment(questionCommentId int) (err error, errMsg string) {
+	errMsg = `操作失败`
+	questionCommentInfo, err := yb_community_question_comment.GetQuestionCommentById(questionCommentId)
+	if err != nil {
+		errMsg = "查找评论失败"
+		if err.Error() == utils.ErrNoRow() {
+			errMsg = "该评论不存在"
+		}
+		return
+	}
+
+	//var isHot int8
+	isHot := int8(1)
+	if questionCommentInfo.IsTop == 1 {
+		isHot = 0
+	}
+	//标记删除
+	questionCommentInfo.IsHot = isHot //是否设置精选(0-未设置,1-已设置)
+	questionCommentInfo.HotTopTime = time.Now()
+	questionCommentInfo.HotTime = time.Now()
+	questionCommentInfo.ModifyTime = time.Now()
+	err = questionCommentInfo.Update([]string{"IsHot", "HotTopTime", "HotTime", "ModifyTime"})
+	if err != nil {
+		errMsg = "操作失败"
+	}
+	return
+}