From c020f31a67fc5aa5644511bddff075f7ecc85234 Mon Sep 17 00:00:00 2001 From: qinchulong <qinchulong@hnkhzn.com> Date: 星期二, 27 五月 2025 15:35:27 +0800 Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/HuaYiZhongHeng/ZhongHeLiTiKu --- 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_SystemRepository/Sys_MenuRepository.cs | 225 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 225 insertions(+), 0 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemRepository/Sys_MenuRepository.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemRepository/Sys_MenuRepository.cs" new file mode 100644 index 0000000..da9c152 --- /dev/null +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemRepository/Sys_MenuRepository.cs" @@ -0,0 +1,225 @@ +锘縰sing AutoMapper; +using SqlSugar; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WIDESEA_Core; +using WIDESEA_Core.BaseRepository; +using WIDESEA_Core.Helper; +using WIDESEA_DTO.System; +using WIDESEA_ISystemRepository; +using WIDESEA_Model; +using WIDESEA_Model.Models; + +namespace WIDESEA_SystemRepository +{ + public class Sys_MenuRepository : RepositoryBase<Sys_Menu>, ISys_MenuRepository + { + private readonly IMapper _mapper; + public Sys_MenuRepository(IUnitOfWorkManage unitOfWorkManage, IMapper mapper) : base(unitOfWorkManage) + { + _mapper = mapper; + } + + public List<MenuDTO> GetAllMenu() + { + List<Sys_Menu> menus = base.QueryData(x => (x.Enable == 1 || x.Enable == 2) && x.MenuType == App.User.MenuType).OrderByDescending(a => a.OrderNo).ThenByDescending(q => q.ParentId).ToList(); + List<MenuDTO> _menus = _mapper.Map<List<MenuDTO>>(menus); + _menus.ForEach(x => + { + if (!string.IsNullOrEmpty(x.Auth) && x.Auth.Length > 10) + { + try + { + x.Actions = x.Auth.DeserializeObject<List<ActionDTO>>(); + } + catch { } + } + x.Actions ??= new List<ActionDTO>(); + }); + string test = _menus.Serialize(); + return _menus; + } + + public List<MenuDTO> GetAllMenuPDA() + { + List<Sys_Menu> menus = base.QueryData(x => (x.Enable == 1 || x.Enable == 2) && x.MenuType == 1).OrderByDescending(a => a.OrderNo).ThenByDescending(q => q.ParentId).ToList(); + List<MenuDTO> _menus = _mapper.Map<List<MenuDTO>>(menus); + _menus.ForEach(x => + { + if (!string.IsNullOrEmpty(x.Auth) && x.Auth.Length > 10) + { + try + { + x.Actions = x.Auth.DeserializeObject<List<ActionDTO>>(); + } + catch { } + } + x.Actions ??= new List<ActionDTO>(); + }); + string test = _menus.Serialize(); + return _menus; + } + + public object GetSuperAdminMenu() + { + return GetAllMenu().Select(x => + new + { + id = x.MenuId, + name = x.MenuName, + url = x.Url, + parentId = x.ParentId, + icon = x.Icon, + x.Enable, + x.TableName, // 2022.03.26澧炵Щ鍔ㄧ鍔犺彍鍗曠被鍨� + permission = x.Actions.Select(s => s.Value).ToArray() + }).ToList(); + } + + public object GetMenuByRoleId(int roleId) + { + var menu = from a in GetPermissions(roleId) + join b in GetAllMenu() + on a.MenuId equals b.MenuId + orderby b.OrderNo descending + select new + { + id = a.MenuId, + name = b.MenuName, + url = b.Url, + parentId = b.ParentId, + icon = b.Icon, + b.Enable, + b.TableName, + permission = a.UserAuthArr + }; + return menu.ToList(); + } + + /// <summary> + /// 鑾峰彇瑙掕壊鏉冮檺鏃堕�氳繃瀹夊叏瀛楀吀閿佸畾鐨勮鑹瞚d + /// </summary> + private static ConcurrentDictionary<string, object> objKeyValue = new ConcurrentDictionary<string, object>(); + + public List<Permissions> GetPermissions(int roleId) + { + if (App.User.IsRoleIdSuperAdmin(roleId)) + { + //2020.12.27澧炲姞鑿滃崟鐣岄潰涓婁笉鏄剧ず锛屼絾鍙互鍒嗛厤鏉冮檺 + var permissions = QueryData(x => x.Enable == 1 || x.Enable == 2) + .Select(a => new Permissions + { + MenuId = a.MenuId, + ParentId = a.ParentId, + TableName = (a.TableName ?? "").ToLower(), + UserAuth = a.Auth, + MenuType = a.MenuType + }).ToList(); + return MenuActionToArray(permissions); + } + + //閿佸畾姣忎釜瑙掕壊锛岄�氳繃瀹夊叏瀛楀吀鍑忓皯閿佺矑搴︼紝鍚﹀垯澶氫釜鍚屾椂瑙掕壊鑾峰彇缂撳瓨浼氬鑷撮樆濉� + object objId = objKeyValue.GetOrAdd(roleId.ToString(), new object()); + //閿佸畾姣忎釜瑙掕壊 + lock (objId) + { + //娌℃湁redis/memory缂撳瓨瑙掕壊鐨勭増鏈彿鎴栦笌褰撳墠鏈嶅姟鍣ㄧ殑瑙掕壊鐗堟湰鍙蜂笉鍚屾椂锛屽埛鏂扮紦瀛� + + List<Permissions> _permissions = QueryTabs<Sys_Menu, Sys_RoleAuth, Permissions>((a, b) => new object[] { JoinType.Inner, a.MenuId == b.MenuId }, (a, b) => new Permissions { MenuId = a.MenuId, ParentId = a.ParentId, TableName = (a.TableName ?? "").ToLower(), MenuAuth = a.Auth, UserAuth = b.AuthValue ?? "", MenuType = a.MenuType }, (a, b) => b.RoleId == roleId, x => true); + + ActionToArray(_permissions); + + return _permissions; + } + } + + private List<Permissions> MenuActionToArray(List<Permissions> permissions) + { + permissions.ForEach(x => + { + try + { + x.UserAuthArr = string.IsNullOrEmpty(x.UserAuth) + ? new string[0] + : x.UserAuth.DeserializeObject<List<ActionDTO>>().Select(s => s.Value).ToArray(); + } + catch { } + finally + { + if (x.UserAuthArr == null) + { + x.UserAuthArr = new string[0]; + } + } + }); + return permissions; + } + + private List<Permissions> ActionToArray(List<Permissions> permissions) + { + permissions.ForEach(x => + { + try + { + var menuAuthArr = x.MenuAuth.DeserializeObject<List<ActionDTO>>(); + x.UserAuthArr = string.IsNullOrEmpty(x.UserAuth) + ? new string[0] + : x.UserAuth.Split(",").Where(c => menuAuthArr.Any(m => m.Value == c)).ToArray(); + + } + catch { } + finally + { + if (x.UserAuthArr == null) + { + x.UserAuthArr = new string[0]; + } + } + }); + return permissions; + } + + public object GetMenu(List<int> menuIds) + { + return QueryData(x => menuIds.Contains(x.MenuId)).Select(a => + new + { + id = a.MenuId, + parentId = a.ParentId, + name = a.MenuName, + a.MenuType, + a.OrderNo + }).OrderByDescending(a => a.OrderNo) + .ThenByDescending(q => q.parentId).ToList(); + } + + public object GetTreeItem(int menuId) + { + var sysMenu = base.QueryData(x => x.MenuId == menuId) + .Select( + p => new + { + p.MenuId, + p.ParentId, + p.MenuName, + p.Url, + p.Auth, + p.OrderNo, + p.Icon, + p.Enable, + // 2022.03.26澧炵Щ鍔ㄧ鍔犺彍鍗曠被鍨� + p.MenuType, + p.CreateDate, + p.Creater, + p.TableName, + p.ModifyDate + }).FirstOrDefault(); + return sysMenu; + } + } +} -- Gitblit v1.9.3