Browse Source

优化auto

main
songzhibin97 4 years ago
parent
commit
8918012e4b
  1. 58
      server/service/sys_auto_code.go
  2. 5
      server/utils/file_operations.go

58
server/service/sys_auto_code.go

@ -149,34 +149,60 @@ func GetColumn(tableName string, dbName string) (err error, Columns []request.Co
return err, Columns return err, Columns
} }
//func addAutoMoveFile(data *tplData) {
// if strings.Contains(data.autoCodePath, "server") {
// if strings.Contains(data.autoCodePath, "router") {
// apiList := strings.Split(data.autoCodePath, "/")
// data.autoMoveFilePath = filepath.Join(apiList[len(apiList)-2], apiList[len(apiList)-1])
// } else if strings.Contains(data.autoCodePath, "api") {
// apiList := strings.Split(data.autoCodePath, "/")
// data.autoMoveFilePath = filepath.Join(apiList[len(apiList)-2], "v1", apiList[len(apiList)-1])
// } else if strings.Contains(data.autoCodePath, "service") {
// serviceList := strings.Split(data.autoCodePath, "/")
// data.autoMoveFilePath = filepath.Join(serviceList[len(serviceList)-2], serviceList[len(serviceList)-1])
// } else if strings.Contains(data.autoCodePath, "model") {
// modelList := strings.Split(data.autoCodePath, "/")
// data.autoMoveFilePath = filepath.Join(modelList[len(modelList)-2], modelList[len(modelList)-1])
// } else if strings.Contains(data.autoCodePath, "request") {
// requestList := strings.Split(data.autoCodePath, "/")
// data.autoMoveFilePath = filepath.Join("model", requestList[len(requestList)-2], requestList[len(requestList)-1])
// }
// } else if strings.Contains(data.autoCodePath, "web") {
// if strings.Contains(data.autoCodePath, "js") {
// jsList := strings.Split(data.autoCodePath, "/")
// data.autoMoveFilePath = filepath.Join("../", "web", "src", jsList[len(jsList)-2], jsList[len(jsList)-1])
// } else if strings.Contains(data.autoCodePath, "form") {
// formList := strings.Split(data.autoCodePath, "/")
// data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", formList[len(formList)-3], strings.Split(formList[len(formList)-1], ".")[0]+"From.vue")
// } else if strings.Contains(data.autoCodePath, "table") {
// vueList := strings.Split(data.autoCodePath, "/")
// data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", vueList[len(vueList)-3], vueList[len(vueList)-1])
// }
// }
//}
func addAutoMoveFile(data *tplData) { func addAutoMoveFile(data *tplData) {
dir := filepath.Dir(data.autoCodePath)
base := filepath.Base(data.autoCodePath)
if strings.Contains(data.autoCodePath, "server") { if strings.Contains(data.autoCodePath, "server") {
if strings.Contains(data.autoCodePath, "router") { if strings.Contains(data.autoCodePath, "router") {
apiList := strings.Split(data.autoCodePath, "/")
data.autoMoveFilePath = filepath.Join(apiList[len(apiList)-2], apiList[len(apiList)-1])
data.autoMoveFilePath = filepath.Join(dir, base)
} else if strings.Contains(data.autoCodePath, "api") { } else if strings.Contains(data.autoCodePath, "api") {
apiList := strings.Split(data.autoCodePath, "/")
data.autoMoveFilePath = filepath.Join(apiList[len(apiList)-2], "v1", apiList[len(apiList)-1])
data.autoMoveFilePath = filepath.Join(dir, "v1", base)
} else if strings.Contains(data.autoCodePath, "service") { } else if strings.Contains(data.autoCodePath, "service") {
serviceList := strings.Split(data.autoCodePath, "/")
data.autoMoveFilePath = filepath.Join(serviceList[len(serviceList)-2], serviceList[len(serviceList)-1])
data.autoMoveFilePath = filepath.Join(dir, base)
} else if strings.Contains(data.autoCodePath, "model") { } else if strings.Contains(data.autoCodePath, "model") {
modelList := strings.Split(data.autoCodePath, "/")
data.autoMoveFilePath = filepath.Join(modelList[len(modelList)-2], modelList[len(modelList)-1])
data.autoMoveFilePath = filepath.Join(dir, base)
} else if strings.Contains(data.autoCodePath, "request") { } else if strings.Contains(data.autoCodePath, "request") {
requestList := strings.Split(data.autoCodePath, "/")
data.autoMoveFilePath = filepath.Join("model", requestList[len(requestList)-2], requestList[len(requestList)-1])
data.autoMoveFilePath = filepath.Join("model", dir, base)
} }
} else if strings.Contains(data.autoCodePath, "web") { } else if strings.Contains(data.autoCodePath, "web") {
if strings.Contains(data.autoCodePath, "js") { if strings.Contains(data.autoCodePath, "js") {
jsList := strings.Split(data.autoCodePath, "/")
data.autoMoveFilePath = filepath.Join("../", "web", "src", jsList[len(jsList)-2], jsList[len(jsList)-1])
data.autoMoveFilePath = filepath.Join("../", "web", "src", dir, base)
} else if strings.Contains(data.autoCodePath, "form") { } else if strings.Contains(data.autoCodePath, "form") {
formList := strings.Split(data.autoCodePath, "/")
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", formList[len(formList)-3], strings.Split(formList[len(formList)-1], ".")[0]+"From.vue")
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Dir(dir), strings.TrimSuffix(base, filepath.Ext(base))+"From.vue")
} else if strings.Contains(data.autoCodePath, "table") { } else if strings.Contains(data.autoCodePath, "table") {
vueList := strings.Split(data.autoCodePath, "/")
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", vueList[len(vueList)-3], vueList[len(vueList)-1])
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Dir(dir), base)
} }
} }
} }

5
server/utils/file_operations.go

@ -21,10 +21,11 @@ func FileMove(src string, dst string) (err error) {
return err return err
} }
var revoke = false var revoke = false
dir := filepath.Dir(dst)
Redirect: Redirect:
_, err = os.Stat(filepath.Dir(dst))
_, err = os.Stat(dir)
if err != nil { if err != nil {
err = os.MkdirAll(filepath.Dir(dst), 0755)
err = os.MkdirAll(dir, 0755)
if err != nil { if err != nil {
return err return err
} }

Loading…
Cancel
Save