From 96d886869456ca3f344b883121fcc5f78b1edc24 Mon Sep 17 00:00:00 2001 From: hoteas Date: Thu, 25 Aug 2022 05:01:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code.go | 61 ++++++++++++++++++++++++------------------------ code/makecode.go | 32 ++++++++++++++----------- 2 files changed, 49 insertions(+), 44 deletions(-) diff --git a/code.go b/code.go index 25fce4a..6b4515d 100644 --- a/code.go +++ b/code.go @@ -96,12 +96,12 @@ var TptProject = Proj{ for _, v := range that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")] { if v.GetString("link") != "" { - + //与用户信息有关联的parent_id自填充 if v.GetString("link") == tableName && that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["parent_id"] != nil { if inData["parent_id"] == nil && data[v.GetString("name")] != nil { inData["parent_id"] = data.GetCeilInt64(v.GetString("name")) - pre := that.Db.Get(v.GetString("link"), "parent_ids", Map{"id": data.GetCeilInt64(v.GetString("name"))}) - inData["parent_ids"] = pre.GetString("parent_ids") + //pre := that.Db.Get(v.GetString("link"), "parent_ids", Map{"id": data.GetCeilInt64(v.GetString("name"))}) + //inData["parent_ids"] = pre.GetString("parent_ids")+ObjToStr(data.GetCeilInt64(v.GetString("name")))+"," } } @@ -209,14 +209,16 @@ var TptProject = Proj{ return } //索引管理,便于检索以及权限 - if inData.Get("parent_id") != nil && inData.GetString("parent_ids") != "" { + if inData.Get("parent_id") != nil { index := that.Db.Get(tableName, "`parent_ids`", Map{"id": inData.Get("parent_id")}) - inData["parent_ids"] = index.GetString("parent_ids") + ObjToStr(re) + "," - that.Db.Update(tableName, Map{"parent_ids": inData["parent_ids"]}, Map{"id": re}) - } else if inData.GetString("parent_ids") != "" { - inData["parent_ids"] = "," + ObjToStr(re) + "," + parent_ids := index.GetString("parent_ids") + if parent_ids == "" { + parent_ids = "," + } + inData["parent_ids"] = parent_ids + ObjToStr(re) + "," that.Db.Update(tableName, Map{"parent_ids": inData["parent_ids"]}, Map{"id": re}) } + that.Log["table_id"] = re that.Display(0, re) }, @@ -354,21 +356,23 @@ var TptProject = Proj{ } - //索引管理,便于检索以及权限 - if inData.GetString("parent_ids") != "" { - if inData.Get("parent_id") != nil { - Index := that.Db.Get(tableName, "`index`", Map{"id": that.RouterString[2]}) - parentIndex := that.Db.Get(tableName, "`index`", Map{"id": inData.Get("parent_id")}) - inData["parent_ids"] = parentIndex.GetString("parent_ids") + that.RouterString[2] + "," - - childNodes := that.Db.Select(tableName, "id,`index``", Map{"index[~]": "," + that.RouterString[2] + ","}) - + if inData.Get("parent_id") != nil { + //1 + //12 62 + //123 623 + Index := that.Db.Get(tableName, "parent_id,`parent_ids`", Map{"id": that.RouterString[2]}) + if inData.GetCeilInt64("parent_id") != Index.GetCeilInt64("parent_id") { + parentIndex := that.Db.Get(tableName, "`parent_ids`", Map{"id": inData.Get("parent_id")}) + if strings.Contains(parentIndex.GetString("parent_ids"), ","+that.RouterString[2]+",") { + that.Display(4, "不能将子级设置为父级") + return + } + parent_ids := parentIndex.GetString("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"), inData.GetString("parent_ids"), -1) + 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")}) } - } else { - delete(inData, "parent_ids") } } @@ -380,25 +384,22 @@ var TptProject = Proj{ return } + //索引管理,便于检索以及权限 that.Display(0, re) }, "remove": func(that *Context) { tableName := that.RouterString[1] that.Log = Map{"table": tableName, "type": 3, "table_id": that.RouterString[2]} hotimeName := that.RouterString[0] - inData := that.MakeCodeRouter[hotimeName].Delete(tableName, that.Req) - if inData == nil { - that.Display(3, "请求参数不足") - return - } + re := int64(0) - //索引管理,便于检索以及权限 - if inData.Get("parent_id") != nil && inData.GetSlice("parent_ids") != nil { - re = that.Db.Delete(tableName, Map{"index[~]": "," + that.RouterString[2] + ","}) - } else { - re = that.Db.Delete(tableName, Map{"id": that.RouterString[2]}) + //有索引则删除对应的参数 + 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{"id": that.RouterString[2]}) + if re == 0 { that.Display(4, "删除数据失败") return diff --git a/code/makecode.go b/code/makecode.go index 14d6cde..bf1d76f 100644 --- a/code/makecode.go +++ b/code/makecode.go @@ -725,9 +725,9 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map { for _, v := range that.TableColumns[table] { //不可使用,未在前端展示,但在内存中保持有 if v.GetBool("notUse") { - if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil { - data[v.GetString("name")] = "," - } + //if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil { + // data[v.GetString("name")] = "," + //} continue } @@ -764,16 +764,16 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map { } func (that *MakeCode) Delete(table string, req *http.Request) Map { data := Map{} - for _, v := range that.TableColumns[table] { - //不可使用,未在前端展示,但在内存中保持有 - if v.GetBool("notUse") { - if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil { - data[v.GetString("name")] = "," - } - continue - } - - } + //for _, v := range that.TableColumns[table] { + // //不可使用,未在前端展示,但在内存中保持有 + // if v.GetBool("notUse") { + // //if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil { + // // data[v.GetString("name")] = "," + // //} + // continue + // } + // + //} return data } @@ -1064,7 +1064,11 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db * data["OR"] = Map{table + ".id": parentID, table + ".parent_id": nil} } else { - data["OR"] = Map{table + ".parent_id": reqValue, table + ".id": reqValue} + if req.FormValue("showself") != "" { + data["OR"] = Map{table + ".parent_id": reqValue, table + ".id": reqValue} + } else { + data[table+".parent_id"] = reqValue + } } continue