From b29b6be734be1ea76d9b0fbdb85b50ff68aecaad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Tue, 26 Oct 2021 00:59:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AccountController.cs | 4 +- .../Controllers/MenuController.cs | 1 + .../Controllers/MouldController.cs | 4 +- .../Controllers/RoleController.cs | 4 +- .../Controllers/UserController.cs | 3 +- .../Yi.Framework.Service/MenuService.cs | 46 ++++++++++++++++--- .../Yi.Framework.Service/MouldService.cs | 8 +++- .../Yi.Framework.Service/RoleService.cs | 26 ++++++++--- .../Yi.Framework.Service/UserService.cs | 2 +- Yi.Vue/src/components/ccTreeview.vue | 2 +- 10 files changed, 80 insertions(+), 20 deletions(-) diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs index d00fab63..81d19655 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -109,6 +110,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// /// [HttpPut] + [Authorize] public async Task ChangePassword(ChangePwdDto pwdDto) { var uid= pwdDto.user.id; diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs index c846a8cf..bbacced2 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs @@ -14,6 +14,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers { [Route("api/[controller]/[action]")] [ApiController] + [Authorize] public class MenuController : ControllerBase { private IMenuService _menuService; diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MouldController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MouldController.cs index 46c17211..7c0ee94a 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MouldController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MouldController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; @@ -12,6 +13,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers { [Route("api/[controller]/[action]")] [ApiController] + [Authorize] public class MouldController : ControllerBase { private IMouldService _mouldService; diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs index ecd5cceb..d912f097 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; @@ -13,6 +14,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers { [Route("api/[controller]/[action]")] [ApiController] + [Authorize] public class RoleController : ControllerBase { private IRoleService _roleService; diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs index 1e896694..383151cf 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs @@ -15,6 +15,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers { [ApiController] [Route("api/[controller]/[action]")] + [Authorize] public class UserController : ControllerBase { private readonly ILogger _logger; @@ -122,7 +123,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// 根据http上下文的用户得到该用户信息,关联角色 /// /// - [Authorize] + [HttpGet] public async Task GetUserInfoById() { diff --git a/Yi.Framework/Yi.Framework.Service/MenuService.cs b/Yi.Framework/Yi.Framework.Service/MenuService.cs index eb0572ed..7b128389 100644 --- a/Yi.Framework/Yi.Framework.Service/MenuService.cs +++ b/Yi.Framework/Yi.Framework.Service/MenuService.cs @@ -20,6 +20,11 @@ namespace Yi.Framework.Service return menu_data; } + /// + /// 这个getEntity没有关联子类,怎么能得到子类呢?这是一个错误的接口 + /// + /// + /// public async Task> GetChildrenByMenu(menu _menu) { var menu_data = await GetEntity(u=>u.id==_menu.id&& u.is_delete == (short)Common.Enum.DelFlagEnum.Normal); @@ -27,10 +32,15 @@ namespace Yi.Framework.Service return childrenList; } + /// + /// 不要返回一个新创的变量,直接返回menu.children,只要id,就不要传一个对象 + /// + /// + /// public async Task> GetChildrenMenu(menu _menu) { var menu= await _Db.Set().Include(u => u.children).Include(u=>u.mould) - .Where(u =>u.id==_menu.id&& u.is_delete == (short)Common.Enum.DelFlagEnum.Normal&& u.is_top == (short)Common.Enum.TopFlagEnum.Children ) + .Where(u =>u.id==_menu.id&& u.is_top == (short)Common.Enum.TopFlagEnum.Children ) .FirstOrDefaultAsync(); var childrenList = menu.children.ToList(); return childrenList; @@ -44,30 +54,48 @@ namespace Yi.Framework.Service return menuList; } + /// + /// 和GetChildrenMenu方法可以合并 + /// + /// + /// public async Task GetMenuMouldByMenu(menu _menu) { var menu_data = await _Db.Set().Include(u => u.children).Include(u=>u.mould) - .Where(u=>u.id==_menu.id&& u.is_delete == (short)Common.Enum.DelFlagEnum.Normal && u.is_delete == (short)Common.Enum.ShowFlagEnum.Show).FirstOrDefaultAsync(); + .Where(u=>u.id==_menu.id&& u.is_delete == (short)Common.Enum.ShowFlagEnum.Show) + .FirstOrDefaultAsync(); return menu_data; } public async Task GetMouldByMenu(menu _menu) { - var menu_data =await _Db.Set().Include(u => u.mould) - .Where(u => u.id == _menu.id & u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync(); + var menu_data =await _Db.Set().Include(u => u.mould).Where(u => u.id == _menu.id).FirstOrDefaultAsync(); return menu_data.mould; } + /// + /// 5层迭代 + /// + /// public async Task> GetTopMenu() { - var menu_data= await _Db.Set().Include(u=>u.mould).Include(u => u.children).ThenInclude(u => u.children).ThenInclude(u => u.children).ThenInclude(u => u.children) + var menu_data= await _Db.Set().Include(u=>u.mould) + .Include(u => u.children).ThenInclude(u => u.mould) + .Include(u=>u.children).ThenInclude(u => u.children).ThenInclude(u => u.mould) + .Include(u => u.children).ThenInclude(u => u.children).ThenInclude(u => u.children).ThenInclude(u => u.mould) + .Include(u => u.children).ThenInclude(u => u.children).ThenInclude(u => u.children).ThenInclude(u => u.children).ThenInclude(u => u.mould) .Where(u =>u.is_delete == (short)Common.Enum.DelFlagEnum.Normal && u.is_top == (short)Common.Enum.ShowFlagEnum.Show) + .OrderByDescending(u=>u.sort) .ToListAsync(); return TopMenuBuild(menu_data); } + /// + /// 过滤已经被删除的(这个应该是别的地方有方法的,不应该写到service层里面的) + /// + /// + /// private List TopMenuBuild(List menu_data) { - for(int i = menu_data.Count()-1; i >=0; i--) { if(menu_data[i].is_delete == (short)Common.Enum.DelFlagEnum.Deleted) @@ -82,6 +110,12 @@ namespace Yi.Framework.Service return menu_data; } + /// + /// 要关联啊,menudata要关联mould,而且能用find就用find + /// + /// + /// + /// public async Task SetMouldByMenu(int mouldId, int menuId) { var menu_data = await GetEntity(u => u.id == menuId); diff --git a/Yi.Framework/Yi.Framework.Service/MouldService.cs b/Yi.Framework/Yi.Framework.Service/MouldService.cs index c46a9bf4..21409683 100644 --- a/Yi.Framework/Yi.Framework.Service/MouldService.cs +++ b/Yi.Framework/Yi.Framework.Service/MouldService.cs @@ -11,10 +11,14 @@ namespace Yi.Framework.Service { public partial class MouldService:BaseService, IMouldService { + /// + /// 这个获取的是菜单,用的是菜单表,应该放到菜单service里面,像这种只用到id的,就传一个id就可以了 + /// + /// + /// public async Task GetMenuByMould(mould _mould) { - var menu_data = await _Db.Set().Include(u => u.mould) - .Where(u => u.mould == _mould && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync(); + var menu_data = await _Db.Set().Include(u => u.mould).Where(u => u.mould == _mould && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync(); return menu_data; } } diff --git a/Yi.Framework/Yi.Framework.Service/RoleService.cs b/Yi.Framework/Yi.Framework.Service/RoleService.cs index 3ab86e21..8419a069 100644 --- a/Yi.Framework/Yi.Framework.Service/RoleService.cs +++ b/Yi.Framework/Yi.Framework.Service/RoleService.cs @@ -11,15 +11,24 @@ namespace Yi.Framework.Service { public partial class RoleService:BaseService, IRoleService { + /// + /// 该方法返回的是并列角色并列的菜单,无递归 + /// + /// + /// public async Task> GetMenusByRole(role _role) { var role_data =await _Db.Set().Include(u => u.menus) .Where(u => u.id == _role.id && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync(); - var menuList =role_data.menus.Where(u => u.is_delete == (short)Common.Enum.DelFlagEnum.Normal) - .ToList(); + var menuList =role_data.menus.Where(u => u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToList(); return menuList; } + /// + /// 这个接口好像没用,算作废吧,怎么能通过角色获取用户呢?数据库表也得改,不能通过角色获取用户 + /// + /// + /// public async Task> GetUsersByRole(role _role) { var role_data = await _Db.Set().Include(u => u.users) @@ -27,10 +36,10 @@ namespace Yi.Framework.Service return role_data.users.ToList(); } + public async Task SetMenusByRolesId(List menuIds,List roleIds) { - var role_data = await _Db.Set().Include(u=>u.menus) - .Where(u =>roleIds.Contains(u.id) && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToListAsync(); + var role_data = await _Db.Set().Include(u=>u.menus).Where(u =>roleIds.Contains(u.id) && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToListAsync(); if (role_data == null) { return false; @@ -42,10 +51,15 @@ namespace Yi.Framework.Service } return await UpdateListAsync(role_data); } + + /// + /// 好像也不需要通过菜单来获取角色啊,这个数据库也得改 + /// + /// + /// public async Task> GetMenusByRoleId(int roleId) { - var role_data = await _Db.Set().Include(u=>u.menus) - .Where(u =>u.id==roleId && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync(); + var role_data = await _Db.Set().Include(u=>u.menus).Where(u =>u.id==roleId && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync(); var menuList = role_data.menus.ToList(); menuList.ForEach(u => u.roles = null); return menuList; diff --git a/Yi.Framework/Yi.Framework.Service/UserService.cs b/Yi.Framework/Yi.Framework.Service/UserService.cs index 0d63eb85..dc919a14 100644 --- a/Yi.Framework/Yi.Framework.Service/UserService.cs +++ b/Yi.Framework/Yi.Framework.Service/UserService.cs @@ -209,7 +209,7 @@ namespace Yi.Framework.Service } /// - /// 这种就命名的话,改成MenuChildrenBuild + /// 这种就命名的话,改成MenuChildrenBuild,这个方法应该可以提到core层,这是一个公用的方法 /// /// /// diff --git a/Yi.Vue/src/components/ccTreeview.vue b/Yi.Vue/src/components/ccTreeview.vue index d9948aa2..38d2462e 100644 --- a/Yi.Vue/src/components/ccTreeview.vue +++ b/Yi.Vue/src/components/ccTreeview.vue @@ -55,7 +55,7 @@ 图标:{{ item.icon }} 路由:{{ item.router }} 接口名:{{ item.mould.mould_name }} - 接口地址:{{ item.mould.url }} + 接口地址:{{ item.mould.url }}