diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj index 9773ae528..b9927d32f 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj @@ -15,14 +15,14 @@ - 1701;1702;1591;1587 + 1701;1702;1591;1587 - + @@ -50,16 +50,16 @@ - - PreserveNewest - true - PreserveNewest - - - Always - true - PreserveNewest - + + PreserveNewest + true + PreserveNewest + + + Always + true + PreserveNewest + @@ -76,16 +76,14 @@ - - - + - true + true - true + true @@ -94,7 +92,7 @@ - true + true diff --git a/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs b/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs index 5ba66e44d..e1d7999e2 100644 --- a/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs +++ b/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs @@ -203,13 +203,35 @@ namespace IRaCIS.Core.Application.Services }; - var unionQuery = systemDocumentQueryable.Union(trialDocQueryable) - .WhereIf(!string.IsNullOrEmpty(querySystemDocument.Name), t => t.Name.Contains(querySystemDocument.Name)) - .WhereIf(querySystemDocument.FileTypeId != null, t => t.FileTypeId == querySystemDocument.FileTypeId) - .WhereIf(querySystemDocument.IsSign == true, t => t.ConfirmTime != null) - .WhereIf(querySystemDocument.IsSign == false, t => t.ConfirmTime == null); + #region 报错 奇怪的bug + //var unionQuery = systemDocumentQueryable.Union(trialDocQueryable) + // .WhereIf(!string.IsNullOrEmpty(querySystemDocument.Name), t => t.Name.Contains(querySystemDocument.Name)) + // .WhereIf(querySystemDocument.FileTypeId != null, t => t.FileTypeId == querySystemDocument.FileTypeId) + // .WhereIf(querySystemDocument.IsSign == true, t => t.ConfirmTime != null) + // .WhereIf(querySystemDocument.IsSign == false, t => t.ConfirmTime == null); - var result = await unionQuery.ToPagedListAsync(querySystemDocument.PageIndex, querySystemDocument.PageSize, querySystemDocument.SortField, querySystemDocument.Asc); + //var result = await unionQuery.ToPagedListAsync(querySystemDocument.PageIndex, querySystemDocument.PageSize, querySystemDocument.SortField, querySystemDocument.Asc); + #endregion + + #region 临时方案 + + var list1 = systemDocumentQueryable + .WhereIf(!string.IsNullOrEmpty(querySystemDocument.Name), t => t.Name.Contains(querySystemDocument.Name)) + .WhereIf(querySystemDocument.FileTypeId != null, t => t.FileTypeId == querySystemDocument.FileTypeId) + .WhereIf(querySystemDocument.IsSign == true, t => t.ConfirmTime != null) + .WhereIf(querySystemDocument.IsSign == false, t => t.ConfirmTime == null).ToList(); + + var list2 = trialDocQueryable + .WhereIf(!string.IsNullOrEmpty(querySystemDocument.Name), t => t.Name.Contains(querySystemDocument.Name)) + .WhereIf(querySystemDocument.FileTypeId != null, t => t.FileTypeId == querySystemDocument.FileTypeId) + .WhereIf(querySystemDocument.IsSign == true, t => t.ConfirmTime != null) + .WhereIf(querySystemDocument.IsSign == false, t => t.ConfirmTime == null).ToList(); + + var list3 = list1.Union(list2).ToList(); + + var result = list3.ToPagedList(querySystemDocument.PageIndex, querySystemDocument.PageSize, querySystemDocument.SortField, querySystemDocument.Asc); + + #endregion var needSignTrialDocCount = await _trialDocumentRepository.AsQueryable(true).Where(t => t.TrialId== querySystemDocument.TrialId && t.Trial.TrialStatusStr != StaticData.TrialState.TrialStopped) .Where(t => t.Trial.TrialUserList.Any(t => t.UserId == _userInfo.Id)) diff --git a/IRaCIS.Core.Infra.EFCore/IRaCIS.Core.Infra.EFCore.csproj b/IRaCIS.Core.Infra.EFCore/IRaCIS.Core.Infra.EFCore.csproj index 5cad3e7b0..d848f33c0 100644 --- a/IRaCIS.Core.Infra.EFCore/IRaCIS.Core.Infra.EFCore.csproj +++ b/IRaCIS.Core.Infra.EFCore/IRaCIS.Core.Infra.EFCore.csproj @@ -17,15 +17,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs b/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs index 547a5119b..5428578f6 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs @@ -157,7 +157,7 @@ namespace IRaCIS.Core.Infra.EFCore { if (deleteFilter == null) throw new ArgumentNullException(nameof(deleteFilter)); - return await _dbContext.Set().IgnoreQueryFilters().Where(deleteFilter).ExecuteDeleteAsync() > 0; + return await _dbContext.Set().IgnoreQueryFilters().Where(deleteFilter).BatchDeleteAsync() > 0; } diff --git a/IRaCIS.Core.Infrastructure/IRaCIS.Core.Infrastructure.csproj b/IRaCIS.Core.Infrastructure/IRaCIS.Core.Infrastructure.csproj index 8007ae0ee..533a51994 100644 --- a/IRaCIS.Core.Infrastructure/IRaCIS.Core.Infrastructure.csproj +++ b/IRaCIS.Core.Infrastructure/IRaCIS.Core.Infrastructure.csproj @@ -11,7 +11,7 @@ - + diff --git a/IRaCIS.Core.Infrastructure/_IRaCIS/IQueryablePageListExtensions.cs b/IRaCIS.Core.Infrastructure/_IRaCIS/IQueryablePageListExtensions.cs index bb102cd7d..2fa3db58a 100644 --- a/IRaCIS.Core.Infrastructure/_IRaCIS/IQueryablePageListExtensions.cs +++ b/IRaCIS.Core.Infrastructure/_IRaCIS/IQueryablePageListExtensions.cs @@ -3,11 +3,50 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using System.Linq.Dynamic.Core; +using System.Collections.Generic; namespace IRaCIS.Core.Infrastructure.Extention { public static class QueryablePageListExtensions { + //内存排序 后期删除 + public static PageOutput ToPagedList(this IList source, int pageIndex, int pageSize, string defaultSortFiled = "Id", bool isAsc = true) + { + if (pageIndex <= 0) + { + pageIndex = 1; + } + if (pageSize <= 0) + { + pageSize = 10; + } + var count = source.Count(); + + if (count == 0) + { + return new PageOutput() { CurrentPageData = new List() }; + } + + var propName = string.IsNullOrWhiteSpace(defaultSortFiled) ? "Id" : defaultSortFiled; + + IQueryable sourceQuery = isAsc ? source.AsQueryable().OrderBy(propName) : source.AsQueryable().OrderBy(propName + " desc"); + + sourceQuery = sourceQuery.Skip((pageIndex - 1) * pageSize); + + var items = sourceQuery + .Take(pageSize) + .ToArray(); + + var pagedList = new PageOutput() + { + PageIndex = pageIndex, + PageSize = pageSize, + TotalCount = count, + CurrentPageData = items + }; + + return pagedList; + } //单字段排序 public static PageOutput ToPagedList(this IQueryable source, int pageIndex, int pageSize, string defaultSortFiled = "Id", bool isAsc = true) { diff --git a/IRaCIS.Core.Test/IRaCIS.Core.Test.csproj b/IRaCIS.Core.Test/IRaCIS.Core.Test.csproj index 899f95036..ef69f8834 100644 --- a/IRaCIS.Core.Test/IRaCIS.Core.Test.csproj +++ b/IRaCIS.Core.Test/IRaCIS.Core.Test.csproj @@ -13,7 +13,6 @@ - diff --git a/IRaCIS.Core.Test/Test/Audit/AuditContext.cs b/IRaCIS.Core.Test/Test/Audit/AuditContext.cs deleted file mode 100644 index 2fc55e0ea..000000000 --- a/IRaCIS.Core.Test/Test/Audit/AuditContext.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.EntityFrameworkCore; - -#region AuditContext -public class AuditContext : DbContext -{ - private readonly string _connectionString; - - public AuditContext(string connectionString) - { - _connectionString = connectionString; - } - - //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - // => optionsBuilder.Usesq(_connectionString); - - public DbSet SaveChangesAudits { get; set; } -} - - -public class SaveChangesAudit -{ - public int Id { get; set; } - public Guid AuditId { get; set; } - public DateTime StartTime { get; set; } - public DateTime EndTime { get; set; } - public bool Succeeded { get; set; } - public string ErrorMessage { get; set; } - - public ICollection Entities { get; } = new List(); -} - -public class EntityAudit -{ - public int Id { get; set; } - public EntityState State { get; set; } - public string AuditMessage { get; set; } - - public SaveChangesAudit SaveChangesAudit { get; set; } -} - -#endregion \ No newline at end of file