优化代码

This commit is contained in:
2021-06-06 07:50:58 +08:00
parent 4038598470
commit 642bf97272
4 changed files with 24 additions and 29 deletions
+20 -29
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 = Map{}
for k, _ := range tables {
tableName := tables.GetMap(k).GetString("table")
that.TableConfig[tableName] = tables.GetMap(k)
columns := tables.GetMap(k).GetSlice("columns")
that.TableConfig = that.Config.GetMap("tables")
if that.TableConfig == nil {
that.TableConfig = Map{}
}
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") {