接入搜索功能

This commit is contained in:
hoteas 2021-06-13 03:08:43 +08:00
parent 5c8df885a2
commit 8b6dd5fdad
2 changed files with 75 additions and 8 deletions

View File

@ -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
}

View File

@ -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++ {