From 2195c7a9443b2037375ca4413d93f4c6aab62068 Mon Sep 17 00:00:00 2001 From: zhangwenjian Date: Sat, 11 Jul 2020 06:29:07 +0800 Subject: [PATCH] fix:Invalid post search criteria --- apis/system/post.go | 19 +++++++++++-------- models/post.go | 3 +++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/apis/system/post.go b/apis/system/post.go index 20350f33..204a5080 100644 --- a/apis/system/post.go +++ b/apis/system/post.go @@ -10,9 +10,10 @@ import ( // @Summary 职位列表数据 // @Description 获取JSON // @Tags 职位 -// @Param name query string false "name" -// @Param id query string false "id" -// @Param position query string false "position" +// @Param postName query string false "postName" +// @Param postCode query string false "postCode" +// @Param postId query string false "postId" +// @Param status query string false "status" // @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/post [get] // @Security @@ -30,11 +31,13 @@ func GetPostList(c *gin.Context) { pageIndex = tools.StrToInt(err, index) } - data.PostName = c.Request.FormValue("postName") id := c.Request.FormValue("postId") data.PostId, _ = tools.StringToInt(id) + data.PostCode = c.Request.FormValue("postCode") data.PostName = c.Request.FormValue("postName") + data.Status = c.Request.FormValue("status") + data.DataScope = tools.GetUserIdStr(c) result, count, err := data.GetPage(pageSize, pageIndex) tools.HasError(err, "", -1) @@ -53,7 +56,7 @@ func GetPost(c *gin.Context) { Post.PostId, _ = tools.StringToInt(c.Param("postId")) result, err := Post.Get() tools.HasError(err, "抱歉未找到相关信息", -1) - app.OK(c,result,"") + app.OK(c, result, "") } // @Summary 添加职位 @@ -73,7 +76,7 @@ func InsertPost(c *gin.Context) { tools.HasError(err, "", 500) result, err := data.Create() tools.HasError(err, "", -1) - app.OK(c,result,"") + app.OK(c, result, "") } // @Summary 修改职位 @@ -94,7 +97,7 @@ func UpdatePost(c *gin.Context) { tools.HasError(err, "", -1) result, err := data.Update(data.PostId) tools.HasError(err, "", -1) - app.OK(c,result,"修改成功") + app.OK(c, result, "修改成功") } // @Summary 删除职位 @@ -110,5 +113,5 @@ func DeletePost(c *gin.Context) { IDS := tools.IdsStrToIdsIntGroup("postId", c) result, err := data.BatchDelete(IDS) tools.HasError(err, "删除失败", 500) - app.OK(c,result,"删除成功") + app.OK(c, result, "删除成功") } diff --git a/models/post.go b/models/post.go index c6226fac..97213bc5 100644 --- a/models/post.go +++ b/models/post.go @@ -90,6 +90,9 @@ func (e *Post) GetPage(pageSize int, pageIndex int) ([]Post, int, error) { if e.PostName != "" { table = table.Where("post_name = ?", e.PostName) } + if e.PostCode != "" { + table = table.Where("post_code = ?", e.PostCode) + } if e.Status != "" { table = table.Where("status = ?", e.Status) }