From 9ea6082d043e7280fdeb4b0cb89d3ccd83cb0f1b Mon Sep 17 00:00:00 2001 From: hoteas <925970985@qq.com> Date: Sun, 13 Jun 2021 10:40:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=85=A5=E6=90=9C=E7=B4=A2=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/makecode.go | 105 +++++++++++++++++++++++++---------------------- code/template.go | 10 +++-- 2 files changed, 62 insertions(+), 53 deletions(-) diff --git a/code/makecode.go b/code/makecode.go index f84f66d..3d70e69 100644 --- a/code/makecode.go +++ b/code/makecode.go @@ -524,24 +524,62 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map { func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (string, Map, Map) { reStr := "" - for _, v := range that.TableColumns[table] { - //不可使用,未在前端展示,但在内存中保持有 - if v.GetBool("notUse") { - continue - } - if v.Get("list") == nil || v.GetBool("list") { - reStr += table + "." + v.GetString("name") + "," - } - } - if len(reStr) != 0 { - reStr = reStr[:len(reStr)-1] - } leftJoin := Map{} data := Map{} keyword := Map{} daterange := Map{} sort := Map{} + keywordStr := req.FormValue("keyword") + for _, v := range that.TableColumns[table] { + //不可使用,未在前端展示,但在内存中保持有 + if v.GetBool("notUse") { + continue + } + if v["list"] != false { + + if v.GetString("link") != "" && + v.GetString("name") != "parent_id" { + + reStr += v.GetString("link") + "." + + v.GetString("value") + " AS " + + v.GetString("link") + "_" + v.GetString("name") + "_" + v.GetString("value") + "," + + leftJoin["[>]"+v.GetString("link")] = + v.GetString("name") + "=" + + v.GetString("link") + ".id" + } else { + reStr += table + "." + v.GetString("name") + "," + } + + if keywordStr != "" { + if v.GetString("type") == "text" { + keyword[table+"."+v.GetString("name")+"[~]"] = keywordStr + + } + if v.GetString("name") == "id" { + keyword[table+"."+v.GetString("name")] = keywordStr + } + if v.GetString("link") != "" && + v.GetString("name") != "parent_id" { + childs := db.Select(v.GetString("link"), "id", Map{v.GetString("value") + "[~]": keywordStr}) + childIds := Slice{} + for _, cv := range childs { + childIds = append(childIds, cv.GetString("id")) + } + if len(childIds) != 0 { + keyword[v.GetString("link")+".id"] = childIds + } + + } + } + + } + } + if len(reStr) != 0 { + reStr = reStr[:len(reStr)-1] + } + search := that.TableConfig.GetMap(table).GetSlice("search") for k, _ := range search { @@ -552,49 +590,16 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) ( searchItem := search.GetMap(k) searchItemName := searchItem.GetString("name") - columns := that.TableConfig.GetMap(table).GetSlice("columns") + //columns := that.TableConfig.GetMap(table).GetSlice("columns") if searchItem.GetString("type") == "search" { - for columnKey, _ := range columns { - if columns.GetMap(columnKey)["list"] == false { + for _, v := range that.TableColumns[table] { + if v["list"] == false { continue } - if searchItemName == "keyword" && - columns.GetMap(columnKey).GetString("type") == "text" { - keyword[table+"."+columns.GetMap(columnKey).GetString("name")+"[~]"] = reqValue - - } - if searchItemName == "keyword" && - columns.GetMap(columnKey).GetString("name") == "id" { - keyword[table+"."+columns.GetMap(columnKey).GetString("name")] = reqValue - - } - - if searchItemName == "keyword" && - columns.GetMap(columnKey).GetString("link") != "" && - columns.GetMap(columnKey).GetString("name") != "parent_id" { - for columnChildKey, _ := range columns { - if columns.GetMap(columnChildKey).GetString("link") != "" && - columns.GetMap(columnChildKey).GetString("name") != "parent_id" { - childs := db.Select(columns.GetMap(columnChildKey).GetString("link"), "id", Map{columns.GetMap(columnChildKey).GetString("value") + "[~]": reqValue}) - childIds := Slice{} - for _, v := range childs { - childIds = append(childIds, v.GetString("id")) - } - if len(childIds) != 0 { - keyword[columns.GetMap(columnChildKey).GetString("link")+".id"] = childIds - leftJoin["[>]"+columns.GetMap(columnChildKey).GetString("link")] = - columns.GetMap(columnChildKey).GetString("name") + "=" + - columns.GetMap(columnChildKey).GetString("link") + ".id" - } - - } - } - - } //日期类型 - if searchItemName == "daterange" && columns.GetMap(columnKey).GetString("type") == "time" { + if searchItemName == "daterange" && v.GetString("type") == "time" { fmt.Println(req.Form["daterange"]) - daterange[table+"."+columns.GetMap(columnKey).GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"]) + daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"]) } } diff --git a/code/template.go b/code/template.go index 3d98f8a..584e79f 100644 --- a/code/template.go +++ b/code/template.go @@ -85,7 +85,7 @@ var {{table}}Ctr = Ctr{ "search": func(that *Context) { - columnStr,leftJoin,where := that.MakeCode.Search(that.RouterString[1], that.Req,that.Db) + columnStr,leftJoin,where := that.MakeCode.Search(that.RouterString[1], that.Req,that.Db) page:=ObjToInt(that.Req.FormValue("page")) pageSize:=ObjToInt(that.Req.FormValue("pageSize")) @@ -109,8 +109,12 @@ var {{table}}Ctr = Ctr{ continue } - if (column["list"]==nil||column.GetBool("list"))&&column.GetString("link")!=""{ - v[column.GetString("link")] = that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)}) + if column["list"]!=false&&column["name"]=="parent_id"&&column.GetString("link")!=""{ + parentC := that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)}) + v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")]="" + if parentC!=nil{ + v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")]=parentC.GetString(column.GetString("value")) + } }