From f1e314fa13bf3032a9c929a0f5b4cae695c27601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Sun, 15 Jan 2023 14:32:43 +0800 Subject: [PATCH] =?UTF-8?q?DDD=20=E5=BA=94=E7=94=A8=E5=B1=82=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApplicationContractsSwaggerDoc.xml | 18 +++ .../Student/Dtos/StudentCreateInputVo.cs | 15 ++ .../Student/Dtos/StudentGetListInputVo.cs | 12 ++ .../Student/Dtos/StudentGetListOutputDto.cs | 14 ++ .../Student/Dtos/StudentGetOutputDto.cs | 14 ++ .../Student/Dtos/StudentUpdateInputVo.cs | 12 ++ .../Student/IStudentService.cs | 4 +- .../Yi.Framework.Application.Contracts.csproj | 12 +- .../ApplicationSwaggerDoc.xml | 19 +++ .../Student/StudentService.cs | 15 +- .../Yi.Framework.Application/SwaggerDoc.xml | 3 +- .../Yi.Framework.Application.csproj | 2 +- .../SwaggerAddExtensions.cs | 17 --- .../Yi.Framework.AspNetCore.csproj | 2 +- .../Repositories/SqlsugarRepository.cs | 36 +++++ .../Repository/SqlsugarRepository.cs | 23 ---- .../YiFrameworkCoreSqlsugarModule.cs | 2 +- .../AppServiceAttribute.cs | 4 +- .../Yi.Framework.Core/Enums/OrderByEnum.cs | 14 ++ .../{Enum => Enums}/ResultCodeEnum.cs | 2 +- .../Exceptions/BusinessException.cs | 2 +- .../Exceptions/ExceptionExtensions.cs | 2 +- .../Exceptions/IHasErrorCode.cs | 2 +- .../Exceptions/UserFriendlyException.cs | 2 +- .../Extensions/AutoIocAddExtensions.cs | 2 +- .../Yi.Framework.Core/Helper/EnumHelper.cs | 20 +++ .../Yi.Framework.Core/Helper/FileHelper.cs | 6 +- .../Dtos/{ => Abstract}/IEntityDto.cs | 0 .../Dtos/Abstract/IHasTotalCount.cs | 13 ++ .../Dtos/Abstract/IListResult.cs | 13 ++ .../Abstract/IPagedAllResultRequestDto.cs | 14 ++ .../IPagedAndSortedResultRequestDto.cs | 15 ++ .../Dtos/Abstract/IPagedResult.cs | 12 ++ .../Dtos/ListResultDto.cs | 29 ++++ .../Dtos/PagedAllResultRequestDto.cs | 14 ++ .../Dtos/PagedAndSortedResultRequestDto.cs | 16 +++ .../Dtos/PagedResultDto.cs | 24 ++++ .../Entities/IEntity.cs | 4 +- .../Repositories/IRepository.cs | 38 +++++ .../{ => Abstract}/IApplicationService.cs | 2 +- .../Services/Abstract/ICreateAppService.cs | 20 +++ .../Abstract/ICreateUpdateAppService.cs | 27 ++++ .../Services/Abstract/ICrudAppService.cs | 42 ++++++ .../Services/Abstract/IDeleteAppService.cs | 13 ++ .../Services/Abstract/IReadOnlyAppService.cs | 30 ++++ .../Services/Abstract/IUpdateAppService.cs | 21 +++ .../Services/ApplicationService.cs | 6 +- .../Services/CrudAppService.cs | 130 ++++++++++++++++++ .../Services/ReadOnlyAppService.cs | 103 ++++++++++++++ .../Yi - Backup.Framework.Ddd.csproj | 16 +++ .../Yi.Framework.Ddd.csproj | 9 ++ .../YiFrameworkSwaggerDoc.xml | 47 +++++++ .../Yi.Framework.Domain/DomainSwaggerDoc.xml | 28 ++++ .../Student/Entities/StudentEntity.cs | 9 +- .../Student/IRepository/IStudentRepository.cs | 1 + .../Yi.Framework.Domain.csproj | 8 ++ .../Student/StudentRepository.cs | 10 +- src/Yi.Framework/Yi.Framework.Web/Program.cs | 5 - .../Yi.Framework.Web/TestEntity.cs | 3 +- .../Yi.Framework.Web/yi-sqlsugar-dev.db | 0 60 files changed, 915 insertions(+), 83 deletions(-) create mode 100644 src/Yi.Framework/Yi.Framework.Application.Contracts/ApplicationContractsSwaggerDoc.xml create mode 100644 src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentCreateInputVo.cs create mode 100644 src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentGetListInputVo.cs create mode 100644 src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentGetListOutputDto.cs create mode 100644 src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentGetOutputDto.cs create mode 100644 src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentUpdateInputVo.cs create mode 100644 src/Yi.Framework/Yi.Framework.Application/ApplicationSwaggerDoc.xml create mode 100644 src/Yi.Framework/Yi.Framework.Core.Sqlsugar/Repositories/SqlsugarRepository.cs delete mode 100644 src/Yi.Framework/Yi.Framework.Core.Sqlsugar/Repository/SqlsugarRepository.cs rename src/Yi.Framework/Yi.Framework.Core/{Attribute => Attributes}/AppServiceAttribute.cs (90%) create mode 100644 src/Yi.Framework/Yi.Framework.Core/Enums/OrderByEnum.cs rename src/Yi.Framework/Yi.Framework.Core/{Enum => Enums}/ResultCodeEnum.cs (93%) create mode 100644 src/Yi.Framework/Yi.Framework.Core/Helper/EnumHelper.cs rename src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/{ => Abstract}/IEntityDto.cs (100%) create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IHasTotalCount.cs create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IListResult.cs create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IPagedAllResultRequestDto.cs create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IPagedAndSortedResultRequestDto.cs create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IPagedResult.cs create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/ListResultDto.cs create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/PagedAllResultRequestDto.cs create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/PagedAndSortedResultRequestDto.cs create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/PagedResultDto.cs rename src/Yi.Framework/Yi.Framework.Ddd.Application/Services/{ => Abstract}/IApplicationService.cs (79%) create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/ICreateAppService.cs create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/ICreateUpdateAppService.cs create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/ICrudAppService.cs create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/IDeleteAppService.cs create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/IReadOnlyAppService.cs create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/IUpdateAppService.cs create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Services/CrudAppService.cs create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Services/ReadOnlyAppService.cs create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/Yi - Backup.Framework.Ddd.csproj create mode 100644 src/Yi.Framework/Yi.Framework.Ddd.Application/YiFrameworkSwaggerDoc.xml create mode 100644 src/Yi.Framework/Yi.Framework.Domain/DomainSwaggerDoc.xml create mode 100644 src/Yi.Framework/Yi.Framework.Web/yi-sqlsugar-dev.db diff --git a/src/Yi.Framework/Yi.Framework.Application.Contracts/ApplicationContractsSwaggerDoc.xml b/src/Yi.Framework/Yi.Framework.Application.Contracts/ApplicationContractsSwaggerDoc.xml new file mode 100644 index 00000000..11e2c951 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Application.Contracts/ApplicationContractsSwaggerDoc.xml @@ -0,0 +1,18 @@ + + + + Yi.Framework.Application.Contracts + + + + + Student输入创建对象 + + + + + 服务抽象 + + + + diff --git a/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentCreateInputVo.cs b/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentCreateInputVo.cs new file mode 100644 index 00000000..fa6c3bbd --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentCreateInputVo.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Application.Contracts.Student.Dtos +{ + /// + /// Student输入创建对象 + /// + public class StudentCreateInputVo + { + } +} diff --git a/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentGetListInputVo.cs b/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentGetListInputVo.cs new file mode 100644 index 00000000..cf548210 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentGetListInputVo.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Application.Contracts.Student.Dtos +{ + public class StudentGetListInputVo + { + } +} diff --git a/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentGetListOutputDto.cs b/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentGetListOutputDto.cs new file mode 100644 index 00000000..02a7bb83 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentGetListOutputDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Ddd.Dtos; + +namespace Yi.Framework.Application.Contracts.Student.Dtos +{ + public class StudentGetListOutputDto : IEntityDto + { + public long Id { get; set; } + } +} diff --git a/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentGetOutputDto.cs b/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentGetOutputDto.cs new file mode 100644 index 00000000..74632e9c --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentGetOutputDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Ddd.Dtos; + +namespace Yi.Framework.Application.Contracts.Student.Dtos +{ + public class StudentGetOutputDto : IEntityDto + { + public long Id { get; set; } + } +} diff --git a/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentUpdateInputVo.cs b/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentUpdateInputVo.cs new file mode 100644 index 00000000..465e9ec1 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/Dtos/StudentUpdateInputVo.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Application.Contracts.Student.Dtos +{ + public class StudentUpdateInputVo + { + } +} diff --git a/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/IStudentService.cs b/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/IStudentService.cs index aca3f0be..e1905472 100644 --- a/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/IStudentService.cs +++ b/src/Yi.Framework/Yi.Framework.Application.Contracts/Student/IStudentService.cs @@ -3,13 +3,15 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Yi.Framework.Application.Contracts.Student.Dtos; +using Yi.Framework.Ddd.Services.Abstract; namespace Yi.Framework.Application.Contracts.Student { /// /// 服务抽象 /// - public interface IStudentService + public interface IStudentService : ICrudAppService { } diff --git a/src/Yi.Framework/Yi.Framework.Application.Contracts/Yi.Framework.Application.Contracts.csproj b/src/Yi.Framework/Yi.Framework.Application.Contracts/Yi.Framework.Application.Contracts.csproj index d012a3c6..9dfc4359 100644 --- a/src/Yi.Framework/Yi.Framework.Application.Contracts/Yi.Framework.Application.Contracts.csproj +++ b/src/Yi.Framework/Yi.Framework.Application.Contracts/Yi.Framework.Application.Contracts.csproj @@ -4,14 +4,18 @@ net6.0 enable enable + True + ./ApplicationContractsSwaggerDoc.xml - - - - + + + Always + + + diff --git a/src/Yi.Framework/Yi.Framework.Application/ApplicationSwaggerDoc.xml b/src/Yi.Framework/Yi.Framework.Application/ApplicationSwaggerDoc.xml new file mode 100644 index 00000000..01c24fd7 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Application/ApplicationSwaggerDoc.xml @@ -0,0 +1,19 @@ + + + + Yi.Framework.Application + + + + + 服务实现 + + + + + 你好世界 + + + + + diff --git a/src/Yi.Framework/Yi.Framework.Application/Student/StudentService.cs b/src/Yi.Framework/Yi.Framework.Application/Student/StudentService.cs index 96c949af..e4a0fd23 100644 --- a/src/Yi.Framework/Yi.Framework.Application/Student/StudentService.cs +++ b/src/Yi.Framework/Yi.Framework.Application/Student/StudentService.cs @@ -9,17 +9,22 @@ using Yi.Framework.Domain.Student.IRepository; using Microsoft.AspNetCore.Mvc; using NET.AutoWebApi.Setting; using Microsoft.AspNetCore.Http; +using Yi.Framework.Ddd.Services.Abstract; +using Yi.Framework.Application.Contracts.Student.Dtos; +using Yi.Framework.Domain.Student.Entities; +using Yi.Framework.Ddd.Services; namespace Yi.Framework.Application.Student { /// /// 服务实现 /// - public class StudentService : IStudentService, IAutoApiService + public class StudentService : CrudAppService, + IStudentService, IAutoApiService { private readonly IStudentRepository _studentRepository; private readonly StudentManager _studentManager; - public StudentService(IStudentRepository studentRepository, StudentManager studentManager ) + public StudentService(IStudentRepository studentRepository, StudentManager studentManager) { _studentRepository = studentRepository; _studentManager = studentManager; @@ -27,11 +32,11 @@ namespace Yi.Framework.Application.Student /// /// 你好世界 /// - /// /// - public string PostShijie(string aaa) + public async Task> PostShijie() { - return aaa; + var entities = await _studentRepository.GetMyListAsync(); + return await MapToGetListOutputDtosAsync(entities); } } } diff --git a/src/Yi.Framework/Yi.Framework.Application/SwaggerDoc.xml b/src/Yi.Framework/Yi.Framework.Application/SwaggerDoc.xml index 1d37e65a..01c24fd7 100644 --- a/src/Yi.Framework/Yi.Framework.Application/SwaggerDoc.xml +++ b/src/Yi.Framework/Yi.Framework.Application/SwaggerDoc.xml @@ -9,11 +9,10 @@ 服务实现 - + 你好世界 - diff --git a/src/Yi.Framework/Yi.Framework.Application/Yi.Framework.Application.csproj b/src/Yi.Framework/Yi.Framework.Application/Yi.Framework.Application.csproj index b3cbc75f..d498f23e 100644 --- a/src/Yi.Framework/Yi.Framework.Application/Yi.Framework.Application.csproj +++ b/src/Yi.Framework/Yi.Framework.Application/Yi.Framework.Application.csproj @@ -5,7 +5,7 @@ enable enable True - ./SwaggerDoc.xml + ./ApplicationSwaggerDoc.xml diff --git a/src/Yi.Framework/Yi.Framework.AspNetCore/Microsoft/Extensions/DependencyInjection/SwaggerAddExtensions.cs b/src/Yi.Framework/Yi.Framework.AspNetCore/Microsoft/Extensions/DependencyInjection/SwaggerAddExtensions.cs index 19e8c804..16932d90 100644 --- a/src/Yi.Framework/Yi.Framework.AspNetCore/Microsoft/Extensions/DependencyInjection/SwaggerAddExtensions.cs +++ b/src/Yi.Framework/Yi.Framework.AspNetCore/Microsoft/Extensions/DependencyInjection/SwaggerAddExtensions.cs @@ -26,9 +26,6 @@ namespace Microsoft.Extensions.DependencyInjection c.SwaggerDoc("v1", apiInfo); - //添加注释服务 - //为 Swagger JSON and UI设置xml文档注释路径 - //获取应用程序所在目录(绝对路径,不受工作目录影响,建议采用此方法获取路径使用windwos&Linux) var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location); if (basePath is not null) @@ -38,21 +35,7 @@ namespace Microsoft.Extensions.DependencyInjection c.IncludeXmlComments(item, true); } } - //控制器层注释 - //var entityXmlPath = Path.Combine(basePath, @"SwaggerDoc.xml");//实体注释 - //c.IncludeXmlComments(apiXmlPath, true);//true表示显示控制器注释 - //c.IncludeXmlComments(apiXmlPath, true); - //这里路径应该动态获取,先暂时写死 - //c.IncludeXmlComments("E:\\Yi\\src\\Yi.Framework\\Yi.Framework.Application\\SwaggerDoc.xml", true); - - - //添加控制器注释 - //c.DocumentFilter(); - - //添加header验证信息 - //c.OperationFilter(); - //var security = new Dictionary> { { "Bearer", new string[] { } }, }; c.AddSecurityDefinition("JwtBearer", new OpenApiSecurityScheme() { Description = "直接输入Token即可", diff --git a/src/Yi.Framework/Yi.Framework.AspNetCore/Yi.Framework.AspNetCore.csproj b/src/Yi.Framework/Yi.Framework.AspNetCore/Yi.Framework.AspNetCore.csproj index 240afa87..1fb2656f 100644 --- a/src/Yi.Framework/Yi.Framework.AspNetCore/Yi.Framework.AspNetCore.csproj +++ b/src/Yi.Framework/Yi.Framework.AspNetCore/Yi.Framework.AspNetCore.csproj @@ -9,7 +9,7 @@ - + diff --git a/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/Repositories/SqlsugarRepository.cs b/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/Repositories/SqlsugarRepository.cs new file mode 100644 index 00000000..3a3ca907 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/Repositories/SqlsugarRepository.cs @@ -0,0 +1,36 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Core.Attributes; +using Yi.Framework.Core.Enums; +using Yi.Framework.Core.Helper; +using Yi.Framework.Ddd.Dtos; +using Yi.Framework.Ddd.Repositories; + +namespace Yi.Framework.Core.Sqlsugar.Repositories +{ + [AppService(ServiceType = typeof(IRepository<>))] + public class SqlsugarRepository : SimpleClient, IRepository where T : class, new() + { + public SqlsugarRepository(ISqlSugarClient context) : base(context) + { + } + protected ISugarQueryable _DbQueryable { get { return base.AsQueryable(); } set { } } + + protected ISqlSugarClient _Db { get { return Context; } set { } } + + public async Task> GetPageListAsync(Expression> whereExpression, IPagedAndSortedResultRequestDto page) + { + return await base.GetPageListAsync(whereExpression, new PageModel { PageIndex = page.PageIndex, PageSize = page.PageSize }); + } + + public async Task> GetPageListAsync(Expression> whereExpression, IPagedAndSortedResultRequestDto page, Expression>? orderByExpression = null, OrderByEnum orderByType = OrderByEnum.Asc) + { + return await base.GetPageListAsync(whereExpression, new PageModel { PageIndex = page.PageIndex, PageSize = page.PageSize }, orderByExpression, orderByType.EnumToEnum()); + } + } +} diff --git a/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/Repository/SqlsugarRepository.cs b/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/Repository/SqlsugarRepository.cs deleted file mode 100644 index 5b9f5fdc..00000000 --- a/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/Repository/SqlsugarRepository.cs +++ /dev/null @@ -1,23 +0,0 @@ -using SqlSugar; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Yi.Framework.Core.Attribute; -using Yi.Framework.Ddd.Repositories; - -namespace Yi.Framework.Core.Sqlsugar.Repository -{ - [AppService(ServiceType =typeof(IRepository<>))] - public class SqlsugarRepository : SimpleClient, IRepository where T : class, new() - { - public SqlsugarRepository(ISqlSugarClient context) : base(context) - { - } - protected ISugarQueryable _DbQueryable { get { return base.Context.Queryable(); } set { } } - - protected ISqlSugarClient _Db { get { return base.Context; } set { } } - - } -} diff --git a/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/YiFrameworkCoreSqlsugarModule.cs b/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/YiFrameworkCoreSqlsugarModule.cs index 3146fedf..8c4cbe06 100644 --- a/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/YiFrameworkCoreSqlsugarModule.cs +++ b/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/YiFrameworkCoreSqlsugarModule.cs @@ -4,7 +4,7 @@ using StartupModules; using Yi.Framework.Core.Configuration; using Yi.Framework.Core.Options; using Yi.Framework.Core.Sqlsugar.Extensions; -using Yi.Framework.Core.Sqlsugar.Repository; +using Yi.Framework.Core.Sqlsugar.Repositories; using Yi.Framework.Ddd; using Yi.Framework.Ddd.Repositories; diff --git a/src/Yi.Framework/Yi.Framework.Core/Attribute/AppServiceAttribute.cs b/src/Yi.Framework/Yi.Framework.Core/Attributes/AppServiceAttribute.cs similarity index 90% rename from src/Yi.Framework/Yi.Framework.Core/Attribute/AppServiceAttribute.cs rename to src/Yi.Framework/Yi.Framework.Core/Attributes/AppServiceAttribute.cs index e9e1ddc7..e1c2cd13 100644 --- a/src/Yi.Framework/Yi.Framework.Core/Attribute/AppServiceAttribute.cs +++ b/src/Yi.Framework/Yi.Framework.Core/Attributes/AppServiceAttribute.cs @@ -4,13 +4,13 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Yi.Framework.Core.Attribute +namespace Yi.Framework.Core.Attributes { /// 1、[AppService]:自动去找接口,如果存在就是接口,如果不存在就是本身 /// 2、[AppService(ServiceType = typeof(注册抽象或者接口或者本身))],手动去注册,放type即可 /// [AttributeUsage(AttributeTargets.Class, Inherited = false)] - public class AppServiceAttribute : System.Attribute + public class AppServiceAttribute : Attribute { /// /// 服务声明周期 diff --git a/src/Yi.Framework/Yi.Framework.Core/Enums/OrderByEnum.cs b/src/Yi.Framework/Yi.Framework.Core/Enums/OrderByEnum.cs new file mode 100644 index 00000000..b1edac3a --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Core/Enums/OrderByEnum.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Core.Enums +{ + public enum OrderByEnum + { + Asc, + Desc + } +} diff --git a/src/Yi.Framework/Yi.Framework.Core/Enum/ResultCodeEnum.cs b/src/Yi.Framework/Yi.Framework.Core/Enums/ResultCodeEnum.cs similarity index 93% rename from src/Yi.Framework/Yi.Framework.Core/Enum/ResultCodeEnum.cs rename to src/Yi.Framework/Yi.Framework.Core/Enums/ResultCodeEnum.cs index ebe11f1d..ecff5e35 100644 --- a/src/Yi.Framework/Yi.Framework.Core/Enum/ResultCodeEnum.cs +++ b/src/Yi.Framework/Yi.Framework.Core/Enums/ResultCodeEnum.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Yi.Framework.Core.Enum +namespace Yi.Framework.Core.Enums { public enum ResultCodeEnum { diff --git a/src/Yi.Framework/Yi.Framework.Core/Exceptions/BusinessException.cs b/src/Yi.Framework/Yi.Framework.Core/Exceptions/BusinessException.cs index 382226d4..61041f19 100644 --- a/src/Yi.Framework/Yi.Framework.Core/Exceptions/BusinessException.cs +++ b/src/Yi.Framework/Yi.Framework.Core/Exceptions/BusinessException.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; -using Yi.Framework.Core.Enum; +using Yi.Framework.Core.Enums; namespace Yi.Framework.Core.Exceptions { diff --git a/src/Yi.Framework/Yi.Framework.Core/Exceptions/ExceptionExtensions.cs b/src/Yi.Framework/Yi.Framework.Core/Exceptions/ExceptionExtensions.cs index e7157b59..e7e21cb4 100644 --- a/src/Yi.Framework/Yi.Framework.Core/Exceptions/ExceptionExtensions.cs +++ b/src/Yi.Framework/Yi.Framework.Core/Exceptions/ExceptionExtensions.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.ExceptionServices; using Microsoft.Extensions.Logging; -using Yi.Framework.Core.Enum; +using Yi.Framework.Core.Enums; namespace Yi.Framework.Core.Exceptions; diff --git a/src/Yi.Framework/Yi.Framework.Core/Exceptions/IHasErrorCode.cs b/src/Yi.Framework/Yi.Framework.Core/Exceptions/IHasErrorCode.cs index f7586014..fa49d5ec 100644 --- a/src/Yi.Framework/Yi.Framework.Core/Exceptions/IHasErrorCode.cs +++ b/src/Yi.Framework/Yi.Framework.Core/Exceptions/IHasErrorCode.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using Yi.Framework.Core.Enum; +using Yi.Framework.Core.Enums; namespace Yi.Framework.Core.Exceptions { diff --git a/src/Yi.Framework/Yi.Framework.Core/Exceptions/UserFriendlyException.cs b/src/Yi.Framework/Yi.Framework.Core/Exceptions/UserFriendlyException.cs index 0ede95d1..16033c68 100644 --- a/src/Yi.Framework/Yi.Framework.Core/Exceptions/UserFriendlyException.cs +++ b/src/Yi.Framework/Yi.Framework.Core/Exceptions/UserFriendlyException.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; -using Yi.Framework.Core.Enum; +using Yi.Framework.Core.Enums; namespace Yi.Framework.Core.Exceptions { diff --git a/src/Yi.Framework/Yi.Framework.Core/Extensions/AutoIocAddExtensions.cs b/src/Yi.Framework/Yi.Framework.Core/Extensions/AutoIocAddExtensions.cs index 51c7a895..53d11f0e 100644 --- a/src/Yi.Framework/Yi.Framework.Core/Extensions/AutoIocAddExtensions.cs +++ b/src/Yi.Framework/Yi.Framework.Core/Extensions/AutoIocAddExtensions.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; -using Yi.Framework.Core.Attribute; +using Yi.Framework.Core.Attributes; using Yi.Framework.Core.DependencyInjection; namespace Yi.Framework.Core.Extensions diff --git a/src/Yi.Framework/Yi.Framework.Core/Helper/EnumHelper.cs b/src/Yi.Framework/Yi.Framework.Core/Helper/EnumHelper.cs new file mode 100644 index 00000000..61d2e842 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Core/Helper/EnumHelper.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Core.Helper +{ + public static class EnumHelper + { + public static New EnumToEnum(this object oldEnum) + { + if (oldEnum is null) + { + throw new ArgumentNullException(nameof(oldEnum)); + } + return (New)Enum.ToObject(typeof(New), oldEnum.GetHashCode()); + } + } +} diff --git a/src/Yi.Framework/Yi.Framework.Core/Helper/FileHelper.cs b/src/Yi.Framework/Yi.Framework.Core/Helper/FileHelper.cs index 7ae1c0c4..906b7253 100644 --- a/src/Yi.Framework/Yi.Framework.Core/Helper/FileHelper.cs +++ b/src/Yi.Framework/Yi.Framework.Core/Helper/FileHelper.cs @@ -4,7 +4,7 @@ using System.IO; using System.Linq; using System.Text; -namespace Yi.Framework.Common.Helper +namespace Yi.Framework.Core.Helper { public class FileHelper : IDisposable { @@ -128,7 +128,7 @@ namespace Yi.Framework.Common.Helper FileStream f = File.Create(Path); f.Close(); } - StreamWriter f2 = new StreamWriter(Path, false, System.Text.Encoding.GetEncoding("gb2312")); + StreamWriter f2 = new StreamWriter(Path, false, Encoding.GetEncoding("gb2312")); f2.Write(Strings); f2.Close(); f2.Dispose(); @@ -175,7 +175,7 @@ namespace Yi.Framework.Common.Helper s = "不存在相应的目录"; else { - StreamReader f2 = new StreamReader(Path, System.Text.Encoding.GetEncoding("gb2312")); + StreamReader f2 = new StreamReader(Path, Encoding.GetEncoding("gb2312")); s = f2.ReadToEnd(); f2.Close(); f2.Dispose(); diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/IEntityDto.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IEntityDto.cs similarity index 100% rename from src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/IEntityDto.cs rename to src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IEntityDto.cs diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IHasTotalCount.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IHasTotalCount.cs new file mode 100644 index 00000000..778fae5a --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IHasTotalCount.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Ddd.Dtos +{ + public interface IHasTotalCount + { + long Total { get; set; } + } +} diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IListResult.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IListResult.cs new file mode 100644 index 00000000..e39bc0d3 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IListResult.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Ddd.Dtos +{ + public interface IListResult + { + IReadOnlyList Items { get; set; } + } +} diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IPagedAllResultRequestDto.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IPagedAllResultRequestDto.cs new file mode 100644 index 00000000..0158dc66 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IPagedAllResultRequestDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Ddd.Dtos.Abstract +{ + public interface IPagedAllResultRequestDto + { + DateTime? StartTime { get; set; } + DateTime? EndTime { get; set; } + } +} diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IPagedAndSortedResultRequestDto.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IPagedAndSortedResultRequestDto.cs new file mode 100644 index 00000000..cb5d91ef --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IPagedAndSortedResultRequestDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Ddd.Dtos +{ + public interface IPagedAndSortedResultRequestDto + { + int PageIndex { get; set; } + int PageSize { get; set; } + string? PageSort { get; set; } + } +} diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IPagedResult.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IPagedResult.cs new file mode 100644 index 00000000..fe9bb5c0 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/Abstract/IPagedResult.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Ddd.Dtos +{ + public interface IPagedResult : IListResult, IHasTotalCount + { + } +} diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/ListResultDto.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/ListResultDto.cs new file mode 100644 index 00000000..630226d1 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/ListResultDto.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Ddd.Dtos +{ + [Serializable] + public class ListResultDto : IListResult + { + public IReadOnlyList Items + { + get { return _items ?? (_items = new List()); } + set { _items = value; } + } + private IReadOnlyList _items; + + public ListResultDto() + { + + } + + public ListResultDto(IReadOnlyList items) + { + Items = items; + } + } +} diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/PagedAllResultRequestDto.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/PagedAllResultRequestDto.cs new file mode 100644 index 00000000..a156a654 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/PagedAllResultRequestDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Ddd.Dtos +{ + public class PagedAllResultRequestDto: PagedAndSortedResultRequestDto + { + public DateTime? StartTime { get; set; } + public DateTime? EndTime { get; set; } + } +} diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/PagedAndSortedResultRequestDto.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/PagedAndSortedResultRequestDto.cs new file mode 100644 index 00000000..b52ebbe8 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/PagedAndSortedResultRequestDto.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Ddd.Dtos +{ + public class PagedAndSortedResultRequestDto : IPagedAndSortedResultRequestDto + { + public int PageIndex { get; set; } + public int PageSize { get; set; } + public string? PageSort { get; set; } + + } +} diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/PagedResultDto.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/PagedResultDto.cs new file mode 100644 index 00000000..81b125aa --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Dtos/PagedResultDto.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Ddd.Dtos +{ + public class PagedResultDto:ListResultDto, IPagedResult + { + public long Total { get; set; } + + public PagedResultDto() + { + + } + + public PagedResultDto(long totalCount, IReadOnlyList items) + : base(items) + { + Total = totalCount; + } + } +} diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Entities/IEntity.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Entities/IEntity.cs index 73c9168e..4537ff2a 100644 --- a/src/Yi.Framework/Yi.Framework.Ddd.Application/Entities/IEntity.cs +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Entities/IEntity.cs @@ -11,13 +11,13 @@ namespace Yi.Framework.Ddd.Entities // // 摘要: // Returns an array of ordered keys for this entity. - object[] GetKeys(); + } public interface IEntity : IEntity { // // 摘要: // Unique identifier for this entity. - TKey Id { get; } + TKey Id { get;} } } diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Repositories/IRepository.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Repositories/IRepository.cs index 5351e7e5..5493c5d3 100644 --- a/src/Yi.Framework/Yi.Framework.Ddd.Application/Repositories/IRepository.cs +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Repositories/IRepository.cs @@ -1,13 +1,51 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; +using Yi.Framework.Core.Enums; +using Yi.Framework.Ddd.Dtos; namespace Yi.Framework.Ddd.Repositories { public interface IRepository { + //单查 Task GetByIdAsync(dynamic id); + Task GetSingleAsync(Expression> whereExpression); + Task GetFirstAsync(Expression> whereExpression); + Task IsAnyAsync(Expression> whereExpression); + Task CountAsync(Expression> whereExpression); + + //多查 + Task> GetListAsync(); + Task> GetListAsync(Expression> whereExpression); + + //分页查 + Task> GetPageListAsync(Expression> whereExpression, IPagedAndSortedResultRequestDto page); + Task> GetPageListAsync(Expression> whereExpression, IPagedAndSortedResultRequestDto page, Expression>? orderByExpression = null, OrderByEnum orderByType = OrderByEnum.Asc); + + //插入 + Task InsertAsync(T insertObj); + Task InsertOrUpdateAsync(T data); + Task InsertOrUpdateAsync(List datas); + Task InsertReturnIdentityAsync(T insertObj); + Task InsertReturnBigIdentityAsync(T insertObj); + Task InsertReturnSnowflakeIdAsync(T insertObj); + Task InsertReturnEntityAsync(T insertObj); + Task InsertRangeAsync(List insertObjs); + + //更新 + Task UpdateAsync(T updateObj); + Task UpdateRangeAsync(List updateObjs); + Task UpdateAsync(Expression> columns, Expression> whereExpression); + + //删除 + Task DeleteAsync(T deleteObj); + Task DeleteAsync(List deleteObjs); + Task DeleteAsync(Expression> whereExpression); + Task DeleteByIdAsync(dynamic id); + Task DeleteByIdsAsync(dynamic[] ids); } } diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/IApplicationService.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/IApplicationService.cs similarity index 79% rename from src/Yi.Framework/Yi.Framework.Ddd.Application/Services/IApplicationService.cs rename to src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/IApplicationService.cs index c5491cb2..ec81ea5d 100644 --- a/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/IApplicationService.cs +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/IApplicationService.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Yi.Framework.Ddd.Services +namespace Yi.Framework.Ddd.Services.Abstract { public interface IApplicationService { diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/ICreateAppService.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/ICreateAppService.cs new file mode 100644 index 00000000..04b443e7 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/ICreateAppService.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Ddd.Services.Abstract +{ + public interface ICreateAppService + : ICreateAppService + { + + } + + public interface ICreateAppService + : IApplicationService + { + Task CreateAsync(TCreateInput input); + } +} diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/ICreateUpdateAppService.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/ICreateUpdateAppService.cs new file mode 100644 index 00000000..2996249b --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/ICreateUpdateAppService.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Ddd.Services.Abstract +{ + public interface ICreateUpdateAppService + : ICreateUpdateAppService + { + + } + + public interface ICreateUpdateAppService + : ICreateUpdateAppService + { + + } + + public interface ICreateUpdateAppService + : ICreateAppService, + IUpdateAppService + { + + } +} diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/ICrudAppService.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/ICrudAppService.cs new file mode 100644 index 00000000..2c87e055 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/ICrudAppService.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Ddd.Dtos; + +namespace Yi.Framework.Ddd.Services.Abstract +{ + + public interface ICrudAppService + : ICrudAppService + { + + } + + public interface ICrudAppService + : ICrudAppService + { + + } + + public interface ICrudAppService + : ICrudAppService + { + + } + + public interface ICrudAppService + : ICrudAppService + { + + } + + public interface ICrudAppService + : IReadOnlyAppService, + ICreateUpdateAppService, + IDeleteAppService + { + + } +} diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/IDeleteAppService.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/IDeleteAppService.cs new file mode 100644 index 00000000..d1c59f86 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/IDeleteAppService.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Ddd.Services.Abstract +{ + public interface IDeleteAppService : IApplicationService + { + Task DeleteAsync(TKey id); + } +} diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/IReadOnlyAppService.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/IReadOnlyAppService.cs new file mode 100644 index 00000000..911b8ee1 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/IReadOnlyAppService.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Ddd.Dtos; +using Yi.Framework.Ddd.Entities; + +namespace Yi.Framework.Ddd.Services.Abstract +{ + public interface IReadOnlyAppService + : IReadOnlyAppService + { + + } + + public interface IReadOnlyAppService + : IReadOnlyAppService + { + + } + + public interface IReadOnlyAppService + : IApplicationService + { + Task GetAsync(TKey id); + + Task> GetListAsync(TGetListInput input); + } +} diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/IUpdateAppService.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/IUpdateAppService.cs new file mode 100644 index 00000000..16b75cb8 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/Abstract/IUpdateAppService.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Ddd.Services.Abstract +{ + public interface IUpdateAppService + : IUpdateAppService + { + + } + + public interface IUpdateAppService + : IApplicationService + { + Task UpdateAsync(TKey id, TUpdateInput input); + } + +} diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/ApplicationService.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/ApplicationService.cs index bda9830b..9b1c7579 100644 --- a/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/ApplicationService.cs +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/ApplicationService.cs @@ -1,4 +1,5 @@ -using System; +using AutoMapper; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -7,6 +8,7 @@ using System.Threading.Tasks; namespace Yi.Framework.Ddd.Services { public abstract class ApplicationService - { + { + public IMapper _mapper { get; set; } } } diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/CrudAppService.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/CrudAppService.cs new file mode 100644 index 00000000..cf6cfcd6 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/CrudAppService.cs @@ -0,0 +1,130 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Ddd.Dtos; +using Yi.Framework.Ddd.Entities; +using Yi.Framework.Ddd.Services.Abstract; + +namespace Yi.Framework.Ddd.Services +{ + + public abstract class CrudAppService + : CrudAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto + { + } + + public abstract class CrudAppService + : CrudAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto + { + } + + public abstract class CrudAppService + : CrudAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto + { + } + + + + + public abstract class CrudAppService + : CrudAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto + { + protected override Task MapToGetListOutputDtoAsync(TEntity entity) + { + return MapToGetOutputDtoAsync(entity); + } + + } + + public abstract class CrudAppService + : ReadOnlyAppService, + ICrudAppService + where TEntity : class, IEntity + where TGetOutputDto : IEntityDto + where TGetListOutputDto : IEntityDto + + { + + protected virtual Task MapToEntityAsync(TCreateInput createInput) + { + var entity = _mapper.Map(createInput); + + //这里判断实体的T,给id赋值 + + //雪花id + //if (entity is IEntity) + //{ + // //使用反射,暂时先使用sqlsuga的雪花id提供 + // entityWithLongId.Id = SqlSugar.SnowFlakeSingle.Instance.NextId(); + //} + + + return Task.FromResult(entity); + } + protected virtual Task MapToEntityAsync(TUpdateInput updateInput, TEntity entity) + { + _mapper.Map(updateInput, entity); + return Task.CompletedTask; + } + + /// + /// 增 + /// + /// + /// + public async Task CreateAsync(TCreateInput input) + { + var entity = await MapToEntityAsync(input); + + await _repository.InsertAsync(entity); + + return await MapToGetOutputDtoAsync(entity); + } + + /// + /// 删 + /// + /// + /// + /// + public async Task DeleteAsync(TKey id) + { + if (id is null) + { + throw new ArgumentNullException(nameof(id)); + } + await _repository.DeleteByIdAsync(id); + } + + /// + /// 改 + /// + /// + /// + /// + /// + public virtual async Task UpdateAsync(TKey id, TUpdateInput input) + { + if (id is null) + { + throw new ArgumentNullException(nameof(id)); + } + var entity = await _repository.GetByIdAsync(id); + + await MapToEntityAsync(input, entity); + await _repository.UpdateAsync(entity); + + return await MapToGetOutputDtoAsync(entity); + } + } +} diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/ReadOnlyAppService.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/ReadOnlyAppService.cs new file mode 100644 index 00000000..b5a1cb60 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Services/ReadOnlyAppService.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Ddd.Dtos; +using Yi.Framework.Ddd.Entities; +using Yi.Framework.Ddd.Repositories; +using Yi.Framework.Ddd.Services.Abstract; + +namespace Yi.Framework.Ddd.Services +{ + + public abstract class ReadOnlyAppService + : ReadOnlyAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto + { + } + + public abstract class ReadOnlyAppService +: ReadOnlyAppService +where TEntity : class, IEntity +where TEntityDto : IEntityDto + { + } + + + public abstract class ReadOnlyAppService : ApplicationService, + IReadOnlyAppService + where TEntity : class, IEntity + { + protected IRepository _repository { get; } + + //Mapper + protected virtual Task MapToGetOutputDtoAsync(TEntity entity) + { + return Task.FromResult(_mapper.Map(entity)); + } + protected virtual Task> MapToGetListOutputDtosAsync(List entities) + { + var dtos = _mapper.Map>(entities); + + return Task.FromResult(dtos); + } + protected virtual Task MapToGetListOutputDtoAsync(TEntity entity) + { + var dto = _mapper.Map(entity); + return Task.FromResult(dto); + } + + /// + /// 单查 + /// + /// + /// + /// + public async Task GetAsync(TKey id) + { + if (id is null) + { + throw new ArgumentNullException(nameof(id)); + } + + var entity = await _repository.GetByIdAsync(id); + + return await MapToGetOutputDtoAsync(entity); + } + + /// + /// 全查 + /// + /// + /// + public async Task> GetListAsync(TGetListInput input) + { + + var totalCount = await _repository.CountAsync(_ => true); + + var entities = new List(); + var entityDtos = new List(); + + if (totalCount > 0) + { + if (input is IPagedAndSortedResultRequestDto sortInput) + { + entities = await _repository.GetPageListAsync(_ => true, sortInput); + } + //这里还可以追加如果是审计日志,继续拼接条件即可 + else + { + entities = await _repository.GetListAsync(); + } + entityDtos = await MapToGetListOutputDtosAsync(entities); + } + + return new PagedResultDto( + totalCount, + entityDtos + ); + } + } +} diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Yi - Backup.Framework.Ddd.csproj b/src/Yi.Framework/Yi.Framework.Ddd.Application/Yi - Backup.Framework.Ddd.csproj new file mode 100644 index 00000000..761ed5d1 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Yi - Backup.Framework.Ddd.csproj @@ -0,0 +1,16 @@ + + + + net6.0 + enable + enable + True + ./SwaggerDoc.xml + + + + + + + + diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Yi.Framework.Ddd.csproj b/src/Yi.Framework/Yi.Framework.Ddd.Application/Yi.Framework.Ddd.csproj index e7101d08..0c576986 100644 --- a/src/Yi.Framework/Yi.Framework.Ddd.Application/Yi.Framework.Ddd.csproj +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Yi.Framework.Ddd.csproj @@ -4,10 +4,19 @@ net6.0 enable enable + True + ./YiFrameworkSwaggerDoc.xml + + + + Always + + + diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/YiFrameworkSwaggerDoc.xml b/src/Yi.Framework/Yi.Framework.Ddd.Application/YiFrameworkSwaggerDoc.xml new file mode 100644 index 00000000..50a29bb6 --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/YiFrameworkSwaggerDoc.xml @@ -0,0 +1,47 @@ + + + + Yi.Framework.Ddd + + + + + 增 + + + + + + + 删 + + + + + + + + 改 + + + + + + + + + 单查 + + + + + + + + 全查 + + + + + + diff --git a/src/Yi.Framework/Yi.Framework.Domain/DomainSwaggerDoc.xml b/src/Yi.Framework/Yi.Framework.Domain/DomainSwaggerDoc.xml new file mode 100644 index 00000000..c12ad92c --- /dev/null +++ b/src/Yi.Framework/Yi.Framework.Domain/DomainSwaggerDoc.xml @@ -0,0 +1,28 @@ + + + + Yi.Framework.Domain + + + + + 学生实体 + + + + + 学生名称 + + + + + 仓储抽象 + + + + + 领域服务 + + + + diff --git a/src/Yi.Framework/Yi.Framework.Domain/Student/Entities/StudentEntity.cs b/src/Yi.Framework/Yi.Framework.Domain/Student/Entities/StudentEntity.cs index f850ab2f..a1cb4a62 100644 --- a/src/Yi.Framework/Yi.Framework.Domain/Student/Entities/StudentEntity.cs +++ b/src/Yi.Framework/Yi.Framework.Domain/Student/Entities/StudentEntity.cs @@ -4,16 +4,21 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Yi.Framework.Ddd.Entities; namespace Yi.Framework.Domain.Student.Entities { /// - /// 实体 + /// 学生实体 /// [SugarTable("Student")] - public class StudentEntity + public class StudentEntity : IEntity { public long Id { get; set; } + + /// + /// 学生名称 + /// public string Name { get; set; } = string.Empty; } } diff --git a/src/Yi.Framework/Yi.Framework.Domain/Student/IRepository/IStudentRepository.cs b/src/Yi.Framework/Yi.Framework.Domain/Student/IRepository/IStudentRepository.cs index a0a09dfe..b5ad134a 100644 --- a/src/Yi.Framework/Yi.Framework.Domain/Student/IRepository/IStudentRepository.cs +++ b/src/Yi.Framework/Yi.Framework.Domain/Student/IRepository/IStudentRepository.cs @@ -13,5 +13,6 @@ namespace Yi.Framework.Domain.Student.IRepository /// public interface IStudentRepository:IRepository { + Task> GetMyListAsync(); } } diff --git a/src/Yi.Framework/Yi.Framework.Domain/Yi.Framework.Domain.csproj b/src/Yi.Framework/Yi.Framework.Domain/Yi.Framework.Domain.csproj index b1d51c1d..4bc01bd2 100644 --- a/src/Yi.Framework/Yi.Framework.Domain/Yi.Framework.Domain.csproj +++ b/src/Yi.Framework/Yi.Framework.Domain/Yi.Framework.Domain.csproj @@ -4,10 +4,18 @@ net6.0 enable enable + True + ./DomainSwaggerDoc.xml + + + Always + + + diff --git a/src/Yi.Framework/Yi.Framework.Sqlsugar/Student/StudentRepository.cs b/src/Yi.Framework/Yi.Framework.Sqlsugar/Student/StudentRepository.cs index 5ba9c262..49865788 100644 --- a/src/Yi.Framework/Yi.Framework.Sqlsugar/Student/StudentRepository.cs +++ b/src/Yi.Framework/Yi.Framework.Sqlsugar/Student/StudentRepository.cs @@ -4,8 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using Yi.Framework.Core.Sqlsugar.Repository; -using Yi.Framework.Ddd.Repository; +using Yi.Framework.Core.Sqlsugar.Repositories; using Yi.Framework.Domain.Student.Entities; using Yi.Framework.Domain.Student.IRepository; @@ -14,10 +13,15 @@ namespace Yi.Framework.Sqlsugar.Student /// /// 仓储实现方式 /// - public class StudentRepository : SqlsugarRepository ,IStudentRepository + public class StudentRepository : SqlsugarRepository, IStudentRepository { public StudentRepository(ISqlSugarClient context) : base(context) { } + + public async Task> GetMyListAsync() + { + return await _DbQueryable.ToListAsync(); + } } } diff --git a/src/Yi.Framework/Yi.Framework.Web/Program.cs b/src/Yi.Framework/Yi.Framework.Web/Program.cs index 90d166df..e86c30d0 100644 --- a/src/Yi.Framework/Yi.Framework.Web/Program.cs +++ b/src/Yi.Framework/Yi.Framework.Web/Program.cs @@ -8,9 +8,7 @@ using Yi.Framework.Core; using Yi.Framework.Core.AutoMapper; using Yi.Framework.Core.Extensions; using Yi.Framework.Core.Sqlsugar; -using Yi.Framework.Core.Sqlsugar.Repository; using Yi.Framework.Ddd; -using Yi.Framework.Ddd.Repository; using Yi.Framework.Domain; using Yi.Framework.Domain.Shared; using Yi.Framework.Sqlsugar; @@ -41,8 +39,5 @@ builder.UseYiModules( builder.Host.UseAutoFacServerProviderFactory(); var app = builder.Build(); - -//ʹö̬api -app.UseAutoApiService(); app.MapControllers(); app.Run(); diff --git a/src/Yi.Framework/Yi.Framework.Web/TestEntity.cs b/src/Yi.Framework/Yi.Framework.Web/TestEntity.cs index 242d5933..b72749ed 100644 --- a/src/Yi.Framework/Yi.Framework.Web/TestEntity.cs +++ b/src/Yi.Framework/Yi.Framework.Web/TestEntity.cs @@ -1,5 +1,4 @@ -using Yi.Framework.Core.Attribute; -using Yi.Framework.Core.DependencyInjection; +using Yi.Framework.Core.DependencyInjection; namespace Yi.Framework.Web { diff --git a/src/Yi.Framework/Yi.Framework.Web/yi-sqlsugar-dev.db b/src/Yi.Framework/Yi.Framework.Web/yi-sqlsugar-dev.db new file mode 100644 index 00000000..e69de29b