From 680ccbedf08839143215f40dea5273dc2819100c Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期三, 30 十月 2024 23:26:33 +0800 Subject: [PATCH] 优化WMS、WCS用户管理 --- 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_RoleService.cs | 52 +++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 45 insertions(+), 7 deletions(-) diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_RoleService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_RoleService.cs" index 3372776..2785def 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_RoleService.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_RoleService.cs" @@ -15,6 +15,7 @@ using WIDESEA_Model.Models; using WIDESEA_Model.Models.System; using WIDESEA_SystemRepository; +using WIDESEA_Core.Helper; namespace WIDESEA_SystemService { @@ -45,7 +46,7 @@ return list; } - public List<RoleNodes> GetAllRoleId() + public List<RoleNodes> GetAllRoleId() { List<RoleNodes> roles = BaseDal.QueryData().Select(s => new RoleNodes() { Id = s.RoleId, ParentId = s.ParentId, RoleName = s.RoleName }).ToList(); @@ -92,7 +93,42 @@ { return GetUserTreePermission(App.User.RoleId); } + public override WebResponseContent UpdateData(SaveModel saveModel) + { + var ParentId = saveModel.MainData[nameof(Sys_Role.ParentId).FirstLetterToLower()].ObjToInt();//鐖剁骇ID + var RoleId = saveModel.MainData[nameof(Sys_Role.RoleId).FirstLetterToLower()].ObjToInt();//瑙掕壊ID + if (RoleId == ParentId) return WebResponseContent.Instance.Error("鐖剁骇ID涓嶈兘涓鸿嚜宸�"); + if (App.User.RoleId == RoleId) return WebResponseContent.Instance.Error("鏃犳搷浣滄潈闄�"); + return base.UpdateData(saveModel); + } + public override PageGridData<Sys_Role> GetPageData(PageDataOptions options) + { + PageGridData<Sys_Role> pageGridData = new PageGridData<Sys_Role>(); + if (App.User.IsSuperAdmin) + { + var GridData = base.GetPageData(options); + pageGridData = new PageGridData<Sys_Role>() + { + Rows = options.Order?.ToLower() == OrderByType.Asc.ToString().ToLower() ? GridData.Rows.OrderBy(x => x.RoleId).ToList() : GridData.Rows, + Total = GridData.Total + }; + return pageGridData; + } + + var roleIds = GetAllChildren(App.User.RoleId).Select(x => x.Id); + //鏍戝舰鑿滃崟浼犳煡璇㈣鑹蹭笅鎵�鏈夌敤鎴� + string where = ValidatePageOptions(options); + + int total = 0; + pageGridData = new PageGridData<Sys_Role>() + { + Rows = BaseDal.Db.Queryable<Sys_Role>().Where(x => roleIds.Contains(x.RoleId)).Where(where).OrderBy(x => x.RoleId).ToPageList(options.Page, options.Rows), + Total = total + }; + + return pageGridData; + } /// <summary> /// 缂栬緫鏉冮檺鏃讹紝鑾峰彇鎸囧畾瑙掕壊鐨勬墍鏈夎彍鍗曟潈闄� /// </summary> @@ -110,7 +146,7 @@ //鑾峰彇鐢ㄦ埛鏉冮檺 List<Permissions> permissions = _MenuRepository.GetPermissions(roleId); //鏉冮檺鐢ㄦ埛鏉冮檺鏌ヨ鎵�鏈夌殑鑿滃崟淇℃伅 - List<MenuDTO> menus = _MenuService.GetUserMenuList(roleId); + List<MenuDTO> menus = _MenuService.GetUserMenuList(roleId); //鑾峰彇褰撳墠鐢ㄦ埛鏉冮檺濡�:(Add,Search)瀵瑰簲鐨勬樉绀烘枃鏈俊鎭:Add锛氭坊鍔狅紝Search:鏌ヨ var data = menus.Select(x => new { @@ -135,7 +171,9 @@ string message = ""; try { - if (!GetAllChildren(App.User.RoleId).Exists(x => x.Id == roleId)) + var RoleNodes = GetAllChildren(App.User.RoleId); + RoleNodes = RoleNodes.Where(x => x.Id != App.User.RoleId).ToList(); + if (!RoleNodes.Exists(x => x.Id == roleId) /*&& !App.User.IsRoleIdSuperAdmin(App.User.RoleId)*/) return WebResponseContent.Instance.Error("娌℃湁鏉冮檺淇敼姝よ鑹茬殑鏉冮檺淇℃伅"); //褰撳墠鐢ㄦ埛鐨勬潈闄� List<Permissions> permissions = _MenuRepository.GetPermissions(App.User.RoleId); @@ -180,9 +218,9 @@ } //鏇存柊鏉冮檺 - _RoleAuthRepository.UpdateData(updateAuths); + _RoleAuthRepository.UpdateData(updateAuths.Where(x => x.AuthId > 0).ToList()); //鏂板鐨勬潈闄� - _RoleAuthRepository.AddData(updateAuths); + _RoleAuthRepository.AddData(updateAuths.Where(x => x.AuthId <= 0).ToList()); //鑾峰彇鏉冮檺鍙栨秷鐨勬潈闄� int[] authIds = roleAuths.Where(x => userPermissions.Select(u => u.Id) @@ -195,11 +233,11 @@ x.AuthValue = ""; }); //灏嗗彇娑堢殑鏉冮檺璁剧疆涓�"" - _RoleAuthRepository.UpdateData(delAuths); + _RoleAuthRepository.DeleteData(delAuths); int addCount = updateAuths.Where(x => x.AuthId <= 0).Count(); int updateCount = updateAuths.Where(x => x.AuthId > 0).Count(); - + string _version = DateTime.Now.ToString("yyyyMMddHHMMssfff"); -- Gitblit v1.9.3