数据库错误操作优化
This commit is contained in:
parent
f7dfd4ec77
commit
615f52d2e4
83
code.go
83
code.go
@ -128,15 +128,18 @@ var TptProject = Proj{
|
||||
name = v1.GetString("table")
|
||||
}
|
||||
if v1["auth"] != nil {
|
||||
linkAuth[name] = v1["auth"]
|
||||
|
||||
}
|
||||
if v1["auth"] == nil {
|
||||
table := that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)
|
||||
if table != nil {
|
||||
linkAuth[name] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)["auth"]
|
||||
if linkAuth[name] == nil {
|
||||
linkAuth[name] = v1["auth"]
|
||||
} else {
|
||||
linkAuth[name] = Slice{"show"}
|
||||
newAuth := Slice{}
|
||||
for k2, _ := range linkAuth.GetSlice(name) {
|
||||
v2 := linkAuth.GetSlice(name).GetString(k2)
|
||||
if strings.Contains(v1.GetString("auth"), v2) {
|
||||
newAuth = append(newAuth, v2)
|
||||
}
|
||||
}
|
||||
linkAuth[name] = newAuth
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,15 +151,22 @@ var TptProject = Proj{
|
||||
name = v2.GetString("table")
|
||||
}
|
||||
if v2["auth"] != nil {
|
||||
|
||||
if linkAuth[name] == nil {
|
||||
linkAuth[name] = v2["auth"]
|
||||
continue
|
||||
}
|
||||
if v2["auth"] == nil {
|
||||
table := that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)
|
||||
if table != nil {
|
||||
linkAuth[name] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)["auth"]
|
||||
|
||||
} else {
|
||||
linkAuth[name] = Slice{"show"}
|
||||
|
||||
newAuth := Slice{}
|
||||
for k3, _ := range linkAuth.GetSlice(name) {
|
||||
v3 := linkAuth.GetSlice(name).GetString(k3)
|
||||
if strings.Contains(v2.GetString("auth"), v3) {
|
||||
newAuth = append(newAuth, v3)
|
||||
}
|
||||
}
|
||||
linkAuth[name] = newAuth
|
||||
continue
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -257,10 +267,12 @@ var TptProject = Proj{
|
||||
if v.GetString("link") != "" && that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"] != nil {
|
||||
linkAuthMap := that.Db.Get(v.GetString("link"), "auth", Map{"id": data.GetCeilInt(v.GetString("name"))})
|
||||
linkAuth := linkAuthMap.GetMap("auth")
|
||||
|
||||
//conf := ObjToMap(string(btes))
|
||||
//menus := conf.GetSlice("menus")
|
||||
if linkAuth == nil {
|
||||
|
||||
linkAuth = Map{}
|
||||
}
|
||||
|
||||
for k1, _ := range menus {
|
||||
v1 := menus.GetMap(k1)
|
||||
name := v1.GetString("name")
|
||||
@ -268,18 +280,21 @@ var TptProject = Proj{
|
||||
name = v1.GetString("table")
|
||||
}
|
||||
if v1["auth"] != nil {
|
||||
linkAuth[name] = v1["auth"]
|
||||
continue
|
||||
}
|
||||
if v1["auth"] == nil {
|
||||
|
||||
table := that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)
|
||||
if table != nil {
|
||||
linkAuth[name] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)["auth"]
|
||||
if linkAuth[name] == nil {
|
||||
linkAuth[name] = v1["auth"]
|
||||
} else {
|
||||
linkAuth[name] = Slice{"show"}
|
||||
newAuth := Slice{}
|
||||
for k2, _ := range linkAuth.GetSlice(name) {
|
||||
v2 := linkAuth.GetSlice(name).GetString(k2)
|
||||
if strings.Contains(v1.GetString("auth"), v2) {
|
||||
newAuth = append(newAuth, v2)
|
||||
}
|
||||
}
|
||||
linkAuth[name] = newAuth
|
||||
}
|
||||
}
|
||||
|
||||
menusChild := v1.GetSlice("menus")
|
||||
for k2, _ := range menusChild {
|
||||
v2 := menusChild.GetMap(k2)
|
||||
@ -288,17 +303,23 @@ var TptProject = Proj{
|
||||
name = v2.GetString("table")
|
||||
}
|
||||
if v2["auth"] != nil {
|
||||
|
||||
if linkAuth[name] == nil {
|
||||
linkAuth[name] = v2["auth"]
|
||||
continue
|
||||
}
|
||||
if v2["auth"] == nil {
|
||||
table := that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)
|
||||
if table != nil {
|
||||
linkAuth[name] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)["auth"]
|
||||
|
||||
} else {
|
||||
linkAuth[name] = Slice{"show"}
|
||||
|
||||
newAuth := Slice{}
|
||||
for k3, _ := range linkAuth.GetSlice(name) {
|
||||
v3 := linkAuth.GetSlice(name).GetString(k3)
|
||||
if strings.Contains(v2.GetString("auth"), v3) {
|
||||
newAuth = append(newAuth, v3)
|
||||
}
|
||||
}
|
||||
linkAuth[name] = newAuth
|
||||
continue
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
132
code/makecode.go
132
code/makecode.go
@ -732,8 +732,11 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
|
||||
}
|
||||
|
||||
if v.Get("edit") == nil || v.GetBool("edit") {
|
||||
if len(req.Form[v.GetString("name")]) == 0 {
|
||||
continue
|
||||
}
|
||||
reqValue := req.FormValue(v.GetString("name"))
|
||||
if reqValue == "" || reqValue == "null" {
|
||||
if reqValue == "null" {
|
||||
continue
|
||||
}
|
||||
if v.GetString("type") == "password" {
|
||||
@ -795,7 +798,6 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
testQu = append(testQu, key)
|
||||
}
|
||||
sort.Strings(testQu)
|
||||
|
||||
for _, k := range testQu {
|
||||
v := testQuData[k]
|
||||
//不可使用,未在前端展示,但在内存中保持有
|
||||
@ -890,7 +892,9 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
|
||||
}
|
||||
|
||||
if v.GetString("type") == "text" {
|
||||
}
|
||||
|
||||
if strings.Contains(v.GetString("type"), "text") {
|
||||
reqValue := req.FormValue(v.GetString("name"))
|
||||
if reqValue != "" {
|
||||
data[table+"."+v.GetString("name")+"[~]"] = reqValue
|
||||
@ -900,21 +904,18 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
|
||||
if v.GetString("type") == "unixtime" {
|
||||
|
||||
if daterangeTableStr == "" || v.GetString("name") == daterangeTableStr {
|
||||
|
||||
if len(req.Form[v.GetString("name")]) == 1 {
|
||||
daterange[table+"."+v.GetString("name")+"[>]"] = req.FormValue("daterange")
|
||||
} else if len(req.Form[v.GetString("name")]) == 2 {
|
||||
daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"])
|
||||
}
|
||||
}
|
||||
|
||||
//fmt.Println(req.Form["daterange"])
|
||||
|
||||
}
|
||||
|
||||
if v.GetString("type") == "time" {
|
||||
//fmt.Println(req.Form["daterange"])
|
||||
if daterangeTableStr == "" || v.GetString("name") == daterangeTableStr {
|
||||
|
||||
if len(req.Form[v.GetString("name")]) == 1 {
|
||||
t := time.Unix(ObjToCeilInt64(req.FormValue(v.GetString("name"))), 0).Format("2006-01-02 15:04:05")
|
||||
@ -928,50 +929,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if keywordStr != "" {
|
||||
if keywordTableStr == v.GetString("name") {
|
||||
keyword[table+"."+keywordTableStr+"[~]"] = keywordStr
|
||||
}
|
||||
|
||||
if keywordTableStr == v.GetString("value") {
|
||||
childs := db.Select(v.GetString("link"), "id", Map{v.GetString("value") + "[~]": keywordStr})
|
||||
childIds := Slice{}
|
||||
for _, cv := range childs {
|
||||
childIds = append(childIds, cv.GetString("id"))
|
||||
}
|
||||
if len(childIds) != 0 {
|
||||
keyword[v.GetString("link")+".id"] = childIds
|
||||
}
|
||||
}
|
||||
|
||||
if keywordTableStr != "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if v.GetString("type") == "text" {
|
||||
keyword[table+"."+v.GetString("name")+"[~]"] = keywordStr
|
||||
|
||||
}
|
||||
if v.GetString("name") == "id" {
|
||||
keyword[table+"."+v.GetString("name")] = keywordStr
|
||||
}
|
||||
if v.GetString("link") != "" &&
|
||||
v.GetString("name") != "parent_id" {
|
||||
childs := db.Select(v.GetString("link"), "id", Map{v.GetString("value") + "[~]": keywordStr})
|
||||
childIds := Slice{}
|
||||
for _, cv := range childs {
|
||||
childIds = append(childIds, cv.GetString("id"))
|
||||
}
|
||||
if len(childIds) != 0 {
|
||||
keyword[v.GetString("link")+".id"] = childIds
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if len(reStr) != 0 {
|
||||
reStr = reStr[:len(reStr)-1]
|
||||
@ -1014,11 +972,15 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
//columns := that.TableConfig.GetMap(table).GetSlice("columns")
|
||||
if searchItem.GetString("type") == "search" {
|
||||
for _, v := range that.TableColumns[table] {
|
||||
if v["list"] == false {
|
||||
continue
|
||||
}
|
||||
//if v["list"] == false {
|
||||
// continue
|
||||
//}
|
||||
//日期类型
|
||||
if searchItemName == "daterange" {
|
||||
|
||||
if daterangeTableStr != "" && daterangeTableStr != v.GetString("name") {
|
||||
continue
|
||||
}
|
||||
if v.GetString("type") == "unixtime" {
|
||||
//fmt.Println(req.Form["daterange"])
|
||||
if len(req.Form["daterange"]) == 1 {
|
||||
@ -1044,6 +1006,48 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if searchItemName == "keyword" && keywordStr != "" {
|
||||
|
||||
if keywordTableStr != "" {
|
||||
if keywordTableStr == v.GetString("name") {
|
||||
keyword[table+"."+keywordTableStr+"[~]"] = keywordStr
|
||||
}
|
||||
|
||||
if keywordTableStr == v.GetString("value") {
|
||||
childs := db.Select(v.GetString("link"), "id", Map{v.GetString("value") + "[~]": keywordStr})
|
||||
childIds := Slice{}
|
||||
for _, cv := range childs {
|
||||
childIds = append(childIds, cv.GetString("id"))
|
||||
}
|
||||
if len(childIds) != 0 {
|
||||
keyword[v.GetString("link")+".id"] = childIds
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.Contains(v.GetString("type"), "text") {
|
||||
keyword[table+"."+v.GetString("name")+"[~]"] = keywordStr
|
||||
|
||||
}
|
||||
if v.GetString("name") == "id" {
|
||||
keyword[table+"."+v.GetString("name")] = keywordStr
|
||||
}
|
||||
if v.GetString("link") != "" &&
|
||||
v.GetString("name") != "parent_id" {
|
||||
childs := db.Select(v.GetString("link"), "id", Map{v.GetString("value") + "[~]": keywordStr})
|
||||
childIds := Slice{}
|
||||
for _, cv := range childs {
|
||||
childIds = append(childIds, cv.GetString("id"))
|
||||
}
|
||||
if len(childIds) != 0 {
|
||||
keyword[v.GetString("link")+".id"] = childIds
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if searchItem.GetString("name") == "sort" {
|
||||
@ -1054,28 +1058,6 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
}
|
||||
//树节点模式搜索
|
||||
if searchItemName == "parent_id" {
|
||||
//if parent_idsStr != "" {
|
||||
//
|
||||
// where := Map{}
|
||||
//
|
||||
// for _, v := range reqValue {
|
||||
// if len(where) == 0 {
|
||||
// where[parent_idsStr] = "," + v + ","
|
||||
// continue
|
||||
// }
|
||||
// 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"))
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
parentID := ObjToInt(req.FormValue("parent_id"))
|
||||
if parentID == 0 {
|
||||
parentID = userData.GetCeilInt(table + "_id")
|
||||
|
Loading…
Reference in New Issue
Block a user