优化日志及config
This commit is contained in:
+71
-62
@@ -27,6 +27,7 @@ type MakeCode struct {
|
||||
|
||||
func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
isMake := false
|
||||
hasConfigFile := false
|
||||
idSlice := Slice{}
|
||||
that.FileConfig = config
|
||||
if that.TableColumns == nil {
|
||||
@@ -50,8 +51,11 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
that.Config[k] = v //程序配置
|
||||
//Config[k] = v //系统配置
|
||||
}
|
||||
hasConfigFile = true
|
||||
} else {
|
||||
|
||||
that.Error.SetError(errors.New("config配置文件不存在,或者配置出错,使用缺省默认配置"))
|
||||
|
||||
}
|
||||
//加载规则文件
|
||||
btesRule, errRule := ioutil.ReadFile(config.GetString("rule"))
|
||||
@@ -79,38 +83,38 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
that.Error.SetError(errors.New("rule配置文件不存在,或者配置出错,使用缺省默认配置"))
|
||||
}
|
||||
|
||||
that.IndexMenus = Map{}
|
||||
menusConfig := that.Config.GetSlice("menus")
|
||||
//将配置写入到内存中仅作为判断用
|
||||
if menusConfig != nil {
|
||||
for kmenu, _ := range menusConfig {
|
||||
menu := menusConfig.GetMap(kmenu)
|
||||
if menu != nil {
|
||||
mname := menu.GetString("table")
|
||||
if mname == "" { //如果为空则不是表格
|
||||
mname = menu.GetString("name")
|
||||
}
|
||||
that.IndexMenus[mname] = menu
|
||||
childMenus := menu.GetSlice("menus")
|
||||
if childMenus != nil {
|
||||
for ckmenu, _ := range childMenus {
|
||||
cmenu := childMenus.GetMap(ckmenu)
|
||||
if cmenu != nil {
|
||||
cname := cmenu.GetString("table")
|
||||
if cmenu.GetString("table") == "" {
|
||||
continue
|
||||
}
|
||||
that.IndexMenus[mname+"/"+cname] = cmenu
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//that.IndexMenus = Map{}
|
||||
//menusConfig := that.Config.GetSlice("menus")
|
||||
////将配置写入到内存中仅作为判断用
|
||||
//if menusConfig != nil {
|
||||
// for kmenu, _ := range menusConfig {
|
||||
// menu := menusConfig.GetMap(kmenu)
|
||||
// if menu != nil {
|
||||
// mname := menu.GetString("table")
|
||||
// if mname == "" { //如果为空则不是表格
|
||||
// mname = menu.GetString("name")
|
||||
// }
|
||||
// that.IndexMenus[mname] = menu
|
||||
// childMenus := menu.GetSlice("menus")
|
||||
// if childMenus != nil {
|
||||
// for ckmenu, _ := range childMenus {
|
||||
// cmenu := childMenus.GetMap(ckmenu)
|
||||
// if cmenu != nil {
|
||||
// cname := cmenu.GetString("table")
|
||||
// if cmenu.GetString("table") == "" {
|
||||
// continue
|
||||
// }
|
||||
// that.IndexMenus[mname+"/"+cname] = cmenu
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
||||
that.TableConfig = that.Config.GetMap("tables")
|
||||
if that.TableConfig == nil {
|
||||
@@ -352,34 +356,35 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
|
||||
//生成id,判断数据库是否有改变,以保证数据库和配置文件匹配唯一
|
||||
id := Md5(ObjToStr(idSlice))
|
||||
if id == that.Config.GetString("id") {
|
||||
if isMake { //有生成包文件
|
||||
fmt.Println("有新的业务代码生成,请重新运行")
|
||||
os.Exit(-1)
|
||||
}
|
||||
//if id == that.Config.GetString("id") {
|
||||
if isMake { //有生成包文件
|
||||
fmt.Println("有新的业务代码生成,请重新运行")
|
||||
os.Exit(-1)
|
||||
return
|
||||
}
|
||||
|
||||
//}
|
||||
//数据生成完后进一步解析
|
||||
for fk, fv := range that.TableColumns {
|
||||
|
||||
//判断是否将表写入menu中
|
||||
isMenusGet := false //判断是否被目录收录
|
||||
for indexKey, _ := range that.IndexMenus {
|
||||
indexCode := strings.Index(indexKey, fk)
|
||||
if indexCode == 0 || indexCode == 4 {
|
||||
isMenusGet = false
|
||||
continue
|
||||
}
|
||||
//如果相等或者表名在目录中已经设置(主要前一位是/并且他是最后一个字符串)
|
||||
if indexKey == fk || (indexCode != -1 && indexKey[indexCode-1] == '/' && indexKey[indexCode:] == fk) {
|
||||
isMenusGet = true
|
||||
break
|
||||
}
|
||||
}
|
||||
//isMenusGet := false //判断是否被目录收录
|
||||
//for indexKey, _ := range that.IndexMenus {
|
||||
// indexCode := strings.Index(indexKey, fk)
|
||||
// if indexCode == 0 || indexCode == 4 {
|
||||
// isMenusGet = false
|
||||
// continue
|
||||
// }
|
||||
// //如果相等或者表名在目录中已经设置(主要前一位是/并且他是最后一个字符串)
|
||||
// if indexKey == fk || (indexCode != -1 && indexKey[indexCode-1] == '/' && indexKey[indexCode:] == fk) {
|
||||
// isMenusGet = true
|
||||
// break
|
||||
// }
|
||||
//}
|
||||
|
||||
//目录没有收录
|
||||
if !isMenusGet {
|
||||
|
||||
//if !isMenusGet {
|
||||
if !hasConfigFile {
|
||||
tablePrefixCode := strings.Index(fk, "_")
|
||||
isNewPrefix := false //假定表名没有前缀
|
||||
prefixName := ""
|
||||
@@ -547,12 +552,12 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println(id, "---", that.Config.GetString("id"))
|
||||
that.Config["id"] = id
|
||||
//fmt.Println(id, "---", that.Config.GetString("id"))
|
||||
//that.Config["id"] = id
|
||||
|
||||
if config.GetInt("mode") != 0 {
|
||||
//init文件初始化
|
||||
myInit = strings.Replace(myInit, "{{id}}", id, -1)
|
||||
//myInit = strings.Replace(myInit, "{{id}}", id, -1)
|
||||
myInit = strings.Replace(myInit, "{{tablesCtr}}", ctrList, -1)
|
||||
_ = os.MkdirAll(config.GetString("name"), os.ModeDir)
|
||||
err = ioutil.WriteFile(config.GetString("name")+"/init.go", []byte(myInit), os.ModePerm)
|
||||
@@ -563,14 +568,18 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
|
||||
//写入配置文件
|
||||
//err = json.Indent(&configByte, []byte(that.Config.ToJsonString()), "", "\t")
|
||||
_ = os.MkdirAll(filepath.Dir(config.GetString("config")), os.ModeDir)
|
||||
err = ioutil.WriteFile(config.GetString("config"), []byte(that.Config.ToJsonString()), os.ModePerm)
|
||||
if err != nil {
|
||||
that.Error.SetError(err)
|
||||
}
|
||||
if !hasConfigFile {
|
||||
that.Config["id"] = id
|
||||
_ = os.MkdirAll(filepath.Dir(config.GetString("config")), os.ModeDir)
|
||||
err = ioutil.WriteFile(config.GetString("config"), []byte(that.Config.ToJsonString()), os.ModePerm)
|
||||
if err != nil {
|
||||
that.Error.SetError(err)
|
||||
}
|
||||
that.Logger.Warn("新建")
|
||||
|
||||
fmt.Println("有新的代码生成,请重新运行")
|
||||
os.Exit(-1)
|
||||
}
|
||||
//fmt.Println("有新的代码生成,请重新运行")
|
||||
//os.Exit(-1)
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user