From 8918012e4bdb950f9eccec36077918a8b1ed10b8 Mon Sep 17 00:00:00 2001 From: songzhibin97 <718428482@qq.com> Date: Sun, 8 Nov 2020 07:52:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96auto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/service/sys_auto_code.go | 58 ++++++++++++++++++++++++--------- server/utils/file_operations.go | 5 +-- 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/server/service/sys_auto_code.go b/server/service/sys_auto_code.go index 04a5047e..6888deb2 100644 --- a/server/service/sys_auto_code.go +++ b/server/service/sys_auto_code.go @@ -149,34 +149,60 @@ func GetColumn(tableName string, dbName string) (err error, Columns []request.Co 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) { + dir := filepath.Dir(data.autoCodePath) + base := filepath.Base(data.autoCodePath) 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]) + data.autoMoveFilePath = filepath.Join(dir, base) } 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") { - 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") { - 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") { - 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") { 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") { - 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") { - 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) } } } diff --git a/server/utils/file_operations.go b/server/utils/file_operations.go index 9eb99232..39f71d59 100644 --- a/server/utils/file_operations.go +++ b/server/utils/file_operations.go @@ -21,10 +21,11 @@ func FileMove(src string, dst string) (err error) { return err } var revoke = false + dir := filepath.Dir(dst) Redirect: - _, err = os.Stat(filepath.Dir(dst)) + _, err = os.Stat(dir) if err != nil { - err = os.MkdirAll(filepath.Dir(dst), 0755) + err = os.MkdirAll(dir, 0755) if err != nil { return err }