forked from golang/hotime
接入搜索功能
This commit is contained in:
parent
5c8df885a2
commit
8b6dd5fdad
@ -135,8 +135,9 @@ func (that *MakeCode) Db2JSON(name string, path string, db db.HoTimeDB) {
|
|||||||
"columns": []Map{},
|
"columns": []Map{},
|
||||||
"search": []Map{
|
"search": []Map{
|
||||||
//{"type": "tree", "name": "oid", "label": "组织", "table": "organization", "showName": "label", "children": "children"},
|
//{"type": "tree", "name": "oid", "label": "组织", "table": "organization", "showName": "label", "children": "children"},
|
||||||
{"type": "text", "name": "keyword", "label": "请输入关键词", "value": nil},
|
{"type": "search", "name": "keyword", "label": "请输入关键词", "value": nil},
|
||||||
{"type": "date", "name": "date", "label": "时间段", "value": nil},
|
{"type": "search", "name": "daterange", "label": "时间段", "value": nil},
|
||||||
|
{"type": "search", "name": "sort", "label": "排序", "value": nil},
|
||||||
//{"type": "select", "name": "state", "label": "状态", "value": nil,
|
//{"type": "select", "name": "state", "label": "状态", "value": nil,
|
||||||
// "options": []Map{
|
// "options": []Map{
|
||||||
// {"name": "正常", "value": 0},
|
// {"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
|
//如果是select类型需要设置options
|
||||||
if coloum.GetString("type") == "select" {
|
if coloum.GetString("type") == "select" {
|
||||||
|
|
||||||
@ -532,17 +538,78 @@ func (that *MakeCode) Search(table string, req *http.Request) (string, Map) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := 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 {
|
for k, _ := range search {
|
||||||
|
|
||||||
reqValue := req.FormValue(search.GetMap(k).GetString("name"))
|
reqValue := req.FormValue(search.GetMap(k).GetString("name"))
|
||||||
if reqValue == "" {
|
if reqValue == "" {
|
||||||
continue
|
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
|
||||||
}
|
}
|
||||||
|
@ -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)[0])
|
||||||
res = append(res, v.(Slice)[1])
|
res = append(res, v.(Slice)[1])
|
||||||
default:
|
default:
|
||||||
if reflect.ValueOf(v).Type().String() == "hotime.Slice" {
|
if reflect.ValueOf(v).Type().String() == "common.Slice" {
|
||||||
where += "`" + k + "` IN ("
|
where += "`" + k + "` IN ("
|
||||||
res = append(res, v.(Slice)...)
|
res = append(res, v.(Slice)...)
|
||||||
if len(v.(Slice)) == 0 {
|
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())
|
//fmt.Println(reflect.ValueOf(v).Type().String())
|
||||||
if v == nil {
|
if v == nil {
|
||||||
where += "`" + k + "` IS NULL"
|
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)
|
//fmt.Println(v)
|
||||||
where += "`" + k + "` IN ("
|
where += "`" + k + "` IN ("
|
||||||
@ -782,7 +782,7 @@ func (that *HoTimeDB) notIn(k string, v interface{}, where string, res []interfa
|
|||||||
|
|
||||||
where += "`" + k + "` IS NOT NULL "
|
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 ("
|
where += "`" + k + "` NOT IN ("
|
||||||
res = append(res, v.(Slice)...)
|
res = append(res, v.(Slice)...)
|
||||||
for i := 0; i < len(v.(Slice)); i++ {
|
for i := 0; i < len(v.(Slice)); i++ {
|
||||||
|
Loading…
Reference in New Issue
Block a user