From 9aa836a72cb8c75e1a09aacee58491cd696450a0 Mon Sep 17 00:00:00 2001 From: hoteas <925970985@qq.com> Date: Mon, 14 Jun 2021 01:19:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E6=A0=91=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/makecode.go | 26 ++++++++++++++++++++++---- db/hotimedb.go | 3 ++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/code/makecode.go b/code/makecode.go index 3d70e69..1e42642 100644 --- a/code/makecode.go +++ b/code/makecode.go @@ -546,7 +546,7 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) ( v.GetString("link") + "_" + v.GetString("name") + "_" + v.GetString("value") + "," leftJoin["[>]"+v.GetString("link")] = - v.GetString("name") + "=" + + table + "." + v.GetString("name") + "=" + v.GetString("link") + ".id" } else { reStr += table + "." + v.GetString("name") + "," @@ -604,7 +604,7 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) ( } if searchItem.GetString("name") == "sort" { - sort["ORDER"] = reqValue + sort["ORDER"] = table + "." + reqValue } continue @@ -613,6 +613,17 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) ( data[searchItemName] = reqValue } + //树节点模式搜索 + if req.Form["parent_id"] != nil { + parentID := ObjToInt(req.FormValue("parent_id")) + if parentID == 0 { + data["OR"] = Map{table + ".parent_id[#]": 0, table + ".parent_id": nil} + } else { + data[table+".parent_id"] = parentID + } + + } + where := Map{} if len(keyword) == 1 { @@ -621,7 +632,12 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) ( } } if len(keyword) > 1 { - data["OR"] = keyword + if data["OR"] != nil { + data = Map{"AND": data, "OR": keyword} + } else { + data["OR"] = keyword + } + } if len(daterange) == 1 { @@ -631,7 +647,9 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) ( } if len(daterange) > 1 { - data["AND"] = Map{"OR": daterange} + if data["AND"] != nil { + data = Map{"AND": Map{"AND": data, "OR": daterange}} + } } if len(data) > 1 { diff --git a/db/hotimedb.go b/db/hotimedb.go index 359ee4c..0b1b8f0 100644 --- a/db/hotimedb.go +++ b/db/hotimedb.go @@ -649,7 +649,8 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) { where := "" res := make([]interface{}, 0) length := len(k) - if length > 4 { + + if length > 0 && strings.Contains(k, "[") && k[length-1] == ']' { def := false switch Substr(k, length-3, 3) {