树状结构优化
This commit is contained in:
parent
96d8868694
commit
72c23499f2
@ -587,9 +587,7 @@ func Init(config string) *Application {
|
||||
appIns.Router[codeMake.GetString("name")][k1] = appIns.Router[codeMake.GetString("name")]["hotimeCommon"]
|
||||
}
|
||||
|
||||
go func() {
|
||||
setMakeCodeLintener(codeMake.GetString("name"), &appIns)
|
||||
}()
|
||||
setMakeCodeListener(codeMake.GetString("name"), &appIns)
|
||||
|
||||
}
|
||||
|
||||
@ -659,7 +657,7 @@ func SetSqliteDB(appIns *Application, config Map) {
|
||||
})
|
||||
}
|
||||
|
||||
func setMakeCodeLintener(name string, appIns *Application) {
|
||||
func setMakeCodeListener(name string, appIns *Application) {
|
||||
appIns.SetConnectListener(func(context *Context) (isFinished bool) {
|
||||
|
||||
codeIns := appIns.MakeCodeRouter[name]
|
||||
|
8
code.go
8
code.go
@ -368,7 +368,7 @@ var TptProject = Proj{
|
||||
return
|
||||
}
|
||||
parent_ids := parentIndex.GetString("parent_ids") + that.RouterString[2] + ","
|
||||
childNodes := that.Db.Select(tableName, "id,`parent_ids``", Map{"parent_ids[~]": "," + that.RouterString[2] + ","})
|
||||
childNodes := that.Db.Select(tableName, "id,`parent_ids`", Map{"parent_ids[~]": "," + that.RouterString[2] + ","})
|
||||
for _, v := range childNodes {
|
||||
v["parent_ids"] = strings.Replace(v.GetString("parent_ids"), Index.GetString("parent_ids"), parent_ids, -1)
|
||||
that.Db.Update(tableName, Map{"parent_ids": v["parent_ids"]}, Map{"id": v.GetCeilInt("id")})
|
||||
@ -395,11 +395,11 @@ var TptProject = Proj{
|
||||
re := int64(0)
|
||||
//有索引则删除对应的参数
|
||||
if that.MakeCodeRouter[hotimeName].TableColumns[tableName]["parent_id"] != nil {
|
||||
that.Db.Delete(tableName, Map{"parent_ids[~]": "," + that.RouterString[2] + ","})
|
||||
re = that.Db.Delete(tableName, Map{"parent_ids[~]": "," + that.RouterString[2] + ","})
|
||||
} else {
|
||||
re = that.Db.Delete(tableName, Map{"id": that.RouterString[2]})
|
||||
}
|
||||
|
||||
re = that.Db.Delete(tableName, Map{"id": that.RouterString[2]})
|
||||
|
||||
if re == 0 {
|
||||
that.Display(4, "删除数据失败")
|
||||
return
|
||||
|
111
code/makecode.go
111
code/makecode.go
@ -939,36 +939,41 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
for k, _ := range search {
|
||||
searchItem := search.GetMap(k)
|
||||
searchItemName := searchItem.GetString("name")
|
||||
if data[table+"."+searchItemName] != nil {
|
||||
delete(data, table+"."+searchItemName)
|
||||
}
|
||||
reqValue := req.Form[searchItemName]
|
||||
parent_idsStr := ""
|
||||
parent_ids := that.TableColumns[searchItem.GetString("link")]["parent_ids"]
|
||||
if parent_ids != nil {
|
||||
parent_idsStr = "parent_ids[~]"
|
||||
}
|
||||
index := that.TableColumns[searchItem.GetString("link")]["index"]
|
||||
if index != nil {
|
||||
parent_idsStr = "index[~]"
|
||||
}
|
||||
|
||||
reqValue := req.Form[search.GetMap(k).GetString("name")]
|
||||
|
||||
//reqValue := req.FormValue(search.GetMap(k).GetString("name"))
|
||||
if len(reqValue) == 0 || reqValue[0] == "" {
|
||||
|
||||
if parent_idsStr != "" && userData[searchItem.GetString("name")] != nil {
|
||||
where := Map{parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ","}
|
||||
r := db.Select(searchItem.GetString("link"), "id", where)
|
||||
reqValue = []string{}
|
||||
for _, v := range r {
|
||||
reqValue = append(reqValue, v.GetString("id"))
|
||||
}
|
||||
|
||||
data[table+"."+searchItemName] = reqValue
|
||||
if searchItem.GetString("link") != "" {
|
||||
|
||||
parent_ids := that.TableColumns[searchItem.GetString("link")]["parent_ids"]
|
||||
if parent_ids != nil {
|
||||
parent_idsStr = "parent_ids[~]"
|
||||
}
|
||||
index := that.TableColumns[searchItem.GetString("link")]["index"]
|
||||
if index != nil {
|
||||
parent_idsStr = "index[~]"
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
//reqValue := req.FormValue(search.GetMap(k).GetString("name"))
|
||||
if len(reqValue) == 0 || reqValue[0] == "" {
|
||||
|
||||
if parent_idsStr != "" && userData[searchItem.GetString("name")] != nil {
|
||||
where := Map{parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ","}
|
||||
r := db.Select(searchItem.GetString("link"), "id", where)
|
||||
reqValue = []string{}
|
||||
for _, v := range r {
|
||||
reqValue = append(reqValue, v.GetString("id"))
|
||||
}
|
||||
|
||||
data[table+"."+searchItemName] = reqValue
|
||||
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
//columns := that.TableConfig.GetMap(table).GetSlice("columns")
|
||||
if searchItem.GetString("type") == "search" {
|
||||
for _, v := range that.TableColumns[table] {
|
||||
@ -983,7 +988,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
}
|
||||
if v.GetString("type") == "unixtime" {
|
||||
//fmt.Println(req.Form["daterange"])
|
||||
if len(req.Form["daterange"]) == 1 {
|
||||
if len(req.Form["daterange"]) == 1 && req.Form["daterange"][0] != "" {
|
||||
daterange[table+"."+v.GetString("name")+"[>]"] = req.FormValue("daterange")
|
||||
} else if len(req.Form["daterange"]) == 2 {
|
||||
|
||||
@ -993,7 +998,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
if v.GetString("type") == "time" {
|
||||
//fmt.Println(req.Form["daterange"])
|
||||
|
||||
if len(req.Form["daterange"]) == 1 {
|
||||
if len(req.Form["daterange"]) == 1 && req.Form["daterange"][0] != "" {
|
||||
t := time.Unix(ObjToCeilInt64(req.FormValue("daterange")), 0).Format("2006-01-02 15:04:05")
|
||||
|
||||
daterange[table+"."+v.GetString("name")+"[>]"] = t
|
||||
@ -1050,12 +1055,13 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
}
|
||||
}
|
||||
|
||||
if searchItem.GetString("name") == "sort" {
|
||||
if len(reqValue) != 0 && searchItem.GetString("name") == "sort" && reqValue[0] != "" {
|
||||
sortMap["ORDER"] = table + "." + reqValue[0]
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
//树节点模式搜索
|
||||
if searchItemName == "parent_id" {
|
||||
parentID := ObjToInt(req.FormValue("parent_id"))
|
||||
@ -1065,7 +1071,15 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
} else {
|
||||
|
||||
if req.FormValue("showself") != "" {
|
||||
data["OR"] = Map{table + ".parent_id": reqValue, table + ".id": reqValue}
|
||||
where := Map{}
|
||||
for _, v := range reqValue {
|
||||
if len(where) == 0 {
|
||||
where[table+"."+parent_idsStr] = "," + v + ","
|
||||
continue
|
||||
}
|
||||
where = Map{"OR": where, table + "." + parent_idsStr: "," + v + ","}
|
||||
}
|
||||
data["OR"] = Map{"OR": where, table + ".id": reqValue}
|
||||
} else {
|
||||
data[table+".parent_id"] = reqValue
|
||||
}
|
||||
@ -1079,28 +1093,43 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
if parent_idsStr != "" {
|
||||
|
||||
where := Map{}
|
||||
|
||||
for _, v := range reqValue {
|
||||
if len(reqValue) == 1 {
|
||||
if len(where) == 0 {
|
||||
where[parent_idsStr] = "," + v + ","
|
||||
continue
|
||||
where[table+"."+searchItem.GetString("name")] = reqValue[0]
|
||||
|
||||
} else {
|
||||
where = Map{"OR": where, table + "." + searchItem.GetString("name"): reqValue[0]}
|
||||
}
|
||||
|
||||
} else {
|
||||
for _, v := range reqValue {
|
||||
if len(where) == 0 {
|
||||
where[searchItem.GetString("link")+"."+parent_idsStr] = "," + v + ","
|
||||
continue
|
||||
}
|
||||
where = Map{"OR": where, searchItem.GetString("link") + "." + parent_idsStr: "," + v + ","}
|
||||
}
|
||||
where = Map{"OR": where, parent_idsStr: "," + v + ","}
|
||||
}
|
||||
//用户
|
||||
if userData[searchItem.GetString("name")] != nil {
|
||||
where = Map{"AND": Map{parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ",", "OR": where}}
|
||||
}
|
||||
r := db.Select(searchItem.GetString("link"), "id", where)
|
||||
for _, v := range r {
|
||||
reqValue = append(reqValue, v.GetString("id"))
|
||||
|
||||
where = Map{"AND": Map{searchItem.GetString("link") + "." + parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ",", "OR": where}}
|
||||
}
|
||||
data["OR"] = where
|
||||
|
||||
continue
|
||||
//r := db.Select(searchItem.GetString("link"), "id", where)
|
||||
//for _, v := range r {
|
||||
// reqValue = append(reqValue, v.GetString("id"))
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data[table+"."+searchItemName] = reqValue
|
||||
if len(reqValue) != 0 && reqValue[0] != "" {
|
||||
data[table+"."+searchItemName] = reqValue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if sortMap["ORDER"] == nil {
|
||||
|
Loading…
Reference in New Issue
Block a user