iedc-go/code/template.go

124 lines
2.6 KiB
Go
Raw Normal View History

2021-06-04 02:04:37 +00:00
package code
var InitTpt = `package {{name}}
import (
. "../../../hotime"
)
var ID = "{{id}}"
// Project 管理端项目
var Project = Proj{
//"user": UserCtr,
{{tablesCtr}}
}
`
var CtrTpt = `package {{name}}
import (
. "../../../hotime"
. "../../../hotime/common"
)
var {{table}}Ctr = Ctr{
"info": func(that *Context) {
re := that.Db.Get(that.RouterString[1], that.MakeCode.Info(that.RouterString[1]), Map{"id": that.RouterString[2]})
2021-06-07 03:32:47 +00:00
if re == nil {
that.Display(4, "找不到对应信息")
return
}
for k, v := range re {
column:=that.MakeCode.TableColumns[that.RouterString[1]][k]
if column==nil{
continue
}
if (column["list"]==nil||column.GetBool("list"))&&column.GetString("link")!=""{
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v})
}
}
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
}
re := that.Db.Insert(that.RouterString[1], inData)
if re == 0 {
that.Display(4, "无法插入对应数据")
return
}
that.Display(0, re)
},
"update": func(that *Context) {
inData := that.MakeCode.Edit(that.RouterString[1], that.Req)
if inData == nil {
that.Display(3, "没有找到要更新的数据")
return
}
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) {
re := that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]})
if re == 0 {
that.Display(4, "删除数据失败")
return
}
that.Display(0, re)
},
"search": func(that *Context) {
2021-06-11 00:06:44 +00:00
2021-06-13 01:53:37 +00:00
columnStr,leftJoin,where := that.MakeCode.Search(that.RouterString[1], that.Req,that.Db)
2021-06-11 00:06:44 +00:00
page:=ObjToInt(that.Req.FormValue("page"))
pageSize:=ObjToInt(that.Req.FormValue("pageSize"))
2021-06-13 01:53:37 +00:00
2021-06-11 00:06:44 +00:00
if page<1{
page=1
}
if pageSize<=0{
pageSize=20
}
2021-06-13 01:53:37 +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-06-13 01:53:37 +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 {
column:=that.MakeCode.TableColumns[that.RouterString[1]][k]
if column==nil{
continue
}
2021-06-11 00:06:44 +00:00
2021-06-07 03:32:47 +00:00
if (column["list"]==nil||column.GetBool("list"))&&column.GetString("link")!=""{
v[column.GetString("link")] = that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)})
}
2021-06-04 02:04:37 +00:00
2021-06-11 00:06:44 +00:00
2021-06-07 03:32:47 +00:00
}
}
2021-06-11 00:06:44 +00:00
that.Display(0, Map{"count":count,"data":reData})
2021-06-04 02:04:37 +00:00
},
}
`