| | |
| | | using WMS.IDAL; |
| | | using WMS.IDAL.ISysInterface; |
| | | using Model.ModelVm.SysVm; |
| | | using WMS.Entity.Context; |
| | | using Utility; |
| | | using Talk.Extensions; |
| | | |
| | | namespace WMS.BLL.SysServer |
| | | { |
| | |
| | | public IRBACRepository _rbac { get; set; } |
| | | private readonly IMenuRepository _menu; |
| | | private readonly IRoleRightRepository _roleright; |
| | | private static readonly SqlSugarScope Db = DataContext.Db; |
| | | private readonly UserManager _userManager; |
| | | /// <summary> |
| | | /// 构造函数 |
| | | /// </summary> |
| | | /// <param name="rbac"></param> |
| | | /// <param name="menu"></param> |
| | | /// <param name="roleright"></param> |
| | | public RBACServer(IRBACRepository rbac, IMenuRepository menu, IRoleRightRepository roleright) |
| | | public RBACServer(IRBACRepository rbac, IMenuRepository menu, IRoleRightRepository roleright, UserManager userManager) |
| | | { |
| | | _rbac = rbac; |
| | | _menu = menu; |
| | | _roleright = roleright; |
| | | _userManager = userManager; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | /// <param name="id"></param> |
| | | /// <returns></returns> |
| | | public List<RoleRightDto> GetRoleRightList(int id) |
| | | public async Task<List<RoleRightDto>> GetRoleRightList(int id) |
| | | { |
| | | List<RoleRightDto> roleRightDtos = _roleright.GetRoleRightListById(id); |
| | | return roleRightDtos; |
| | | return await Db.Queryable<SysRoleRight>() |
| | | .LeftJoin<SysRoles>((a, b) => a.RoleNo == b.RoleNo) |
| | | .LeftJoin<SysFunctionMenu>((a, b, c) => a.MenuNo == c.MenuNo) |
| | | .Where((a, b, c) => a.Id == id && a.IsDel == "0") |
| | | .Select<RoleRightDto>() |
| | | .ToListAsync(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | /// <param name="id"></param> |
| | | /// <returns></returns> |
| | | public object GetMenuByroleIdNew(int id) |
| | | public async Task<List<FunctionMenuDto>> GetMenuByroleIdNew(int id) |
| | | { |
| | | try |
| | | List<RoleRightDto> rolerightlist = await Db.Queryable<SysRoleRight>().LeftJoin<SysRoles>((a, b) => a.RoleNo == b.RoleNo) |
| | | .LeftJoin<SysFunctionMenu>((a, b, c) => a.MenuNo == c.MenuNo) |
| | | .Where((a, b, c) => a.Id == id && a.IsDel == "0") |
| | | .Select<RoleRightDto>() |
| | | .ToListAsync(); |
| | | var listMenuNo = rolerightlist.Select(s => s.MenuNo).Distinct().ToList(); |
| | | List<FunctionMenuDto> listMenu = await Db.Queryable<SysFunctionMenu>().OrderBy(m => m.MenuNo).Select(m => new FunctionMenuDto() |
| | | { |
| | | List<RoleRightDto> rolerightlist = _roleright.GetRoleRightListById(id); |
| | | //var list = DataContext.WmsSysRight.Where(m => m.UserGroupId == id).ToList(); |
| | | var str = new List<string>(); |
| | | foreach (var item in rolerightlist) |
| | | { |
| | | str.Add(item.MenuNo); |
| | | } |
| | | string sql1 = $"select * from SysFunctionMenu where IsDel = '0' and ParentNo = ''"; |
| | | List<FunctionMenuDto> parent = _menu.GetMenuList(sql1).OrderBy(m => m.MenuNo).Select(m => new FunctionMenuDto() |
| | | { |
| | | //Id = m.Id, |
| | | MenuNo = m.MenuNo, |
| | | ParentId = m.ParentNo, |
| | | title = m.MenuName, |
| | | //expand = str.Contains(m.Id), |
| | | @checked = str.Contains(m.MenuNo) |
| | | }).ToList(); |
| | | |
| | | string sql2 = $"select * from SysFunctionMenu where IsDel = '0' and ParentNo != ''"; |
| | | List<FunctionMenuDto> child = _menu.GetMenuList(sql2).OrderBy(m => m.MenuNo).Select(m => new FunctionMenuDto() |
| | | { |
| | | //Id = m.Id, |
| | | MenuNo = m.MenuNo, |
| | | ParentId = m.ParentNo, |
| | | title = m.MenuName, |
| | | Expand = str.Contains(m.MenuNo), |
| | | @checked = str.Contains(m.MenuNo) |
| | | }).ToList(); |
| | | |
| | | List<FunctionMenuDto> data = new List<FunctionMenuDto>(); |
| | | |
| | | foreach (var item in parent) |
| | | { |
| | | data.Add(item); |
| | | FunNew(child, item); |
| | | } |
| | | return data; |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | //Id = m.Id, |
| | | MenuNo = m.MenuNo, |
| | | ParentId = m.ParentNo, |
| | | title = m.MenuName, |
| | | Expand = listMenuNo.Contains(m.MenuNo), |
| | | @checked = listMenuNo.Contains(m.MenuNo) |
| | | }).ToListAsync(); |
| | | var listParent = listMenu.Where(s => s.ParentId == "").ToList(); |
| | | var listChild = listMenu.Where(s => s.ParentId != "").ToList(); |
| | | foreach (var item in listParent) |
| | | { |
| | | throw new Exception("获取角色对应的菜单信息" + ex.Message); |
| | | FunNew(listChild, item); |
| | | } |
| | | return listParent; |
| | | |
| | | } |
| | | public void FunNew(List<FunctionMenuDto> all, FunctionMenuDto curItem) |
| | | { |
| | |
| | | { |
| | | FunNew(all, subItem); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | /// <param name="MenuNo"></param> |
| | | /// <param name="UserId"></param> |
| | | /// <returns></returns> |
| | | public List<FunctionMenuDto> GetRoleRightRBAC(string MenuNo, string UserId) |
| | | public async Task<List<FunctionMenuDto>> GetRoleRightRBAC(string MenuNo, string UserId) |
| | | { |
| | | List<FunctionMenuDto> menudto = _menu.GetMenuDtoList(MenuNo,UserId); |
| | | |
| | | return menudto; |
| | | var modUser = await Db.Queryable<SysUserInfor>().FirstAsync(s => s.Id == _userManager.UserId); |
| | | return await Db.Queryable<SysFunctionMenu>() |
| | | .Where(s => s.IsDel == "0") |
| | | .WhereIF(!string.IsNullOrEmpty(MenuNo), s => s.ParentNo == MenuNo) |
| | | .WhereIF(modUser.UserName.ToUpper() != "ADMIN", s => SqlFunc.Subqueryable<SysRoleRight>().Where(c => c.RoleNo == modUser.RoleNo && s.MenuNo == c.MenuNo).Any()) |
| | | .OrderBy(s => s.Ord, OrderByType.Asc) |
| | | .Select<FunctionMenuDto>() |
| | | .ToListAsync(); |
| | | } |
| | | } |
| | | } |