From 889cd8a5b6b4a0f05237041185e7eb97c544242e Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 8 Sep 2023 11:22:38 +0800 Subject: [PATCH] fix(identity): fix issues #853 --- aspnet-core/LINGYUN.MicroService.All.sln | 4 +- .../Identity/OrganizationUnitAppService.cs | 7 ++- .../OrganizationUnitGetListSpecification.cs | 23 ++++++++++ .../Identity/IOrganizationUnitRepository.cs | 22 +++++++++ .../Expressions/ExpressionFuncExtensions.cs | 32 +++++++++++++ .../AbpIdentityEntityFrameworkCoreModule.cs | 1 + .../EfCoreOrganizationUnitRepository.cs | 46 +++++++++++++++++++ 7 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitGetListSpecification.cs create mode 100644 aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN/Abp/Identity/IOrganizationUnitRepository.cs create mode 100644 aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/System/Linq/Expressions/ExpressionFuncExtensions.cs create mode 100644 aspnet-core/modules/identity/LINGYUN.Abp.Identity.EntityFrameworkCore/LINGYUN/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs diff --git a/aspnet-core/LINGYUN.MicroService.All.sln b/aspnet-core/LINGYUN.MicroService.All.sln index 023038f5f..568fb4098 100644 --- a/aspnet-core/LINGYUN.MicroService.All.sln +++ b/aspnet-core/LINGYUN.MicroService.All.sln @@ -645,9 +645,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cli", "cli", "{59627844-A66 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Cli", "modules\cli\LINGYUN.Abp.Cli\LINGYUN.Abp.Cli.csproj", "{2F49E870-DAE2-4D89-98CA-46BBD91C68E2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.OssManagement.FileSystem.Imaging", "modules\oss-management\LINGYUN.Abp.OssManagement.FileSystem.Imaging\LINGYUN.Abp.OssManagement.FileSystem.Imaging.csproj", "{6C8489F4-68B5-4CBC-8463-010C71C23245}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.OssManagement.FileSystem.Imaging", "modules\oss-management\LINGYUN.Abp.OssManagement.FileSystem.Imaging\LINGYUN.Abp.OssManagement.FileSystem.Imaging.csproj", "{6C8489F4-68B5-4CBC-8463-010C71C23245}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp", "modules\oss-management\LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp\LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp.csproj", "{5177C729-7666-4A6C-9D54-D7E5DEF0E857}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp", "modules\oss-management\LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp\LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp.csproj", "{5177C729-7666-4A6C-9D54-D7E5DEF0E857}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitAppService.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitAppService.cs index 3581a8a6a..86318b537 100644 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitAppService.cs +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitAppService.cs @@ -102,9 +102,12 @@ public async virtual Task> GetAllListAsync() public async virtual Task> GetListAsync(OrganizationUnitGetByPagedDto input) { - var origanizationUnitCount = await OrganizationUnitRepository.GetCountAsync(); + var specification = new OrganizationUnitGetListSpecification(input); + + var origanizationUnitCount = await OrganizationUnitRepository.GetCountAsync(specification); + var origanizationUnits = await OrganizationUnitRepository - .GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, false); + .GetListAsync(specification, input.Sorting, input.MaxResultCount, input.SkipCount, false); return new PagedResultDto(origanizationUnitCount, ObjectMapper.Map, List>(origanizationUnits)); diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitGetListSpecification.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitGetListSpecification.cs new file mode 100644 index 000000000..e9a45cbc6 --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitGetListSpecification.cs @@ -0,0 +1,23 @@ +using System; +using System.Linq.Expressions; +using Volo.Abp.Identity; +using Volo.Abp.Specifications; + +namespace LINGYUN.Abp.Identity; +public class OrganizationUnitGetListSpecification : Specification +{ + protected OrganizationUnitGetByPagedDto Input { get; } + public OrganizationUnitGetListSpecification(OrganizationUnitGetByPagedDto input) + { + Input = input; + } + + public override Expression> ToExpression() + { + Expression> expression = _ => true; + + return expression + .AndIf(!Input.Filter.IsNullOrWhiteSpace(), x => + x.DisplayName.Contains(Input.Filter) || x.Code.Contains(Input.Filter)); + } +} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN/Abp/Identity/IOrganizationUnitRepository.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN/Abp/Identity/IOrganizationUnitRepository.cs new file mode 100644 index 000000000..5a15c6bc6 --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN/Abp/Identity/IOrganizationUnitRepository.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Volo.Abp.Identity; +using Volo.Abp.Specifications; + +namespace LINGYUN.Abp.Identity; + +public interface IOrganizationUnitRepository : Volo.Abp.Identity.IOrganizationUnitRepository +{ + Task GetCountAsync( + ISpecification specification, + CancellationToken cancellationToken = default); + + Task> GetListAsync( + ISpecification specification, + string sorting = nameof(OrganizationUnit.Code), + int maxResultCount = 10, + int skipCount = 0, + bool includeDetails = false, + CancellationToken cancellationToken = default); +} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/System/Linq/Expressions/ExpressionFuncExtensions.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/System/Linq/Expressions/ExpressionFuncExtensions.cs new file mode 100644 index 000000000..b8629f860 --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/System/Linq/Expressions/ExpressionFuncExtensions.cs @@ -0,0 +1,32 @@ +using Volo.Abp.Specifications; + +namespace System.Linq.Expressions; + +public static class ExpressionFuncExtensions +{ + public static Expression> AndIf( + this Expression> first, + bool condition, + Expression> second) + { + if (condition) + { + return ExpressionFuncExtender.And(first, second); + } + + return first; + } + + public static Expression> OrIf( + this Expression> first, + bool condition, + Expression> second) + { + if (condition) + { + return ExpressionFuncExtender.Or(first, second); + } + + return first; + } +} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.EntityFrameworkCore/LINGYUN/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreModule.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.EntityFrameworkCore/LINGYUN/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreModule.cs index 8c5557ec7..c907fa58c 100644 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.EntityFrameworkCore/LINGYUN/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreModule.cs +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.EntityFrameworkCore/LINGYUN/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreModule.cs @@ -17,6 +17,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) { options.AddRepository(); options.AddRepository(); + options.AddRepository(); }); } diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.EntityFrameworkCore/LINGYUN/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.EntityFrameworkCore/LINGYUN/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs new file mode 100644 index 000000000..ccbfb55a8 --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.EntityFrameworkCore/LINGYUN/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs @@ -0,0 +1,46 @@ +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Threading; +using System.Threading.Tasks; +using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.Identity; +using Volo.Abp.Identity.EntityFrameworkCore; +using Volo.Abp.Specifications; + +namespace LINGYUN.Abp.Identity.EntityFrameworkCore; + +public class EfCoreOrganizationUnitRepository : Volo.Abp.Identity.EntityFrameworkCore.EfCoreOrganizationUnitRepository, IOrganizationUnitRepository +{ + public EfCoreOrganizationUnitRepository( + IDbContextProvider dbContextProvider) + : base(dbContextProvider) + { + } + + public async virtual Task GetCountAsync( + ISpecification specification, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .Where(specification.ToExpression()) + .CountAsync(GetCancellationToken(cancellationToken)); + } + + public async virtual Task> GetListAsync( + ISpecification specification, + string sorting = nameof(OrganizationUnit.Code), + int maxResultCount = 10, + int skipCount = 0, + bool includeDetails = false, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .IncludeDetails(includeDetails) + .Where(specification.ToExpression()) + .OrderBy(sorting) + .PageBy(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } +}