优化代码

This commit is contained in:
hoteas 2021-06-06 07:50:58 +08:00
parent 4038598470
commit 642bf97272
4 changed files with 24 additions and 29 deletions

View File

@ -15,7 +15,9 @@ var Config = Map{
"menu": []Map{
{"label": "用户管理", "table": "user"},
{"label": "组织管理", "table": "organization"},
{"label": "地区管理", "table": "area"},
{"label": "角色管理", "table": "role"},
{"label": "日志管理", "table": "log"},
{"label": "系统设置", "table": "system", "default": "edit"},
},
},

View File

@ -41,20 +41,22 @@ func (that *MakeCode) Db2JSON(name string, path string, db db.HoTimeDB) {
} else {
that.Error.SetError(errors.New("配置文件不存在,或者配置出错,使用缺省默认配置"))
}
tables := that.Config.GetSlice("tables")
that.TableConfig = that.Config.GetMap("tables")
if that.TableConfig == nil {
that.TableConfig = Map{}
for k, _ := range tables {
tableName := tables.GetMap(k).GetString("table")
that.TableConfig[tableName] = tables.GetMap(k)
columns := tables.GetMap(k).GetSlice("columns")
}
for tableName, _ := range that.TableConfig {
columns := that.TableConfig.GetMap(tableName).GetSlice("columns")
//初始化
if that.TableColumns[tableName] == nil {
that.TableColumns[tableName] = map[string]Map{}
}
//注入源数据
for k, _ := range columns {
columnsName := columns.GetMap(k).GetString("name")
that.TableColumns[tableName][columnsName] = columns.GetMap(k)
for index, _ := range columns {
columnsName := columns.GetMap(index).GetString("name")
that.TableColumns[tableName][columnsName] = columns.GetMap(index)
}
}
@ -117,25 +119,26 @@ func (that *MakeCode) Db2JSON(name string, path string, db db.HoTimeDB) {
if info.GetString("label") == "" {
info["label"] = "备注"
}
coloums := that.TableColumns[v.GetString("name")][info.GetString("name")]
coloum := that.TableColumns[v.GetString("name")][info.GetString("name")]
if coloums == nil {
coloums = Map{
if coloum == nil {
coloum = Map{
"name": info.GetString("name"),
"type": info.GetString("type"),
"label": info.GetString("label"),
//"add": false, "info": false, "edit": false, "list": true,
"must": false,
}
that.TableConfig.GetMap(v.GetString("name"))["columns"] = append(that.TableConfig.GetMap(v.GetString("name")).GetSlice("columns"), coloum)
} else {
if !(coloums.GetString("label") != "备注" && info.GetString("label") == "备注") {
coloums["label"] = info.GetString("label")
if !(coloum.GetString("label") != "备注" && info.GetString("label") == "备注") {
coloum["label"] = info.GetString("label")
}
coloums["type"] = info.GetString("type")
coloum["type"] = info.GetString("type")
}
that.TableColumns[v.GetString("name")][info.GetString("name")] = coloums
that.TableColumns[v.GetString("name")][info.GetString("name")] = coloum
}
@ -158,20 +161,8 @@ func (that *MakeCode) Db2JSON(name string, path string, db db.HoTimeDB) {
}
newTables := []Map{}
for k, _ := range that.TableConfig {
newTable := that.TableConfig.GetMap(k)
newTables = append(newTables, newTable)
columns := []Map{}
for _, v := range that.TableColumns[newTable.GetString("table")] {
columns = append(columns, v)
}
newTable["columns"] = columns
}
that.Config["tables"] = newTables
that.Config["tables"] = that.TableConfig
//}
//fmt.Println(ObjToStr(idSlice))
id := Md5(ObjToStr(idSlice))
if id == that.Config.GetString("id") {

View File

@ -9,6 +9,7 @@
"codeConfig": {
"admin": "config/app.json"
},
"crossDomain": "auto",
"db": {
"mysql": {
"host": "192.168.6.250",

View File

@ -62,6 +62,7 @@ func main() {
"app": hotime.Proj{
"index": hotime.Ctr{
"test": func(this *hotime.Context) {
data := this.Db.Get("cached", "*")
fmt.Println(data)
fmt.Println(this.Session("test").ToCeilInt())