diff --git a/console/commands/bean.go b/console/commands/bean.go index bda2316..d7b73dd 100644 --- a/console/commands/bean.go +++ b/console/commands/bean.go @@ -86,8 +86,8 @@ func (BeanCommand) Execute(input command.Input) { for _, goType := range fileParser.Types { for _, attr := range goType.Attrs { if attr.HasTag("inject") { - for _, impStr := range fileParser.Imports { - bc.imports[impStr] = impStr + for alias, impStr := range fileParser.Imports { + bc.imports[impStr] = alias } break @@ -105,7 +105,8 @@ func (BeanCommand) Execute(input command.Input) { } type beanCache struct { - name string + name string + // path => alias imports map[string]string structList []parser.GoType } @@ -210,14 +211,18 @@ func getInitializeNewFunName(k parser.GoTypeAttr, m map[string]string) string { if !k.InPackage { a := m[k.TypeImport] - alias = a + "." + if a == "" { + panic("识别到不明确的import, 最后一个目录和package名称不一致时,需要手动, 例如\nredis \"github.com/go-redis/redis/v8\"") + } else { + alias = a + "." + } arr := strings.Split(k.TypeName, ".") name = arr[len(arr)-1] } else if name[0:1] == "*" { name = name[1:] } tag := k.Tag["inject"] - if tag.Count() < 2 { + if tag == "" { return alias + genInitializeNewStr(name) + "()" } else { beanAlias := tag.Get(0) @@ -237,7 +242,7 @@ func getInitializeNewFunName(k parser.GoTypeAttr, m map[string]string) string { } beanValueNextVal := strings.Trim(beanValue[startTemp+1:], ")") got = got + ".GetBean(*" + providers + "GetBean(\"" + beanValueNextName + "\").(" + providers + "Bean).GetBean(\"" + beanValueNextVal + "\").(*string))" - } else if tag.Count() == 2 { + } else if tag.Count() <= 2 { got = got + ".GetBean(\"" + beanValue + "\")" } else if tag.Count() == 3 { beanValue = beanValue + ", " + tag.Get(2) diff --git a/console/commands/orm/mysql.go b/console/commands/orm/mysql.go index 03eb148..f9b3aa5 100644 --- a/console/commands/orm/mysql.go +++ b/console/commands/orm/mysql.go @@ -475,21 +475,26 @@ func Filter(tableColumns map[string][]tableColumn) TableInfo { Columns: make(map[string][]tableColumn), Infos: make(map[string]TableInfos), } - + tableSort := make(map[string]int) for tableName, columns := range tableColumns { arr := strings.Split(tableName, "_") arrLen := len(arr) if arrLen > 1 { str := arr[arrLen-1] - _, err := strconv.Atoi(str) + tn, err := strconv.Atoi(str) if err == nil { tableName = strings.ReplaceAll(tableName, "_"+str, "") info.Infos[tableName] = TableInfos{ "sub": "true", // 分表 } + // 保留数字最大的 + n, ok := tableSort[tableName] + if ok && n > tn { + continue + } + tableSort[tableName] = tn } } - info.Columns[tableName] = columns } return info diff --git a/console/commands/route.go b/console/commands/route.go index 39a71f0..1194ff5 100644 --- a/console/commands/route.go +++ b/console/commands/route.go @@ -194,7 +194,7 @@ func (RouteCommand) Execute(input command.Input) { if group != "" { g := agl[group] - imports := module + "/app/http/" + fileParser.PackageName + "/" + parser.StringToSnake(service.Name) + imports := strings.Replace(outHttp, getRootPath(), module, 1) + "/" + fileParser.PackageName + "/" + parser.StringToSnake(service.Name) g.imports[imports] = imports g.controllers = append(g.controllers, Controller{ diff --git a/parser/go.go b/parser/go.go index ad81c9d..8a88709 100644 --- a/parser/go.go +++ b/parser/go.go @@ -227,6 +227,9 @@ type TagDoc string func (t TagDoc) Get(num int) string { s := string(t) sr := strings.Split(s, ",") + if len(sr) <= num { + return "" + } return strings.Trim(sr[num], " ") } diff --git a/parser/help_str.go b/parser/help_str.go index 2df4a24..665f49f 100644 --- a/parser/help_str.go +++ b/parser/help_str.go @@ -450,16 +450,20 @@ func GetImportStrForMap(m map[string]string) string { func GenImportAlias(path, packageName string, m map[string]string) map[string]string { aliasMapImport := make(map[string]string) importMapAlias := make(map[string]string) + importCheck := make(map[string]map[string]bool) keys := make([]string, 0) for s, _ := range m { keys = append(keys, s) } sort.Strings(keys) - for _, k := range keys { - imp := m[k] - temp := strings.Split(imp, "/") - key := temp[len(temp)-1] + for _, imp := range keys { + key := m[imp] + + temp := strings.Split(key, "/") + if len(temp) != 1 { + key = temp[len(temp)-1] + } if _, ok := aliasMapImport[key]; ok { for i := 1; i < 1000; i++ { @@ -471,8 +475,14 @@ func GenImportAlias(path, packageName string, m map[string]string) map[string]st } } if key == packageName { - if "/bootstrap/providers" != path { - aliasMapImport[key+"_2"] = imp + kk := len(importCheck[key]) + if kk == 0 { + importCheck[key] = map[string]bool{} + } + kkk := key + "_" + strconv.Itoa(kk) + if "/bootstrap/providers" != path && !importCheck[key][kkk] { + aliasMapImport[kkk] = imp + importCheck[key][kkk] = true } } else { aliasMapImport[key] = imp