加入树节点功能

This commit is contained in:
hoteas 2021-06-14 01:19:05 +08:00
parent 9ea6082d04
commit 9aa836a72c
2 changed files with 24 additions and 5 deletions

View File

@ -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") + "," v.GetString("link") + "_" + v.GetString("name") + "_" + v.GetString("value") + ","
leftJoin["[>]"+v.GetString("link")] = leftJoin["[>]"+v.GetString("link")] =
v.GetString("name") + "=" + table + "." + v.GetString("name") + "=" +
v.GetString("link") + ".id" v.GetString("link") + ".id"
} else { } else {
reStr += table + "." + v.GetString("name") + "," 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" { if searchItem.GetString("name") == "sort" {
sort["ORDER"] = reqValue sort["ORDER"] = table + "." + reqValue
} }
continue continue
@ -613,6 +613,17 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
data[searchItemName] = reqValue 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{} where := Map{}
if len(keyword) == 1 { if len(keyword) == 1 {
@ -621,9 +632,14 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
} }
} }
if len(keyword) > 1 { if len(keyword) > 1 {
if data["OR"] != nil {
data = Map{"AND": data, "OR": keyword}
} else {
data["OR"] = keyword data["OR"] = keyword
} }
}
if len(daterange) == 1 { if len(daterange) == 1 {
for k, v := range daterange { for k, v := range daterange {
data[k] = v data[k] = v
@ -631,7 +647,9 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
} }
if len(daterange) > 1 { 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 { if len(data) > 1 {

View File

@ -649,7 +649,8 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
where := "" where := ""
res := make([]interface{}, 0) res := make([]interface{}, 0)
length := len(k) length := len(k)
if length > 4 {
if length > 0 && strings.Contains(k, "[") && k[length-1] == ']' {
def := false def := false
switch Substr(k, length-3, 3) { switch Substr(k, length-3, 3) {