|
@ -7,12 +7,13 @@ import ( |
|
|
"gin-vue-admin/model" |
|
|
"gin-vue-admin/model" |
|
|
"gin-vue-admin/model/request" |
|
|
"gin-vue-admin/model/request" |
|
|
"gin-vue-admin/utils" |
|
|
"gin-vue-admin/utils" |
|
|
"gorm.io/gorm" |
|
|
|
|
|
"io/ioutil" |
|
|
"io/ioutil" |
|
|
"os" |
|
|
"os" |
|
|
"path/filepath" |
|
|
"path/filepath" |
|
|
"strings" |
|
|
"strings" |
|
|
"text/template" |
|
|
"text/template" |
|
|
|
|
|
|
|
|
|
|
|
"gorm.io/gorm" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type tplData struct { |
|
|
type tplData struct { |
|
@ -65,12 +66,12 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) { |
|
|
origFileName := strings.TrimSuffix(trimBase[lastSeparator+1:], ".tpl") |
|
|
origFileName := strings.TrimSuffix(trimBase[lastSeparator+1:], ".tpl") |
|
|
firstDot := strings.Index(origFileName, ".") |
|
|
firstDot := strings.Index(origFileName, ".") |
|
|
if firstDot != -1 { |
|
|
if firstDot != -1 { |
|
|
dataList[index].autoCodePath = autoPath + trimBase[:lastSeparator] + "/" + autoCode.PackageName + "/" + |
|
|
|
|
|
origFileName[:firstDot] + "/" + autoCode.PackageName + origFileName[firstDot:] |
|
|
|
|
|
|
|
|
dataList[index].autoCodePath = filepath.Join(autoPath, trimBase[:lastSeparator], autoCode.PackageName, |
|
|
|
|
|
origFileName[:firstDot], autoCode.PackageName+origFileName[firstDot:]) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if lastSeparator := strings.LastIndex(dataList[index].autoCodePath, "/"); lastSeparator != -1 { |
|
|
|
|
|
|
|
|
if lastSeparator := strings.LastIndex(dataList[index].autoCodePath, string(os.PathSeparator)); lastSeparator != -1 { |
|
|
needMkdir = append(needMkdir, dataList[index].autoCodePath[:lastSeparator]) |
|
|
needMkdir = append(needMkdir, dataList[index].autoCodePath[:lastSeparator]) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -186,26 +187,31 @@ func GetColumn(tableName string, dbName string) (err error, Columns []request.Co |
|
|
func addAutoMoveFile(data *tplData) { |
|
|
func addAutoMoveFile(data *tplData) { |
|
|
dir := filepath.Base(filepath.Dir(data.autoCodePath)) |
|
|
dir := filepath.Base(filepath.Dir(data.autoCodePath)) |
|
|
base := filepath.Base(data.autoCodePath) |
|
|
base := filepath.Base(data.autoCodePath) |
|
|
if strings.Contains(data.autoCodePath, "server") { |
|
|
|
|
|
if strings.Contains(data.autoCodePath, "router") { |
|
|
|
|
|
|
|
|
fileSlice := strings.Split(data.autoCodePath, string(os.PathSeparator)) |
|
|
|
|
|
n := len(fileSlice) |
|
|
|
|
|
if n <= 2 { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
if strings.Contains(fileSlice[1], "server") { |
|
|
|
|
|
if strings.Contains(fileSlice[n-2], "router") { |
|
|
data.autoMoveFilePath = filepath.Join(dir, base) |
|
|
data.autoMoveFilePath = filepath.Join(dir, base) |
|
|
} else if strings.Contains(data.autoCodePath, "api") { |
|
|
|
|
|
|
|
|
} else if strings.Contains(fileSlice[n-2], "api") { |
|
|
data.autoMoveFilePath = filepath.Join(dir, "v1", base) |
|
|
data.autoMoveFilePath = filepath.Join(dir, "v1", base) |
|
|
} else if strings.Contains(data.autoCodePath, "service") { |
|
|
|
|
|
|
|
|
} else if strings.Contains(fileSlice[n-2], "service") { |
|
|
data.autoMoveFilePath = filepath.Join(dir, base) |
|
|
data.autoMoveFilePath = filepath.Join(dir, base) |
|
|
} else if strings.Contains(data.autoCodePath, "model") { |
|
|
|
|
|
|
|
|
} else if strings.Contains(fileSlice[n-2], "model") { |
|
|
data.autoMoveFilePath = filepath.Join(dir, base) |
|
|
data.autoMoveFilePath = filepath.Join(dir, base) |
|
|
} else if strings.Contains(data.autoCodePath, "request") { |
|
|
|
|
|
|
|
|
} else if strings.Contains(fileSlice[n-2], "request") { |
|
|
data.autoMoveFilePath = filepath.Join("model", dir, base) |
|
|
data.autoMoveFilePath = filepath.Join("model", dir, base) |
|
|
} |
|
|
} |
|
|
} else if strings.Contains(data.autoCodePath, "web") { |
|
|
|
|
|
if strings.Contains(data.autoCodePath, "js") { |
|
|
|
|
|
|
|
|
} else if strings.Contains(fileSlice[1], "web") { |
|
|
|
|
|
if strings.Contains(fileSlice[n-1], "js") { |
|
|
data.autoMoveFilePath = filepath.Join("../", "web", "src", dir, base) |
|
|
data.autoMoveFilePath = filepath.Join("../", "web", "src", dir, base) |
|
|
} else if strings.Contains(data.autoCodePath, "workflowForm") { |
|
|
|
|
|
|
|
|
} else if strings.Contains(fileSlice[n-2], "workflowForm") { |
|
|
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), strings.TrimSuffix(base, filepath.Ext(base))+"WorkflowForm.vue") |
|
|
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), strings.TrimSuffix(base, filepath.Ext(base))+"WorkflowForm.vue") |
|
|
} else if strings.Contains(data.autoCodePath, "form") { |
|
|
|
|
|
|
|
|
} else if strings.Contains(fileSlice[n-2], "form") { |
|
|
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), strings.TrimSuffix(base, filepath.Ext(base))+"Form.vue") |
|
|
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), strings.TrimSuffix(base, filepath.Ext(base))+"Form.vue") |
|
|
} else if strings.Contains(data.autoCodePath, "table") { |
|
|
|
|
|
|
|
|
} else if strings.Contains(fileSlice[n-2], "table") { |
|
|
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), base) |
|
|
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), base) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|