From 8b6dd5fdad775950c6c0a73c460e0e4d08c56ba7 Mon Sep 17 00:00:00 2001 From: hoteas <925970985@qq.com> Date: Sun, 13 Jun 2021 03:08:43 +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 | 77 ++++++++++++++++++++++++++++++++++++++++++++---- db/hotimedb.go | 6 ++-- 2 files changed, 75 insertions(+), 8 deletions(-) diff --git a/code/makecode.go b/code/makecode.go index a0a6340..461de86 100644 --- a/code/makecode.go +++ b/code/makecode.go @@ -135,8 +135,9 @@ func (that *MakeCode) Db2JSON(name string, path string, db db.HoTimeDB) { "columns": []Map{}, "search": []Map{ //{"type": "tree", "name": "oid", "label": "组织", "table": "organization", "showName": "label", "children": "children"}, - {"type": "text", "name": "keyword", "label": "请输入关键词", "value": nil}, - {"type": "date", "name": "date", "label": "时间段", "value": nil}, + {"type": "search", "name": "keyword", "label": "请输入关键词", "value": nil}, + {"type": "search", "name": "daterange", "label": "时间段", "value": nil}, + {"type": "search", "name": "sort", "label": "排序", "value": nil}, //{"type": "select", "name": "state", "label": "状态", "value": nil, // "options": []Map{ // {"name": "正常", "value": 0}, @@ -228,6 +229,11 @@ func (that *MakeCode) Db2JSON(name string, path string, db db.HoTimeDB) { } } + //如果是select类型需要设置options + if coloum.GetString("type") == "number" { + coloum["sortable"] = true + } + //如果是select类型需要设置options if coloum.GetString("type") == "select" { @@ -532,17 +538,78 @@ func (that *MakeCode) Search(table string, req *http.Request) (string, Map) { } data := Map{} - search := that.TableConfig.GetSlice("search") + keyword := Map{} + daterange := Map{} + sort := Map{} + + search := that.TableConfig.GetMap(table).GetSlice("search") for k, _ := range search { reqValue := req.FormValue(search.GetMap(k).GetString("name")) if reqValue == "" { continue } + searchItem := search.GetMap(k) + searchItemName := searchItem.GetString("name") - data[search.GetMap(k).GetString("name")] = reqValue + columns := that.TableConfig.GetMap(table).GetSlice("columns") + if searchItem.GetString("type") == "search" { + for columnKey, _ := range columns { + if searchItemName == "keyword" && + columns.GetMap(columnKey).GetString("type") == "text" { + keyword[columns.GetMap(columnKey).GetString("name")+"[~]"] = reqValue + } + //日期类型 + if searchItemName == "daterange" && columns.GetMap(columnKey).GetString("type") == "time" { + fmt.Println(req.Form["daterange"]) + daterange[columns.GetMap(columnKey).GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"]) + } + } + if searchItem.GetString("name") == "sort" { + sort["ORDER"] = reqValue + } + + continue + } + + data[searchItemName] = reqValue } - return reStr, data + where := Map{} + + if len(keyword) == 1 { + for k, v := range keyword { + data[k] = v + } + } + if len(keyword) > 1 { + data["OR"] = keyword + } + + if len(daterange) == 1 { + for k, v := range daterange { + data[k] = v + } + } + + if len(daterange) > 1 { + data["AND"] = Map{"OR": daterange} + } + + if len(data) > 1 { + where["AND"] = data + } + + if len(data) == 1 { + where = data + } + + if len(sort) != 0 { + for k, v := range sort { + where[k] = v + } + } + + return reStr, where } diff --git a/db/hotimedb.go b/db/hotimedb.go index e77cc96..7bed21a 100644 --- a/db/hotimedb.go +++ b/db/hotimedb.go @@ -708,7 +708,7 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) { res = append(res, v.(Slice)[0]) res = append(res, v.(Slice)[1]) default: - if reflect.ValueOf(v).Type().String() == "hotime.Slice" { + if reflect.ValueOf(v).Type().String() == "common.Slice" { where += "`" + k + "` IN (" res = append(res, v.(Slice)...) if len(v.(Slice)) == 0 { @@ -739,7 +739,7 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) { //fmt.Println(reflect.ValueOf(v).Type().String()) if v == nil { where += "`" + k + "` IS NULL" - } else if reflect.ValueOf(v).Type().String() == "hotime.Slice" { + } else if reflect.ValueOf(v).Type().String() == "common.Slice" { //fmt.Println(v) where += "`" + k + "` IN (" @@ -782,7 +782,7 @@ func (that *HoTimeDB) notIn(k string, v interface{}, where string, res []interfa where += "`" + k + "` IS NOT NULL " - } else if reflect.ValueOf(v).Type().String() == "hotime.Slice" { + } else if reflect.ValueOf(v).Type().String() == "common.Slice" { where += "`" + k + "` NOT IN (" res = append(res, v.(Slice)...) for i := 0; i < len(v.(Slice)); i++ {