From cdba8af129a96b317656ba36d741e9fdd8d5e365 Mon Sep 17 00:00:00 2001 From: hoteas Date: Wed, 19 Oct 2022 21:29:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E6=B5=81=E7=A8=8B=E5=BC=95?= =?UTF-8?q?=E6=93=8E=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code.go | 103 ++++++++++++++++++++++++++++++++----- code/makecode.go | 72 +++++++++++++++++++++++--- example/config/config.json | 2 +- 3 files changed, 157 insertions(+), 20 deletions(-) diff --git a/code.go b/code.go index 144d3cf..060dbfc 100644 --- a/code.go +++ b/code.go @@ -247,20 +247,28 @@ var TptProject = Proj{ } conf := ObjToMap(string(btes)) - - stop := conf.GetSlice("stop") - for k, _ := range stop { - v := stop.GetString(k) - //不能改对应行数据 - if tableName == v && data.GetCeilInt64(v+"_id") == ObjToCeilInt64(that.RouterString[2]) { - that.Display(4, "你没有权限修改当前数据") - return + //相同则 + if tableName == fileConfig.GetString("table") { + flows := conf.GetMap("flow") + for k, _ := range flows { + v := flows.GetMap(k) + if v.GetBool("stop") { + //不能改自身对应的数据 + if inData[k+"_id"] != nil { + //fmt.Println(inData[k+"_id"]) + delete(inData, k+"_id") + //fmt.Println(inData[k+"_id"]) + } + } } - //不能改自身对应的数据 - if tableName == fileConfig.GetString("table") && inData[v+"_id"] != nil { - delete(inData, v+"_id") + } else { + flow := conf.GetMap("flow").GetMap(tableName) + if flow != nil && flow.GetBool("stop") { + if data.GetCeilInt64(tableName+"_id") == ObjToCeilInt64(that.RouterString[2]) { + that.Display(4, "你没有权限修改当前数据") + return + } } - } if inData["auth"] != nil { @@ -392,7 +400,33 @@ var TptProject = Proj{ tableName := that.RouterString[1] that.Log = Map{"table": tableName, "type": 3, "table_id": that.RouterString[2]} hotimeName := that.RouterString[0] + fileConfig := that.MakeCodeRouter[hotimeName].FileConfig + //树状结构不允许修改自身的属性,修改别人的可以 + btes, err := ioutil.ReadFile(fileConfig.GetString("config")) + if err != nil { + that.Display(4, "找不到权限配置文件") + return + } + + conf := ObjToMap(string(btes)) + data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()}) + //相同则 + if tableName == fileConfig.GetString("table") { + + if data.GetCeilInt64("id") == ObjToCeilInt64(that.RouterString[2]) { + that.Display(4, "你不能删除自己") + return + } + } else { + flow := conf.GetMap("flow").GetMap(tableName) + if flow != nil && flow.GetBool("stop") { + if data.GetCeilInt64(tableName+"_id") == ObjToCeilInt64(that.RouterString[2]) { + that.Display(4, "你没有权限修改当前数据") + return + } + } + } re := int64(0) //有索引则删除对应的参数 if that.MakeCodeRouter[hotimeName].TableColumns[tableName]["parent_id"] != nil { @@ -412,8 +446,51 @@ var TptProject = Proj{ fileConfig := that.MakeCodeRouter[hotimeName].FileConfig tableName := that.RouterString[1] data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()}) + where := Map{} - columnStr, leftJoin, where := that.MakeCodeRouter[hotimeName].Search(tableName, data, that.Req, that.Db) + //树状结构不允许修改自身的属性,修改别人的可以 + btes, err := ioutil.ReadFile(fileConfig.GetString("config")) + if err != nil { + that.Display(4, "找不到权限配置文件") + return + } + + conf := ObjToMap(string(btes)) + //相同则 + //if tableName!=fileConfig.GetString("table"){ + + flow := conf.GetMap("flow").GetMap(tableName) + if flow != nil && flow.GetMap("sql") != nil { + sql := ObjToMap(DeepCopyMap(flow.GetMap("sql"))) + for k, _ := range sql { + //for uk,_:=range data{ + // if sql[uk]==nil{ + // continue + // } + // uv:=data.GetString(uk) + // + // tv:=strings.Replace(sql.GetString(uk),uk,uv,-1) + // if tv!=uv{ + // where[k]=tv + // break + // } + //} + if k == "parent_ids[~]" && tableName == fileConfig.GetString("table") { + where[tableName+"."+k] = strings.Replace(sql.GetString(k), "id", data.GetString("id"), -1) + continue + } + if k == "parent_ids[~]" && data[tableName+"_id"] != nil { + where[tableName+"."+k] = strings.Replace(sql.GetString(k), tableName+"_id", data.GetString(tableName+"_id"), -1) + continue + } + if data[sql.GetString(k)] != nil { + where[tableName+"."+k] = data[sql.GetString(k)] + } + } + } + //} + + columnStr, leftJoin, where := that.MakeCodeRouter[hotimeName].Search(tableName, data, where, that.Req, that.Db) page := ObjToInt(that.Req.FormValue("page")) pageSize := ObjToInt(that.Req.FormValue("pageSize")) diff --git a/code/makecode.go b/code/makecode.go index f13d004..07c2af8 100644 --- a/code/makecode.go +++ b/code/makecode.go @@ -508,7 +508,12 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) { } } - + flow := Map{} + //"user": {"table": "user", "stop": true, + // "SQL": { + // "role_id": "role_id", + // "admin_id": "admin_id", + // "parent_ids": "%,user_id,%"}} //搜索增加树节点 for fk, fv := range that.TableColumns { for k, v := range fv { @@ -521,12 +526,61 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) { that.SearchColumns[fk][k] = sv } - if fk == that.FileConfig.GetString("table") && v["link"] != nil && that.TableColumns[v.GetString("link")]["parent_id"] != nil { - that.Config["stop"] = append(that.Config.GetSlice("stop"), v.GetString("link")) + //if fk == that.FileConfig.GetString("table") && v["link"] != nil && that.TableColumns[v.GetString("link")]["parent_id"] != nil { + // that.Config["stop"] = append(that.Config.GetSlice("stop"), v.GetString("link")) + // //that. + //} + + for _, av := range that.TableColumns[that.FileConfig.GetString("table")] { + //同字段 + if av["link"] != nil && av.GetString("link") == v.GetString("link") { + if flow[fk] == nil { + flow[fk] = Map{"table": fk, "stop": false, "sql": Map{}} + } + sql := flow.GetMap(fk).GetMap("sql") + if k == "parent_id" { + sql["parent_ids[~]"] = "%," + av.GetString("name") + ",%" + } else { + sql[k] = k + } + + flow.GetMap(fk)["sql"] = sql + + } + //同表 + if av["link"] != nil && av.GetString("link") == fk { + if flow[fk] == nil { + flow[fk] = Map{"table": fk, "stop": false, "sql": Map{}} + } + ta := flow.GetMap(fk) + ta["stop"] = true + flow[fk] = ta + } + } + if k == that.FileConfig.GetString("table")+"_id" { + if flow[fk] == nil { + flow[fk] = Map{"table": fk, "stop": false, "sql": Map{}} + } + sql := flow.GetMap(fk).GetMap("sql") + sql[k] = "id" + flow.GetMap(fk)["sql"] = sql + } + + //当前用户 + if k == "parent_id" && that.FileConfig.GetString("table") == fk { + if flow[fk] == nil { + flow[fk] = Map{"table": fk, "stop": false, "sql": Map{}} + } + sql := flow.GetMap(fk).GetMap("sql") + sql["parent_ids[~]"] = "%,id,%" + flow.GetMap(fk)["sql"] = sql + } + } } - + //fmt.Println(flow) + that.Config["flow"] = flow //fmt.Println(id, "---", that.Config.GetString("id")) //that.Config["id"] = id @@ -786,10 +840,13 @@ func (that *MakeCode) Delete(table string, req *http.Request) Map { return data } -func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *db.HoTimeDB) (string, Map, Map) { +func (that *MakeCode) Search(table string, userData Map, data Map, req *http.Request, db *db.HoTimeDB) (string, Map, Map) { reStr := "" leftJoin := Map{} - data := Map{} + //data := Map{} + if data == nil { + data = Map{} + } keyword := Map{} daterange := Map{} sortMap := Map{} @@ -1155,6 +1212,9 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db * } where := Map{} + //if where==nil{ + // where=Map{} + //} if len(keyword) == 1 { for k, v := range keyword { diff --git a/example/config/config.json b/example/config/config.json index ee1cf4c..0299c1d 100644 --- a/example/config/config.json +++ b/example/config/config.json @@ -24,7 +24,7 @@ "db": { "mysql": { "host": "192.168.6.253", - "name": "dgs-cms", + "name": "rfcb", "password": "dasda8454456", "port": "3306", "user": "root"