From 48f1792f322156e53e7a9ab696e05a5354853367 Mon Sep 17 00:00:00 2001 From: PandaX <18610165312@163.com> Date: Wed, 6 Dec 2023 10:58:03 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E6=9F=A5=E8=AF=A2=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E8=AE=A4=E8=AF=81=E6=9D=83=E9=99=90=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/system/entity/role.go | 7 ++++--- apps/system/services/role.go | 18 ++++-------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/apps/system/entity/role.go b/apps/system/entity/role.go index fdea425..c605a5f 100644 --- a/apps/system/entity/role.go +++ b/apps/system/entity/role.go @@ -27,10 +27,11 @@ type SysRole struct { ApiIds []casbin.CasbinRule `json:"apiIds" gorm:"-"` MenuIds []int64 `json:"menuIds" gorm:"-"` OrganizationIds []int64 `json:"organizationIds" gorm:"-"` - - Org string `json:"org" gorm:"-"` } - +type SysRoleAuth struct { + Org string `json:"org" gorm:"column:org"` + DataScope string `json:"dataScope"` +} type MenuIdList struct { MenuId int64 `json:"menuId"` } diff --git a/apps/system/services/role.go b/apps/system/services/role.go index ad109ae..6b93c2b 100644 --- a/apps/system/services/role.go +++ b/apps/system/services/role.go @@ -17,7 +17,7 @@ type ( Delete(roleId []int64) GetRoleMeunId(data entity.SysRole) []int64 GetRoleOrganizationId(data entity.SysRole) []int64 - FindOrganizationsByRoleId(roleId int64) (entity.SysRole, error) + FindOrganizationsByRoleId(roleId int64) (entity.SysRoleAuth, error) } sysRoleModel struct { @@ -132,18 +132,8 @@ func (m *sysRoleModel) GetRoleOrganizationId(data entity.SysRole) []int64 { return organizationIds } -func (m *sysRoleModel) FindOrganizationsByRoleId(roleId int64) (entity.SysRole, error) { - var roleData entity.SysRole - db := global.Db.Table(m.table) - if global.Conf.Server.DbType == "mysql" { - db.Select("sys_roles.data_scope, GROUP_CONCAT(sys_role_organizations.organization_id) as org") - } else { - db.Select("sys_roles.data_scope, STRING_AGG(sys_role_organizations.organization_id::text,',') as org") - } - err := db. - Joins("LEFT JOIN sys_role_organizations ON sys_roles.role_id = sys_role_organizations.role_id"). - Where("sys_roles.role_id = ?", roleId). - Group("sys_roles.role_id"). - First(&roleData).Error +func (m *sysRoleModel) FindOrganizationsByRoleId(roleId int64) (entity.SysRoleAuth, error) { + var roleData entity.SysRoleAuth + err := global.Db.Raw("SELECT sys_roles.data_scope, GROUP_CONCAT(sys_role_organizations.organization_id) as org FROM sys_roles LEFT JOIN sys_role_organizations ON sys_roles.role_id = sys_role_organizations.role_id WHERE sys_roles.role_id = ? GROUP BY sys_roles.role_id", roleId).Scan(&roleData).Error return roleData, err }