Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
zodial committed Jun 16, 2023
2 parents 081a0cf + ae88475 commit 100a438
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
17 changes: 11 additions & 6 deletions console/commands/bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions console/commands/orm/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion console/commands/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
3 changes: 3 additions & 0 deletions parser/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -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], " ")
}

Expand Down
22 changes: 16 additions & 6 deletions parser/help_str.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand All @@ -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
Expand Down

0 comments on commit 100a438

Please sign in to comment.