diff --git a/WebFirst/database/sqlite.db b/WebFirst/database/sqlite.db index 756d21fa..b2cc0ab3 100644 Binary files a/WebFirst/database/sqlite.db and b/WebFirst/database/sqlite.db differ 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 b16cd971..a7bd1cea 100644 Binary files a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db differ 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(); + + } } }