修复文章管理查找的bug

master
a7458969 2020-03-01 22:33:00 +08:00
parent 181a9552b1
commit d6ec44d4ef
1 changed files with 14 additions and 3 deletions

View File

@ -27,6 +27,7 @@ func GetPageParaFromQuery(c *gin.Context) (int,int){
func GetArticles(c *gin.Context) {
type ReqArticles struct {
Name string `json:"name"`
Type int32 `json:"types"`
}
var req ReqArticles
rsp := RespBase{"ERR",-1,nil}
@ -42,13 +43,23 @@ func GetArticles(c *gin.Context) {
limit,offset := GetPageParaFromQuery(c)
var sql string
if req.Name != ""{
sql = fmt.Sprintf("select * from doc where doc.name like '%%%s%%' limit %d offset %d",req.Name,limit,offset*limit)
if req.Type == 110{
sql = fmt.Sprintf("select * from doc where doc.title like '%%%s%%' limit %d offset %d ",req.Name,limit,offset*limit)
}else{
sql = fmt.Sprintf("select * from doc where doc.title like '%%%s%%' and doc.type = %d limit %d offset %d ",req.Name,req.Type,limit,offset*limit)
}
}else{
sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title,doc.type from doc limit %d offset %d",limit,offset)
if req.Type == 110{
sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title from doc " +
"limit %d offset %d",limit,offset)
}else{
sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title,doc.type from doc where doc.type = %d " +
"limit %d offset %d",req.Type,limit,offset)
}
}
e = db.GetMysqlClient().Query2(sql,&article)
if nil != e{
logs.Error(e.Error())
logs.Error(e.Error(),sql)
return
}
for k,_ := range article{