Skip to content

Commit c91dcf2

Browse files
author
奇淼(piexlmax
authored
Merge pull request flipped-aurora#397 from songzhibin97/gva_gormv2_dev
代码自动迁移动态适配
2 parents b737b6c + 1cf61a6 commit c91dcf2

File tree

5 files changed

+59
-18
lines changed

5 files changed

+59
-18
lines changed

server/config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ mysql:
6464
log-mode: false
6565
log-zap: ""
6666

67+
autoCode:
68+
root: ''
69+
server: '/server'
70+
server-api: '/api/v1'
71+
server-model: '/model'
72+
server-request: '/model/request/'
73+
server-router: '/router'
74+
server-service: '/service'
75+
76+
web: '/web/src'
77+
web-api: '/api'
78+
web-form: '/view'
79+
web-table: '/view'
80+
web-flow: '/view'
81+
6782
# local configuration
6883
local:
6984
path: 'uploads/file'

server/config/auto_code.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package config
2+
3+
type Autocode struct {
4+
Root string `mapstructure:"root" json:"root" yaml:"root"`
5+
Server string `mapstructure:"server" json:"server" yaml:"server"`
6+
SApi string `mapstructure:"server-api" json:"serverApi" yaml:"server-api"`
7+
SModel string `mapstructure:"server-model" json:"serverModel" yaml:"server-model"`
8+
SRequest string `mapstructure:"server-request" json:"serverRequest" yaml:"server-request"`
9+
SRouter string `mapstructure:"server-router" json:"serverRouter" yaml:"server-router"`
10+
SService string `mapstructure:"server-service" json:"serverService" yaml:"server-service"`
11+
Web string `mapstructure:"web" json:"web" yaml:"web"`
12+
WApi string `mapstructure:"web-api" json:"webApi" yaml:"web-api"`
13+
WForm string `mapstructure:"web-form" json:"webForm" yaml:"web-form"`
14+
WTable string `mapstructure:"web-table" json:"webTable" yaml:"web-table"`
15+
WFlow string `mapstructure:"web-flow" json:"webFlow" yaml:"web-flow"`
16+
}

server/config/config.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ type Server struct {
88
Casbin Casbin `mapstructure:"casbin" json:"casbin" yaml:"casbin"`
99
System System `mapstructure:"system" json:"system" yaml:"system"`
1010
Captcha Captcha `mapstructure:"captcha" json:"captcha" yaml:"captcha"`
11+
// aoto
12+
AutoCode Autocode `mapstructure:"autoCode" json:"autoCode" yaml:"autoCode"`
1113
// gorm
1214
Mysql Mysql `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
1315
// oss
14-
Local Local `mapstructure:"local" json:"local" yaml:"local"`
15-
Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
16-
AliyunOSS AliyunOSS `mapstructure:"aliyun-oss" json:"aliyunOSS" yaml:"aliyun-oss"`
16+
Local Local `mapstructure:"local" json:"local" yaml:"local"`
17+
Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
18+
AliyunOSS AliyunOSS `mapstructure:"aliyun-oss" json:"aliyunOSS" yaml:"aliyun-oss"`
1719
TencentCOS TencentCOS `mapstructure:"tencent-cos" json:"tencentCOS" yaml:"tencent-cos"`
18-
Excel Excel `mapstructure:"excel" json:"excel" yaml:"excel"`
20+
Excel Excel `mapstructure:"excel" json:"excel" yaml:"excel"`
1921
}

server/core/viper.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import (
66
"gin-vue-admin/global"
77
_ "gin-vue-admin/packfile"
88
"gin-vue-admin/utils"
9+
"os"
10+
"path/filepath"
11+
912
"github.com/fsnotify/fsnotify"
1013
"github.com/spf13/viper"
11-
"os"
1214
)
1315

1416
func Viper(path ...string) *viper.Viper {
@@ -46,9 +48,9 @@ func Viper(path ...string) *viper.Viper {
4648
fmt.Println(err)
4749
}
4850
})
49-
5051
if err := v.Unmarshal(&global.GVA_CONFIG); err != nil {
5152
fmt.Println(err)
5253
}
54+
global.GVA_CONFIG.AutoCode.Root, _ = filepath.Abs("..")
5355
return v
5456
}

server/service/sys_auto_code.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package service
22

33
import (
44
"errors"
5-
"fmt"
65
"gin-vue-admin/global"
76
"gin-vue-admin/model"
87
"gin-vue-admin/model/request"
@@ -132,7 +131,6 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) {
132131
}
133132
for _, value := range dataList { // 移动文件
134133
if err := utils.FileMove(value.autoCodePath, value.autoMoveFilePath); err != nil {
135-
fmt.Println(err)
136134
return err
137135
}
138136
}
@@ -212,7 +210,6 @@ func GetColumn(tableName string, dbName string) (err error, Columns []request.Co
212210
//@return: null
213211

214212
func addAutoMoveFile(data *tplData) {
215-
dir := filepath.Base(filepath.Dir(data.autoCodePath))
216213
base := filepath.Base(data.autoCodePath)
217214
fileSlice := strings.Split(data.autoCodePath, string(os.PathSeparator))
218215
n := len(fileSlice)
@@ -221,25 +218,34 @@ func addAutoMoveFile(data *tplData) {
221218
}
222219
if strings.Contains(fileSlice[1], "server") {
223220
if strings.Contains(fileSlice[n-2], "router") {
224-
data.autoMoveFilePath = filepath.Join(dir, base)
221+
data.autoMoveFilePath = filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server,
222+
global.GVA_CONFIG.AutoCode.SRouter, base)
225223
} else if strings.Contains(fileSlice[n-2], "api") {
226-
data.autoMoveFilePath = filepath.Join(dir, "v1", base)
224+
data.autoMoveFilePath = filepath.Join(global.GVA_CONFIG.AutoCode.Root,
225+
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SApi, base)
227226
} else if strings.Contains(fileSlice[n-2], "service") {
228-
data.autoMoveFilePath = filepath.Join(dir, base)
227+
data.autoMoveFilePath = filepath.Join(global.GVA_CONFIG.AutoCode.Root,
228+
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SService, base)
229229
} else if strings.Contains(fileSlice[n-2], "model") {
230-
data.autoMoveFilePath = filepath.Join(dir, base)
230+
data.autoMoveFilePath = filepath.Join(global.GVA_CONFIG.AutoCode.Root,
231+
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SModel, base)
231232
} else if strings.Contains(fileSlice[n-2], "request") {
232-
data.autoMoveFilePath = filepath.Join("model", dir, base)
233+
data.autoMoveFilePath = filepath.Join(global.GVA_CONFIG.AutoCode.Root,
234+
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SRequest, base)
233235
}
234236
} else if strings.Contains(fileSlice[1], "web") {
235237
if strings.Contains(fileSlice[n-1], "js") {
236-
data.autoMoveFilePath = filepath.Join("../", "web", "src", dir, base)
238+
data.autoMoveFilePath = filepath.Join(global.GVA_CONFIG.AutoCode.Root,
239+
global.GVA_CONFIG.AutoCode.Web, global.GVA_CONFIG.AutoCode.WApi, base)
237240
} else if strings.Contains(fileSlice[n-2], "workflowForm") {
238-
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), strings.TrimSuffix(base, filepath.Ext(base))+"WorkflowForm.vue")
241+
data.autoMoveFilePath = filepath.Join(global.GVA_CONFIG.AutoCode.Root,
242+
global.GVA_CONFIG.AutoCode.Web, global.GVA_CONFIG.AutoCode.WFlow, filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), strings.TrimSuffix(base, filepath.Ext(base))+"WorkflowForm.vue")
239243
} else if strings.Contains(fileSlice[n-2], "form") {
240-
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), strings.TrimSuffix(base, filepath.Ext(base))+"Form.vue")
244+
data.autoMoveFilePath = filepath.Join(global.GVA_CONFIG.AutoCode.Root,
245+
global.GVA_CONFIG.AutoCode.Web, global.GVA_CONFIG.AutoCode.WForm, filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), strings.TrimSuffix(base, filepath.Ext(base))+"Form.vue")
241246
} else if strings.Contains(fileSlice[n-2], "table") {
242-
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), base)
247+
data.autoMoveFilePath = filepath.Join(global.GVA_CONFIG.AutoCode.Root,
248+
global.GVA_CONFIG.AutoCode.Web, global.GVA_CONFIG.AutoCode.WTable, filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), base)
243249
}
244250
}
245251
}

0 commit comments

Comments
 (0)