Skip to content

Commit edee38d

Browse files
committed
Merge remote-tracking branch 'origin/main' into plugin_study
# Conflicts: # server/api/v1/system/sys_auto_code.go # server/config.yaml
2 parents f342b00 + 894cf8e commit edee38d

File tree

95 files changed

+2299
-930
lines changed

Some content is hidden

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

95 files changed

+2299
-930
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,9 @@ cd server
9494
# 使用 go mod 并安装go依赖包
9595
go generate
9696

97-
# 编译
98-
go build -o server main.go (windows编译命令为go build -o server.exe main.go )
97+
# 运行
98+
go run .
9999

100-
# 运行二进制
101-
./server (windows运行命令为 server.exe)
102100
```
103101

104102
### 2.2 web项目

server/api/v1/example/exa_breakpoint_continue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (b *FileUploadAndDownloadApi) BreakpointContinue(c *gin.Context) {
8484
// @Produce application/json
8585
// @Param file formData file true "Find the file, 查找文件"
8686
// @Success 200 {object} response.Response{data=exampleRes.FileResponse,msg=string} "查找文件,返回包括文件详情"
87-
// @Router /fileUploadAndDownload/findFile [post]
87+
// @Router /fileUploadAndDownload/findFile [get]
8888
func (b *FileUploadAndDownloadApi) FindFile(c *gin.Context) {
8989
fileMd5 := c.Query("fileMd5")
9090
fileName := c.Query("fileName")

server/api/v1/system/auto_code_plugin.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"github.com/flipped-aurora/gin-vue-admin/server/global"
66
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
7+
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
78
"github.com/gin-gonic/gin"
89
"go.uber.org/zap"
910
)
@@ -57,7 +58,7 @@ func (a *AutoCodePluginApi) Install(c *gin.Context) {
5758
// @Produce application/json
5859
// @Param plugName query string true "插件名称"
5960
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "打包插件成功"
60-
// @Router /autoCode/pubPlug [get]
61+
// @Router /autoCode/pubPlug [post]
6162
func (a *AutoCodePluginApi) Packaged(c *gin.Context) {
6263
plugName := c.Query("plugName")
6364
zipPath, err := autoCodePluginService.PubPlug(plugName)
@@ -68,3 +69,51 @@ func (a *AutoCodePluginApi) Packaged(c *gin.Context) {
6869
}
6970
response.OkWithMessage(fmt.Sprintf("打包成功,文件路径为:%s", zipPath), c)
7071
}
72+
73+
// Packaged
74+
// @Tags AutoCodePlugin
75+
// @Summary 打包插件
76+
// @Security ApiKeyAuth
77+
// @accept application/json
78+
// @Produce application/json
79+
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "打包插件成功"
80+
// @Router /autoCode/initMenu [post]
81+
func (a *AutoCodePluginApi) InitMenu(c *gin.Context) {
82+
var menuInfo request.InitMenu
83+
err := c.ShouldBindJSON(&menuInfo)
84+
if err != nil {
85+
response.FailWithMessage(err.Error(), c)
86+
return
87+
}
88+
err = autoCodePluginService.InitMenu(menuInfo)
89+
if err != nil {
90+
global.GVA_LOG.Error("创建初始化Menu失败!", zap.Error(err))
91+
response.FailWithMessage("创建初始化Menu失败"+err.Error(), c)
92+
return
93+
}
94+
response.OkWithMessage("文件变更成功", c)
95+
}
96+
97+
// Packaged
98+
// @Tags AutoCodePlugin
99+
// @Summary 打包插件
100+
// @Security ApiKeyAuth
101+
// @accept application/json
102+
// @Produce application/json
103+
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "打包插件成功"
104+
// @Router /autoCode/initAPI [post]
105+
func (a *AutoCodePluginApi) InitAPI(c *gin.Context) {
106+
var apiInfo request.InitApi
107+
err := c.ShouldBindJSON(&apiInfo)
108+
if err != nil {
109+
response.FailWithMessage(err.Error(), c)
110+
return
111+
}
112+
err = autoCodePluginService.InitAPI(apiInfo)
113+
if err != nil {
114+
global.GVA_LOG.Error("创建初始化API失败!", zap.Error(err))
115+
response.FailWithMessage("创建初始化API失败"+err.Error(), c)
116+
return
117+
}
118+
response.OkWithMessage("文件变更成功", c)
119+
}

server/api/v1/system/auto_code_template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (a *AutoCodeTemplateApi) Create(c *gin.Context) {
7676
err = autoCodeTemplateService.Create(c.Request.Context(), info)
7777
if err != nil {
7878
global.GVA_LOG.Error("创建失败!", zap.Error(err))
79-
response.FailWithMessage("创建失败", c)
79+
response.FailWithMessage(err.Error(), c)
8080
} else {
8181
response.OkWithMessage("创建成功", c)
8282
}

server/api/v1/system/sys_api.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (s *SystemApiApi) SyncApi(c *gin.Context) {
7474
// @accept application/json
7575
// @Produce application/json
7676
// @Success 200 {object} response.Response{msg=string} "获取API分组"
77-
// @Router /api/getApiGroups [post]
77+
// @Router /api/getApiGroups [get]
7878
func (s *SystemApiApi) GetApiGroups(c *gin.Context) {
7979
groups, apiGroupMap, err := apiService.GetApiGroups()
8080
if err != nil {
@@ -270,7 +270,8 @@ func (s *SystemApiApi) UpdateApi(c *gin.Context) {
270270
// @Success 200 {object} response.Response{data=systemRes.SysAPIListResponse,msg=string} "获取所有的Api 不分页,返回包括api列表"
271271
// @Router /api/getAllApis [post]
272272
func (s *SystemApiApi) GetAllApis(c *gin.Context) {
273-
apis, err := apiService.GetAllApis()
273+
authorityID := utils.GetUserAuthorityId(c)
274+
apis, err := apiService.GetAllApis(authorityID)
274275
if err != nil {
275276
global.GVA_LOG.Error("获取失败!", zap.Error(err))
276277
response.FailWithMessage("获取失败", c)

server/api/v1/system/sys_authority.go

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ 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"
65
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
76
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
87
systemRes "github.com/flipped-aurora/gin-vue-admin/server/model/system/response"
@@ -77,7 +76,8 @@ func (a *AuthorityApi) CopyAuthority(c *gin.Context) {
7776
response.FailWithMessage(err.Error(), c)
7877
return
7978
}
80-
authBack, err := authorityService.CopyAuthority(copyInfo)
79+
adminAuthorityID := utils.GetUserAuthorityId(c)
80+
authBack, err := authorityService.CopyAuthority(adminAuthorityID, copyInfo)
8181
if err != nil {
8282
global.GVA_LOG.Error("拷贝失败!", zap.Error(err))
8383
response.FailWithMessage("拷贝失败"+err.Error(), c)
@@ -124,7 +124,7 @@ func (a *AuthorityApi) DeleteAuthority(c *gin.Context) {
124124
// @Produce application/json
125125
// @Param data body system.SysAuthority true "权限id, 权限名, 父角色id"
126126
// @Success 200 {object} response.Response{data=systemRes.SysAuthorityResponse,msg=string} "更新角色信息,返回包括系统角色详情"
127-
// @Router /authority/updateAuthority [post]
127+
// @Router /authority/updateAuthority [put]
128128
func (a *AuthorityApi) UpdateAuthority(c *gin.Context) {
129129
var auth system.SysAuthority
130130
err := c.ShouldBindJSON(&auth)
@@ -156,29 +156,14 @@ func (a *AuthorityApi) UpdateAuthority(c *gin.Context) {
156156
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取角色列表,返回包括列表,总数,页码,每页数量"
157157
// @Router /authority/getAuthorityList [post]
158158
func (a *AuthorityApi) GetAuthorityList(c *gin.Context) {
159-
var pageInfo request.PageInfo
160-
err := c.ShouldBindJSON(&pageInfo)
161-
if err != nil {
162-
response.FailWithMessage(err.Error(), c)
163-
return
164-
}
165-
err = utils.Verify(pageInfo, utils.PageInfoVerify)
166-
if err != nil {
167-
response.FailWithMessage(err.Error(), c)
168-
return
169-
}
170-
list, total, err := authorityService.GetAuthorityInfoList(pageInfo)
159+
authorityID := utils.GetUserAuthorityId(c)
160+
list, err := authorityService.GetAuthorityInfoList(authorityID)
171161
if err != nil {
172162
global.GVA_LOG.Error("获取失败!", zap.Error(err))
173163
response.FailWithMessage("获取失败"+err.Error(), c)
174164
return
175165
}
176-
response.OkWithDetailed(response.PageResult{
177-
List: list,
178-
Total: total,
179-
Page: pageInfo.Page,
180-
PageSize: pageInfo.PageSize,
181-
}, "获取成功", c)
166+
response.OkWithDetailed(list, "获取成功", c)
182167
}
183168

184169
// SetDataAuthority
@@ -202,7 +187,8 @@ func (a *AuthorityApi) SetDataAuthority(c *gin.Context) {
202187
response.FailWithMessage(err.Error(), c)
203188
return
204189
}
205-
err = authorityService.SetDataAuthority(auth)
190+
adminAuthorityID := utils.GetUserAuthorityId(c)
191+
err = authorityService.SetDataAuthority(adminAuthorityID, auth)
206192
if err != nil {
207193
global.GVA_LOG.Error("设置失败!", zap.Error(err))
208194
response.FailWithMessage("设置失败"+err.Error(), c)

server/api/v1/system/sys_auto_code.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type AutoCodeApi struct{}
2121
// @accept application/json
2222
// @Produce application/json
2323
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取当前所有数据库"
24-
// @Router /autoCode/getDatabase [get]
24+
// @Router /autoCode/getDB [get]
2525
func (autoApi *AutoCodeApi) GetDB(c *gin.Context) {
2626
businessDB := c.Query("businessDB")
2727
dbs, err := autoCodeService.Database(businessDB).GetDB(businessDB)
@@ -54,7 +54,7 @@ func (autoApi *AutoCodeApi) GetTables(c *gin.Context) {
5454
dbName := c.Query("dbName")
5555
businessDB := c.Query("businessDB")
5656
if dbName == "" {
57-
dbName = global.GVA_CONFIG.Mysql.Dbname
57+
dbName = *global.GVA_ACTIVE_DBNAME
5858
if businessDB != "" {
5959
for _, db := range global.GVA_CONFIG.DBList {
6060
if db.AliasName == businessDB {
@@ -85,7 +85,7 @@ func (autoApi *AutoCodeApi) GetColumn(c *gin.Context) {
8585
businessDB := c.Query("businessDB")
8686
dbName := c.Query("dbName")
8787
if dbName == "" {
88-
dbName = global.GVA_CONFIG.Mysql.Dbname
88+
dbName = *global.GVA_ACTIVE_DBNAME
8989
if businessDB != "" {
9090
for _, db := range global.GVA_CONFIG.DBList {
9191
if db.AliasName == businessDB {

server/api/v1/system/sys_casbin.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ func (cas *CasbinApi) UpdateCasbin(c *gin.Context) {
3333
response.FailWithMessage(err.Error(), c)
3434
return
3535
}
36-
err = casbinService.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos)
36+
adminAuthorityID := utils.GetUserAuthorityId(c)
37+
err = casbinService.UpdateCasbin(adminAuthorityID, cmr.AuthorityId, cmr.CasbinInfos)
3738
if err != nil {
3839
global.GVA_LOG.Error("更新失败!", zap.Error(err))
3940
response.FailWithMessage("更新失败", c)

server/api/v1/system/sys_menu.go

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ func (a *AuthorityMenuApi) GetMenu(c *gin.Context) {
4545
// @Success 200 {object} response.Response{data=systemRes.SysBaseMenusResponse,msg=string} "获取用户动态路由,返回包括系统菜单列表"
4646
// @Router /menu/getBaseMenuTree [post]
4747
func (a *AuthorityMenuApi) GetBaseMenuTree(c *gin.Context) {
48-
menus, err := menuService.GetBaseMenuTree()
48+
authority := utils.GetUserAuthorityId(c)
49+
menus, err := menuService.GetBaseMenuTree(authority)
4950
if err != nil {
5051
global.GVA_LOG.Error("获取失败!", zap.Error(err))
5152
response.FailWithMessage("获取失败", c)
@@ -74,7 +75,8 @@ func (a *AuthorityMenuApi) AddMenuAuthority(c *gin.Context) {
7475
response.FailWithMessage(err.Error(), c)
7576
return
7677
}
77-
if err := menuService.AddMenuAuthority(authorityMenu.Menus, authorityMenu.AuthorityId); err != nil {
78+
adminAuthorityID := utils.GetUserAuthorityId(c)
79+
if err := menuService.AddMenuAuthority(authorityMenu.Menus, adminAuthorityID, authorityMenu.AuthorityId); err != nil {
7880
global.GVA_LOG.Error("添加失败!", zap.Error(err))
7981
response.FailWithMessage("添加失败", c)
8082
} else {
@@ -171,7 +173,7 @@ func (a *AuthorityMenuApi) DeleteBaseMenu(c *gin.Context) {
171173
err = baseMenuService.DeleteBaseMenu(menu.ID)
172174
if err != nil {
173175
global.GVA_LOG.Error("删除失败!", zap.Error(err))
174-
response.FailWithMessage("删除失败", c)
176+
response.FailWithMessage("删除失败:"+err.Error(), c)
175177
return
176178
}
177179
response.OkWithMessage("删除成功", c)
@@ -252,27 +254,12 @@ func (a *AuthorityMenuApi) GetBaseMenuById(c *gin.Context) {
252254
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取基础menu列表,返回包括列表,总数,页码,每页数量"
253255
// @Router /menu/getMenuList [post]
254256
func (a *AuthorityMenuApi) GetMenuList(c *gin.Context) {
255-
var pageInfo request.PageInfo
256-
err := c.ShouldBindJSON(&pageInfo)
257-
if err != nil {
258-
response.FailWithMessage(err.Error(), c)
259-
return
260-
}
261-
err = utils.Verify(pageInfo, utils.PageInfoVerify)
262-
if err != nil {
263-
response.FailWithMessage(err.Error(), c)
264-
return
265-
}
266-
menuList, total, err := menuService.GetInfoList()
257+
authorityID := utils.GetUserAuthorityId(c)
258+
menuList, err := menuService.GetInfoList(authorityID)
267259
if err != nil {
268260
global.GVA_LOG.Error("获取失败!", zap.Error(err))
269261
response.FailWithMessage("获取失败", c)
270262
return
271263
}
272-
response.OkWithDetailed(response.PageResult{
273-
List: menuList,
274-
Total: total,
275-
Page: pageInfo.Page,
276-
PageSize: pageInfo.PageSize,
277-
}, "获取成功", c)
264+
response.OkWithDetailed(menuList, "获取成功", c)
278265
}

server/api/v1/system/sys_user.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ func (b *BaseApi) SetUserAuthorities(c *gin.Context) {
285285
response.FailWithMessage(err.Error(), c)
286286
return
287287
}
288-
err = userService.SetUserAuthorities(sua.ID, sua.AuthorityIds)
288+
authorityID := utils.GetUserAuthorityId(c)
289+
err = userService.SetUserAuthorities(authorityID, sua.ID, sua.AuthorityIds)
289290
if err != nil {
290291
global.GVA_LOG.Error("修改失败!", zap.Error(err))
291292
response.FailWithMessage("修改失败", c)
@@ -350,9 +351,9 @@ func (b *BaseApi) SetUserInfo(c *gin.Context) {
350351
response.FailWithMessage(err.Error(), c)
351352
return
352353
}
353-
354354
if len(user.AuthorityIds) != 0 {
355-
err = userService.SetUserAuthorities(user.ID, user.AuthorityIds)
355+
authorityID := utils.GetUserAuthorityId(c)
356+
err = userService.SetUserAuthorities(authorityID, user.ID, user.AuthorityIds)
356357
if err != nil {
357358
global.GVA_LOG.Error("设置失败!", zap.Error(err))
358359
response.FailWithMessage("设置失败", c)

0 commit comments

Comments
 (0)