forked from golang/hotime
技术性调整
This commit is contained in:
parent
f390617167
commit
be02b3418d
26
code.go
26
code.go
@ -150,13 +150,13 @@ var TptProject = Proj{
|
|||||||
return
|
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")})
|
index := that.Db.Get(tableName, "`index`", Map{"id": inData.Get("parent_id")})
|
||||||
inData["index"] = index.GetString("index") + ObjToStr(re) + ","
|
inData["parent_ids"] = index.GetString("parent_ids") + ObjToStr(re) + ","
|
||||||
that.Db.Update(tableName, Map{"index": inData["index"]}, Map{"id": re})
|
that.Db.Update(tableName, Map{"parent_ids": inData["parent_ids"]}, Map{"id": re})
|
||||||
} else if inData.GetString("index") != "" {
|
} else if inData.GetString("parent_ids") != "" {
|
||||||
inData["index"] = "," + ObjToStr(re) + ","
|
inData["parent_ids"] = "," + ObjToStr(re) + ","
|
||||||
that.Db.Update(tableName, Map{"index": inData["index"]}, Map{"id": re})
|
that.Db.Update(tableName, Map{"parent_ids": inData["parent_ids"]}, Map{"id": re})
|
||||||
}
|
}
|
||||||
that.Log["table_id"] = re
|
that.Log["table_id"] = re
|
||||||
that.Display(0, 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 {
|
if inData.Get("parent_id") != nil {
|
||||||
Index := that.Db.Get(tableName, "`index`", Map{"id": that.RouterString[2]})
|
Index := that.Db.Get(tableName, "`index`", Map{"id": that.RouterString[2]})
|
||||||
parentIndex := that.Db.Get(tableName, "`index`", Map{"id": inData.Get("parent_id")})
|
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] + ","})
|
childNodes := that.Db.Select(tableName, "id,`index``", Map{"index[~]": "," + that.RouterString[2] + ","})
|
||||||
|
|
||||||
for _, v := range childNodes {
|
for _, v := range childNodes {
|
||||||
v["index"] = strings.Replace(v.GetString("index"), Index.GetString("index"), inData.GetString("index"), -1)
|
v["parent_ids"] = strings.Replace(v.GetString("parent_ids"), Index.GetString("parent_ids"), inData.GetString("parent_ids"), -1)
|
||||||
that.Db.Update(tableName, Map{"index": v["index"]}, Map{"id": v.GetCeilInt("id")})
|
that.Db.Update(tableName, Map{"parent_ids": v["parent_ids"]}, Map{"id": v.GetCeilInt("id")})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
delete(inData, "index")
|
delete(inData, "parent_ids")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -301,7 +301,7 @@ var TptProject = Proj{
|
|||||||
}
|
}
|
||||||
re := int64(0)
|
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] + ","})
|
re = that.Db.Delete(tableName, Map{"index[~]": "," + that.RouterString[2] + ","})
|
||||||
} else {
|
} else {
|
||||||
re = that.Db.Delete(tableName, Map{"id": that.RouterString[2]})
|
re = that.Db.Delete(tableName, Map{"id": that.RouterString[2]})
|
||||||
@ -531,7 +531,7 @@ var TptProject = Proj{
|
|||||||
where := Map{"name": name}
|
where := Map{"name": name}
|
||||||
if that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")]["phone"] != nil {
|
if that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")]["phone"] != nil {
|
||||||
where["phone"] = name
|
where["phone"] = name
|
||||||
where = Map{"AND": Map{"OR": where}, "password": Md5(password)}
|
where = Map{"AND": Map{"OR": where, "password": Md5(password)}}
|
||||||
} else {
|
} else {
|
||||||
where["password"] = Md5(password)
|
where["password"] = Md5(password)
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,7 @@ var ColumnNameType = []ColumnShow{
|
|||||||
{"longitude", false, true, true, false, "", false},
|
{"longitude", false, true, true, false, "", false},
|
||||||
|
|
||||||
{"index", false, false, false, false, "index", false},
|
{"index", false, false, false, false, "index", false},
|
||||||
|
{"parent_ids", false, false, false, false, "index", false},
|
||||||
{"password", false, true, false, false, "password", false},
|
{"password", false, true, false, false, "password", false},
|
||||||
{"pwd", false, true, false, false, "password", false},
|
{"pwd", false, true, false, false, "password", false},
|
||||||
|
|
||||||
|
@ -855,7 +855,18 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
|||||||
if ruleData[v.GetString("link")] != nil {
|
if ruleData[v.GetString("link")] != nil {
|
||||||
|
|
||||||
if v.GetString("name") == "parent_id" {
|
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 {
|
} else {
|
||||||
idMap := db.Select(v.GetString("link"), "id", Map{"index[~]": "," + ruleData.GetString(v.GetString("link")) + ","})
|
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")
|
search := that.TableConfig.GetMap(table).GetSlice("search")
|
||||||
for k, _ := range search {
|
for k, _ := range search {
|
||||||
|
|
||||||
reqValue := req.FormValue(search.GetMap(k).GetString("name"))
|
|
||||||
if reqValue == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
searchItem := search.GetMap(k)
|
searchItem := search.GetMap(k)
|
||||||
searchItemName := searchItem.GetString("name")
|
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")
|
//columns := that.TableConfig.GetMap(table).GetSlice("columns")
|
||||||
if searchItem.GetString("type") == "search" {
|
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" {
|
if searchItem.GetString("name") == "sort" {
|
||||||
sortMap["ORDER"] = table + "." + reqValue
|
sortMap["ORDER"] = table + "." + reqValue[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
@ -960,10 +995,36 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
//如果是树节点则需要判断是否符合权限
|
||||||
|
if searchItem.GetString("type") == "tree" {
|
||||||
|
|
||||||
|
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
|
data[table+"."+searchItemName] = reqValue
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if sortMap["ORDER"] == nil {
|
if sortMap["ORDER"] == nil {
|
||||||
sortMap["ORDER"] = table + ".id DESC"
|
sortMap["ORDER"] = table + ".id DESC"
|
||||||
}
|
}
|
||||||
|
@ -810,14 +810,15 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
|||||||
if !strings.Contains(k, ".") {
|
if !strings.Contains(k, ".") {
|
||||||
k = "`" + 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 ("
|
where += k + " IN ("
|
||||||
res = append(res, v.(Slice)...)
|
res = append(res, vs...)
|
||||||
if len(v.(Slice)) == 0 {
|
if len(v.(Slice)) == 0 {
|
||||||
where += ") "
|
where += ") "
|
||||||
} else {
|
} else {
|
||||||
for i := 0; i < len(v.(Slice)); i++ {
|
for i := 0; i < len(vs); i++ {
|
||||||
if i+1 != len(v.(Slice)) {
|
if i+1 != len(vs) {
|
||||||
where += "?,"
|
where += "?,"
|
||||||
} else {
|
} else {
|
||||||
where += "?) "
|
where += "?) "
|
||||||
@ -841,25 +842,13 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
|||||||
}
|
}
|
||||||
if v == nil {
|
if v == nil {
|
||||||
where += k + " IS NULL"
|
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)
|
//fmt.Println(v)
|
||||||
where += k + " IN ("
|
where += k + " IN ("
|
||||||
res = append(res, v.(Slice)...)
|
res = append(res, vs...)
|
||||||
for i := 0; i < len(v.(Slice)); i++ {
|
for i := 0; i < len(vs); i++ {
|
||||||
if i+1 != len(v.(Slice)) {
|
if i+1 != len(vs) {
|
||||||
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{})) {
|
|
||||||
where += "?,"
|
where += "?,"
|
||||||
} else {
|
} else {
|
||||||
where += "?) "
|
where += "?) "
|
||||||
@ -885,22 +874,12 @@ func (that *HoTimeDB) notIn(k string, v interface{}, where string, res []interfa
|
|||||||
|
|
||||||
where += k + " IS NOT NULL "
|
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 ("
|
where += k + " NOT IN ("
|
||||||
res = append(res, v.(Slice)...)
|
res = append(res, vs...)
|
||||||
for i := 0; i < len(v.(Slice)); i++ {
|
for i := 0; i < len(vs); i++ {
|
||||||
if i+1 != len(v.(Slice)) {
|
if i+1 != len(vs) {
|
||||||
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{})) {
|
|
||||||
where += "?,"
|
where += "?,"
|
||||||
} else {
|
} else {
|
||||||
where += "?) "
|
where += "?) "
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
{
|
{
|
||||||
"cache": {
|
"cache": {
|
||||||
|
"db": {
|
||||||
|
"db": false,
|
||||||
|
"session": true,
|
||||||
|
"timeout": 7200
|
||||||
|
},
|
||||||
"memory": {
|
"memory": {
|
||||||
"db": true,
|
"db": true,
|
||||||
"session": true,
|
"session": true,
|
||||||
@ -19,7 +24,7 @@
|
|||||||
"db": {
|
"db": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"host": "192.168.6.253",
|
"host": "192.168.6.253",
|
||||||
"name": "iedc_dev",
|
"name": "dgs-cms",
|
||||||
"password": "dasda8454456",
|
"password": "dasda8454456",
|
||||||
"port": "3306",
|
"port": "3306",
|
||||||
"user": "root"
|
"user": "root"
|
||||||
|
Loading…
Reference in New Issue
Block a user