From 5ab4107ffa5d79d0abea5a3f43c76d23a61dc7bb Mon Sep 17 00:00:00 2001 From: lzw <605106923@qq.com> Date: Fri, 15 Oct 2021 14:45:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8E=A7=E5=88=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AccountController.cs | 1 + .../Controllers/RoleController.cs | 7 ++++++- .../Controllers/UserController.cs | 7 +++++-- .../Yi.Framework.Core.csproj | 1 + .../Yi.Framework.Interface/T4IService.tt | 19 +++++++++++++++++++ .../Yi.Framework.Model/DataContext.cs | 2 +- .../Yi.Framework.Model/T4DaraContext.tt | 19 +++++++++++++++++++ .../Yi.Framework.Model.csproj | 8 -------- .../Yi.Framework.Service/UserService.cs | 10 ++++++---- 9 files changed, 58 insertions(+), 16 deletions(-) diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs index 3891129c..06c7d7cf 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Yi.Framework.Common; using Yi.Framework.Common.Helper; using Yi.Framework.Common.Models; using Yi.Framework.Core; diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs index 0858911a..a62cc81e 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs @@ -70,7 +70,12 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// [HttpPost] public async Task SetMenuByRole(IdsListDto idsListDto) - { + { + foreach(var id in idsListDto.ids1) + { + await _roleService.SetMenusByRolesId(idsListDto.ids2, id); + } + return Result.Success(); } } } diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs index 22930893..73e0951c 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs @@ -85,13 +85,16 @@ namespace Yi.Framework.ApiMicroservice.Controllers } /// - /// 给单个用户设置多个角色,ids有用户id与 角列表色ids,1对多 + /// 给单个用户设置多个角色,ids有用户id与 角色列表ids,1对多 /// /// /// [HttpPost] public async Task SetRoleByUser(IdsDto idsDto) - { + { + var _user = this.HttpContext.GetCurrentUserInfo(); + await _userService.SetRolesByUserId(idsDto.ids, _user.id); + return Result.Success(); } } } diff --git a/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj b/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj index 5af9d499..e441d22a 100644 --- a/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj +++ b/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj @@ -15,6 +15,7 @@ + diff --git a/Yi.Framework/Yi.Framework.Interface/T4IService.tt b/Yi.Framework/Yi.Framework.Interface/T4IService.tt index 2570a5f1..0956330b 100644 --- a/Yi.Framework/Yi.Framework.Interface/T4IService.tt +++ b/Yi.Framework/Yi.Framework.Interface/T4IService.tt @@ -13,3 +13,22 @@ Type[] ts = assembly.GetTypes(); #> +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Model.Models; + +namespace Yi.Framework.Interface +{ + public partial class BaseContext :DbContext + { +<# foreach(string item in ts){ + #> + public partial interface I<#=item #>Dal:IBaseDal<<#=item #>> + { + } +<# } #> + } +} \ No newline at end of file diff --git a/Yi.Framework/Yi.Framework.Model/DataContext.cs b/Yi.Framework/Yi.Framework.Model/DataContext.cs index 6c3f0195..439c7e98 100644 --- a/Yi.Framework/Yi.Framework.Model/DataContext.cs +++ b/Yi.Framework/Yi.Framework.Model/DataContext.cs @@ -12,7 +12,7 @@ namespace Yi.Framework.Model { //Add-Migration yi-1 //Update-Database yi-1 - public class DataContext : DbContext + public partial class DataContext : DbContext { private readonly IOptionsMonitor _optionsMonitor; private readonly string _connStr; diff --git a/Yi.Framework/Yi.Framework.Model/T4DaraContext.tt b/Yi.Framework/Yi.Framework.Model/T4DaraContext.tt index 2570a5f1..32c6bc39 100644 --- a/Yi.Framework/Yi.Framework.Model/T4DaraContext.tt +++ b/Yi.Framework/Yi.Framework.Model/T4DaraContext.tt @@ -11,5 +11,24 @@ string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径 Assembly assembly = Assembly.LoadFrom(System.IO.Path.Combine(solutionsPath, @"Yi.Framework.ApiMicroservice\bin\Debug\net5.0\Yi.Framework.Model.dll")); Type[] ts = assembly.GetTypes(); + #> +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Model +{ + public partial class BaseContext :DbContext + { +<# foreach(var item in ts){ + + #> + public DbSet<<#=item#>> <#=item#> { get; set; } +<# } #> + } +} \ No newline at end of file diff --git a/Yi.Framework/Yi.Framework.Model/Yi.Framework.Model.csproj b/Yi.Framework/Yi.Framework.Model/Yi.Framework.Model.csproj index abe851b9..92106451 100644 --- a/Yi.Framework/Yi.Framework.Model/Yi.Framework.Model.csproj +++ b/Yi.Framework/Yi.Framework.Model/Yi.Framework.Model.csproj @@ -8,14 +8,6 @@ - - - True - True - T4DaraContext.tt - - - diff --git a/Yi.Framework/Yi.Framework.Service/UserService.cs b/Yi.Framework/Yi.Framework.Service/UserService.cs index 35567401..abcc455c 100644 --- a/Yi.Framework/Yi.Framework.Service/UserService.cs +++ b/Yi.Framework/Yi.Framework.Service/UserService.cs @@ -41,9 +41,9 @@ namespace Yi.Framework.Service public async Task> GetMenusByUser(user _user) { - var user_data= await _Db.Set().Include(u => u.roles).ThenInclude(u => u.menus) + var user_data= await _Db.Set().Include(u => u.roles).ThenInclude(u=>u.menus).ThenInclude(u=>u.mould) .Where(u=>u.id==_user.id&& u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync(); - var menuList= user_data.roles.Select(u => u.menus); + var menuList= user_data.roles.Select(u=>u.menus); return (List)menuList; } @@ -57,8 +57,10 @@ namespace Yi.Framework.Service public async Task> GetRolesByUser(user _user) { - var user_data = await GetEntity(u => u.id == _user.id && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal); - return (List)user_data.roles; + 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(); + return roleList; } public async Task Login(user _user)