From abdc80b756a51ab418f84ee3d626282decce8ebb Mon Sep 17 00:00:00 2001 From: inits Date: Mon, 10 Jan 2022 10:21:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=89=8D=E7=AB=AF=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90=E4=B8=8D=E7=94=9F?= =?UTF-8?q?=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/service/sys_role.go | 6 +++--- template/v4/dto.go.template | 6 ++++-- template/v4/no_actions/router_check_role.go.template | 7 ++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/admin/service/sys_role.go b/app/admin/service/sys_role.go index ab374822..c10c18c2 100644 --- a/app/admin/service/sys_role.go +++ b/app/admin/service/sys_role.go @@ -142,7 +142,7 @@ func (e *SysRole) Update(c *dto.SysRoleUpdateReq, cb *casbin.SyncedEnforcer) err e.Log.Errorf("delete policy error:%s", err) return err } - mp:=make(map [string] interface{} ,0) + mp := make(map[string]interface{}, 0) polices := make([][]string, 0) for _, menu := range mlist { for _, api := range menu.SysApi { @@ -214,7 +214,7 @@ func (e *SysRole) UpdateDataScope(c *dto.RoleDataScopeReq) *SysRole { var dlist = make([]models.SysDept, 0) var model = models.SysRole{} tx.Preload("SysDept").First(&model, c.RoleId) - tx.Where("id in ?", c.DeptIds).Find(&dlist) + tx.Where("dept_id in ?", c.DeptIds).Find(&dlist) err = tx.Model(&model).Association("SysDept").Delete(model.SysDept) if err != nil { e.Log.Errorf("delete SysDept error:%s", err) @@ -299,4 +299,4 @@ func (e *SysRole) GetById(roleId int) ([]string, error) { permissions = append(permissions, l[i].Permission) } return permissions, nil -} \ No newline at end of file +} diff --git a/template/v4/dto.go.template b/template/v4/dto.go.template index 1aa5bfe4..82ee1355 100644 --- a/template/v4/dto.go.template +++ b/template/v4/dto.go.template @@ -70,7 +70,8 @@ func (s *{{.ClassName}}InsertReq) Generate(model *models.{{.ClassName}}) { {{- else if eq .GoField "CreatedAt" -}} {{- else if eq .GoField "UpdatedAt" -}} {{- else if eq .GoField "DeletedAt" -}} - {{- else if eq .GoField "CreateBy" -}} + {{- else if eq .GoField "CreateBy"}} + model.{{.GoField}} = s.{{.GoField}} // 添加这而,需要记录是被谁创建的 {{- else if eq .GoField "UpdateBy" -}} {{- else }} model.{{.GoField}} = s.{{.GoField}} @@ -110,7 +111,8 @@ func (s *{{.ClassName}}UpdateReq) Generate(model *models.{{.ClassName}}) { {{- else if eq .GoField "UpdatedAt" -}} {{- else if eq .GoField "DeletedAt" -}} {{- else if eq .GoField "CreateBy" -}} - {{- else if eq .GoField "UpdateBy" -}} + {{- else if eq .GoField "UpdateBy"}} + model.{{.GoField}} = s.{{.GoField}} // 添加这而,需要记录是被谁更新的 {{- else }} model.{{.GoField}} = s.{{.GoField}} {{- end -}} diff --git a/template/v4/no_actions/router_check_role.go.template b/template/v4/no_actions/router_check_role.go.template index 249c61c4..f8a3c3a7 100644 --- a/template/v4/no_actions/router_check_role.go.template +++ b/template/v4/no_actions/router_check_role.go.template @@ -6,6 +6,7 @@ import ( "go-admin/app/{{.PackageName}}/apis" "go-admin/common/middleware" + "go-admin/common/actions" ) func init() { @@ -17,10 +18,10 @@ func register{{.ClassName}}Router(v1 *gin.RouterGroup, authMiddleware *jwt.GinJW api := apis.{{.ClassName}}{} r := v1.Group("/{{.ModuleName}}").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole()) { - r.GET("", api.GetPage) - r.GET("/:id", api.Get) + r.GET("", actions.PermissionAction(), api.GetPage) + r.GET("/:id", actions.PermissionAction(), api.Get) r.POST("", api.Insert) - r.PUT("/:id", api.Update) + r.PUT("/:id", actions.PermissionAction(), api.Update) r.DELETE("", api.Delete) } } \ No newline at end of file