开始新增代码生成配置2.0功能,配置文件格式规定完成

This commit is contained in:
hoteas
2021-09-16 04:33:10 +08:00
parent acb7cdd4b8
commit 9513b80a24
10 changed files with 131 additions and 1326 deletions
+5 -4
View File
@@ -67,7 +67,7 @@ var ColumnNameType = []ColumnShow{
{"latitude", false, true, true, false, "", false},
{"longitude", false, true, true, false, "", false},
{"index", false, false, false, false, "", false},
{"index", false, false, false, false, "index", false},
{"password", false, true, false, false, "password", false},
{"pwd", false, true, false, false, "password", false},
{"info", false, true, true, false, "", false},
@@ -80,14 +80,15 @@ var ColumnNameType = []ColumnShow{
{"content", false, true, true, false, "", false},
{"address", false, true, true, false, "", false},
{"full_name", false, true, true, false, "", false},
{"create_time", false, false, true, false, "", false},
{"modify_time", false, false, true, false, "", false},
{"create_time", false, false, true, false, "time", true},
{"modify_time", true, false, true, false, "time", true},
{"image", false, true, true, false, "image", false},
{"img", false, true, true, false, "image", false},
{"icon", false, true, true, false, "image", false},
{"avatar", false, true, true, false, "image", false},
{"file", false, true, true, false, "file", false},
{"age", false, true, true, false, "", false},
{"email", false, true, true, false, "", false},
{"time", true, false, true, false, "", false},
{"time", true, false, true, false, "time", false},
{"level", false, false, true, false, "", false},
}
+57 -47
View File
@@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
"strings"
"time"
)
type MakeCode struct {
@@ -112,7 +113,7 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
}
if db==nil{
if db == nil {
return
}
@@ -143,27 +144,14 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
"auth": []string{"add", "delete", "edit", "info"},
"columns": []Map{},
"search": []Map{
//{"type": "tree", "name": "oid", "label": "组织", "table": "organization", "showName": "label", "children": "children"},
{"type": "search", "name": "keyword", "label": "请输入关键词", "value": nil},
{"type": "search", "name": "daterange", "label": "时间段", "value": nil},
{"type": "search", "name": "sort", "label": "排序", "value": nil},
//{"type": "select", "name": "state", "label": "状态", "value": nil,
// "options": []Map{
// {"name": "正常", "value": 0},
// {"name": "异常", "value": 1},
// {"name": "全部", "value": nil},
// },
//},
},
}
}
//else {
// if !(that.TableConfig.GetMap(v.GetString("name")).GetString("label") != "备注" &&
// v.GetString("label") == "备注") {
// that.TableConfig.GetMap(v.GetString("name"))["label"] = v.GetString("label")
// }
//
//}
//初始化
if that.TableColumns[v.GetString("name")] == nil {
that.TableColumns[v.GetString("name")] = make(map[string]Map)
@@ -184,6 +172,7 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
idSlice = append(idSlice, tableInfo)
for _, info := range tableInfo {
if info.GetString("label") == "" {
info["label"] = info.GetString("name")
}
@@ -191,10 +180,9 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
if coloum == nil {
//根据类型判断真实类型
for k, v := range ColumnDataType {
if strings.Contains(info.GetString("type"), k) || strings.Contains(info.GetString("name"), k) {
info["type"] = v
break
for k, v1 := range ColumnDataType {
if strings.Contains(info.GetString("name"), k) || strings.Contains(info.GetString("type"), k) {
info["type"] = v1
}
}
@@ -211,30 +199,41 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
coloum["label"] = info.GetString("label")[:indexNum]
}
for _, v := range ColumnNameType {
if (v.Strict && coloum.GetString("name") == v.Name) || (!v.Strict && strings.Contains(coloum.GetString("name"), v.Name)) {
for _, ColumnName := range ColumnNameType {
if (ColumnName.Strict && coloum.GetString("name") == ColumnName.Name) ||
(!ColumnName.Strict && strings.Contains(coloum.GetString("name"), ColumnName.Name)) {
//全部都不需要则不加入
if v.Edit == false && v.List == false && v.Info == false {
if ColumnName.Edit == false && ColumnName.List == false && ColumnName.Info == false {
coloum["notUse"] = true
//continue
}
coloum["info"] = ColumnName.Info
coloum["edit"] = ColumnName.Edit
coloum["add"] = ColumnName.Edit
coloum["list"] = ColumnName.List
coloum["must"] = ColumnName.Must
if ColumnName.Info {
delete(coloum, "info")
}
if ColumnName.Edit {
delete(coloum, "edit")
delete(coloum, "add")
}
if ColumnName.List {
delete(coloum, "list")
}
if ColumnName.Must {
delete(coloum, "must")
}
if ColumnName.Type != "" {
coloum["type"] = ColumnName.Type
}
if ColumnName.Strict && coloum.GetString("name") == ColumnName.Name {
break
}
if v.Info == false {
coloum["info"] = v.Info
}
if v.Edit == false {
coloum["edit"] = v.Edit
coloum["add"] = v.Edit
}
if v.List == false {
coloum["list"] = v.List
}
if v.Must == true {
coloum["must"] = v.Must
}
if v.Type != "" {
coloum["type"] = v.Type
}
break
}
}
@@ -243,9 +242,9 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
coloum["sortable"] = true
}
if !coloum.GetBool("notUse") {
that.TableConfig.GetMap(v.GetString("name"))["columns"] = append(that.TableConfig.GetMap(v.GetString("name")).GetSlice("columns"), coloum)
}
//if !coloum.GetBool("notUse") {
that.TableConfig.GetMap(v.GetString("name"))["columns"] = append(that.TableConfig.GetMap(v.GetString("name")).GetSlice("columns"), coloum)
//}
//如果是select类型需要设置options
//if coloum.GetString("type") == "select" {
@@ -535,7 +534,13 @@ func (that *MakeCode) Add(table string, req *http.Request) Map {
}
}
}
if v.GetString("name") == "create_time" {
data[v.GetString("name")] = time.Now().Unix()
continue
}
if v.GetString("name") == "modify_time" {
data[v.GetString("name")] = time.Now().Unix()
}
}
if len(data) == 0 {
@@ -562,6 +567,9 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
data[v.GetString("name")] = reqValue
}
}
if v.GetString("name") == "modify_time" {
data[v.GetString("name")] = time.Now().Unix()
}
}
if len(data) == 0 {
@@ -590,13 +598,15 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
if v.GetString("link") != "" &&
v.GetString("name") != "parent_id" {
reStr += v.GetString("link") + "." +
v.GetString("value") + " AS " +
reStr += table + "." + v.GetString("name") + "," +
v.GetString("link") + "." + v.GetString("value") + " AS " +
v.GetString("link") + "_" + v.GetString("name") + "_" + v.GetString("value") + ","
leftJoin["[>]"+v.GetString("link")] =
table + "." + v.GetString("name") + "=" +
v.GetString("link") + ".id"
//准备加入索引
} else {
reStr += table + "." + v.GetString("name") + ","
}
@@ -647,7 +657,7 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
}
//日期类型
if searchItemName == "daterange" && v.GetString("type") == "time" {
fmt.Println(req.Form["daterange"])
//fmt.Println(req.Form["daterange"])
daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"])
}
}
+35 -13
View File
@@ -15,26 +15,48 @@ var Project = Proj{
{{tablesCtr}}
"hotime":Ctr{
"login": func(this *Context) {
name:=this.Req.FormValue("name")
password:=this.Req.FormValue("password")
if name==""||password==""{
this.Display(3,"参数不足")
name := this.Req.FormValue("name")
password := this.Req.FormValue("password")
if name == "" || password == "" {
this.Display(3, "参数不足")
return
}
user:=this.Db.Get("{{name}}","*",Map{"AND":Map{"name":name,"password":Md5(password)}})
if user==nil{
this.Display(5,"登录失败")
user := this.Db.Get("admin", "*", Map{"AND": Map{"name": name, "password": Md5(password)}})
if user == nil {
this.Display(5, "登录失败")
return
}
this.Session("id",user.GetCeilInt("id"))
this.Session("name",name)
this.Display(0,"登录成功")
this.Session("admin_id", user.GetCeilInt("id"))
this.Session("admin_name", name)
this.Display(0, this.SessionId)
},
"logout": func(this *Context) {
this.Session("id",nil)
this.Session("name",nil)
this.Display(0,"退出登录成功")
this.Session("admin_id", nil)
this.Session("admin_name", nil)
this.Display(0, "退出登录成功")
},
"info": func(that *Context) {
re := that.Db.Get("admin", that.MakeCode.Info("admin"), Map{"id": that.Session("admin_id").ToCeilInt()})
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") != "" {
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v})
}
}
that.Display(0, re)
},
},
}
`
var CtrTpt = `package {{name}}