Skip to content

Commit 6e4dc10

Browse files
pixelmaxQmzayn-codeSliverHornkrank666cjk
authored
文件结构调整,支持插件自动化 (#1824)
* Update index.vue 多个详情页之间切换tab,页面没有重新渲染 * feature:新增同步API功能 * feature: 同步表数据 * feature:新增同步API功能 * feature: 增加V2插件注册 * feature:给Enter的依赖结构增加单独的New 方便引用 * feature: 调整关联属性的选择模式 * feature: 增加component组件和name的映射插件,防止keepalive的懒加载失效。 * update: PluginInitializeRouter && 修复TypePluginInitializeMenu ast 类型错误 * update: 测试文件的astType 类型错误 * feature: 文件变更自动同步componentName.json。 * feature: 文件变更自动同步componentName.json。 * feat: UI美化 * feat: 自动化页面顺序调整 * feature:修改404页面 * update: PluginInitializeMenu * update: Plugin template * fixed systemApi 重复声明 * api.vue:update:修改API分组为下拉列表 * update: import添加注释 * update: plugin_enter_test.go 增加测试用例 * update: ast 预览文件路径 * update: config Autocode 新增Module字段以及如果为空的情况下自动获取运行目录下的go.mod文件 * update: auto_code_package.go 完善调用ast工具类的封装使用 * update: auto_code_template.go Create方法和修正SysAutoCodeHistory * feat:调整自动化package为模板,增加初始化配置信息,调整页面信息。 * update: ast PreviewPath MkdirAll * update: ast type错误, PluginEnter and PackageModuleEnter add TemplatePath模版路径 * update: autoCodePackage and autoCodeTemplate bug修正 * update: PackageInitializeRouter 传入两个路由组 * update: PackageModuleEnter 处理空变量时与type冲突注入 * update: Package 模版更新 * update: utils/ast 优化统一 * update: 注入内容修复错误 * fix: 修复注释错误 * update: plugin 模版 完成 * feature: 文件watch功能只在development下开启 * update: viper.go.template 因为viper不区分配置的key的大小写所以用package * update: ast 测试代码规范化 * update: package 删除api和router多余导包 * update: plugin template * update: auto_code_package 问题修复 * update: ast 测试插件的预览功能 * update: gorm_biz 更新注册方式 * update: go.mod tidy * remove: plugin template gen main.go.template * update: ast 重构, 分离读取和写入步骤支持 * update: AutoCodePackageApi 传入参数错误修复 * rename: sys_autocode_history.go => sys_auto_code_history.go * update: 预览无需落盘, 创建落盘,抽离公共参数 * update: api.go.tpl 导包位置fmt 和package js位置存放错误 * update: 测试用例修复 and PackageInitializeGorm 重构 * update: ast 新增相对路径, 代码生成器历史回滚功能 * update: ast 工具类回滚失败修复以及测试文件 * update: 代码生成器历史 回滚问题修复 * update: 代码生成器模版忽略.DS_Store * featute: 自动化GORM结构的注入和剔除 * feature: 插件模板调整 * feature: 增加公告插件示例,调整代码模板。 * feature: 自动注册插件V2。 --------- Co-authored-by: zayn <[email protected]> Co-authored-by: SliverHorn <[email protected]> Co-authored-by: krank <[email protected]> Co-authored-by: cjk <[email protected]> Co-authored-by: piexlMax(奇淼 <[email protected]> Co-authored-by: maxwell <[email protected]>
1 parent 6b3a902 commit 6e4dc10

File tree

193 files changed

+9409
-2903
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+9409
-2903
lines changed

Diff for: server/api/v1/enter.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/system"
66
)
77

8+
var ApiGroupApp = new(ApiGroup)
9+
810
type ApiGroup struct {
911
SystemApiGroup system.ApiGroup
1012
ExampleApiGroup example.ApiGroup
1113
}
12-
13-
var ApiGroupApp = new(ApiGroup)

Diff for: server/api/v1/system/sys_auto_code_history.go renamed to server/api/v1/system/auto_code_history.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package system
22

33
import (
44
"github.com/flipped-aurora/gin-vue-admin/server/global"
5-
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
5+
common "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
66
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
7-
systemReq "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
7+
request "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
88
"github.com/gin-gonic/gin"
99
"go.uber.org/zap"
1010
)
@@ -21,13 +21,13 @@ type AutoCodeHistoryApi struct{}
2121
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取meta信息"
2222
// @Router /autoCode/getMeta [post]
2323
func (a *AutoCodeHistoryApi) First(c *gin.Context) {
24-
var info request.GetById
24+
var info common.GetById
2525
err := c.ShouldBindJSON(&info)
2626
if err != nil {
2727
response.FailWithMessage(err.Error(), c)
2828
return
2929
}
30-
data, err := autoCodeHistoryService.First(&info)
30+
data, err := autoCodeHistoryService.First(c.Request.Context(), info)
3131
if err != nil {
3232
response.FailWithMessage(err.Error(), c)
3333
return
@@ -45,13 +45,13 @@ func (a *AutoCodeHistoryApi) First(c *gin.Context) {
4545
// @Success 200 {object} response.Response{msg=string} "删除回滚记录"
4646
// @Router /autoCode/delSysHistory [post]
4747
func (a *AutoCodeHistoryApi) Delete(c *gin.Context) {
48-
var info request.GetById
48+
var info common.GetById
4949
err := c.ShouldBindJSON(&info)
5050
if err != nil {
5151
response.FailWithMessage(err.Error(), c)
5252
return
5353
}
54-
err = autoCodeHistoryService.Delete(&info)
54+
err = autoCodeHistoryService.Delete(c.Request.Context(), info)
5555
if err != nil {
5656
global.GVA_LOG.Error("删除失败!", zap.Error(err))
5757
response.FailWithMessage("删除失败", c)
@@ -70,13 +70,13 @@ func (a *AutoCodeHistoryApi) Delete(c *gin.Context) {
7070
// @Success 200 {object} response.Response{msg=string} "回滚自动生成代码"
7171
// @Router /autoCode/rollback [post]
7272
func (a *AutoCodeHistoryApi) RollBack(c *gin.Context) {
73-
var info systemReq.RollBack
73+
var info request.SysAutoHistoryRollBack
7474
err := c.ShouldBindJSON(&info)
7575
if err != nil {
7676
response.FailWithMessage(err.Error(), c)
7777
return
7878
}
79-
err = autoCodeHistoryService.RollBack(&info)
79+
err = autoCodeHistoryService.RollBack(c.Request.Context(), info)
8080
if err != nil {
8181
response.FailWithMessage(err.Error(), c)
8282
return
@@ -94,13 +94,13 @@ func (a *AutoCodeHistoryApi) RollBack(c *gin.Context) {
9494
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "查询回滚记录,返回包括列表,总数,页码,每页数量"
9595
// @Router /autoCode/getSysHistory [post]
9696
func (a *AutoCodeHistoryApi) GetList(c *gin.Context) {
97-
var search systemReq.SysAutoHistory
98-
err := c.ShouldBindJSON(&search)
97+
var info common.PageInfo
98+
err := c.ShouldBindJSON(&info)
9999
if err != nil {
100100
response.FailWithMessage(err.Error(), c)
101101
return
102102
}
103-
list, total, err := autoCodeHistoryService.GetList(search.PageInfo)
103+
list, total, err := autoCodeHistoryService.GetList(c.Request.Context(), info)
104104
if err != nil {
105105
global.GVA_LOG.Error("获取失败!", zap.Error(err))
106106
response.FailWithMessage("获取失败", c)
@@ -109,7 +109,7 @@ func (a *AutoCodeHistoryApi) GetList(c *gin.Context) {
109109
response.OkWithDetailed(response.PageResult{
110110
List: list,
111111
Total: total,
112-
Page: search.Page,
113-
PageSize: search.PageSize,
112+
Page: info.Page,
113+
PageSize: info.PageSize,
114114
}, "获取成功", c)
115115
}

Diff for: server/api/v1/system/auto_code_package.go

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package system
2+
3+
import (
4+
"github.com/flipped-aurora/gin-vue-admin/server/global"
5+
common "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
6+
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
7+
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
8+
"github.com/flipped-aurora/gin-vue-admin/server/utils"
9+
"github.com/gin-gonic/gin"
10+
"go.uber.org/zap"
11+
"strings"
12+
)
13+
14+
type AutoCodePackageApi struct{}
15+
16+
// Create
17+
// @Tags AutoCodePackage
18+
// @Summary 创建package
19+
// @Security ApiKeyAuth
20+
// @accept application/json
21+
// @Produce application/json
22+
// @Param data body system.SysAutoCode true "创建package"
23+
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "创建package成功"
24+
// @Router /autoCode/createPackage [post]
25+
func (a *AutoCodePackageApi) Create(c *gin.Context) {
26+
var info request.SysAutoCodePackageCreate
27+
_ = c.ShouldBindJSON(&info)
28+
if err := utils.Verify(info, utils.AutoPackageVerify); err != nil {
29+
response.FailWithMessage(err.Error(), c)
30+
return
31+
}
32+
if strings.Contains(info.PackageName, "\\") || strings.Contains(info.PackageName, "/") || strings.Contains(info.PackageName, "..") {
33+
response.FailWithMessage("包名不合法", c)
34+
return
35+
} // PackageName可能导致路径穿越的问题 / 和 \ 都要防止
36+
err := autoCodePackageService.Create(c.Request.Context(), &info)
37+
if err != nil {
38+
global.GVA_LOG.Error("创建失败!", zap.Error(err))
39+
response.FailWithMessage("创建失败", c)
40+
return
41+
}
42+
response.OkWithMessage("创建成功", c)
43+
}
44+
45+
// Delete
46+
// @Tags AutoCode
47+
// @Summary 删除package
48+
// @Security ApiKeyAuth
49+
// @accept application/json
50+
// @Produce application/json
51+
// @Param data body system.SysAutoCode true "创建package"
52+
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "删除package成功"
53+
// @Router /autoCode/delPackage [post]
54+
func (a *AutoCodePackageApi) Delete(c *gin.Context) {
55+
var info common.GetById
56+
_ = c.ShouldBindJSON(&info)
57+
err := autoCodePackageService.Delete(c.Request.Context(), info)
58+
if err != nil {
59+
global.GVA_LOG.Error("删除失败!", zap.Error(err))
60+
response.FailWithMessage("删除失败", c)
61+
return
62+
}
63+
response.OkWithMessage("删除成功", c)
64+
}
65+
66+
// All
67+
// @Tags AutoCodePackage
68+
// @Summary 获取package
69+
// @Security ApiKeyAuth
70+
// @accept application/json
71+
// @Produce application/json
72+
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "创建package成功"
73+
// @Router /autoCode/getPackage [post]
74+
func (a *AutoCodePackageApi) All(c *gin.Context) {
75+
data, err := autoCodePackageService.All(c.Request.Context())
76+
if err != nil {
77+
global.GVA_LOG.Error("获取失败!", zap.Error(err))
78+
response.FailWithMessage("获取失败", c)
79+
return
80+
}
81+
response.OkWithDetailed(gin.H{"pkgs": data}, "获取成功", c)
82+
}
83+
84+
// Templates
85+
// @Tags AutoCodePackage
86+
// @Summary 获取package
87+
// @Security ApiKeyAuth
88+
// @accept application/json
89+
// @Produce application/json
90+
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "创建package成功"
91+
// @Router /autoCode/getTemplates [get]
92+
func (a *AutoCodePackageApi) Templates(c *gin.Context) {
93+
data, err := autoCodePackageService.Templates(c.Request.Context())
94+
if err != nil {
95+
global.GVA_LOG.Error("获取失败!", zap.Error(err))
96+
response.FailWithMessage("获取失败", c)
97+
return
98+
}
99+
response.OkWithDetailed(data, "获取成功", c)
100+
}

Diff for: server/api/v1/system/auto_code_plugin.go

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package system
2+
3+
import (
4+
"fmt"
5+
"github.com/flipped-aurora/gin-vue-admin/server/global"
6+
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
7+
"github.com/gin-gonic/gin"
8+
"go.uber.org/zap"
9+
)
10+
11+
type AutoCodePluginApi struct{}
12+
13+
// Install
14+
// @Tags AutoCodePlugin
15+
// @Summary 安装插件
16+
// @Security ApiKeyAuth
17+
// @accept multipart/form-data
18+
// @Produce application/json
19+
// @Param plug formData file true "this is a test file"
20+
// @Success 200 {object} response.Response{data=[]interface{},msg=string} "安装插件成功"
21+
// @Router /autoCode/installPlugin [post]
22+
func (a *AutoCodePluginApi) Install(c *gin.Context) {
23+
header, err := c.FormFile("plug")
24+
if err != nil {
25+
response.FailWithMessage(err.Error(), c)
26+
return
27+
}
28+
web, server, err := autoCodePluginService.Install(header)
29+
webStr := "web插件安装成功"
30+
serverStr := "server插件安装成功"
31+
if web == -1 {
32+
webStr = "web端插件未成功安装,请按照文档自行解压安装,如果为纯后端插件请忽略此条提示"
33+
}
34+
if server == -1 {
35+
serverStr = "server端插件未成功安装,请按照文档自行解压安装,如果为纯前端插件请忽略此条提示"
36+
}
37+
if err != nil {
38+
response.FailWithMessage(err.Error(), c)
39+
return
40+
}
41+
response.OkWithData([]interface{}{
42+
gin.H{
43+
"code": web,
44+
"msg": webStr,
45+
},
46+
gin.H{
47+
"code": server,
48+
"msg": serverStr,
49+
}}, c)
50+
}
51+
52+
// Packaged
53+
// @Tags AutoCodePlugin
54+
// @Summary 打包插件
55+
// @Security ApiKeyAuth
56+
// @accept application/json
57+
// @Produce application/json
58+
// @Param data body system.SysAutoCode true "打包插件"
59+
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "打包插件成功"
60+
// @Router /autoCode/pubPlug [get]
61+
func (a *AutoCodePluginApi) Packaged(c *gin.Context) {
62+
plugName := c.Query("plugName")
63+
zipPath, err := autoCodePluginService.PubPlug(plugName)
64+
if err != nil {
65+
global.GVA_LOG.Error("打包失败!", zap.Error(err))
66+
response.FailWithMessage("打包失败"+err.Error(), c)
67+
return
68+
}
69+
response.OkWithMessage(fmt.Sprintf("打包成功,文件路径为:%s", zipPath), c)
70+
}

Diff for: server/api/v1/system/auto_code_template.go

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package system
2+
3+
import (
4+
"github.com/flipped-aurora/gin-vue-admin/server/global"
5+
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
6+
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
7+
"github.com/flipped-aurora/gin-vue-admin/server/utils"
8+
"github.com/gin-gonic/gin"
9+
"go.uber.org/zap"
10+
"net/url"
11+
)
12+
13+
type AutoCodeTemplateApi struct{}
14+
15+
// Preview
16+
// @Tags AutoCodeTemplate
17+
// @Summary 预览创建后的代码
18+
// @Security ApiKeyAuth
19+
// @accept application/json
20+
// @Produce application/json
21+
// @Param data body system.AutoCodeStruct true "预览创建代码"
22+
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "预览创建后的代码"
23+
// @Router /autoCode/preview [post]
24+
func (a *AutoCodeTemplateApi) Preview(c *gin.Context) {
25+
var info request.AutoCode
26+
err := c.ShouldBindJSON(&info)
27+
if err != nil {
28+
response.FailWithMessage(err.Error(), c)
29+
return
30+
}
31+
err = utils.Verify(info, utils.AutoCodeVerify)
32+
if err != nil {
33+
response.FailWithMessage(err.Error(), c)
34+
return
35+
}
36+
err = info.Pretreatment()
37+
if err != nil {
38+
response.FailWithMessage(err.Error(), c)
39+
return
40+
}
41+
info.PackageT = utils.FirstUpper(info.Package)
42+
autoCode, err := autoCodeTemplateService.Preview(c.Request.Context(), info)
43+
if err != nil {
44+
global.GVA_LOG.Error("预览失败!", zap.Error(err))
45+
response.FailWithMessage("预览失败", c)
46+
} else {
47+
response.OkWithDetailed(gin.H{"autoCode": autoCode}, "预览成功", c)
48+
}
49+
}
50+
51+
// Create
52+
// @Tags AutoCodeTemplate
53+
// @Summary 自动代码模板
54+
// @Security ApiKeyAuth
55+
// @accept application/json
56+
// @Produce application/json
57+
// @Param data body system.AutoCodeStruct true "创建自动代码"
58+
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
59+
// @Router /autoCode/createTemp [post]
60+
func (a *AutoCodeTemplateApi) Create(c *gin.Context) {
61+
var info request.AutoCode
62+
err := c.ShouldBindJSON(&info)
63+
if err != nil {
64+
response.FailWithMessage(err.Error(), c)
65+
return
66+
}
67+
err = utils.Verify(info, utils.AutoCodeVerify)
68+
if err != nil {
69+
response.FailWithMessage(err.Error(), c)
70+
return
71+
}
72+
err = info.Pretreatment()
73+
if err != nil {
74+
response.FailWithMessage(err.Error(), c)
75+
return
76+
}
77+
err = autoCodeTemplateService.Create(c.Request.Context(), info)
78+
if err != nil {
79+
c.Writer.Header().Add("success", "false")
80+
c.Writer.Header().Add("msg", url.QueryEscape(err.Error()))
81+
return
82+
}
83+
c.Writer.Header().Add("Content-Type", "application/json")
84+
c.Writer.Header().Add("success", "true")
85+
}

Diff for: server/api/v1/system/enter.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ type ApiGroup struct {
1414
DictionaryApi
1515
AuthorityMenuApi
1616
OperationRecordApi
17-
AutoCodeHistoryApi
1817
DictionaryDetailApi
1918
AuthorityBtnApi
2019
SysExportTemplateApi
20+
AutoCodePluginApi
21+
AutoCodePackageApi
22+
AutoCodeHistoryApi
23+
AutoCodeTemplateApi
2124
}
2225

2326
var (
@@ -27,13 +30,16 @@ var (
2730
userService = service.ServiceGroupApp.SystemServiceGroup.UserService
2831
initDBService = service.ServiceGroupApp.SystemServiceGroup.InitDBService
2932
casbinService = service.ServiceGroupApp.SystemServiceGroup.CasbinService
30-
autoCodeService = service.ServiceGroupApp.SystemServiceGroup.AutoCodeService
3133
baseMenuService = service.ServiceGroupApp.SystemServiceGroup.BaseMenuService
3234
authorityService = service.ServiceGroupApp.SystemServiceGroup.AuthorityService
3335
dictionaryService = service.ServiceGroupApp.SystemServiceGroup.DictionaryService
36+
authorityBtnService = service.ServiceGroupApp.SystemServiceGroup.AuthorityBtnService
3437
systemConfigService = service.ServiceGroupApp.SystemServiceGroup.SystemConfigService
3538
operationRecordService = service.ServiceGroupApp.SystemServiceGroup.OperationRecordService
36-
autoCodeHistoryService = service.ServiceGroupApp.SystemServiceGroup.AutoCodeHistoryService
3739
dictionaryDetailService = service.ServiceGroupApp.SystemServiceGroup.DictionaryDetailService
38-
authorityBtnService = service.ServiceGroupApp.SystemServiceGroup.AuthorityBtnService
40+
autoCodeService = service.ServiceGroupApp.SystemServiceGroup.AutoCodeService
41+
autoCodePluginService = service.ServiceGroupApp.SystemServiceGroup.AutoCodePlugin
42+
autoCodePackageService = service.ServiceGroupApp.SystemServiceGroup.AutoCodePackage
43+
autoCodeHistoryService = service.ServiceGroupApp.SystemServiceGroup.AutoCodeHistory
44+
autoCodeTemplateService = service.ServiceGroupApp.SystemServiceGroup.AutoCodeTemplate
3945
)

0 commit comments

Comments
 (0)