Compare commits

...

9 Commits

Author SHA1 Message Date
hoteas 127e027940 修复重复执行context.View()的bug 2022-08-25 14:06:31 +08:00
hoteas 2ee0838d8a 树状结构优化 2022-08-25 13:06:26 +08:00
hoteas 72c23499f2 树状结构优化 2022-08-25 13:02:44 +08:00
hoteas 96d8868694 数据库错误操作优化 2022-08-25 05:01:50 +08:00
hoteas 1533a57cb8 数据库错误操作优化 2022-08-25 03:48:09 +08:00
hoteas 615f52d2e4 数据库错误操作优化 2022-08-25 03:44:58 +08:00
hoteas f7dfd4ec77 增加记录IP 2022-08-21 03:49:56 +08:00
hoteas 2276aa12ef Merge remote-tracking branch 'origin/master' 2022-08-20 22:38:40 +08:00
hoteas 6505594fd0 增加记录IP 2022-08-20 22:38:15 +08:00
9 changed files with 299 additions and 713 deletions
+10 -10
View File
@@ -374,15 +374,17 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
}() }()
//访问拦截true继续false暂停 //访问拦截true继续false暂停
connectListenerLen := len(that.connectListener) connectListenerLen := len(that.connectListener) - 1
for i := connectListenerLen - 1; i >= 0; i-- {
if that.connectListener[i](&context) {
for true {
if connectListenerLen < 0 {
break
}
if that.connectListener[connectListenerLen](&context) {
context.View() context.View()
return return
} }
connectListenerLen--
} }
//接口服务 //接口服务
@@ -587,9 +589,7 @@ func Init(config string) *Application {
appIns.Router[codeMake.GetString("name")][k1] = appIns.Router[codeMake.GetString("name")]["hotimeCommon"] appIns.Router[codeMake.GetString("name")][k1] = appIns.Router[codeMake.GetString("name")]["hotimeCommon"]
} }
go func() { setMakeCodeListener(codeMake.GetString("name"), &appIns)
setMakeCodeLintener(codeMake.GetString("name"), &appIns)
}()
} }
@@ -659,7 +659,7 @@ func SetSqliteDB(appIns *Application, config Map) {
}) })
} }
func setMakeCodeLintener(name string, appIns *Application) { func setMakeCodeListener(name string, appIns *Application) {
appIns.SetConnectListener(func(context *Context) (isFinished bool) { appIns.SetConnectListener(func(context *Context) (isFinished bool) {
codeIns := appIns.MakeCodeRouter[name] codeIns := appIns.MakeCodeRouter[name]
@@ -753,7 +753,7 @@ func setMakeCodeLintener(name string, appIns *Application) {
context.Router[context.RouterString[0]][context.RouterString[1]]["remove"](context) context.Router[context.RouterString[0]][context.RouterString[1]]["remove"](context)
} }
context.View() //context.View()
return true return true
}) })
} }
+102 -80
View File
@@ -96,12 +96,12 @@ var TptProject = Proj{
for _, v := range that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")] { for _, v := range that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")] {
if v.GetString("link") != "" { if v.GetString("link") != "" {
//与用户信息有关联的parent_id自填充
if v.GetString("link") == tableName && that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["parent_id"] != nil { 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 { if inData["parent_id"] == nil && data[v.GetString("name")] != nil {
inData["parent_id"] = data.GetCeilInt64(v.GetString("name")) inData["parent_id"] = data.GetCeilInt64(v.GetString("name"))
pre := that.Db.Get(v.GetString("link"), "parent_ids", Map{"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") //inData["parent_ids"] = pre.GetString("parent_ids")+ObjToStr(data.GetCeilInt64(v.GetString("name")))+","
} }
} }
@@ -128,15 +128,18 @@ var TptProject = Proj{
name = v1.GetString("table") name = v1.GetString("table")
} }
if v1["auth"] != nil { if v1["auth"] != nil {
linkAuth[name] = v1["auth"]
} if linkAuth[name] == nil {
if v1["auth"] == nil { linkAuth[name] = v1["auth"]
table := that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)
if table != nil {
linkAuth[name] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)["auth"]
} else { } 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") name = v2.GetString("table")
} }
if v2["auth"] != nil { if v2["auth"] != nil {
linkAuth[name] = v2["auth"]
continue if linkAuth[name] == nil {
} linkAuth[name] = v2["auth"]
if v2["auth"] == nil {
table := that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)
if table != nil {
linkAuth[name] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)["auth"]
} else { } 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
} }
} }
} }
@@ -199,14 +209,16 @@ var TptProject = Proj{
return 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")}) index := that.Db.Get(tableName, "`parent_ids`", Map{"id": inData.Get("parent_id")})
inData["parent_ids"] = index.GetString("parent_ids") + ObjToStr(re) + "," parent_ids := index.GetString("parent_ids")
that.Db.Update(tableName, Map{"parent_ids": inData["parent_ids"]}, Map{"id": re}) if parent_ids == "" {
} else if inData.GetString("parent_ids") != "" { parent_ids = ","
inData["parent_ids"] = "," + ObjToStr(re) + "," }
inData["parent_ids"] = parent_ids + ObjToStr(re) + ","
that.Db.Update(tableName, Map{"parent_ids": inData["parent_ids"]}, 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)
}, },
@@ -257,48 +269,59 @@ var TptProject = Proj{
if v.GetString("link") != "" && that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"] != nil { 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"))}) linkAuthMap := that.Db.Get(v.GetString("link"), "auth", Map{"id": data.GetCeilInt(v.GetString("name"))})
linkAuth := linkAuthMap.GetMap("auth") linkAuth := linkAuthMap.GetMap("auth")
//conf := ObjToMap(string(btes))
//menus := conf.GetSlice("menus")
if linkAuth == nil { if linkAuth == nil {
linkAuth = Map{} linkAuth = Map{}
for k1, _ := range menus { }
v1 := menus.GetMap(k1)
name := v1.GetString("name")
if name == "" {
name = v1.GetString("table")
}
if v1["auth"] != nil {
linkAuth[name] = v1["auth"]
continue
}
if v1["auth"] == nil {
table := that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name) for k1, _ := range menus {
if table != nil { v1 := menus.GetMap(k1)
linkAuth[name] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)["auth"] name := v1.GetString("name")
} else { if name == "" {
linkAuth[name] = Slice{"show"} name = v1.GetString("table")
} }
} if v1["auth"] != nil {
menusChild := v1.GetSlice("menus")
for k2, _ := range menusChild { if linkAuth[name] == nil {
v2 := menusChild.GetMap(k2) linkAuth[name] = v1["auth"]
name := v2.GetString("name") } else {
if name == "" { newAuth := Slice{}
name = v2.GetString("table") for k2, _ := range linkAuth.GetSlice(name) {
} v2 := linkAuth.GetSlice(name).GetString(k2)
if v2["auth"] != nil { if strings.Contains(v1.GetString("auth"), v2) {
linkAuth[name] = v2["auth"] newAuth = append(newAuth, v2)
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"}
} }
} }
linkAuth[name] = newAuth
}
}
menusChild := v1.GetSlice("menus")
for k2, _ := range menusChild {
v2 := menusChild.GetMap(k2)
name := v2.GetString("name")
if name == "" {
name = v2.GetString("table")
}
if v2["auth"] != nil {
if linkAuth[name] == nil {
linkAuth[name] = v2["auth"]
} else {
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
}
} }
} }
} }
@@ -333,21 +356,23 @@ var TptProject = Proj{
} }
//索引管理,便于检索以及权限 if inData.Get("parent_id") != nil {
if inData.GetString("parent_ids") != "" { //1
if inData.Get("parent_id") != nil { //12 62
Index := that.Db.Get(tableName, "`index`", Map{"id": that.RouterString[2]}) //123 623
parentIndex := that.Db.Get(tableName, "`index`", Map{"id": inData.Get("parent_id")}) Index := that.Db.Get(tableName, "parent_id,`parent_ids`", Map{"id": that.RouterString[2]})
inData["parent_ids"] = parentIndex.GetString("parent_ids") + 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")})
childNodes := that.Db.Select(tableName, "id,`index``", Map{"index[~]": "," + that.RouterString[2] + ","}) 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 { 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")}) that.Db.Update(tableName, Map{"parent_ids": v["parent_ids"]}, Map{"id": v.GetCeilInt("id")})
} }
} else {
delete(inData, "parent_ids")
} }
} }
@@ -359,21 +384,18 @@ var TptProject = Proj{
return return
} }
//索引管理,便于检索以及权限
that.Display(0, re) that.Display(0, re)
}, },
"remove": func(that *Context) { "remove": func(that *Context) {
tableName := that.RouterString[1] tableName := that.RouterString[1]
that.Log = Map{"table": tableName, "type": 3, "table_id": that.RouterString[2]} that.Log = Map{"table": tableName, "type": 3, "table_id": that.RouterString[2]}
hotimeName := that.RouterString[0] hotimeName := that.RouterString[0]
inData := that.MakeCodeRouter[hotimeName].Delete(tableName, that.Req)
if inData == nil {
that.Display(3, "请求参数不足")
return
}
re := int64(0) re := int64(0)
//索引管理,便于检索以及权限 //索引则删除对应的参数
if inData.Get("parent_id") != nil && inData.GetSlice("parent_ids") != nil { if that.MakeCodeRouter[hotimeName].TableColumns[tableName]["parent_id"] != nil {
re = that.Db.Delete(tableName, Map{"index[~]": "," + that.RouterString[2] + ","}) re = that.Db.Delete(tableName, Map{"parent_ids[~]": "," + 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]})
} }
+176 -159
View File
@@ -725,15 +725,18 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
for _, v := range that.TableColumns[table] { for _, v := range that.TableColumns[table] {
//不可使用,未在前端展示,但在内存中保持有 //不可使用,未在前端展示,但在内存中保持有
if v.GetBool("notUse") { if v.GetBool("notUse") {
if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil { //if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
data[v.GetString("name")] = "," // data[v.GetString("name")] = ","
} //}
continue continue
} }
if v.Get("edit") == nil || v.GetBool("edit") { if v.Get("edit") == nil || v.GetBool("edit") {
if len(req.Form[v.GetString("name")]) == 0 {
continue
}
reqValue := req.FormValue(v.GetString("name")) reqValue := req.FormValue(v.GetString("name"))
if reqValue == "" || reqValue == "null" { if reqValue == "null" {
continue continue
} }
if v.GetString("type") == "password" { if v.GetString("type") == "password" {
@@ -761,16 +764,16 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
} }
func (that *MakeCode) Delete(table string, req *http.Request) Map { func (that *MakeCode) Delete(table string, req *http.Request) Map {
data := Map{} data := Map{}
for _, v := range that.TableColumns[table] { //for _, v := range that.TableColumns[table] {
//不可使用,未在前端展示,但在内存中保持有 // //不可使用,未在前端展示,但在内存中保持有
if v.GetBool("notUse") { // if v.GetBool("notUse") {
if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil { // //if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
data[v.GetString("name")] = "," // // data[v.GetString("name")] = ","
} // //}
continue // continue
} // }
//
} //}
return data return data
} }
@@ -795,7 +798,6 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
testQu = append(testQu, key) testQu = append(testQu, key)
} }
sort.Strings(testQu) sort.Strings(testQu)
for _, k := range testQu { for _, k := range testQu {
v := testQuData[k] v := testQuData[k]
//不可使用,未在前端展示,但在内存中保持有 //不可使用,未在前端展示,但在内存中保持有
@@ -890,88 +892,44 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
} }
if v.GetString("type") == "text" { }
reqValue := req.FormValue(v.GetString("name"))
if reqValue != "" {
data[table+"."+v.GetString("name")+"[~]"] = reqValue
}
} if strings.Contains(v.GetString("type"), "text") {
reqValue := req.FormValue(v.GetString("name"))
if v.GetString("type") == "unixtime" { if reqValue != "" {
data[table+"."+v.GetString("name")+"[~]"] = reqValue
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")
daterange[table+"."+v.GetString("name")+"[>]"] = t
} else if len(req.Form[v.GetString("name")]) == 2 {
t1 := time.Unix(ObjToCeilInt64(req.Form[v.GetString("name")][0]), 0).Format("2006-01-02 15:04:05")
t2 := time.Unix(ObjToCeilInt64(req.Form[v.GetString("name")][1]), 0).Format("2006-01-02 15:04:05")
daterange[table+"."+v.GetString("name")+"[<>]"] = Slice{t1, t2}
}
}
}
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 v.GetString("type") == "unixtime" {
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 len(req.Form[v.GetString("name")]) == 1 {
t := time.Unix(ObjToCeilInt64(req.FormValue(v.GetString("name"))), 0).Format("2006-01-02 15:04:05")
daterange[table+"."+v.GetString("name")+"[>]"] = t
} else if len(req.Form[v.GetString("name")]) == 2 {
t1 := time.Unix(ObjToCeilInt64(req.Form[v.GetString("name")][0]), 0).Format("2006-01-02 15:04:05")
t2 := time.Unix(ObjToCeilInt64(req.Form[v.GetString("name")][1]), 0).Format("2006-01-02 15:04:05")
daterange[table+"."+v.GetString("name")+"[<>]"] = Slice{t1, t2}
}
}
} }
if len(reStr) != 0 { if len(reStr) != 0 {
reStr = reStr[:len(reStr)-1] reStr = reStr[:len(reStr)-1]
@@ -981,47 +939,56 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
for k, _ := range search { for k, _ := range search {
searchItem := search.GetMap(k) searchItem := search.GetMap(k)
searchItemName := searchItem.GetString("name") searchItemName := searchItem.GetString("name")
if data[table+"."+searchItemName] != nil {
delete(data, table+"."+searchItemName)
}
reqValue := req.Form[searchItemName]
parent_idsStr := "" parent_idsStr := ""
parent_ids := that.TableColumns[searchItem.GetString("link")]["parent_ids"] if searchItem.GetString("link") != "" {
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
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[~]"
} }
continue //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" {
for _, v := range that.TableColumns[table] { for _, v := range that.TableColumns[table] {
if v["list"] == false { //if v["list"] == false {
continue // continue
} //}
//日期类型 //日期类型
if searchItemName == "daterange" { if searchItemName == "daterange" {
if daterangeTableStr != "" && daterangeTableStr != v.GetString("name") {
continue
}
if v.GetString("type") == "unixtime" { if v.GetString("type") == "unixtime" {
//fmt.Println(req.Form["daterange"]) //fmt.Println(req.Form["daterange"])
if len(req.Form["daterange"]) == 1 { if len(req.Form["daterange"]) == 1 && req.Form["daterange"][0] != "" {
daterange[table+"."+v.GetString("name")+"[>]"] = req.FormValue("daterange") daterange[table+"."+v.GetString("name")+"[>]"] = req.FormValue("daterange")
} else if len(req.Form["daterange"]) == 2 { } else if len(req.Form["daterange"]) == 2 {
@@ -1031,7 +998,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
if v.GetString("type") == "time" { if v.GetString("type") == "time" {
//fmt.Println(req.Form["daterange"]) //fmt.Println(req.Form["daterange"])
if len(req.Form["daterange"]) == 1 { if len(req.Form["daterange"]) == 1 && req.Form["daterange"][0] != "" {
t := time.Unix(ObjToCeilInt64(req.FormValue("daterange")), 0).Format("2006-01-02 15:04:05") t := time.Unix(ObjToCeilInt64(req.FormValue("daterange")), 0).Format("2006-01-02 15:04:05")
daterange[table+"."+v.GetString("name")+"[>]"] = t daterange[table+"."+v.GetString("name")+"[>]"] = t
@@ -1044,44 +1011,79 @@ 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" { if len(reqValue) != 0 && searchItem.GetString("name") == "sort" && reqValue[0] != "" {
sortMap["ORDER"] = table + "." + reqValue[0] sortMap["ORDER"] = table + "." + reqValue[0]
} }
continue continue
} }
//树节点模式搜索 //树节点模式搜索
if searchItemName == "parent_id" { 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")) parentID := ObjToInt(req.FormValue("parent_id"))
if parentID == 0 { if parentID == 0 {
parentID = userData.GetCeilInt(table + "_id") parentID = userData.GetCeilInt(table + "_id")
data["OR"] = Map{table + ".id": parentID, table + ".parent_id": nil} data["OR"] = Map{table + ".id": parentID, table + ".parent_id": nil}
} else { } else {
data[table+".parent_id"] = reqValue
if req.FormValue("showself") != "" {
where := Map{}
for _, v := range reqValue {
if len(where) == 0 {
where[table+"."+parent_idsStr] = "," + v + ","
continue
}
where = Map{"OR": where, table + "." + parent_idsStr: "," + v + ","}
}
data["OR"] = Map{"OR": where, table + ".id": reqValue}
} else {
data[table+".parent_id"] = reqValue
}
} }
continue continue
} }
@@ -1091,28 +1093,43 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
if parent_idsStr != "" { if parent_idsStr != "" {
where := Map{} where := Map{}
if len(reqValue) == 1 {
for _, v := range reqValue {
if len(where) == 0 { if len(where) == 0 {
where[parent_idsStr] = "," + v + "," where[table+"."+searchItem.GetString("name")] = reqValue[0]
continue
} else {
where = Map{"OR": where, table + "." + searchItem.GetString("name"): reqValue[0]}
}
} else {
for _, v := range reqValue {
if len(where) == 0 {
where[searchItem.GetString("link")+"."+parent_idsStr] = "," + v + ","
continue
}
where = Map{"OR": where, searchItem.GetString("link") + "." + parent_idsStr: "," + v + ","}
} }
where = Map{"OR": where, parent_idsStr: "," + v + ","}
} }
//用户 //用户
if userData[searchItem.GetString("name")] != nil { if userData[searchItem.GetString("name")] != nil {
where = Map{"AND": Map{parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ",", "OR": where}}
} where = Map{"AND": Map{searchItem.GetString("link") + "." + 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["OR"] = where
continue
//r := db.Select(searchItem.GetString("link"), "id", where)
//for _, v := range r {
// reqValue = append(reqValue, v.GetString("id"))
//}
} }
} }
data[table+"."+searchItemName] = reqValue if len(reqValue) != 0 && reqValue[0] != "" {
data[table+"."+searchItemName] = reqValue
}
} }
if sortMap["ORDER"] == nil { if sortMap["ORDER"] == nil {
+11
View File
@@ -5,6 +5,7 @@ import (
. "code.hoteas.com/golang/hotime/db" . "code.hoteas.com/golang/hotime/db"
"encoding/json" "encoding/json"
"net/http" "net/http"
"strings"
"time" "time"
) )
@@ -74,6 +75,16 @@ func (that *Context) View() {
if that.Session("user_id").Data != nil { if that.Session("user_id").Data != nil {
that.Log["user_id"] = that.Session("user_id").ToCeilInt() that.Log["user_id"] = that.Session("user_id").ToCeilInt()
} }
ipStr := Substr(that.Req.RemoteAddr, 0, strings.Index(that.Req.RemoteAddr, ":"))
//负载均衡优化
if ipStr == "127.0.0.1" {
if that.Req.Header.Get("X-Forwarded-For") != "" {
ipStr = that.Req.Header.Get("X-Forwarded-For")
} else if that.Req.Header.Get("X-Real-IP") != "" {
ipStr = that.Req.Header.Get("X-Real-IP")
}
}
that.Log["ip"] = ipStr
that.Db.Insert("logs", that.Log) that.Db.Insert("logs", that.Log)
} }
-104
View File
@@ -1,104 +0,0 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"time"
)
var ArticleCtr = Ctr{
"info": func(that *Context) {
sn := that.Req.FormValue("sn")
article := that.Db.Get("article", Map{"[><]ctg_article": "article.id=ctg_article.article_id"}, "article.*,ctg_article.ctg_id AS sctg_id", Map{"ctg_article.sn": sn})
if article == nil {
that.Display(4, "找不到对应数据")
return
}
ctgId := article.GetCeilInt64("sctg_id")
ctg := that.Db.Get("ctg", "*", Map{"id": ctgId})
parents := []Map{}
parentId := ctg.GetCeilInt64("parent_id")
article["tongji"] = that.Db.Select("ctg", "sn,name,img,parent_id", Map{"parent_id": parentId})
for true {
if parentId == 0 {
break
}
parent := that.Db.Get("ctg", "sn,name,img,parent_id", Map{"id": parentId})
if parent == nil {
break
}
parents = append(parents, parent)
parentId = parent.GetCeilInt64("parent_id")
}
ctg["parents"] = parents
article["ctg"] = ctg
that.Display(0, article)
},
"list": func(that *Context) {
sn := that.Req.FormValue("ctg_sn") //ctgsn
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page == 0 {
page = 1
}
if pageSize == 0 {
pageSize = 10
}
keywords := that.Req.FormValue("keywords")
lunbo := ObjToInt(that.Req.FormValue("lunbo"))
sort := that.Req.FormValue("sort")
where := Map{"article.push_time[<]": time.Now().Format("2006-01-02 15:04"), "article.state": 0}
if sn != "" {
ctg := that.Db.Get("ctg", "id", Map{"sn": sn})
if ctg != nil {
where["ctg_article.ctg_id"] = ctg.GetCeilInt("id")
}
}
startTime := that.Req.FormValue("start_time") //ctgsn
finishTime := that.Req.FormValue("finish_time") //ctgsn
if lunbo != 0 {
where["article.lunbo"] = lunbo
}
if len(startTime) > 5 {
where["article.push_time[>=]"] = startTime
}
if len(finishTime) > 5 {
where["article.push_time[<=]"] = finishTime
}
if keywords != "" {
where["OR"] = Map{"article.title[~]": keywords, "article.description[~]": keywords, "article.author[~]": keywords, "article.sn[~]": keywords, "article.origin[~]": keywords, "article.url[~]": keywords}
}
if len(where) > 1 {
where = Map{"AND": where}
}
if sort == "" {
where["ORDER"] = Slice{"article.sort DESC", "article.push_time DESC"}
}
if sort == "time" {
where["ORDER"] = "article.push_time DESC"
}
count := that.Db.Count("article", Map{"[><]ctg_article": "article.id=ctg_article.article_id"}, where)
article := that.Db.Page(page, pageSize).PageSelect("article", Map{"[><]ctg_article": "article.id=ctg_article.article_id"}, "ctg_article.sn,article.img,article.title,article.description,article.push_time,article.lunbo,article.author,article.origin,article.url", where)
that.Display(0, Map{"count": count, "data": article})
},
}
-77
View File
@@ -1,77 +0,0 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var CtgCtr = Ctr{
"info": func(that *Context) {
sn := that.Req.FormValue("sn")
ctg := that.Db.Get("ctg", "*", Map{"sn": sn})
parents := []Map{}
parentId := ctg.GetCeilInt64("parent_id")
ctg["tongji"] = that.Db.Select("ctg", "sn,name,img,parent_id", Map{"parent_id": parentId})
for true {
if parentId == 0 {
break
}
parent := that.Db.Get("ctg", "sn,name,img,parent_id", Map{"id": parentId})
if parent == nil {
break
}
parents = append(parents, parent)
parentId = parent.GetCeilInt64("parent_id")
}
if ctg.GetCeilInt64("article_id") != 0 {
ctg["article"] = that.Db.Get("article", "*", Map{"id": ctg.GetCeilInt64("article_id")})
}
ctg["parents"] = parents
that.Display(0, ctg)
},
"list": func(that *Context) {
sn := that.Req.FormValue("sn") //ctgsn
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page == 0 {
page = 1
}
if pageSize == 0 {
pageSize = 50
}
keywords := that.Req.FormValue("keywords")
//sort:=that.Req.FormValue("sort")
where := Map{"state": 0}
if sn != "" {
ctg := that.Db.Get("ctg", "id", Map{"sn": sn})
if ctg != nil {
where["parent_id"] = ctg.GetCeilInt("id")
}
}
if keywords != "" {
where["OR"] = Map{"name[~]": keywords, "url[~]": keywords, "sn[~]": keywords}
}
if len(where) > 1 {
where = Map{"AND": where}
}
where["ORDER"] = Slice{"sort DESC", "id DESC"}
article := that.Db.Page(page, pageSize).PageSelect("ctg", "name,sn,sort,url,img", where)
that.Display(0, article)
},
}
-127
View File
@@ -1,127 +0,0 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"time"
)
var AppProj = Proj{
"article": ArticleCtr,
"org": OrgCtr,
"ctg": CtgCtr,
"mail": MailCtr,
"test": {
"test": func(that *Context) {
//data:=that.Db.Table("admin").Order("id DESC").Select("*")
//data1:=that.Db.Table("admin").Where(Map{"name[~]":"m"}).Order("id DESC").Select("*")
//
//data3:=that.Db.Select("admin","*",Map{"name[~]":"m"})
data2 := that.Db.Table("article").Where(Map{"title[~]": "m"}).Order("id DESC").Page(1, 10).Select("*")
c := that.Db.Table("article").Where(Map{"title[~]": "m"}).Order("id DESC").Group("title").Select("*")
//that.Display(0,Slice{data1,data,data3,data2})
that.Display(0, Slice{data2, c})
},
"res": func(that *Context) {
ebw_res := that.Db.Select("ebw_res", "*")
for _, v := range ebw_res {
data := Map{"id": v.GetCeilInt("id"), "name": v.GetString("name"),
"parent_id": v.GetCeilInt64("pid"),
"sn": v.GetString("url"), "create_time": time.Now().Format("2006-01-02 15:04"),
"modify_time": time.Now().Format("2006-01-02 15:04"), "admin_id": 1}
if data.GetCeilInt("parent_id") == 0 {
data["parent_id"] = nil
}
that.Db.Insert("ctg", data)
}
that.Db.Exec("UPDATE ctg SET parent_id =NULL WHERE parent_id=id")
ss(0, that)
that.Display(0, len(ebw_res))
},
"news": func(that *Context) {
ebw_news := that.Db.Select("ebw_news", "*")
for _, v := range ebw_news {
ctg := that.Db.Get("ctg", "*", Map{"sn": v.GetString("type")})
data := Map{"sn": v.GetString("id"), "title": v.GetString("title"),
"content": v.GetString("content"), "push_time": v.GetString("timedate"),
"author": v.GetString("owner"), "origin": v.GetString("source"), "click_num": v.GetString("readtime"),
"sort": v.GetCeilInt("zhiding"), "create_time": time.Now().Format("2006-01-02 15:04"),
"modify_time": time.Now().Format("2006-01-02 15:04"), "admin_id": 1}
if ctg != nil {
data["ctg_id"] = ctg.GetCeilInt("id")
}
that.Db.Insert("article", data)
}
that.Display(0, len(ebw_news))
},
"res2news": func(that *Context) {
ebw_news_addition_res := that.Db.Select("ebw_news_addition_res", "*")
for _, v := range ebw_news_addition_res {
ctg := that.Db.Get("ctg", "*", Map{"sn": v.GetString("fk_res")})
article := that.Db.Get("article", "*", Map{"sn": v.GetString("fk_newsid")})
data := Map{"sn": Md5(ObjToStr(time.Now().UnixNano()) + ObjToStr(RandX(10000, 100000))),
"create_time": time.Now().Format("2006-01-02 15:04"),
"modify_time": time.Now().Format("2006-01-02 15:04"), "admin_id": 1}
if ctg != nil {
data["ctg_id"] = ctg.GetCeilInt("id")
}
if article != nil {
data["article_id"] = article.GetCeilInt("id")
}
that.Db.Insert("ctg_article", data)
}
that.Display(0, len(ebw_news_addition_res))
},
//将文章没有关联的ctg_article进行关联
"article": func(that *Context) {
articles := that.Db.Select("article", "id,ctg_id")
for _, v := range articles {
ctg_article := that.Db.Get("ctg_article", "id", Map{"article_id": v.GetCeilInt("id")})
if ctg_article == nil {
data := Map{"sn": Md5(ObjToStr(time.Now().UnixNano()) + ObjToStr(RandX(10000, 100000))),
"create_time": time.Now().Format("2006-01-02 15:04"),
"modify_time": time.Now().Format("2006-01-02 15:04"), "admin_id": 1}
if v.GetCeilInt("ctg_id") == 0 || v.GetCeilInt("id") == 0 {
continue
}
data["ctg_id"] = v.GetCeilInt("ctg_id")
data["article_id"] = v.GetCeilInt("id")
that.Db.Insert("ctg_article", data)
}
}
that.Display(0, len(articles))
},
},
}
func ss(parent_id int, that *Context) {
var ctgs []Map
ctg := that.Db.Get("ctg", "*", Map{"id": parent_id})
if parent_id == 0 {
ctgs = that.Db.Select("ctg", "*", Map{"parent_id": nil})
} else {
ctgs = that.Db.Select("ctg", "*", Map{"parent_id": parent_id})
}
for _, v := range ctgs {
if ctg == nil {
ctg = Map{"parent_ids": ","}
}
ids := ctg.GetString("parent_ids") + ObjToStr(v.GetCeilInt("id")) + ","
that.Db.Update("ctg", Map{"parent_ids": ids}, Map{"id": v.GetCeilInt("id")})
ss(v.GetCeilInt("id"), that)
}
}
-96
View File
@@ -1,96 +0,0 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"time"
)
var MailCtr = Ctr{
"add": func(that *Context) {
title := that.Req.FormValue("title")
name := that.Req.FormValue("name")
phone := that.Req.FormValue("phone")
content := that.Req.FormValue("content")
tp := ObjToInt(that.Req.FormValue("type"))
show := ObjToInt(that.Req.FormValue("show"))
if len(title) < 5 {
that.Display(3, "标题过短")
return
}
if len(name) < 2 {
that.Display(3, "姓名错误")
return
}
if len(phone) < 8 {
that.Display(3, "联系方式错误")
return
}
if len(content) < 10 {
that.Display(3, "内容过短")
return
}
data := Map{
"sn": Md5(ObjToStr(time.Now().UnixNano()) + ObjToStr(RandX(10000, 100000))),
"name": name, "title": title, "phone": phone, "content": content, "type": tp, "show": show,
"modify_time[#]": "NOW()", "create_time[#]": "NOW()",
}
id := that.Db.Insert("mail", data)
if id == 0 {
that.Display(4, "创建失败")
return
}
that.Display(0, "成功")
return
},
"info": func(that *Context) {
sn := that.Req.FormValue("sn")
mail := that.Db.Get("mail", "*", Map{"sn": sn})
that.Display(0, mail)
},
"list": func(that *Context) {
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page == 0 {
page = 1
}
if pageSize == 0 {
pageSize = 10
}
//keywords:=that.Req.FormValue("keywords")
//sort:=that.Req.FormValue("sort")
where := Map{"state": 0, "show": 1}
//if keywords!=""{
// where["OR"]=Map{"title[~]":keywords,"description[~]":keywords,"author[~]":keywords,"sn[~]":keywords,"origin[~]":keywords,"url[~]":keywords}
//}
if len(where) > 1 {
where = Map{"AND": where}
}
//if sort==""{
// where["ORDER"]=Slice{"sort DESC","push_time DESC"}
//}
//
//if sort=="time"{
where["ORDER"] = "create_time DESC"
//}
count := that.Db.Count("mail", where)
mail := that.Db.Page(page, pageSize).PageSelect("mail", "*", where)
that.Display(0, Map{"count": count, "data": mail})
},
}
-60
View File
@@ -1,60 +0,0 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"time"
)
var OrgCtr = Ctr{
"info": func(that *Context) {
sn := that.Req.FormValue("sn")
article := that.Db.Get("article", "*", Map{"sn": sn})
that.Display(0, article)
},
"list": func(that *Context) {
sn := that.Req.FormValue("sn") //orgsn
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page == 0 {
page = 1
}
if pageSize == 0 {
pageSize = 50
}
keywords := that.Req.FormValue("keywords")
sort := that.Req.FormValue("sort")
where := Map{"push_time[<=]": time.Now().Format("2006-01-02 15:04"), "state": 0}
if sn != "" {
org := that.Db.Get("org", "id", Map{"sn": sn})
if org != nil {
where["org_id"] = org.GetCeilInt("id")
}
}
if keywords != "" {
where["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "author[~]": keywords, "sn[~]": keywords, "origin[~]": keywords, "url[~]": keywords}
}
if len(where) > 1 {
where = Map{"AND": where}
}
if sort == "" {
where["ORDER"] = Slice{"sort DESC", "id DESC"}
}
if sort == "time" {
where["ORDER"] = "push_time DESC"
}
article := that.Db.Page(page, pageSize).PageSelect("article", "sn,title,description,push_time,lunbo,author,origin,url", where)
that.Display(0, article)
},
}