From d215841b67d63c80abda18adeb77ce48663db601 Mon Sep 17 00:00:00 2001 From: lzw <605106923@qq.com> Date: Tue, 19 Oct 2021 17:33:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8E=A7=E5=88=B6=E5=99=A8?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/MenuController.cs | 2 +- .../Controllers/RoleController.cs | 9 ++++++--- .../Controllers/UserController.cs | 7 +++---- .../Yi.Framework.ApiMicroservice/YIDB.db-wal | Bin 86552 -> 206032 bytes .../Yi.Framework.Interface/IRoleService.cs | 11 ++++++++--- .../Yi.Framework.Interface/IUserService.cs | 2 +- .../Yi.Framework.Service/MenuService.cs | 10 ++++++++-- .../Yi.Framework.Service/RoleService.cs | 12 ++++++++++++ .../Yi.Framework.Service/UserService.cs | 3 ++- 9 files changed, 41 insertions(+), 15 deletions(-) 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 bf0bc32d0646f6abfed7e4e988b4659af9e8e054..9ce3a1253c6f427f4e2a59bb3e281e3bff4a4e63 100644 GIT binary patch delta 2006 zcmb`|dq`7J90%~--Me``*PSz&Z=;RCsNL-@iwt_2*^`1^)*po}NP9T5v=tPnQCVg} zdI+pP%vsT!wyu_DMJYx_S(YKxA2QM`GAaeJl<1tRhOaWM{d31<_s98tzF+PN&T5`N z^2;n?LRMn8UC$p%YPcrA>8v?6zW*738{1{-*@sn2p!cYXDrac`zjG+ z=go;zgKUpW1ZtCrmkA-*uG4anXq*|R`x&vL%Qk2W- ziGBgG-N>ntc*bsIP=PaR?Wye-PIv#xj8jZ;YGfu0Jb@aHRWTxN*x*HrJ0@t~c{i^b zbQ~X(D5#8q;driJ=uqbYc%Gj>E`nN|BnZERQA^~ZGg@}(@jstUbH^Mhue;dzr?b`d zPsEVkHC>y#o*6z7%Lo&Bo8J=CthxG{5?H_%k_ZQ~!4{8;2Wq1QrwC(tI692IW%`fJ zvk&U%nij;7pv=A;I*j6xglJ%omB4st(Xb5D6Wbbx6IrtSKX*S9L1W{P8AZsorfLXi zaF*Wm1_;&ej+vTT&n6EqWF4W=3R%HIBBZ54V4=s=;!QZr;CYIh-`VAg(g zUUW3JQQGB`8~WRwJUu&+>uB?LpNQqBOsxApnw{b+>R4cSdi(Ep8c>HtrRU;jO=~m^ zUk7P~bvSI_Q}wk9@{~>j<4GO(?mB?+9#nGx_|(9mkYeD2Qr> 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; }