From da6248e6b3dbfe2990d00372cb6c1cd4a6bc2309 Mon Sep 17 00:00:00 2001 From: yeslode <605106923@qq.com> Date: Sun, 17 Oct 2021 17:35:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0T4=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/MenuController.cs | 20 ++++++++- .../Yi.Framework.Interface/IMenuService.cs | 4 +- .../Yi.Framework.Interface/IMouldService.cs | 2 +- .../Yi.Framework.Interface/IRoleService.cs | 2 +- .../Yi.Framework.Interface/IUserService.cs | 11 ++++- .../Yi.Framework.Interface/T4Iservice.cs | 30 +++++++++++++ .../Yi.Framework.Interface/T4Iservice.tt | 41 ++++++++++++++++++ .../Yi.Framework.Interface.csproj | 10 ++++- .../{Models => BaseModels}/baseModel.cs | 0 .../{Models => BaseModels}/loopModel.cs | 1 + .../Yi.Framework.Model/DataContext.cs | 3 +- .../Yi.Framework.Model/Models/menu.cs | 2 +- .../Yi.Framework.Model/T4DataContext.cs | 17 ++++++++ .../Yi.Framework.Model/T4DataContext.tt | 39 +++++++++++++++++ .../Yi.Framework.Model.csproj | 17 ++++++++ .../Yi.Framework.Service/MenuService.cs | 13 +++--- .../Yi.Framework.Service/MouldService.cs | 2 +- .../Yi.Framework.Service/RoleService.cs | 6 ++- .../Yi.Framework.Service/T4Service.cs | 32 ++++++++++++++ .../Yi.Framework.Service/T4Service.tt | 43 +++++++++++++++++++ .../Yi.Framework.Service/UserService.cs | 20 ++++++++- .../Yi.Framework.Service.csproj | 8 ++++ 22 files changed, 302 insertions(+), 21 deletions(-) create mode 100644 Yi.Framework/Yi.Framework.Interface/T4Iservice.cs create mode 100644 Yi.Framework/Yi.Framework.Interface/T4Iservice.tt rename Yi.Framework/Yi.Framework.Model/{Models => BaseModels}/baseModel.cs (100%) rename Yi.Framework/Yi.Framework.Model/{Models => BaseModels}/loopModel.cs (87%) create mode 100644 Yi.Framework/Yi.Framework.Model/T4DataContext.cs create mode 100644 Yi.Framework/Yi.Framework.Model/T4DataContext.tt create mode 100644 Yi.Framework/Yi.Framework.Service/T4Service.cs create mode 100644 Yi.Framework/Yi.Framework.Service/T4Service.tt diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs index 40cff08b..5ce56e65 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs @@ -92,6 +92,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers var _user = this.HttpContext.GetCurrentUserInfo(); var menuList= await _userService.GetMenusByUser(_user); return Result.Success().SetData(menuList); + } /// @@ -105,7 +106,24 @@ namespace Yi.Framework.ApiMicroservice.Controllers var _children= await _menuService.AddChildrenMenu(new menu() { id=childrenDto.parentId}, childrenDto.data); return Result.Success(); - + } + /// + /// 获取用户的目录菜单,不包含接口 + /// + /// + [HttpGet] + public async Task GeTopMenuByUser() + { + var _user = this.HttpContext.GetCurrentUserInfo(); + var menuList =await _userService.GetMenuByUser(_user); + return Result.Success().SetData(menuList); + } + public async Task GeTopMenuByUser(menu _menu) + { + var _user = this.HttpContext.GetCurrentUserInfo(); + var menu_data= await _userService.GetMenuByUser(_user); + var menuList = await _menuService.GetChildrenMenu(_menu); + return Result.Success().SetData(menuList); } } } diff --git a/Yi.Framework/Yi.Framework.Interface/IMenuService.cs b/Yi.Framework/Yi.Framework.Interface/IMenuService.cs index 223df12c..98ea93d7 100644 --- a/Yi.Framework/Yi.Framework.Interface/IMenuService.cs +++ b/Yi.Framework/Yi.Framework.Interface/IMenuService.cs @@ -7,7 +7,7 @@ using Yi.Framework.Model.Models; namespace Yi.Framework.Interface { - public interface IMenuService:IBaseService + public partial interface IMenuService:IBaseService { Task DelListByUpdateAsync(List _ids); /// @@ -59,6 +59,6 @@ namespace Yi.Framework.Interface /// 获取子菜单 /// /// - Task> GetChildrenMenu(); + Task> GetChildrenMenu(menu _menu); } } diff --git a/Yi.Framework/Yi.Framework.Interface/IMouldService.cs b/Yi.Framework/Yi.Framework.Interface/IMouldService.cs index 7aafaff2..905a6bca 100644 --- a/Yi.Framework/Yi.Framework.Interface/IMouldService.cs +++ b/Yi.Framework/Yi.Framework.Interface/IMouldService.cs @@ -7,7 +7,7 @@ using Yi.Framework.Model.Models; namespace Yi.Framework.Interface { - public interface IMouldService : IBaseService + public partial interface IMouldService : IBaseService { Task DelListByUpdateAsync(List _ids); Task> GetAllEntitiesTrueAsync(); diff --git a/Yi.Framework/Yi.Framework.Interface/IRoleService.cs b/Yi.Framework/Yi.Framework.Interface/IRoleService.cs index 6d9a47a7..a8295ddb 100644 --- a/Yi.Framework/Yi.Framework.Interface/IRoleService.cs +++ b/Yi.Framework/Yi.Framework.Interface/IRoleService.cs @@ -7,7 +7,7 @@ using Yi.Framework.Model.Models; namespace Yi.Framework.Interface { - public interface IRoleService:IBaseService + public partial interface IRoleService:IBaseService { Task DelListByUpdateAsync(List _ids); Task> GetAllEntitiesTrueAsync(); diff --git a/Yi.Framework/Yi.Framework.Interface/IUserService.cs b/Yi.Framework/Yi.Framework.Interface/IUserService.cs index 32df6a1a..27c5c206 100644 --- a/Yi.Framework/Yi.Framework.Interface/IUserService.cs +++ b/Yi.Framework/Yi.Framework.Interface/IUserService.cs @@ -7,7 +7,7 @@ using Yi.Framework.Model.Models; namespace Yi.Framework.Interface { - public interface IUserService:IBaseService + public partial interface IUserService:IBaseService { Task DelListByUpdateAsync(List _ids); Task> GetAllEntitiesTrueAsync(); @@ -58,6 +58,13 @@ namespace Yi.Framework.Interface /// /// Task EmailIsExsit(string emailAddress); - + /// + /// 获取用户的目录菜单,没有绑定接口 + /// + /// + /// + Task>> GetMenuByUser(user _user); + + } } diff --git a/Yi.Framework/Yi.Framework.Interface/T4Iservice.cs b/Yi.Framework/Yi.Framework.Interface/T4Iservice.cs new file mode 100644 index 00000000..a3d5323f --- /dev/null +++ b/Yi.Framework/Yi.Framework.Interface/T4Iservice.cs @@ -0,0 +1,30 @@ +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 interface IMenuService:IBaseService + { + + } + + public partial interface IMouldService:IBaseService + { + + } + + public partial interface IRoleService:IBaseService + { + + } + + public partial interface IUserService:IBaseService + { + + } +} diff --git a/Yi.Framework/Yi.Framework.Interface/T4Iservice.tt b/Yi.Framework/Yi.Framework.Interface/T4Iservice.tt new file mode 100644 index 00000000..5dc74831 --- /dev/null +++ b/Yi.Framework/Yi.Framework.Interface/T4Iservice.tt @@ -0,0 +1,41 @@ +<#@ template debug="false" hostspecific="true" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.IO" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ output extension=".cs" #> +<# + + DirectoryInfo dir = new DirectoryInfo(@"D:\YiFramework\Yi\Yi.Framework\Yi.Framework.Model\Models\"); + FileInfo[] finfo = dir.GetFiles(); + string filenames = string.Empty; + List filenameList = new List(); + for (int i = 0; i < finfo.Length; i++) + { + filenames = finfo[i].Name ; + string[] fname=filenames.Split('.'); + filenameList.Add(fname[0]); + } + + +#> +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 +{ + <# foreach(string k in filenameList){ + string fn= k.Substring(0,1).ToUpper()+k.Substring(1); + #> + + public partial interface I<#= fn #>Service:IBaseService<<#= k #>> + { + + } +<# } #> +} diff --git a/Yi.Framework/Yi.Framework.Interface/Yi.Framework.Interface.csproj b/Yi.Framework/Yi.Framework.Interface/Yi.Framework.Interface.csproj index 4a1fafcd..54e221d2 100644 --- a/Yi.Framework/Yi.Framework.Interface/Yi.Framework.Interface.csproj +++ b/Yi.Framework/Yi.Framework.Interface/Yi.Framework.Interface.csproj @@ -8,13 +8,21 @@ + + + True + True + T4Iservice.tt + + + - T4IService.cs + T4Iservice.cs TextTemplatingFileGenerator diff --git a/Yi.Framework/Yi.Framework.Model/Models/baseModel.cs b/Yi.Framework/Yi.Framework.Model/BaseModels/baseModel.cs similarity index 100% rename from Yi.Framework/Yi.Framework.Model/Models/baseModel.cs rename to Yi.Framework/Yi.Framework.Model/BaseModels/baseModel.cs diff --git a/Yi.Framework/Yi.Framework.Model/Models/loopModel.cs b/Yi.Framework/Yi.Framework.Model/BaseModels/loopModel.cs similarity index 87% rename from Yi.Framework/Yi.Framework.Model/Models/loopModel.cs rename to Yi.Framework/Yi.Framework.Model/BaseModels/loopModel.cs index 91e43bed..f1d257e5 100644 --- a/Yi.Framework/Yi.Framework.Model/Models/loopModel.cs +++ b/Yi.Framework/Yi.Framework.Model/BaseModels/loopModel.cs @@ -10,5 +10,6 @@ namespace Yi.Framework.Model.Models { public int? is_top { get; set; } public int? sort { get; set; } + public int? is_show { get; set; } } } diff --git a/Yi.Framework/Yi.Framework.Model/DataContext.cs b/Yi.Framework/Yi.Framework.Model/DataContext.cs index 439c7e98..6bbc6f4f 100644 --- a/Yi.Framework/Yi.Framework.Model/DataContext.cs +++ b/Yi.Framework/Yi.Framework.Model/DataContext.cs @@ -34,7 +34,6 @@ namespace Yi.Framework.Model optionsBuilder.UseSqlite(_connStr); } } - public DbSet user { get; set; } - public DbSet role { get; set; } + } } diff --git a/Yi.Framework/Yi.Framework.Model/Models/menu.cs b/Yi.Framework/Yi.Framework.Model/Models/menu.cs index dfab5c4c..8602a1f2 100644 --- a/Yi.Framework/Yi.Framework.Model/Models/menu.cs +++ b/Yi.Framework/Yi.Framework.Model/Models/menu.cs @@ -11,7 +11,7 @@ namespace Yi.Framework.Model.Models public string icon { get; set; } public string router { get; set; } public string menu_name { get; set; } - + public ICollection children { get; set; } diff --git a/Yi.Framework/Yi.Framework.Model/T4DataContext.cs b/Yi.Framework/Yi.Framework.Model/T4DataContext.cs new file mode 100644 index 00000000..4c6778cb --- /dev/null +++ b/Yi.Framework/Yi.Framework.Model/T4DataContext.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Text; +using Yi.Framework.Model.Models; + +namespace Yi.Framework.Model +{ + public partial class DataContext :DbContext + { + public DbSet menu { get; set; } + public DbSet mould { get; set; } + public DbSet role { get; set; } + public DbSet user { get; set; } + } +} + diff --git a/Yi.Framework/Yi.Framework.Model/T4DataContext.tt b/Yi.Framework/Yi.Framework.Model/T4DataContext.tt new file mode 100644 index 00000000..c41c4ba3 --- /dev/null +++ b/Yi.Framework/Yi.Framework.Model/T4DataContext.tt @@ -0,0 +1,39 @@ +<#@ template debug="false" hostspecific="true" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.IO" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ output extension=".cs" #> +<# + + DirectoryInfo dir = new DirectoryInfo(@"D:\YiFramework\Yi\Yi.Framework\Yi.Framework.Model\Models\"); + FileInfo[] finfo = dir.GetFiles(); + string filenames = string.Empty; + List filenameList = new List(); + for (int i = 0; i < finfo.Length; i++) + { + filenames = finfo[i].Name ; + string[] f=filenames.Split('.'); + filenameList.Add(f[0]); + } + + +#> +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Text; +using Yi.Framework.Model.Models; + +namespace Yi.Framework.Model +{ + public partial class DataContext :DbContext + { +<# foreach(string k in filenameList){ + #> + public DbSet<<#=k #>> <#=k #> { get; set; } +<# } #> + } +} + diff --git a/Yi.Framework/Yi.Framework.Model/Yi.Framework.Model.csproj b/Yi.Framework/Yi.Framework.Model/Yi.Framework.Model.csproj index 92106451..f8cb44ac 100644 --- a/Yi.Framework/Yi.Framework.Model/Yi.Framework.Model.csproj +++ b/Yi.Framework/Yi.Framework.Model/Yi.Framework.Model.csproj @@ -8,6 +8,14 @@ + + + True + True + T4DataContext.tt + + + @@ -21,6 +29,10 @@ TextTemplatingFileGenerator T4DaraContext.cs + + TextTemplatingFileGenerator + T4DataContext.cs + @@ -33,6 +45,11 @@ True T4DaraContext.tt + + True + True + T4DataContext.tt + diff --git a/Yi.Framework/Yi.Framework.Service/MenuService.cs b/Yi.Framework/Yi.Framework.Service/MenuService.cs index 96999a96..4af787c7 100644 --- a/Yi.Framework/Yi.Framework.Service/MenuService.cs +++ b/Yi.Framework/Yi.Framework.Service/MenuService.cs @@ -9,7 +9,7 @@ using Yi.Framework.Model.Models; namespace Yi.Framework.Service { - public class MenuService:BaseService, IMenuService + public partial class MenuService:BaseService, IMenuService { public MenuService(DbContext Db) : base(Db) { } @@ -41,11 +41,13 @@ namespace Yi.Framework.Service return childrenList; } - public async Task> GetChildrenMenu() + public async Task> GetChildrenMenu(menu _menu) { - 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.Children ) - .ToListAsync(); + 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 ) + .FirstOrDefaultAsync(); + var childrenList = menu.children.ToList(); + return childrenList; } public async Task GetMenuMouldByMenu(menu _menu) @@ -75,5 +77,6 @@ namespace Yi.Framework.Service menu_data.mould = mould_data; return await UpdateAsync(menu_data); } + } } diff --git a/Yi.Framework/Yi.Framework.Service/MouldService.cs b/Yi.Framework/Yi.Framework.Service/MouldService.cs index 7746b640..9fc6ebc6 100644 --- a/Yi.Framework/Yi.Framework.Service/MouldService.cs +++ b/Yi.Framework/Yi.Framework.Service/MouldService.cs @@ -9,7 +9,7 @@ using Yi.Framework.Model.Models; namespace Yi.Framework.Service { - public class MouldService:BaseService, IMouldService + public partial class MouldService:BaseService, IMouldService { public MouldService(DbContext Db) : base(Db) { } diff --git a/Yi.Framework/Yi.Framework.Service/RoleService.cs b/Yi.Framework/Yi.Framework.Service/RoleService.cs index e8dc9390..e0e38b50 100644 --- a/Yi.Framework/Yi.Framework.Service/RoleService.cs +++ b/Yi.Framework/Yi.Framework.Service/RoleService.cs @@ -9,7 +9,7 @@ using Yi.Framework.Model.Models; namespace Yi.Framework.Service { - public class RoleService:BaseService, IRoleService + public partial class RoleService:BaseService, IRoleService { public RoleService(DbContext Db):base(Db) { @@ -30,7 +30,9 @@ namespace Yi.Framework.Service { 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(); - return role_data.menus.ToList(); + var menuList =role_data.menus.Where(u => u.is_top == (short)Common.Enum.TopFlagEnum.Top && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal) + .ToList(); + return menuList; } public async Task> GetUsersByRole(role _role) diff --git a/Yi.Framework/Yi.Framework.Service/T4Service.cs b/Yi.Framework/Yi.Framework.Service/T4Service.cs new file mode 100644 index 00000000..00858584 --- /dev/null +++ b/Yi.Framework/Yi.Framework.Service/T4Service.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Model.Models; +using Yi.Framework.Interface; +using Microsoft.EntityFrameworkCore; + +namespace Yi.Framework.Service +{ + + public partial class MenuService:BaseService,IMenuService + { + //public MenuService(DbContext Db):base(Db){ } + } + + public partial class MouldService:BaseService,IMouldService + { + //public MouldService(DbContext Db):base(Db){ } + } + + public partial class RoleService:BaseService,IRoleService + { + //public RoleService(DbContext Db):base(Db){ } + } + + public partial class UserService:BaseService,IUserService + { + //public UserService(DbContext Db):base(Db){ } + } +} diff --git a/Yi.Framework/Yi.Framework.Service/T4Service.tt b/Yi.Framework/Yi.Framework.Service/T4Service.tt new file mode 100644 index 00000000..5becaf0f --- /dev/null +++ b/Yi.Framework/Yi.Framework.Service/T4Service.tt @@ -0,0 +1,43 @@ +<#@ template debug="false" hostspecific="true" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.IO" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ output extension=".cs" #> +<# + + DirectoryInfo dir = new DirectoryInfo(@"D:\YiFramework\Yi\Yi.Framework\Yi.Framework.Model\Models\"); + FileInfo[] finfo = dir.GetFiles(); + string filenames = string.Empty; + List filenameList = new List(); + for (int i = 0; i < finfo.Length; i++) + { + filenames = finfo[i].Name ; + string[] fname=filenames.Split('.'); + filenameList.Add(fname[0]); + } + + +#> +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Model.Models; +using Yi.Framework.Interface; +using Microsoft.EntityFrameworkCore; + +namespace Yi.Framework.Service +{ + <# foreach(string k in filenameList){ + string fn= k.Substring(0,1).ToUpper()+k.Substring(1); + #> + + public partial class <#= fn #>Service:BaseService<<#= k #>>,I<#= fn #>Service + { + //public <#= fn #>Service(DbContext Db):base(Db){ } + } +<# } #> +} diff --git a/Yi.Framework/Yi.Framework.Service/UserService.cs b/Yi.Framework/Yi.Framework.Service/UserService.cs index 39fd1557..e95d4dd9 100644 --- a/Yi.Framework/Yi.Framework.Service/UserService.cs +++ b/Yi.Framework/Yi.Framework.Service/UserService.cs @@ -11,10 +11,12 @@ using Yi.Framework.Model.Models; namespace Yi.Framework.Service { - public class UserService: BaseService,IUserService + public partial class UserService: BaseService,IUserService { - public UserService(DbContext Db) :base(Db) + private IRoleService _roleService; + public UserService(DbContext Db, IRoleService roleService) :base(Db) { + _roleService = roleService; } public async Task DelListByUpdateAsync(List _ids) { @@ -97,5 +99,19 @@ namespace Yi.Framework.Service return await UpdateListAsync(user_data); } + public async Task >> GetMenuByUser(user _user) + { + var user_data =await _Db.Set().Include(u => u.roles).ThenInclude(u => u.menus) + .Where(u => u.id == _user.id && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync(); + var roleList= user_data.roles.ToList(); + var menuList = new List>(); + foreach (var role in roleList) + { + var menu= await _roleService.GetMenusByRole(role); + menuList.Add(menu); + } + return menuList; + } + } } diff --git a/Yi.Framework/Yi.Framework.Service/Yi.Framework.Service.csproj b/Yi.Framework/Yi.Framework.Service/Yi.Framework.Service.csproj index 104a6f4d..10f15f2f 100644 --- a/Yi.Framework/Yi.Framework.Service/Yi.Framework.Service.csproj +++ b/Yi.Framework/Yi.Framework.Service/Yi.Framework.Service.csproj @@ -8,6 +8,14 @@ + + + True + True + T4Service.tt + + +