权限管理优化

This commit is contained in:
hoteas 2022-08-01 18:48:08 +08:00
parent 6fe44cb1cb
commit 6034598bb4

View File

@ -456,7 +456,7 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
if !strings.Contains(table, ".") && !strings.Contains(table, " AS ") {
query += " FROM `" + that.Prefix + table + "` "
} else {
query += " FROM " + that.Prefix + table
query += " FROM " + that.Prefix + table + " "
}
if join {
@ -472,15 +472,15 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
v := testQuData[k]
switch Substr(k, 0, 3) {
case "[>]":
query += " LEFT JOIN `" + Substr(k, 3, len(k)-3) + "` ON " + v.(string)
query += " LEFT JOIN `" + Substr(k, 3, len(k)-3) + "` ON " + v.(string) + " "
case "[<]":
query += " RIGHT JOIN `" + Substr(k, 3, len(k)-3) + "` ON " + v.(string)
query += " RIGHT JOIN `" + Substr(k, 3, len(k)-3) + "` ON " + v.(string) + " "
}
switch Substr(k, 0, 4) {
case "[<>]":
query += " FULL JOIN `" + Substr(k, 4, len(k)-4) + "` ON " + v.(string)
query += " FULL JOIN `" + Substr(k, 4, len(k)-4) + "` ON " + v.(string) + " "
case "[><]":
query += " INNER JOIN `" + Substr(k, 4, len(k)-4) + "` ON " + v.(string)
query += " INNER JOIN `" + Substr(k, 4, len(k)-4) + "` ON " + v.(string) + " "
}
}
}
@ -631,7 +631,16 @@ func (that *HoTimeDB) where(data Map) (string, []interface{}) {
}
if len(where) != 0 {
where = " WHERE " + where
hasWhere := true
for _, v := range vcond {
if strings.Index(where, v) == 0 {
hasWhere = false
}
}
if hasWhere {
where = " WHERE " + where + " "
}
}
//特殊字符
@ -647,21 +656,21 @@ func (that *HoTimeDB) where(data Map) (string, []interface{}) {
v := data[k]
if vcond[j] == k {
if k == "ORDER" {
where += " " + k + " BY "
where += k + " BY "
//fmt.Println(reflect.ValueOf(v).Type())
//break
} else if k == "GROUP" {
where += " " + k + " BY "
where += k + " BY "
} else {
where += " " + k
where += k
}
if reflect.ValueOf(v).Type().String() == "common.Slice" {
for i := 0; i < len(v.(Slice)); i++ {
where += " " + ObjToStr(v.(Slice)[i])
where += " " + ObjToStr(v.(Slice)[i]) + " "
if len(v.(Slice)) != i+1 {
where += ", "
@ -671,7 +680,7 @@ func (that *HoTimeDB) where(data Map) (string, []interface{}) {
} else {
//fmt.Println(v)
where += " " + ObjToStr(v)
where += " " + ObjToStr(v) + " "
}
break
@ -721,7 +730,7 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
if !strings.Contains(k, ".") {
k = "`" + k + "` "
}
where += " " + k + "=" + ObjToStr(v)
where += " " + k + "=" + ObjToStr(v) + " "
case "[##]": //直接添加value到sql需要考虑防注入value比如"a>b"
where += " " + ObjToStr(v)
@ -730,13 +739,13 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
if !strings.Contains(k, ".") {
k = "`" + k + "` "
}
where += " " + k + "!=" + ObjToStr(v)
where += " " + k + "!=" + ObjToStr(v) + " "
case "[!#]":
k = strings.Replace(k, "[!#]", "", -1)
if !strings.Contains(k, ".") {
k = "`" + k + "` "
}
where += " " + k + "!=" + ObjToStr(v)
where += " " + k + "!=" + ObjToStr(v) + " "
case "[~]":
k = strings.Replace(k, "[~]", "", -1)
if !strings.Contains(k, ".") {
@ -751,7 +760,7 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
k = "`" + k + "` "
}
where += k + " LIKE ? "
v = "%" + ObjToStr(v)
v = "%" + ObjToStr(v) + " "
res = append(res, v)
case "[~!]": //右边任意
k = strings.Replace(k, "[~]", "", -1)
@ -811,11 +820,13 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
}
if reflect.ValueOf(v).Type().String() == "common.Slice" || strings.Contains(reflect.ValueOf(v).Type().String(), "[]") {
vs := ObjToSlice(v)
if len(vs) == 0 {
return where, res
}
where += k + " IN ("
res = append(res, vs...)
if len(v.(Slice)) == 0 {
where += ") "
} else {
for i := 0; i < len(vs); i++ {
if i+1 != len(vs) {
where += "?,"
@ -824,7 +835,6 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
}
//res=append(res,(v.(Slice))[i])
}
}
} else {
where += k + "=? "
@ -844,8 +854,12 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
} else if reflect.ValueOf(v).Type().String() == "common.Slice" || strings.Contains(reflect.ValueOf(v).Type().String(), "[]") {
vs := ObjToSlice(v)
//fmt.Println(v)
if len(vs) == 0 {
return where, res
}
where += k + " IN ("
res = append(res, vs...)
for i := 0; i < len(vs); i++ {
if i+1 != len(vs) {
where += "?,"
@ -854,6 +868,7 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
}
//res=append(res,(v.(Slice))[i])
}
} else {
where += k + "=? "
@ -875,8 +890,12 @@ func (that *HoTimeDB) notIn(k string, v interface{}, where string, res []interfa
} else if reflect.ValueOf(v).Type().String() == "common.Slice" || strings.Contains(reflect.ValueOf(v).Type().String(), "[]") {
vs := ObjToSlice(v)
if len(vs) == 0 {
return where, res
}
where += k + " NOT IN ("
res = append(res, vs...)
for i := 0; i < len(vs); i++ {
if i+1 != len(vs) {
where += "?,"
@ -885,6 +904,7 @@ func (that *HoTimeDB) notIn(k string, v interface{}, where string, res []interfa
}
//res=append(res,(v.(Slice))[i])
}
} else {
where += k + " !=? "
@ -931,7 +951,10 @@ func (that *HoTimeDB) cond(tag string, data Map) (string, []interface{}) {
if x == len(condition) {
tv, vv := that.varCond(k, v)
if tv == "" {
lens--
continue
}
res = append(res, vv...)
if lens--; lens <= 0 {
where += tv + ""