From 89a40b3165de28474512ca71ef9b994327cdf09d Mon Sep 17 00:00:00 2001 From: yuanzhao <2206582181@qq.com> Date: Wed, 17 May 2023 16:10:16 +0800 Subject: [PATCH 1/6] =?UTF-8?q?add:=20=E5=85=81=E8=AE=B8=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89http=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- console/commands/route.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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{ From bf0c2cd73822612f47c329bfc83d4045312da60b Mon Sep 17 00:00:00 2001 From: yuanzhao <2206582181@qq.com> Date: Wed, 17 May 2023 16:39:11 +0800 Subject: [PATCH 2/6] =?UTF-8?q?add:=20=E5=88=86=E8=A1=A8=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E6=95=B0=E5=AD=97=E6=9C=80=E5=A4=A7=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- console/commands/orm/mysql.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/console/commands/orm/mysql.go b/console/commands/orm/mysql.go index 62e68de..1ae2a45 100644 --- a/console/commands/orm/mysql.go +++ b/console/commands/orm/mysql.go @@ -473,21 +473,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 From db6d0c3efd5edb126011dc917a6e93c87cba40a2 Mon Sep 17 00:00:00 2001 From: yuanzhao <2206582181@qq.com> Date: Mon, 29 May 2023 20:21:58 +0800 Subject: [PATCH 3/6] =?UTF-8?q?add:=20=E8=AE=A1=E7=AE=97=E5=BC=95=E5=85=A5?= =?UTF-8?q?=E5=88=AB=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parser/help_str.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/parser/help_str.go b/parser/help_str.go index 2df4a24..12b31cd 100644 --- a/parser/help_str.go +++ b/parser/help_str.go @@ -450,6 +450,7 @@ 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][]string) keys := make([]string, 0) for s, _ := range m { @@ -471,8 +472,14 @@ func GenImportAlias(path, packageName string, m map[string]string) map[string]st } } if key == packageName { + kk := len(importCheck[key]) + if kk == 0 { + importCheck[key] = []string{} + } if "/bootstrap/providers" != path { - aliasMapImport[key+"_2"] = imp + kkk := key + "_" + strconv.Itoa(kk) + aliasMapImport[kkk] = imp + importCheck[key] = append(importCheck[key], kkk) } } else { aliasMapImport[key] = imp From 160d7f0f7e0ccc45f032db11e7c1d8a4820c4263 Mon Sep 17 00:00:00 2001 From: yuanzhao <2206582181@qq.com> Date: Mon, 29 May 2023 20:23:54 +0800 Subject: [PATCH 4/6] =?UTF-8?q?add:=20=E8=AE=A1=E7=AE=97=E5=BC=95=E5=85=A5?= =?UTF-8?q?=E5=88=AB=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parser/help_str.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/parser/help_str.go b/parser/help_str.go index 12b31cd..9d149a9 100644 --- a/parser/help_str.go +++ b/parser/help_str.go @@ -450,7 +450,7 @@ 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][]string) + importCheck := make(map[string]map[string]bool) keys := make([]string, 0) for s, _ := range m { @@ -474,12 +474,12 @@ func GenImportAlias(path, packageName string, m map[string]string) map[string]st if key == packageName { kk := len(importCheck[key]) if kk == 0 { - importCheck[key] = []string{} + importCheck[key] = map[string]bool{} } - if "/bootstrap/providers" != path { - kkk := key + "_" + strconv.Itoa(kk) + kkk := key + "_" + strconv.Itoa(kk) + if "/bootstrap/providers" != path && !importCheck[key][kkk] { aliasMapImport[kkk] = imp - importCheck[key] = append(importCheck[key], kkk) + importCheck[key][kkk] = true } } else { aliasMapImport[key] = imp From ddee9662318f453c4a01259761045cdf92fc5a45 Mon Sep 17 00:00:00 2001 From: yuanzhao <2206582181@qq.com> Date: Tue, 30 May 2023 10:17:19 +0800 Subject: [PATCH 5/6] =?UTF-8?q?add:=20=E4=BF=AE=E5=A4=8D=E6=B3=A8=E5=85=A5?= =?UTF-8?q?=E5=88=AB=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- console/commands/bean.go | 4 ++-- parser/go.go | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/console/commands/bean.go b/console/commands/bean.go index bda2316..51d9949 100644 --- a/console/commands/bean.go +++ b/console/commands/bean.go @@ -217,7 +217,7 @@ func getInitializeNewFunName(k parser.GoTypeAttr, m map[string]string) string { name = name[1:] } tag := k.Tag["inject"] - if tag.Count() < 2 { + if tag == "" { return alias + genInitializeNewStr(name) + "()" } else { beanAlias := tag.Get(0) @@ -237,7 +237,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/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], " ") } From ae8847565ee4e3b7068f6df31da9d792d3868806 Mon Sep 17 00:00:00 2001 From: yuanzhao <2206582181@qq.com> Date: Thu, 1 Jun 2023 14:56:53 +0800 Subject: [PATCH 6/6] =?UTF-8?q?add:=20=E8=AF=86=E5=88=AB=E5=88=B0=E4=B8=8D?= =?UTF-8?q?=E6=98=8E=E7=A1=AE=E7=9A=84import,=20=E6=9C=80=E5=90=8E?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E7=9B=AE=E5=BD=95=E5=92=8Cpackage=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E4=B8=8D=E4=B8=80=E8=87=B4=E6=97=B6=EF=BC=8C=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E6=89=8B=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- console/commands/bean.go | 13 +++++++++---- parser/help_str.go | 11 +++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/console/commands/bean.go b/console/commands/bean.go index 51d9949..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,7 +211,11 @@ 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] == "*" { diff --git a/parser/help_str.go b/parser/help_str.go index 9d149a9..665f49f 100644 --- a/parser/help_str.go +++ b/parser/help_str.go @@ -457,10 +457,13 @@ func GenImportAlias(path, packageName string, m map[string]string) map[string]st 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++ {