2021-06-04 02:04:37 +00:00
|
|
|
package code
|
|
|
|
|
|
|
|
var InitTpt = `package {{name}}
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "../../../hotime"
|
2021-08-29 23:36:17 +00:00
|
|
|
. "../../../hotime/common"
|
2021-06-04 02:04:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var ID = "{{id}}"
|
|
|
|
|
|
|
|
// Project 管理端项目
|
|
|
|
var Project = Proj{
|
|
|
|
//"user": UserCtr,
|
|
|
|
{{tablesCtr}}
|
2021-08-29 23:36:17 +00:00
|
|
|
"hotime":Ctr{
|
|
|
|
"login": func(this *Context) {
|
2021-09-15 20:33:10 +00:00
|
|
|
name := this.Req.FormValue("name")
|
|
|
|
password := this.Req.FormValue("password")
|
|
|
|
if name == "" || password == "" {
|
|
|
|
this.Display(3, "参数不足")
|
2021-08-29 23:36:17 +00:00
|
|
|
return
|
|
|
|
}
|
2021-09-15 20:33:10 +00:00
|
|
|
user := this.Db.Get("admin", "*", Map{"AND": Map{"name": name, "password": Md5(password)}})
|
|
|
|
if user == nil {
|
|
|
|
this.Display(5, "登录失败")
|
2021-08-29 23:36:17 +00:00
|
|
|
return
|
|
|
|
}
|
2021-09-15 20:33:10 +00:00
|
|
|
this.Session("admin_id", user.GetCeilInt("id"))
|
|
|
|
this.Session("admin_name", name)
|
|
|
|
this.Display(0, this.SessionId)
|
2021-08-29 23:36:17 +00:00
|
|
|
},
|
|
|
|
"logout": func(this *Context) {
|
2021-09-15 20:33:10 +00:00
|
|
|
this.Session("admin_id", nil)
|
|
|
|
this.Session("admin_name", nil)
|
|
|
|
this.Display(0, "退出登录成功")
|
2021-08-29 23:36:17 +00:00
|
|
|
},
|
2021-09-15 20:33:10 +00:00
|
|
|
"info": func(that *Context) {
|
2021-09-16 20:00:49 +00:00
|
|
|
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
|
|
|
str, inData := that.MakeCode.Info("admin", data, that.Db)
|
|
|
|
where := Map{"id": that.Session("admin_id").ToCeilInt()}
|
|
|
|
if len(inData) ==1 {
|
|
|
|
inData["id"] =where["id"]
|
|
|
|
where = Map{"AND": inData}
|
|
|
|
}else if len(inData) >1 {
|
|
|
|
where["OR"]=inData
|
|
|
|
where = Map{"AND": where}
|
|
|
|
}
|
|
|
|
re := that.Db.Get("admin", str, where)
|
2021-09-15 20:33:10 +00:00
|
|
|
if re == nil {
|
|
|
|
that.Display(4, "找不到对应信息")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for k, v := range re {
|
|
|
|
column := that.MakeCode.TableColumns["admin"][k]
|
|
|
|
if column == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
|
2021-09-16 20:00:49 +00:00
|
|
|
re[column.GetString("link")] = that.Db.Get(column.GetString("link"),"id," +column.GetString("value"), Map{"id": v})
|
2021-09-15 20:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
that.Display(0, re)
|
|
|
|
},
|
|
|
|
},
|
2021-06-04 02:04:37 +00:00
|
|
|
}
|
|
|
|
`
|
|
|
|
var CtrTpt = `package {{name}}
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "../../../hotime"
|
|
|
|
. "../../../hotime/common"
|
2021-09-16 20:00:49 +00:00
|
|
|
"strings"
|
2021-06-04 02:04:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var {{table}}Ctr = Ctr{
|
|
|
|
"info": func(that *Context) {
|
2021-09-16 20:00:49 +00:00
|
|
|
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
|
|
|
str, inData := that.MakeCode.Info(that.RouterString[1], data, that.Db)
|
|
|
|
where := Map{"id": that.RouterString[2]}
|
|
|
|
|
|
|
|
if len(inData) ==1 {
|
|
|
|
inData["id"] =where["id"]
|
|
|
|
where = Map{"AND": inData}
|
|
|
|
}else if len(inData) >1 {
|
|
|
|
where["OR"]=inData
|
|
|
|
where = Map{"AND": where}
|
|
|
|
}
|
|
|
|
|
|
|
|
re := that.Db.Get(that.RouterString[1], str, where)
|
2021-06-07 03:32:47 +00:00
|
|
|
|
|
|
|
if re == nil {
|
|
|
|
that.Display(4, "找不到对应信息")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for k, v := range re {
|
2021-09-16 20:00:49 +00:00
|
|
|
column := that.MakeCode.TableColumns[that.RouterString[1]][k]
|
|
|
|
if column == nil {
|
2021-06-07 03:32:47 +00:00
|
|
|
continue
|
|
|
|
}
|
2021-09-16 20:00:49 +00:00
|
|
|
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
|
|
|
|
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), "id,"+column.GetString("value"), Map{"id": v})
|
2021-06-07 03:32:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-04 02:04:37 +00:00
|
|
|
that.Display(0, re)
|
|
|
|
},
|
|
|
|
"add": func(that *Context) {
|
|
|
|
inData := that.MakeCode.Add(that.RouterString[1], that.Req)
|
|
|
|
if inData == nil {
|
|
|
|
that.Display(3, "请求参数不足")
|
|
|
|
return
|
|
|
|
}
|
2021-09-16 20:00:49 +00:00
|
|
|
|
|
|
|
|
2021-06-04 02:04:37 +00:00
|
|
|
re := that.Db.Insert(that.RouterString[1], inData)
|
|
|
|
|
|
|
|
if re == 0 {
|
|
|
|
that.Display(4, "无法插入对应数据")
|
|
|
|
return
|
|
|
|
}
|
2021-09-16 20:00:49 +00:00
|
|
|
//索引管理,便于检索以及权限
|
|
|
|
if inData.Get("parent_id") != nil && inData.GetSlice("index") != nil {
|
|
|
|
index := that.Db.Get(that.RouterString[1], "` + "`index`" + `", Map{"id": inData.Get("parent_id")})
|
|
|
|
inData["index"] = index.GetString("index")+ObjToStr(re)+","
|
|
|
|
that.Db.Update(that.RouterString[1],Map{"index":inData["index"]},Map{"id":re})
|
|
|
|
}
|
2021-06-04 02:04:37 +00:00
|
|
|
|
|
|
|
that.Display(0, re)
|
|
|
|
},
|
|
|
|
"update": func(that *Context) {
|
|
|
|
inData := that.MakeCode.Edit(that.RouterString[1], that.Req)
|
|
|
|
if inData == nil {
|
|
|
|
that.Display(3, "没有找到要更新的数据")
|
|
|
|
return
|
|
|
|
}
|
2021-09-16 20:00:49 +00:00
|
|
|
|
|
|
|
//索引管理,便于检索以及权限
|
|
|
|
if inData.Get("parent_id") != nil && inData.GetSlice("index") != nil {
|
|
|
|
Index := that.Db.Get(that.RouterString[1], "` + "`index`" + `", Map{"id": that.RouterString[2]})
|
|
|
|
parentIndex := that.Db.Get(that.RouterString[1], "` + "`index`" + `", Map{"id": inData.Get("parent_id")})
|
|
|
|
inData["index"] = parentIndex.GetString("index") + that.RouterString[2] + ","
|
|
|
|
|
|
|
|
childNodes := that.Db.Select(that.RouterString[1], "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(that.RouterString[1], Map{"index": v["index"]}, Map{"id": v.GetCeilInt("id")})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-06-04 02:04:37 +00:00
|
|
|
re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]})
|
|
|
|
|
|
|
|
if re == 0 {
|
|
|
|
that.Display(4, "更新数据失败")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
that.Display(0, re)
|
|
|
|
},
|
|
|
|
"remove": func(that *Context) {
|
2021-09-16 20:00:49 +00:00
|
|
|
inData := that.MakeCode.Delete(that.RouterString[1], that.Req)
|
|
|
|
if inData == nil {
|
|
|
|
that.Display(3, "请求参数不足")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
re :=int64(0)
|
|
|
|
//索引管理,便于检索以及权限
|
|
|
|
if inData.Get("parent_id") != nil && inData.GetSlice("index") != nil {
|
|
|
|
re=that.Db.Delete(that.RouterString[1], Map{"index[~]": "," + that.RouterString[2] + ","})
|
|
|
|
}else {
|
|
|
|
re=that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]})
|
|
|
|
}
|
2021-06-04 02:04:37 +00:00
|
|
|
|
|
|
|
if re == 0 {
|
|
|
|
that.Display(4, "删除数据失败")
|
|
|
|
return
|
|
|
|
}
|
2021-09-16 20:00:49 +00:00
|
|
|
that.Display(0, "删除成功")
|
2021-06-04 02:04:37 +00:00
|
|
|
},
|
2021-09-16 20:00:49 +00:00
|
|
|
|
2021-06-04 02:04:37 +00:00
|
|
|
"search": func(that *Context) {
|
|
|
|
|
2021-09-16 20:00:49 +00:00
|
|
|
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
2021-06-11 00:06:44 +00:00
|
|
|
|
2021-09-16 20:00:49 +00:00
|
|
|
columnStr, leftJoin, where := that.MakeCode.Search(that.RouterString[1], data, that.Req, that.Db)
|
2021-06-13 01:53:37 +00:00
|
|
|
|
2021-09-16 20:00:49 +00:00
|
|
|
page := ObjToInt(that.Req.FormValue("page"))
|
|
|
|
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
|
|
|
|
|
|
|
if page < 1 {
|
|
|
|
page = 1
|
2021-06-11 00:06:44 +00:00
|
|
|
}
|
|
|
|
|
2021-09-16 20:00:49 +00:00
|
|
|
if pageSize <= 0 {
|
|
|
|
pageSize = 20
|
2021-06-11 00:06:44 +00:00
|
|
|
}
|
2021-06-13 01:53:37 +00:00
|
|
|
|
2021-09-16 20:00:49 +00:00
|
|
|
count := that.Db.Count(that.RouterString[1], leftJoin, where)
|
2021-06-11 00:06:44 +00:00
|
|
|
reData := that.Db.Page(page, pageSize).
|
2021-09-16 20:00:49 +00:00
|
|
|
PageSelect(that.RouterString[1], leftJoin, columnStr, where)
|
2021-06-11 00:06:44 +00:00
|
|
|
|
2021-06-07 03:32:47 +00:00
|
|
|
for _, v := range reData {
|
|
|
|
for k, _ := range v {
|
2021-09-16 20:00:49 +00:00
|
|
|
column := that.MakeCode.TableColumns[that.RouterString[1]][k]
|
|
|
|
if column == nil {
|
2021-06-07 03:32:47 +00:00
|
|
|
continue
|
|
|
|
}
|
2021-06-11 00:06:44 +00:00
|
|
|
|
2021-09-16 20:00:49 +00:00
|
|
|
if column["list"] != false && column["name"] == "parent_id" && column.GetString("link") != "" {
|
2021-06-13 02:40:19 +00:00
|
|
|
parentC := that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)})
|
2021-09-16 20:00:49 +00:00
|
|
|
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = ""
|
|
|
|
if parentC != nil {
|
|
|
|
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = parentC.GetString(column.GetString("value"))
|
2021-06-13 02:40:19 +00:00
|
|
|
}
|
2021-06-07 03:32:47 +00:00
|
|
|
}
|
2021-06-04 02:04:37 +00:00
|
|
|
|
2021-06-07 03:32:47 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-16 20:00:49 +00:00
|
|
|
|
|
|
|
that.Display(0, Map{"count": count, "data": reData})
|
2021-06-04 02:04:37 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
`
|