diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs index 39cf7e08..babd9cfc 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs @@ -27,7 +27,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers public async Task GetMenu() { - return Result.Success().SetData(await _menuService.GetAllEntitiesTrueAsync()); + return Result.Success().SetData(await _menuService.GetTopMenu()); } /// diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs index eac2eb9a..9f08925f 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs @@ -74,8 +74,11 @@ namespace Yi.Framework.ApiMicroservice.Controllers await _roleService.SetMenusByRolesId(idsListDto.ids2, idsListDto.ids1); return Result.Success(); } - - - + [HttpPost] + public async Task GetMenuByRloeIds(List roleIds) + { + var menuList =await _roleService.GetMenusByRoleId(roleIds); + return Result.Success().SetData(menuList); + } } } diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs index 5f2225d9..45ce5679 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs @@ -112,10 +112,9 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// 根据用户id得到该用户有哪些角色 /// /// - [HttpGet] - public async Task GetRolesByUserId(int user_id) - { - var _user =await _userService.GetEntityById(user_id); + [HttpPost] + public async Task GetRolesByUserId(user _user) + { var roleList = await _userService.GetRolesByUser(_user); return Result.Success().SetData(roleList); } diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/YIDB.db-wal b/Yi.Framework/Yi.Framework.ApiMicroservice/YIDB.db-wal index bf0bc32d..9ce3a125 100644 Binary files a/Yi.Framework/Yi.Framework.ApiMicroservice/YIDB.db-wal and b/Yi.Framework/Yi.Framework.ApiMicroservice/YIDB.db-wal differ diff --git a/Yi.Framework/Yi.Framework.Interface/IRoleService.cs b/Yi.Framework/Yi.Framework.Interface/IRoleService.cs index e41b3efd..8262c3d8 100644 --- a/Yi.Framework/Yi.Framework.Interface/IRoleService.cs +++ b/Yi.Framework/Yi.Framework.Interface/IRoleService.cs @@ -27,13 +27,18 @@ namespace Yi.Framework.Interface Task> GetUsersByRole(role _role); /// - /// 给单个角色设置多个菜单 + /// 给多个角色设置多个菜单 /// /// - /// + /// /// Task SetMenusByRolesId(List menuIds, List roleIds); - + /// + /// 获取多个用户的菜单,并列,不包含子菜单 + /// + /// + /// + Task> GetMenusByRoleId(List roleIds); } } diff --git a/Yi.Framework/Yi.Framework.Interface/IUserService.cs b/Yi.Framework/Yi.Framework.Interface/IUserService.cs index b0160e82..508cf1f0 100644 --- a/Yi.Framework/Yi.Framework.Interface/IUserService.cs +++ b/Yi.Framework/Yi.Framework.Interface/IUserService.cs @@ -25,7 +25,7 @@ namespace Yi.Framework.Interface Task Register(user _user); /// - /// 根据http上下文的用户得到该用户有哪些角色 + /// 根据用户得到该用户有哪些角色 /// /// Task> GetRolesByUser(user _user); diff --git a/Yi.Framework/Yi.Framework.Service/MenuService.cs b/Yi.Framework/Yi.Framework.Service/MenuService.cs index 0a73b762..46e61ba6 100644 --- a/Yi.Framework/Yi.Framework.Service/MenuService.cs +++ b/Yi.Framework/Yi.Framework.Service/MenuService.cs @@ -72,9 +72,15 @@ namespace Yi.Framework.Service public async Task> GetTopMenu() { - return await _Db.Set().Include(u => u.children) - .Where(u => u.is_delete == (short)Common.Enum.DelFlagEnum.Normal && u.is_top == (short)Common.Enum.TopFlagEnum.Top) + var menu_data= await _Db.Set().Include(u => u.children).Include(u=>u.mould) + .Where(u =>u.is_delete == (short)Common.Enum.DelFlagEnum.Normal && u.is_top == (short)Common.Enum.TopFlagEnum.Top) .ToListAsync(); + return TopMenuBuilder(menu_data); + } + private List TopMenuBuilder(List menu_data) + { + + return menu_data; } public async Task SetMouldByMenu(int mouldId, int menuId) diff --git a/Yi.Framework/Yi.Framework.Service/RoleService.cs b/Yi.Framework/Yi.Framework.Service/RoleService.cs index d2e46348..6622f3e4 100644 --- a/Yi.Framework/Yi.Framework.Service/RoleService.cs +++ b/Yi.Framework/Yi.Framework.Service/RoleService.cs @@ -53,5 +53,17 @@ namespace Yi.Framework.Service } return await UpdateListAsync(role_data); } + public async Task> GetMenusByRoleId(List roleIds) + { + var roleList = await _Db.Set().Include(u=>u.menus) + .Where(u => roleIds.Contains(u.id) && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToListAsync(); + var menuList=new List(); + roleList.ForEach(item => + { + var menus = item.menus.Where(u => u.is_delete == (short)Common.Enum.DelFlagEnum.Normal); + menuList = menuList.Concat(menus).ToList(); + }); + return menuList; + } } } diff --git a/Yi.Framework/Yi.Framework.Service/UserService.cs b/Yi.Framework/Yi.Framework.Service/UserService.cs index 31835bb8..c0577095 100644 --- a/Yi.Framework/Yi.Framework.Service/UserService.cs +++ b/Yi.Framework/Yi.Framework.Service/UserService.cs @@ -61,7 +61,8 @@ namespace Yi.Framework.Service { var user_data = await _Db.Set().Include(u=>u.roles) .Where(u => u.id == _user.id && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync(); - var roleList = user_data.roles.ToList(); + var roleList = user_data.roles.Where(u=> u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToList(); + roleList.ForEach(u => u.users = null); return roleList; }