From 285e0e30c123c59f872149911cb6ef5842428ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZR20090193-=E9=99=88=E6=95=AC=E5=8B=87?= Date: Tue, 20 Feb 2024 18:05:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ds-wms-client-web/src/api/system/role.ts | 2 +- .../Constants/MultiLanguageConst.cs | 3 + .../System/Interface/ISysRoleService.cs | 6 ++ .../System/Method/CommonService.cs | 2 +- .../System/Method/SysRoleService.cs | 84 +++++++++++++++++++ .../Controllers/RoleController.cs | 8 +- 6 files changed, 99 insertions(+), 6 deletions(-) diff --git a/ds-wms-client-web/src/api/system/role.ts b/ds-wms-client-web/src/api/system/role.ts index b9dc8091..9e184343 100644 --- a/ds-wms-client-web/src/api/system/role.ts +++ b/ds-wms-client-web/src/api/system/role.ts @@ -7,7 +7,7 @@ enum Api { getRole = '/mainApi/Role/GetRoleInfo', getPermissionTree = '/mainApi/Role/GetClientRolePermissionTree', getRolePermission = '/mainApi/Role/GetRolePermission', - updateRolePermission = '/mainApi/Role/UpdateRolePermission', + updateRolePermission = '/mainApi/Role/UpdateClientRolePermission', } export function getRoleList(data: PageRequest) { return request({ diff --git a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs index eecadf17..fbc865b8 100644 --- a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs +++ b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs @@ -44,6 +44,9 @@ public static class MultiLanguageConst [Description("用户授权数量限制")] public const string UserAuthNumLimit = "User_AuthNum_Limit"; + [Description("{0}模块数量超出授权数量{1}")] + public const string PerAuthNumLimit = "Permission_AuthNum_Limit"; + [Description("用户唯一编码已存在")] public const string UserCodeExist = "UserCode_Exist"; [Description("角色唯一编码已存在")] diff --git a/ds-wms-service/DS.WMS.Core/System/Interface/ISysRoleService.cs b/ds-wms-service/DS.WMS.Core/System/Interface/ISysRoleService.cs index a4faeccf..a1bd67f8 100644 --- a/ds-wms-service/DS.WMS.Core/System/Interface/ISysRoleService.cs +++ b/ds-wms-service/DS.WMS.Core/System/Interface/ISysRoleService.cs @@ -55,4 +55,10 @@ public interface ISysRoleService /// /// DataResult UpdateRolePermission(RolePermissionInput model); + /// + /// 更新角色权限-客户端 + /// + /// + /// + public DataResult UpdateClientRolePermission(RolePermissionInput model); } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/System/Method/CommonService.cs b/ds-wms-service/DS.WMS.Core/System/Method/CommonService.cs index 770e7432..7f8aa215 100644 --- a/ds-wms-service/DS.WMS.Core/System/Method/CommonService.cs +++ b/ds-wms-service/DS.WMS.Core/System/Method/CommonService.cs @@ -604,7 +604,7 @@ public class CommonService : ICommonService { var childs = db.Queryable().Where(x => x.MenuType == 2 && x.ParentId == item.ParentId && x.IsHidden == false && permissions.Contains(x.PermissionId) && - (x.PermissionType == 1 || x.PermissionType == 0)) + (x.PermissionType == 1 || x.PermissionType == 0) && x.PermissionId!=1744968217220222976)//排除企业用户维护 .OrderBy(x => x.SortCode) .Select(a => new RouteItem { diff --git a/ds-wms-service/DS.WMS.Core/System/Method/SysRoleService.cs b/ds-wms-service/DS.WMS.Core/System/Method/SysRoleService.cs index a845004a..e57dc94e 100644 --- a/ds-wms-service/DS.WMS.Core/System/Method/SysRoleService.cs +++ b/ds-wms-service/DS.WMS.Core/System/Method/SysRoleService.cs @@ -1,5 +1,6 @@ using DS.Module.Core; using DS.Module.Core.Extensions; +using DS.Module.Core.Helpers; using DS.Module.UserModule; using DS.WMS.Core.System.Dtos; using DS.WMS.Core.System.Entity; @@ -245,4 +246,87 @@ public class SysRoleService : ISysRoleService } return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess); } + + + public DataResult UpdateClientRolePermission(RolePermissionInput model) + { + var existPermissions = db.Queryable().Where(x => x.RoleId == model.RoleId && x.IsPermission == 1).Select(n => n.PermissionId).ToArray(); + + IEnumerable delPermissions = existPermissions.AsQueryable().Except(model.PermissionIds); + if (delPermissions.Count() > 0) + { + db.Updateable() + .SetColumns(it => it.IsPermission == 0)//SetColumns是可以叠加的 写2个就2个字段赋值 + .Where(it => it.RoleId == model.RoleId && delPermissions.Contains(it.PermissionId)) + .ExecuteCommand(); + } + IEnumerable addPermissions = model.PermissionIds.AsQueryable().Except(existPermissions); + if (addPermissions.Count() > 0) + { + var existNoPermissions = db.Queryable().Where(x => x.RoleId == model.RoleId && x.IsPermission == 0).Select(n => n.PermissionId).ToArray(); + IEnumerable updatePermissions = existNoPermissions.AsQueryable().Except(addPermissions); + if (updatePermissions.Count() > 0) + { + db.Updateable() + .SetColumns(it => it.IsPermission == 1) + .Where(it => it.RoleId == model.RoleId && updatePermissions.Contains(it.PermissionId)) + .ExecuteCommand(); + } + IEnumerable addRolePermissions = addPermissions.AsQueryable().Except(existNoPermissions); + + #region 租户模块权限检测 + + var tenant = db.Queryable().Where(x=>x.Id ==long.Parse(user.TenantId)).First(); + foreach (var item in addRolePermissions) + { + var per = db.Queryable().Where(x => x.Id == item) + .First(); + if (per.MenuType == 2) + { + var perAuth = db.Queryable().Where(x=>x.PermissionId == item).First(); + if (perAuth.IsNotNull()) + { + var authNum = EncrypteHelper.DecryptData(perAuth.AuthNum, tenant.AppSecret); + + var roleList = db.Queryable() + .Where(x => x.PermissionId == item && x.IsPermission == 1).Select(n => n.RoleId).ToList(); + + roleList.Add(model.RoleId); + roleList.Distinct(); + var userList = new List(); + foreach (var role in roleList) + { + var userArr = db.Queryable().Where(x => x.RoleId == role).Select(n => n.UserId) + .ToList(); + userList.AddRange(userArr); + } + + userList.Distinct(); + + var userCount = userList.Count(); + if (userCount>= int.Parse(authNum)) + { + + return DataResult.Failed(string.Format("{0}模块数量超出授权数量{1}",per.PermissionName, int.Parse(authNum)),MultiLanguageConst.PerAuthNumLimit); + } + } + } + } + + + #endregion + + foreach (var item in addRolePermissions) + { + var permission = new SysRolePermission + { + RoleId = model.RoleId, + PermissionId = item, + IsPermission = 1, + }; + db.Insertable(permission).ExecuteCommand(); + } + } + return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess); + } } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.MainApi/Controllers/RoleController.cs b/ds-wms-service/DS.WMS.MainApi/Controllers/RoleController.cs index 61dbb778..07e7a444 100644 --- a/ds-wms-service/DS.WMS.MainApi/Controllers/RoleController.cs +++ b/ds-wms-service/DS.WMS.MainApi/Controllers/RoleController.cs @@ -87,15 +87,15 @@ public class RoleController : ApiController } /// - /// 更新角色权限 + /// 更新角色权限-客户端 /// /// /// [HttpPost] - [Route("UpdateRolePermission")] - public DataResult UpdateRolePermission([FromBody] RolePermissionInput model) + [Route("UpdateClientRolePermission")] + public DataResult UpdateClientRolePermission([FromBody] RolePermissionInput model) { - var res = _invokeService.UpdateRolePermission(model); + var res = _invokeService.UpdateClientRolePermission(model); return res; } } \ No newline at end of file