Skip to content

Commit 0227a66

Browse files
author
piexlmax
committed
自动化代码不同包结构体不再冲突
1 parent 5e26a38 commit 0227a66

File tree

3 files changed

+67
-64
lines changed

3 files changed

+67
-64
lines changed

server/model/system/sys_autocode_history.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
// SysAutoCodeHistory 自动迁移代码记录,用于回滚,重放使用
1212
type SysAutoCodeHistory struct {
1313
global.GVA_MODEL
14+
Package string `json:"package"`
1415
TableName string `json:"tableName"`
1516
RequestMeta string `gorm:"type:text" json:"requestMeta,omitempty"` // 前端传入的结构化信息
1617
AutoCodePath string `gorm:"type:text" json:"autoCodePath,omitempty"` // 其他meta信息 path;path

server/service/system/sys_auto_code.go

Lines changed: 62 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -49,65 +49,65 @@ var (
4949
)
5050

5151
func Init(Package string) {
52-
injectionPaths = []injectionMeta{
53-
{
54-
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
55-
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SInitialize, "gorm.go"),
56-
funcName: "MysqlTables",
57-
structNameF: Package + ".%s{},",
58-
},
59-
{
60-
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
61-
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SInitialize, "router.go"),
62-
funcName: "Routers",
63-
structNameF: Package + "Router.Init%sRouter(PrivateGroup)",
64-
},
65-
{
66-
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
67-
global.GVA_CONFIG.AutoCode.Server, fmt.Sprintf(global.GVA_CONFIG.AutoCode.SApi, Package), "enter.go"),
68-
funcName: "ApiGroup",
69-
structNameF: "%sApi",
70-
},
71-
{
72-
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
73-
global.GVA_CONFIG.AutoCode.Server, fmt.Sprintf(global.GVA_CONFIG.AutoCode.SRouter, Package), "enter.go"),
74-
funcName: "RouterGroup",
75-
structNameF: "%sRouter",
76-
},
77-
{
78-
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
79-
global.GVA_CONFIG.AutoCode.Server, fmt.Sprintf(global.GVA_CONFIG.AutoCode.SService, Package), "enter.go"),
80-
funcName: "ServiceGroup",
81-
structNameF: "%sService",
82-
},
83-
}
52+
injectionPaths = []injectionMeta{
53+
{
54+
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
55+
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SInitialize, "gorm.go"),
56+
funcName: "MysqlTables",
57+
structNameF: Package + ".%s{},",
58+
},
59+
{
60+
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
61+
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SInitialize, "router.go"),
62+
funcName: "Routers",
63+
structNameF: Package + "Router.Init%sRouter(PrivateGroup)",
64+
},
65+
{
66+
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
67+
global.GVA_CONFIG.AutoCode.Server, fmt.Sprintf(global.GVA_CONFIG.AutoCode.SApi, Package), "enter.go"),
68+
funcName: "ApiGroup",
69+
structNameF: "%sApi",
70+
},
71+
{
72+
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
73+
global.GVA_CONFIG.AutoCode.Server, fmt.Sprintf(global.GVA_CONFIG.AutoCode.SRouter, Package), "enter.go"),
74+
funcName: "RouterGroup",
75+
structNameF: "%sRouter",
76+
},
77+
{
78+
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
79+
global.GVA_CONFIG.AutoCode.Server, fmt.Sprintf(global.GVA_CONFIG.AutoCode.SService, Package), "enter.go"),
80+
funcName: "ServiceGroup",
81+
structNameF: "%sService",
82+
},
83+
}
8484

85-
packageInjectionMap = map[string]astInjectionMeta{
86-
packageServiceName: {
87-
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
88-
global.GVA_CONFIG.AutoCode.Server, "service", "enter.go"),
89-
importCodeF: "github.com/flipped-aurora/gin-vue-admin/server/%s/%s",
90-
packageNameF: "%s",
91-
groupName: "ServiceGroup",
92-
structNameF: "%sServiceGroup",
93-
},
94-
packageRouterName: {
95-
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
96-
global.GVA_CONFIG.AutoCode.Server, "router", "enter.go"),
97-
importCodeF: "github.com/flipped-aurora/gin-vue-admin/server/%s/%s",
98-
packageNameF: "%s",
99-
groupName: "RouterGroup",
100-
structNameF: "%s",
101-
},
102-
packageAPIName: {
103-
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
104-
global.GVA_CONFIG.AutoCode.Server, "api/v1", "enter.go"),
105-
importCodeF: "github.com/flipped-aurora/gin-vue-admin/server/%s/%s",
106-
packageNameF: "%s",
107-
groupName: "ApiGroup",
108-
structNameF: "%sApiGroup",
109-
},
110-
}
85+
packageInjectionMap = map[string]astInjectionMeta{
86+
packageServiceName: {
87+
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
88+
global.GVA_CONFIG.AutoCode.Server, "service", "enter.go"),
89+
importCodeF: "github.com/flipped-aurora/gin-vue-admin/server/%s/%s",
90+
packageNameF: "%s",
91+
groupName: "ServiceGroup",
92+
structNameF: "%sServiceGroup",
93+
},
94+
packageRouterName: {
95+
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
96+
global.GVA_CONFIG.AutoCode.Server, "router", "enter.go"),
97+
importCodeF: "github.com/flipped-aurora/gin-vue-admin/server/%s/%s",
98+
packageNameF: "%s",
99+
groupName: "RouterGroup",
100+
structNameF: "%s",
101+
},
102+
packageAPIName: {
103+
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
104+
global.GVA_CONFIG.AutoCode.Server, "api/v1", "enter.go"),
105+
importCodeF: "github.com/flipped-aurora/gin-vue-admin/server/%s/%s",
106+
packageNameF: "%s",
107+
groupName: "ApiGroup",
108+
structNameF: "%sApiGroup",
109+
},
110+
}
111111
}
112112

113113
type injectionMeta struct {
@@ -224,7 +224,7 @@ func makeDictTypes(autoCode *system.AutoCodeStruct) {
224224
func (autoCodeService *AutoCodeService) CreateTemp(autoCode system.AutoCodeStruct, ids ...uint) (err error) {
225225
makeDictTypes(&autoCode)
226226
// 增加判断: 重复创建struct
227-
if autoCode.AutoMoveFile && AutoCodeHistoryServiceApp.Repeat(autoCode.StructName) {
227+
if autoCode.AutoMoveFile && AutoCodeHistoryServiceApp.Repeat(autoCode.StructName, autoCode.Package) {
228228
return RepeatErr
229229
}
230230
dataList, fileList, needMkdir, err := autoCodeService.getNeedList(&autoCode)
@@ -312,6 +312,7 @@ func (autoCodeService *AutoCodeService) CreateTemp(autoCode system.AutoCodeStruc
312312
injectionCodeMeta.String(),
313313
autoCode.TableName,
314314
idBf.String(),
315+
autoCode.Package,
315316
)
316317
} else {
317318
err = AutoCodeHistoryServiceApp.CreateAutoCodeHistory(
@@ -322,6 +323,7 @@ func (autoCodeService *AutoCodeService) CreateTemp(autoCode system.AutoCodeStruc
322323
injectionCodeMeta.String(),
323324
autoCode.StructName,
324325
idBf.String(),
326+
autoCode.Package,
325327
)
326328
}
327329
}
@@ -565,7 +567,7 @@ func (autoCodeService *AutoCodeService) GetPackage() (pkgList []system.SysAutoCo
565567
return pkgList, err
566568
}
567569

568-
func (AutoCodeService *AutoCodeService) DelPackage(a system.SysAutoCode) error{
570+
func (AutoCodeService *AutoCodeService) DelPackage(a system.SysAutoCode) error {
569571
return global.GVA_DB.Delete(a).Error
570572
}
571573

@@ -787,4 +789,3 @@ func ImportReference(filepath, importCode, structName, packageName, groupName st
787789
// 写回数据
788790
return ioutil.WriteFile(filepath, buffer.Bytes(), 0o600)
789791
}
790-

server/service/system/sys_autocode_history.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ var AutoCodeHistoryServiceApp = new(AutoCodeHistoryService)
2727
// RouterPath : RouterPath@RouterString;RouterPath2@RouterString2
2828
// Author [SliverHorn](https://github.com/SliverHorn)
2929
// Author [songzhibin97](https://github.com/songzhibin97)
30-
func (autoCodeHistoryService *AutoCodeHistoryService) CreateAutoCodeHistory(meta, structName, structCNName, autoCodePath string, injectionMeta string, tableName string, apiIds string) error {
30+
func (autoCodeHistoryService *AutoCodeHistoryService) CreateAutoCodeHistory(meta, structName, structCNName, autoCodePath string, injectionMeta string, tableName string, apiIds string, Package string) error {
3131
return global.GVA_DB.Create(&system.SysAutoCodeHistory{
32+
Package: Package,
3233
RequestMeta: meta,
3334
AutoCodePath: autoCodePath,
3435
InjectionMeta: injectionMeta,
@@ -50,9 +51,9 @@ func (autoCodeHistoryService *AutoCodeHistoryService) First(info *request.GetByI
5051
// Repeat 检测重复
5152
// Author [SliverHorn](https://github.com/SliverHorn)
5253
// Author [songzhibin97](https://github.com/songzhibin97)
53-
func (autoCodeHistoryService *AutoCodeHistoryService) Repeat(structName string) bool {
54+
func (autoCodeHistoryService *AutoCodeHistoryService) Repeat(structName string, Package string) bool {
5455
var count int64
55-
global.GVA_DB.Model(&system.SysAutoCodeHistory{}).Where("struct_name = ? and flag = 0", structName).Count(&count)
56+
global.GVA_DB.Model(&system.SysAutoCodeHistory{}).Where("struct_name = ? and package = ? and flag = 0", structName, Package).Count(&count)
5657
return count > 0
5758
}
5859

0 commit comments

Comments
 (0)