数据库错误操作优化
This commit is contained in:
parent
1533a57cb8
commit
96d8868694
59
code.go
59
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] + ","})
|
||||
|
||||
//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
|
||||
|
@ -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 {
|
||||
|
||||
if req.FormValue("showself") != "" {
|
||||
data["OR"] = Map{table + ".parent_id": reqValue, table + ".id": reqValue}
|
||||
} else {
|
||||
data[table+".parent_id"] = reqValue
|
||||
}
|
||||
|
||||
}
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user