/// <summary> /// 根据菜单,获得当前菜单的所有功能权限 /// </summary> /// <returns></returns> public Task <ApiResult <List <SysCodeDto> > > GetCodeByMenu(string role, string menu) { var res = new ApiResult <List <SysCodeDto> >() { statusCode = (int)ApiEnum.Error }; try { //获得角色权限Guid-List var menuModel = SysMenuDb.GetSingle(m => m.Guid == menu); //查询授权菜单里面的按钮功能 var btnFunModel = SysPermissionsDb.GetSingle(m => m.RoleGuid == role && m.MenuGuid == menu && m.Types == 1); var codeList = new List <SysCodeDto>(); if (!string.IsNullOrEmpty(menuModel.BtnFunJson)) { var list = JsonConvert.DeserializeObject <List <string> >(menuModel.BtnFunJson); codeList = SysCodeDb.GetList(m => list.Contains(m.Guid)).Select(m => new SysCodeDto() { guid = m.Guid, name = m.Name, codeType = m.CodeType, status = string.IsNullOrEmpty(btnFunModel.BtnFunJson)?false:btnFunModel.BtnFunJson.Contains(m.Guid)?true:false }).ToList(); } res.statusCode = (int)ApiEnum.Status; res.data = codeList; } catch (Exception ex) { res.message = ex.Message; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(Task.Run(() => res)); }
/// <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 ApiResult <List <SysCodeDto> > GetCodeByMenu(string role, string menu) { var res = new ApiResult <List <SysCodeDto> >() { statusCode = (int)ApiEnum.Error }; try { //获得角色权限Guid-List var menuModel = SysMenuDb.GetSingle(m => m.Guid == menu); if (menuModel == null) { return(new ApiResult <List <SysCodeDto> >()); } //查询授权菜单里面的按钮功能 var btnFunModel = SysPermissionsDb.GetSingle(m => m.RoleGuid == role && m.MenuGuid == menu && m.Types == 1); if (btnFunModel == null) { return(new ApiResult <List <SysCodeDto> >()); } var list = JsonConvert.DeserializeObject <List <string> >(menuModel.BtnFunJson); var codeList = Db.Queryable <SysCode>().Where(m => list.Contains(m.Guid)).Select(m => new SysCodeDto() { guid = m.Guid, name = m.Name, codeType = m.CodeType, status = false }).ToList(); if (btnFunModel != null && !string.IsNullOrEmpty(btnFunModel.BtnFunJson) && btnFunModel.BtnFunJson != "[]") { foreach (var item in codeList) { if (btnFunModel.BtnFunJson.Contains(item.guid)) { item.status = true; } } } res.statusCode = (int)ApiEnum.Status; res.data = codeList; } catch (Exception ex) { res.message = ex.Message; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(res); }
/// <summary> /// 用户授权角色 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <string> > ToRoleAsync(SysPermissions parm, bool status) { var res = new ApiResult <string> { statusCode = 200, data = "1" }; try { if (status) { //授权 var dbres = SysPermissionsDb.Insert(new SysPermissions() { RoleGuid = parm.RoleGuid, AdminGuid = parm.AdminGuid, MenuGuid = parm.MenuGuid, BtnFunGuid = parm.BtnFunGuid, Types = parm.Types }); if (!dbres) { res.statusCode = (int)ApiEnum.Error; res.message = "插入数据失败~"; } } else { //取消授权 if (parm.Types == 2) { SysPermissionsDb.Delete(m => m.AdminGuid == parm.AdminGuid && m.RoleGuid == parm.RoleGuid && m.Types == 2); } if (parm.Types == 3) { //角色-菜单-按钮功能 SysPermissionsDb.Delete(m => m.BtnFunGuid == parm.BtnFunGuid && m.RoleGuid == parm.RoleGuid && m.MenuGuid == parm.MenuGuid && m.Types == 3); } } } catch (Exception ex) { Db.Ado.CommitTran(); res.statusCode = (int)ApiEnum.Error; res.message = ApiEnum.Error.GetEnumText() + ex.Message; } return(await Task.Run(() => res)); }
/// <summary> /// 删除部门 /// </summary> /// <param name="parm"></param> /// <returns></returns> public new async Task <ApiResult <string> > DeleteAsync(string parm) { var list = Utils.StrToListString(parm); var isok = SysAdminDb.Delete(m => list.Contains(m.Guid)); //删除授权 SysPermissionsDb.Delete(m => list.Contains(m.MenuGuid) && m.Types == 2); var res = new ApiResult <string> { statusCode = isok ? 200 : 500, data = isok ? "1" : "0", message = isok ? "删除成功~" : "删除失败~" }; return(await Task.Run(() => 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)); }
/// <summary> /// 菜单授权-菜单功能 /// role=角色 /// funguid=按钮的编号 /// status=取消还是授权 /// </summary> /// <returns></returns> public Task <ApiResult <string> > RoleMenuToFunAsync(SysPermissionsParm parm) { var res = new ApiResult <string>() { statusCode = (int)ApiEnum.Error }; try { //根据角色和菜单查询内容 var model = SysPermissionsDb.GetSingle(m => m.RoleGuid == parm.role && m.MenuGuid == parm.menu && m.Types == 1); if (model == null) { res.message = "您还没有授权当前菜单功能模块"; return(Task.Run(() => res)); } if (!string.IsNullOrEmpty(model.BtnFunJson)) { //判断授权还是取消 var list = JsonConvert.DeserializeObject <List <string> >(model.BtnFunJson); if (parm.status == 0) { if (list.Contains(parm.btnfun)) { list.Remove(parm.btnfun); } } else { //授权 if (!list.Contains(parm.btnfun)) { list.Add(parm.btnfun); } } model.BtnFunJson = JsonConvert.SerializeObject(list); } else { //肯定是增加 model.BtnFunJson = JsonConvert.SerializeObject(new List <string>() { parm.btnfun }); } Db.Updateable <SysPermissions>() .UpdateColumns(m => new SysPermissions() { BtnFunJson = model.BtnFunJson }) .Where(m => m.RoleGuid == parm.role && m.MenuGuid == parm.menu && m.Types == 1).ExecuteCommand(); res.statusCode = (int)ApiEnum.Status; } catch (Exception ex) { res.message = ex.Message; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(Task.Run(() => res)); }