/// <summary> /// 根据登录账号,获得相应权限 /// </summary> /// <returns></returns> public ApiResult <List <SysMenuDto> > GetAuthorizeAsync(string admin) { var res = new ApiResult <List <SysMenuDto> >() { statusCode = (int)ApiEnum.Error }; try { //根据用户查询角色列表, 一个用户对应多个角色 var roleList = SysPermissionsDb.GetList(m => m.AdminGuid == admin && m.Types == 2).Select(m => m.RoleGuid).ToList(); //根据角色查询菜单,并查询到菜单涉及的功能 var query = Db.Queryable <SysMenu, SysPermissions>((sm, sp) => new object[] { JoinType.Left, sm.Guid == sp.MenuGuid }) .Where((sm, sp) => roleList.Contains(sp.RoleGuid) && sp.Types == 1 && sm.Status) .OrderBy((sm, sp) => sm.Sort) .Select((sm, sp) => new SysMenuDto() { guid = sm.Guid, parentGuid = sm.ParentGuid, parentName = sm.ParentName, name = sm.Name, nameCode = sm.NameCode, parentGuidList = sm.ParentGuidList, layer = sm.Layer, urls = sm.Urls, icon = sm.Icon, sort = sm.Sort, btnJson = sp.BtnFunJson }) .Mapper((it, cache) => { var codeList = cache.Get(list => { return(Db.Queryable <SysCode>().Where(m => m.ParentGuid == "a88fa4d3-3658-4449-8f4a-7f438964d716") .Select(m => new SysCodeDto() { guid = m.Guid, name = m.Name, codeType = m.CodeType }) .ToList()); }); if (!string.IsNullOrEmpty(it.btnJson)) { it.btnFun = codeList.Where(m => it.btnJson.Contains(m.guid)).ToList(); } }); res.data = query.ToList(); res.statusCode = (int)ApiEnum.Status; } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(res); }
/// <summary> /// 根据登录账号,返回菜单信息 /// </summary> /// <param name="admin"></param> /// <returns></returns> List <SysMenuDto> GetMenuByAdmin(string admin) { List <SysMenuDto> res = null; try { //根据用户查询角色列表, 一个用户对应多个角色 var roleList = SysPermissionsDb.GetList(m => m.AdminGuid == admin && m.Types == 2).Select(m => m.RoleGuid).ToList(); //根据角色查询菜单,并查询到菜单涉及的功能 var query = Db.Queryable <SysMenu, SysPermissions>((sm, sp) => new object[] { JoinType.Inner, sm.Guid == sp.MenuGuid }) .Where((sm, sp) => roleList.Contains(sp.RoleGuid) && sp.Types == 3 && sm.Status) .OrderBy((sm, sp) => sm.Sort) .Select((sm, sp) => new SysMenuDto() { guid = sm.Guid, parentGuid = sm.ParentGuid, parentName = sm.ParentName, name = sm.Name, nameCode = sm.NameCode, parentGuidList = sm.ParentGuidList, layer = sm.Layer, urls = sm.Urls, icon = sm.Icon, sort = sm.Sort, btnJson = sp.BtnFunJson }) .Mapper((it, cache) => { var codeList = cache.Get(list => { return(Db.Queryable <SysCode>().Where(m => m.ParentGuid == "a88fa4d3-3658-4449-8f4a-7f438964d716") .Select(m => new SysCodeDto() { guid = m.Guid, name = m.Name, codeType = m.CodeType }) .ToList()); }); if (!string.IsNullOrEmpty(it.btnJson)) { it.btnFun = codeList.Where(m => it.btnJson.Contains(m.guid)).ToList(); } }); var result = query.ToList(); res = result.CurDistinct(m => m.guid).ToList(); } catch { res = null; } return(res); }
/// <summary> /// 根据登录账号,获得相应权限 /// </summary> /// <returns></returns> public async Task <ApiResult <List <SysMenu> > > GetAuthorizeAsync(string admin) { var res = new ApiResult <List <SysMenu> >() { statusCode = (int)ApiEnum.Error }; try { //根据用户查询角色列表, 一个用户对应多个角色 var roleList = SysPermissionsDb.GetList(m => m.AdminGuid == admin && m.Types == 2).Select(m => m.RoleGuid).ToList(); //根据角色获得多个菜单 var menuList = SysPermissionsDb.GetList(m => roleList.Contains(m.RoleGuid) && m.Types == 1).Select(m => m.MenuGuid).ToList(); //根据权限菜单查询列表 res.data = SysMenuDb.GetList(m => menuList.Contains(m.Guid) && m.Status).OrderBy(m => m.Sort).ToList(); res.statusCode = (int)ApiEnum.Status; } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; } return(await Task.Run(() => res)); }