From 88b968e8266ca731c1a451e055525150fe83037b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Sat, 16 Apr 2022 00:01:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=BC=E8=88=AA=E5=B1=9E?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebFirst/database/sqlite.db | Bin 139264 -> 139264 bytes .../Config/SwaggerDoc.xml | 12 ++++++++ .../BaseController/BaseCrudController.cs | 7 ++--- .../Controllers/TestController.cs | 29 ++++++++++++------ .../yi-sqlsugar-dev.db | Bin 12288 -> 28672 bytes .../Yi.Framework.Interface/IRoleService.cs | 16 ++++++++++ .../IServiceTemplate/IRoleService.cs | 9 ++++++ .../IServiceTemplate/IUserRoleService.cs | 9 ++++++ .../Yi.Framework.Interface/IUserService.cs | 7 +++++ .../Yi.Framework.Model/Models/RoleEntity.cs | 24 +++++++++++++++ .../Models/UserRoleEntity.cs | 29 ++++++++++++++++++ .../Yi.Framework.Model/UserEntity.cs | 15 +++++++++ .../Yi.Framework.Service/RoleService.cs | 17 ++++++++++ .../ServiceTemplate/RoleService.cs | 14 +++++++++ .../ServiceTemplate/UserRoleService.cs | 14 +++++++++ .../Yi.Framework.Service/UserService.cs | 6 ++++ 16 files changed, 195 insertions(+), 13 deletions(-) create mode 100644 Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs create mode 100644 Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IRoleService.cs create mode 100644 Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IUserRoleService.cs create mode 100644 Yi.Framework.Net6/Yi.Framework.Model/Models/RoleEntity.cs create mode 100644 Yi.Framework.Net6/Yi.Framework.Model/Models/UserRoleEntity.cs create mode 100644 Yi.Framework.Net6/Yi.Framework.Model/UserEntity.cs create mode 100644 Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs create mode 100644 Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/RoleService.cs create mode 100644 Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/UserRoleService.cs diff --git a/WebFirst/database/sqlite.db b/WebFirst/database/sqlite.db index 756d21fab4db4d1c719eafbcceba8a2d1d28bcd6..b2cc0ab3a96a95c01951b9f5f03bca6ea556ba0a 100644 GIT binary patch delta 557 zcmZoTz|nAkV}i6`5Ca2)5)i{c%0wMw#-NP}V)~4BlgssG8Fy@+s-M4sS&^w>GW!F2 z7N!Qi+nXH)w3%F3jTw$GN=nK*8ym;kax*Z>%JKr492_j6#i>O>`8laD+Q`7jNY}tb z*U(hK$k58vz{ zu4iUyYGgKf<0Fk`qxaj5-ZNfOV0L7cp3W}7l&Hi%kNqtBI`(PoY3%xJKiH15&0#BL zb7kXWz0SIfwVKtNRT}92i7d>ztrpWi9%a@}HIO(bcMYdljRBv^X;8*!#( a?EL&d|8hbc93a}N0XCY^cKSAXCNBV)8Hc;R+)IBO_e{6I}yK1w#`n z6H6;&3q3<~VFfebi9pA+uy21O&a{kOMV&!bmXm{nSC)|>AhEc( YJijOfMi-Y9W#*+D8rV$VCeP#r031|F1poj5 diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml index 24e6af67..cd8585fa 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml @@ -87,5 +87,17 @@ + + + 极爽导航属性 + + + + + + 自由导航属性 + + + diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseCrudController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseCrudController.cs index 69bf1deb..acc74cd8 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseCrudController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseCrudController.cs @@ -15,12 +15,11 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// /// [ApiController] - [Route("api/[controller]/[action]")] public class BaseCrudController : ControllerBase where T : BaseModelEntity,new() { - public readonly ILogger _logger; - public IBaseService _baseService; - public IRepository _repository; + private readonly ILogger _logger; + private IBaseService _baseService; + private IRepository _repository; public BaseCrudController(ILogger logger, IBaseService iBaseService) { _logger = logger; diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs index 2f4f1232..873b8701 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs @@ -23,11 +23,13 @@ namespace Yi.Framework.ApiMicroservice.Controllers { private IStringLocalizer _local; private IUserService _iUserService; + private IRoleService _iRoleService; //你可以依赖注入服务层各各接口,也可以注入其他仓储层,怎么爽怎么来! - public TestController(ILogger logger, IUserService iUserService, IStringLocalizer local) + public TestController(ILogger logger, IRoleService iRoleService, IUserService iUserService, IStringLocalizer local) { _local = local; _iUserService = iUserService; + _iRoleService = iRoleService; } /// @@ -42,19 +44,19 @@ namespace Yi.Framework.ApiMicroservice.Controllers //非常好,使用UserService的特有方法 await _iUserService.DbTest(); - //非常好,依赖注入使用其他Service的特有方法(就tm一张表,现在自己注入自己) - await _iUserService.DbTest(); + //非常好,依赖注入使用其他Service的特有方法 + await _iRoleService.DbTest(); //很核理,使用仓储的通用方法 await _iUserService._repository.GetListAsync(); - //挺不错,依赖注入其他仓储(就tm一张表,现在自己注入自己) - await _iUserService._repository.GetListAsync(); + //挺不错,依赖注入其他仓储 + await _iRoleService._repository.GetListAsync(); - //不建议操作,直接切换其他仓储(就tm一张表,现在自己切换自己) - await _iUserService._repository.ChangeRepository>().GetListAsync(); + //不建议操作,直接切换其他仓储 + await _iUserService._repository.ChangeRepository>().GetListAsync(); - //恭喜你已经毕业了!此后将有一天,接手到这个的软件的程序员将破口大骂。 + //直接操作Db对象???恭喜你已经毕业了!此后将有一天,接手到这个的软件的程序员将破口大骂。 await _iUserService._repository._Db.Queryable().ToListAsync(); return Result.Success().SetData(await _iUserService.DbTest()); @@ -132,6 +134,15 @@ namespace Yi.Framework.ApiMicroservice.Controllers } - //emmmm,看来一张表已经满足不了,接下来将要大更新一波 + /// + /// 极爽导航属性 + /// + /// + [HttpGet] + //Sqlsugar精髓之一!必学!最新版本 + public async Task IncludeTest() + { + return Result.Success().SetData(await _iUserService.GetListInRole()); + } } } diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db index b16cd971c015be366d0c05ff85a05f977d37791d..a7bd1cea37e75b9538e3112579a0af8c171d1943 100644 GIT binary patch delta 601 zcmZojXn4RlL0V9qfq{V?h+%+rqK>hoI)k3|M_%q*3~XGR8Tg#|&vR|&6Xa##xw5g) zn#-(7g_&JkR+h0vx+F0vCpEM{P=hXj~Fbl4#Q zMv;G}hfA9T7`VXNzA*5AfojVa<7Q^#geixZ`kaCPIaE4HS)7rRO%h=!$gt;2_C23E M2h%7Xm{A}_08)yoX8-^I delta 56 zcmZp8z}S#5L0V9efq{V;h+%+nqK+|8P|x}!FaHk)CO#(yJ}3V3n-vu<@oskF+ouQs DCQS?I diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs new file mode 100644 index 00000000..7b83b9d2 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Yi.Framework.Model.Models; +using Yi.Framework.Repository; + +namespace Yi.Framework.Interface +{ + public partial interface IRoleService + { + /// + /// DbTest + /// + /// + public Task> DbTest(); + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IRoleService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IRoleService.cs new file mode 100644 index 00000000..10846b67 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IRoleService.cs @@ -0,0 +1,9 @@ +using Yi.Framework.Model.Models; +using Yi.Framework.Repository; + +namespace Yi.Framework.Interface +{ + public partial interface IRoleService:IBaseService + { + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IUserRoleService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IUserRoleService.cs new file mode 100644 index 00000000..a299d0af --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IUserRoleService.cs @@ -0,0 +1,9 @@ +using Yi.Framework.Model.Models; +using Yi.Framework.Repository; + +namespace Yi.Framework.Interface +{ + public partial interface IUserRoleService:IBaseService + { + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IUserService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IUserService.cs index 6504f5be..9c6ebe80 100644 --- a/Yi.Framework.Net6/Yi.Framework.Interface/IUserService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Interface/IUserService.cs @@ -30,5 +30,12 @@ namespace Yi.Framework.Interface /// /// public Task Register(UserEntity userEntity, Action userAction = null); + + + /// + /// 导航属性关联角色 + /// + /// + public Task> GetListInRole(); } } diff --git a/Yi.Framework.Net6/Yi.Framework.Model/Models/RoleEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/Models/RoleEntity.cs new file mode 100644 index 00000000..aac22b81 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Model/Models/RoleEntity.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using SqlSugar; +namespace Yi.Framework.Model.Models +{ + /// + /// + /// + [SugarTable("Role")] + public partial class RoleEntity:BaseModelEntity + { + /// + /// + /// + [SugarColumn(ColumnName="RoleName" )] + public string RoleName { get; set; } + /// + /// 租户Id + /// + [SugarColumn(ColumnName="TenantId" )] + public long? TenantId { get; set; } + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Model/Models/UserRoleEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/Models/UserRoleEntity.cs new file mode 100644 index 00000000..00386154 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Model/Models/UserRoleEntity.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using SqlSugar; +namespace Yi.Framework.Model.Models +{ + /// + /// + /// + [SugarTable("UserRole")] + public partial class UserRoleEntity:BaseModelEntity + { + /// + /// + /// + [SugarColumn(ColumnName="RoleId" )] + public long? RoleId { get; set; } + /// + /// + /// + [SugarColumn(ColumnName="UserId" )] + public long? UserId { get; set; } + /// + /// 租户Id + /// + [SugarColumn(ColumnName="TenantId" )] + public long? TenantId { get; set; } + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Model/UserEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/UserEntity.cs new file mode 100644 index 00000000..b2d8eb37 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Model/UserEntity.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using SqlSugar; +namespace Yi.Framework.Model.Models +{ + public partial class UserEntity:BaseModelEntity + { + /// + /// 看好啦!ORM精髓,导航属性 + /// + [Navigate(typeof(UserRoleEntity), nameof(UserRoleEntity.UserId), nameof(UserRoleEntity.RoleId))] + public List Roles { get; set; } + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs b/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs new file mode 100644 index 00000000..ead1ea03 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs @@ -0,0 +1,17 @@ +using SqlSugar; +using System.Collections.Generic; +using System.Threading.Tasks; +using Yi.Framework.Interface; +using Yi.Framework.Model.Models; +using Yi.Framework.Repository; + +namespace Yi.Framework.Service +{ + public partial class RoleService + { + public async Task> DbTest() + { + return await _repository._Db.Queryable().ToListAsync(); + } + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/RoleService.cs b/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/RoleService.cs new file mode 100644 index 00000000..39adab0f --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/RoleService.cs @@ -0,0 +1,14 @@ +using SqlSugar; +using Yi.Framework.Interface; +using Yi.Framework.Model.Models; +using Yi.Framework.Repository; + +namespace Yi.Framework.Service +{ + public partial class RoleService : BaseService, IRoleService + { + public RoleService(IRepository repository) : base(repository) + { + } + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/UserRoleService.cs b/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/UserRoleService.cs new file mode 100644 index 00000000..d48f838e --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/UserRoleService.cs @@ -0,0 +1,14 @@ +using SqlSugar; +using Yi.Framework.Interface; +using Yi.Framework.Model.Models; +using Yi.Framework.Repository; + +namespace Yi.Framework.Service +{ + public partial class UserRoleService : BaseService, IUserRoleService + { + public UserRoleService(IRepository repository) : base(repository) + { + } + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs b/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs index 8124274a..0db1c3d5 100644 --- a/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs @@ -65,5 +65,11 @@ namespace Yi.Framework.Service } return false; } + + public async Task> GetListInRole() + { + return await _repository._Db.Queryable().Includes(u => u.Roles).ToListAsync(); + + } } }