技术性调整

This commit is contained in:
hoteas 2022-07-25 05:37:19 +08:00
parent f390617167
commit be02b3418d
5 changed files with 104 additions and 58 deletions

26
code.go
View File

@ -150,13 +150,13 @@ var TptProject = Proj{
return
}
//索引管理,便于检索以及权限
if inData.Get("parent_id") != nil && inData.GetString("index") != "" {
if inData.Get("parent_id") != nil && inData.GetString("parent_ids") != "" {
index := that.Db.Get(tableName, "`index`", Map{"id": inData.Get("parent_id")})
inData["index"] = index.GetString("index") + ObjToStr(re) + ","
that.Db.Update(tableName, Map{"index": inData["index"]}, Map{"id": re})
} else if inData.GetString("index") != "" {
inData["index"] = "," + ObjToStr(re) + ","
that.Db.Update(tableName, Map{"index": inData["index"]}, Map{"id": re})
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) + ","
that.Db.Update(tableName, Map{"parent_ids": inData["parent_ids"]}, Map{"id": re})
}
that.Log["table_id"] = re
that.Display(0, re)
@ -263,20 +263,20 @@ var TptProject = Proj{
}
//索引管理,便于检索以及权限
if inData.GetString("index") != "" {
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["index"] = parentIndex.GetString("index") + that.RouterString[2] + ","
inData["parent_ids"] = parentIndex.GetString("parent_ids") + that.RouterString[2] + ","
childNodes := that.Db.Select(tableName, "id,`index``", Map{"index[~]": "," + that.RouterString[2] + ","})
for _, v := range childNodes {
v["index"] = strings.Replace(v.GetString("index"), Index.GetString("index"), inData.GetString("index"), -1)
that.Db.Update(tableName, Map{"index": v["index"]}, Map{"id": v.GetCeilInt("id")})
v["parent_ids"] = strings.Replace(v.GetString("parent_ids"), Index.GetString("parent_ids"), inData.GetString("parent_ids"), -1)
that.Db.Update(tableName, Map{"parent_ids": v["parent_ids"]}, Map{"id": v.GetCeilInt("id")})
}
} else {
delete(inData, "index")
delete(inData, "parent_ids")
}
}
@ -301,7 +301,7 @@ var TptProject = Proj{
}
re := int64(0)
//索引管理,便于检索以及权限
if inData.Get("parent_id") != nil && inData.GetSlice("index") != nil {
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]})
@ -531,7 +531,7 @@ var TptProject = Proj{
where := Map{"name": name}
if that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")]["phone"] != nil {
where["phone"] = name
where = Map{"AND": Map{"OR": where}, "password": Md5(password)}
where = Map{"AND": Map{"OR": where, "password": Md5(password)}}
} else {
where["password"] = Md5(password)
}

View File

@ -79,6 +79,7 @@ var ColumnNameType = []ColumnShow{
{"longitude", false, true, true, false, "", false},
{"index", false, false, false, false, "index", false},
{"parent_ids", false, false, false, false, "index", false},
{"password", false, true, false, false, "password", false},
{"pwd", false, true, false, false, "password", false},

View File

@ -855,7 +855,18 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
if ruleData[v.GetString("link")] != nil {
if v.GetString("name") == "parent_id" {
data[table+".index[~]"] = "," + ruleData.GetString(v.GetString("link")) + ","
parent_idsStr := ""
parent_ids := that.TableColumns[v.GetString("link")]["parent_ids"]
if parent_ids != nil {
parent_idsStr = "parent_ids[~]"
}
index := that.TableColumns[v.GetString("link")]["index"]
if index != nil {
parent_idsStr = "index[~]"
}
data[table+"."+parent_idsStr] = "," + ruleData.GetString(v.GetString("link")) + ","
} else {
idMap := db.Select(v.GetString("link"), "id", Map{"index[~]": "," + ruleData.GetString(v.GetString("link")) + ","})
@ -900,13 +911,37 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
search := that.TableConfig.GetMap(table).GetSlice("search")
for k, _ := range search {
reqValue := req.FormValue(search.GetMap(k).GetString("name"))
if reqValue == "" {
continue
}
searchItem := search.GetMap(k)
searchItemName := searchItem.GetString("name")
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
}
continue
}
//columns := that.TableConfig.GetMap(table).GetSlice("columns")
if searchItem.GetString("type") == "search" {
@ -944,7 +979,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
}
if searchItem.GetString("name") == "sort" {
sortMap["ORDER"] = table + "." + reqValue
sortMap["ORDER"] = table + "." + reqValue[0]
}
continue
@ -960,10 +995,36 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
}
continue
}
//如果是树节点则需要判断是否符合权限
if searchItem.GetString("type") == "tree" {
data[table+"."+searchItemName] = reqValue
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"))
}
}
}
data[table+"."+searchItemName] = reqValue
}
if sortMap["ORDER"] == nil {
sortMap["ORDER"] = table + ".id DESC"
}

View File

@ -810,14 +810,15 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
if !strings.Contains(k, ".") {
k = "`" + k + "`"
}
if reflect.ValueOf(v).Type().String() == "common.Slice" {
if reflect.ValueOf(v).Type().String() == "common.Slice" || strings.Contains(reflect.ValueOf(v).Type().String(), "[]") {
vs := ObjToSlice(v)
where += k + " IN ("
res = append(res, v.(Slice)...)
res = append(res, vs...)
if len(v.(Slice)) == 0 {
where += ") "
} else {
for i := 0; i < len(v.(Slice)); i++ {
if i+1 != len(v.(Slice)) {
for i := 0; i < len(vs); i++ {
if i+1 != len(vs) {
where += "?,"
} else {
where += "?) "
@ -841,25 +842,13 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
}
if v == nil {
where += k + " IS NULL"
} else if reflect.ValueOf(v).Type().String() == "common.Slice" {
} else if reflect.ValueOf(v).Type().String() == "common.Slice" || strings.Contains(reflect.ValueOf(v).Type().String(), "[]") {
vs := ObjToSlice(v)
//fmt.Println(v)
where += k + " IN ("
res = append(res, v.(Slice)...)
for i := 0; i < len(v.(Slice)); i++ {
if i+1 != len(v.(Slice)) {
where += "?,"
} else {
where += "?) "
}
//res=append(res,(v.(Slice))[i])
}
} else if reflect.ValueOf(v).Type().String() == "[]interface {}" {
where += k + " IN ("
res = append(res, v.([]interface{})...)
for i := 0; i < len(v.([]interface{})); i++ {
if i+1 != len(v.([]interface{})) {
res = append(res, vs...)
for i := 0; i < len(vs); i++ {
if i+1 != len(vs) {
where += "?,"
} else {
where += "?) "
@ -885,22 +874,12 @@ func (that *HoTimeDB) notIn(k string, v interface{}, where string, res []interfa
where += k + " IS NOT NULL "
} else if reflect.ValueOf(v).Type().String() == "common.Slice" {
} else if reflect.ValueOf(v).Type().String() == "common.Slice" || strings.Contains(reflect.ValueOf(v).Type().String(), "[]") {
vs := ObjToSlice(v)
where += k + " NOT IN ("
res = append(res, v.(Slice)...)
for i := 0; i < len(v.(Slice)); i++ {
if i+1 != len(v.(Slice)) {
where += "?,"
} else {
where += "?) "
}
//res=append(res,(v.(Slice))[i])
}
} else if reflect.ValueOf(v).Type().String() == "[]interface {}" {
where += k + " NOT IN ("
res = append(res, v.([]interface{})...)
for i := 0; i < len(v.([]interface{})); i++ {
if i+1 != len(v.([]interface{})) {
res = append(res, vs...)
for i := 0; i < len(vs); i++ {
if i+1 != len(vs) {
where += "?,"
} else {
where += "?) "

View File

@ -1,5 +1,10 @@
{
"cache": {
"db": {
"db": false,
"session": true,
"timeout": 7200
},
"memory": {
"db": true,
"session": true,
@ -19,7 +24,7 @@
"db": {
"mysql": {
"host": "192.168.6.253",
"name": "iedc_dev",
"name": "dgs-cms",
"password": "dasda8454456",
"port": "3306",
"user": "root"