diff --git a/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs b/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs index eb34d3eb7..cde6c7e41 100644 --- a/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs +++ b/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs @@ -60,7 +60,7 @@ namespace IRaCIS.Core.Application.Services var trialDocumentQueryable = _trialDocumentRepository.AsQueryable(true).Where(t => t.TrialId == queryTrialDocument.TrialId) .WhereIf(!string.IsNullOrEmpty(queryTrialDocument.Name), t => t.Name.Contains(queryTrialDocument.Name)) .WhereIf(queryTrialDocument.FileTypeId != null, t => t.FileTypeId == queryTrialDocument.FileTypeId) - .ProjectTo(_mapper.ConfigurationProvider, new { token = _userInfo.UserToken, isEn_Us=_userInfo.IsEn_Us }); + .ProjectTo(_mapper.ConfigurationProvider, new { token = _userInfo.UserToken, isEn_Us = _userInfo.IsEn_Us }); return await trialDocumentQueryable.ToPagedListAsync(queryTrialDocument.PageIndex, queryTrialDocument.PageSize, queryTrialDocument.SortField, queryTrialDocument.Asc); } @@ -74,12 +74,12 @@ namespace IRaCIS.Core.Application.Services [HttpPost] public async Task GetNextUnSignDocument(GetNextUnSignDocumentInDto inDto) { - var result =await this.GetUserDocumentList(new TrialUserDocUnionQuery() + var result = await this.GetUserDocumentList(new TrialUserDocUnionQuery() { Asc = inDto.Asc, IsSign = false, SortField = inDto.SortField, - TrialId= inDto.TrialId, + TrialId = inDto.TrialId, PageIndex = 1, PageSize = 1, }); @@ -88,7 +88,8 @@ namespace IRaCIS.Core.Application.Services { return result.Data.CurrentPageData.First(); } - else { + else + { return null; } @@ -100,7 +101,7 @@ namespace IRaCIS.Core.Application.Services /// /// [HttpPost] - public async Task< IResponseOutput> > GetUserDocumentList(TrialUserDocUnionQuery querySystemDocument) + public async Task>> GetUserDocumentList(TrialUserDocUnionQuery querySystemDocument) { #region https://github.com/dotnet/efcore/issues/16243 操作不行 ////系统文档查询 @@ -164,7 +165,7 @@ namespace IRaCIS.Core.Application.Services var trialId = querySystemDocument.TrialId; - var trialInfo = await (_repository.Where(t => t.Id == querySystemDocument.TrialId).Select(t => new { t.TrialFinishedTime,t.TrialStatusStr } ).FirstOrDefaultAsync()); + var trialInfo = await (_repository.Where(t => t.Id == querySystemDocument.TrialId).Select(t => new { t.TrialFinishedTime, t.TrialStatusStr }).FirstOrDefaultAsync()); //系统文档查询 var systemDocumentQueryable = from needConfirmedUserType in _repository.Where(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId) @@ -187,10 +188,10 @@ namespace IRaCIS.Core.Application.Services Name = needConfirmedUserType.SystemDocument.Name, Path = needConfirmedUserType.SystemDocument.Path, FileTypeId = needConfirmedUserType.SystemDocument.FileTypeId, - FileType = _userInfo.IsEn_Us? needConfirmedUserType.SystemDocument.FileType.Value: needConfirmedUserType.SystemDocument.FileType.ValueCN, + FileType = _userInfo.IsEn_Us ? needConfirmedUserType.SystemDocument.FileType.Value : needConfirmedUserType.SystemDocument.FileType.ValueCN, UpdateTime = needConfirmedUserType.SystemDocument.UpdateTime, - FullFilePath = needConfirmedUserType.SystemDocument.Path , + FullFilePath = needConfirmedUserType.SystemDocument.Path, ConfirmUserId = confirm.ConfirmUserId, ConfirmTime = confirm.ConfirmTime, @@ -214,12 +215,12 @@ namespace IRaCIS.Core.Application.Services Id = trialDoc.Id, IsSystemDoc = false, CreateTime = trialDoc.CreateTime, - FullFilePath = trialDoc.Path , + FullFilePath = trialDoc.Path, IsDeleted = trialDoc.IsDeleted, Name = trialDoc.Name, Path = trialDoc.Path, FileTypeId = trialDoc.FileTypeId, - FileType = _userInfo.IsEn_Us ? trialDoc.FileType.Value: trialDoc.FileType.ValueCN, + FileType = _userInfo.IsEn_Us ? trialDoc.FileType.Value : trialDoc.FileType.ValueCN, UpdateTime = trialDoc.UpdateTime, SignViewMinimumMinutes = trialDoc.SignViewMinimumMinutes, @@ -232,18 +233,44 @@ namespace IRaCIS.Core.Application.Services }; + #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 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 needSignTrialDocCount = await _trialDocumentRepository.AsQueryable(true).Where(t => t.TrialId== querySystemDocument.TrialId && t.Trial.TrialStatusStr != StaticData.TrialState.TrialStopped) + //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)) - .Where(t => t.IsDeleted == false && !t.TrialDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id && t.ConfirmTime!=null) && t.NeedConfirmedUserTypeList.Any(u => u.NeedConfirmUserTypeId == _userInfo.UserTypeId)) + .Where(t => t.IsDeleted == false && !t.TrialDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id && t.ConfirmTime != null) && t.NeedConfirmedUserTypeList.Any(u => u.NeedConfirmUserTypeId == _userInfo.UserTypeId)) .CountAsync(); @@ -254,15 +281,12 @@ namespace IRaCIS.Core.Application.Services var trialTaskConfig = _trialRepository.Where(t => t.Id == querySystemDocument.TrialId).ProjectTo(_mapper.ConfigurationProvider).FirstOrDefault(); - //var trialCriterionAdditionalAssessmentTypeList = _trialCriterionAdditionalAssessmentTypeRepository - // .Where(t => t.TrialReadingCriterion.TrialId == trialId && t.IsSelected == true && t.TrialReadingCriterion.IsSigned).Select(t=>new { t.CriterionType,t.AdditionalAssessmentType}).ToList(); + var isManualGenerateTask = _readingQuestionCriterionTrialRepository.Where(t => t.TrialId == trialId && t.IsSigned && t.IsAutoCreate == false).Any(); + var isAdditionalAssessment = _readingQuestionCriterionTrialRepository.Where(t => t.TrialId == trialId && t.IsSigned && t.IsAdditionalAssessment == true + && t.TrialCriterionAdditionalAssessmentTypeList.Any(c =>/*c.AdditionalAssessmentType==Domain.Share.Reading.AdditionalAssessmentType.BrainMetastasis &&*/ c.IsSelected == true)).Any(); - var isManualGenerateTask= _readingQuestionCriterionTrialRepository.Where(t=>t.TrialId==trialId && t.IsSigned && t.IsAutoCreate==false).Any(); - var isAdditionalAssessment = _readingQuestionCriterionTrialRepository.Where(t => t.TrialId == trialId && t.IsSigned && t.IsAdditionalAssessment == true - &&t.TrialCriterionAdditionalAssessmentTypeList.Any(c=>/*c.AdditionalAssessmentType==Domain.Share.Reading.AdditionalAssessmentType.BrainMetastasis &&*/ c.IsSelected==true)).Any(); - - return ResponseOutput.Ok>( result, new { NeedSignCount = needSignTrialDocCount + needSignSystemDocCount, NeedSignTrialDocCount = needSignTrialDocCount, NeedSignSystemDocCount = needSignSystemDocCount, IsAdditionalAssessment = isAdditionalAssessment && isManualGenerateTask, TrialStatusStr = trialInfo.TrialStatusStr,TrialConfig= trialTaskConfig }); + return ResponseOutput.Ok>(result, new { NeedSignCount = needSignTrialDocCount + needSignSystemDocCount, NeedSignTrialDocCount = needSignTrialDocCount, NeedSignSystemDocCount = needSignSystemDocCount, IsAdditionalAssessment = isAdditionalAssessment && isManualGenerateTask, TrialStatusStr = trialInfo.TrialStatusStr, TrialConfig = trialTaskConfig }); } @@ -274,7 +298,7 @@ namespace IRaCIS.Core.Application.Services /// /// [HttpPost] - public async Task<(PageOutput,object)> GetDocumentConfirmList(DocumentTrialUnionQuery querySystemDocument) + public async Task<(PageOutput, object)> GetDocumentConfirmList(DocumentTrialUnionQuery querySystemDocument) { @@ -345,7 +369,7 @@ namespace IRaCIS.Core.Application.Services UserTypeId = trialUser.User.UserTypeId, UserTypeShortName = trialUser.User.UserTypeRole.UserTypeShortName, - FullFilePath = trialDocumentNeedConfirmedUserType.TrialDocument.Path + FullFilePath = trialDocumentNeedConfirmedUserType.TrialDocument.Path }; @@ -400,7 +424,7 @@ namespace IRaCIS.Core.Application.Services .CountAsync(); - return (result, new { NeedSignCount = needSignTrialDocCount + needSignSystemDocCount, NeedSignTrialDocCount = needSignTrialDocCount, NeedSignSystemDocCount = needSignSystemDocCount,TrialStatusStr = trialInfo.TrialStatusStr }); + return (result, new { NeedSignCount = needSignTrialDocCount + needSignSystemDocCount, NeedSignTrialDocCount = needSignTrialDocCount, NeedSignSystemDocCount = needSignSystemDocCount, TrialStatusStr = trialInfo.TrialStatusStr }); } @@ -426,14 +450,14 @@ namespace IRaCIS.Core.Application.Services [HttpGet("{trialId:guid}")] public async Task GetTrialDocAndSystemDocType(Guid trialId) { - var result = await _trialDocumentRepository.Where(t => t.TrialId == trialId).Select(t => new { FileType = _userInfo.IsEn_Us? t.FileType.Value :t.FileType.ValueCN, t.FileTypeId }) + var result = await _trialDocumentRepository.Where(t => t.TrialId == trialId).Select(t => new { FileType = _userInfo.IsEn_Us ? t.FileType.Value : t.FileType.ValueCN, t.FileTypeId }) .Union(_systemDocumentRepository.Select(t => new { FileType = _userInfo.IsEn_Us ? t.FileType.Value : t.FileType.ValueCN, t.FileTypeId })) .ToListAsync(); return ResponseOutput.Ok(result); } - [TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "BeforeOngoingCantOpt", "AfterStopCannNotOpt" })] + [TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "BeforeOngoingCantOpt", "AfterStopCannNotOpt" })] //[Authorize(Policy = IRaCISPolicy.PM)] public async Task AddOrUpdateTrialDocument(AddOrEditTrialDocument addOrEditTrialDocument) { @@ -444,7 +468,7 @@ namespace IRaCIS.Core.Application.Services if (await _trialDocumentRepository.AnyAsync(t => t.FileTypeId == addOrEditTrialDocument.FileTypeId && t.Name == addOrEditTrialDocument.Name && t.TrialId == addOrEditTrialDocument.TrialId, true)) { - //---该项目中已经存在同类型的同名文件。 + //---该项目中已经存在同类型的同名文件。 return ResponseOutput.NotOk(_localizer["TrialD_DuplicateFileInProject"]); } @@ -456,7 +480,7 @@ namespace IRaCIS.Core.Application.Services { if (await _trialDocumentRepository.AnyAsync(t => t.FileTypeId == addOrEditTrialDocument.FileTypeId && t.Name == addOrEditTrialDocument.Name && t.Id != addOrEditTrialDocument.Id && t.TrialId == addOrEditTrialDocument.TrialId, true)) { - //---该项目中已经存在同类型的同名文件。 + //---该项目中已经存在同类型的同名文件。 return ResponseOutput.NotOk(_localizer["TrialD_DuplicateFileInProject"]); } @@ -505,7 +529,7 @@ namespace IRaCIS.Core.Application.Services /// [HttpDelete("{trialId:guid}/{trialDocumentId:guid}")] //[Authorize(Policy = IRaCISPolicy.PM)] - [TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "BeforeOngoingCantOpt", "AfterStopCannNotOpt" })] + [TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "BeforeOngoingCantOpt", "AfterStopCannNotOpt" })] public async Task DeleteTrialDocument(Guid trialDocumentId, Guid trialId) { if (await _trialDocumentRepository.AsQueryable(true).Where(t => t.Id == trialDocumentId).AnyAsync(t => t.TrialDocConfirmedUserList.Any())) @@ -534,7 +558,7 @@ namespace IRaCIS.Core.Application.Services var success = false; if (isSystemDoc) { - if(!await _systemDocConfirmedUserRepository.AnyAsync(t=>t.SystemDocumentId==documentId && t.ConfirmUserId == _userInfo.Id)) + if (!await _systemDocConfirmedUserRepository.AnyAsync(t => t.SystemDocumentId == documentId && t.ConfirmUserId == _userInfo.Id)) { await _repository.AddAsync(new SystemDocConfirmedUser() { SystemDocumentId = documentId, ConfirmUserId = _userInfo.Id, SignFirstViewTime = DateTime.Now }); @@ -598,17 +622,17 @@ namespace IRaCIS.Core.Application.Services if (userConfirmCommand.isSystemDoc) { - var sysDocConfirm = await _systemDocConfirmedUserRepository.FirstOrDefaultAsync(t => t.SystemDocumentId == userConfirmCommand.DocumentId && t.ConfirmUserId == _userInfo.Id,true); + var sysDocConfirm = await _systemDocConfirmedUserRepository.FirstOrDefaultAsync(t => t.SystemDocumentId == userConfirmCommand.DocumentId && t.ConfirmUserId == _userInfo.Id, true); - if(sysDocConfirm.ConfirmTime != null) + if (sysDocConfirm.ConfirmTime != null) { - //---该文件已经签名 + //---该文件已经签名 return ResponseOutput.NotOk(_localizer["TrialD_FileAlreadySigned"]); } if (sysDocConfirm.IsDeleted) { - //---文件已废除,签署失败! + //---文件已废除,签署失败! return ResponseOutput.NotOk(_localizer["TrialD_ObsoleteFile"]); } @@ -629,13 +653,13 @@ namespace IRaCIS.Core.Application.Services if (trialDocConfirm.ConfirmTime != null) { - //---该文件已经签名 + //---该文件已经签名 return ResponseOutput.NotOk(_localizer["TrialD_FileAlreadySigned"]); } if (trialDocConfirm.IsDeleted) { - //---文件已废除,签署失败! + //---文件已废除,签署失败! return ResponseOutput.NotOk(_localizer["TrialD_ObsoleteFile"]); } @@ -730,7 +754,7 @@ namespace IRaCIS.Core.Application.Services Id = t.Id, IsSystemDoc = true, CreateTime = t.CreateTime, - FullFilePath = t.Path , + FullFilePath = t.Path, IsDeleted = t.IsDeleted, Name = t.Name, Path = t.Path, @@ -748,7 +772,7 @@ namespace IRaCIS.Core.Application.Services Id = t.Id, IsSystemDoc = false, CreateTime = t.CreateTime, - FullFilePath = t.Path , + FullFilePath = t.Path, IsDeleted = t.IsDeleted, Name = t.Name, Path = t.Path, diff --git a/IRaCIS.Core.Infra.EFCore/IRaCIS.Core.Infra.EFCore.csproj b/IRaCIS.Core.Infra.EFCore/IRaCIS.Core.Infra.EFCore.csproj index c763a7435..9b1305d72 100644 --- a/IRaCIS.Core.Infra.EFCore/IRaCIS.Core.Infra.EFCore.csproj +++ b/IRaCIS.Core.Infra.EFCore/IRaCIS.Core.Infra.EFCore.csproj @@ -20,7 +20,6 @@ - diff --git a/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs b/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs index 07246c223..4e58ccad4 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs @@ -257,11 +257,6 @@ namespace IRaCIS.Core.Infra.EFCore #endregion - - - - - } diff --git a/IRaCIS.Core.Infrastructure/_IRaCIS/IQueryablePageListExtensions.cs b/IRaCIS.Core.Infrastructure/_IRaCIS/IQueryablePageListExtensions.cs index bb102cd7d..ee6aa1189 100644 --- a/IRaCIS.Core.Infrastructure/_IRaCIS/IQueryablePageListExtensions.cs +++ b/IRaCIS.Core.Infrastructure/_IRaCIS/IQueryablePageListExtensions.cs @@ -3,6 +3,8 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using System.Linq.Dynamic.Core; +using System.Collections.Generic; +using System; namespace IRaCIS.Core.Infrastructure.Extention { @@ -23,7 +25,7 @@ namespace IRaCIS.Core.Infrastructure.Extention if (count == 0) { - return new PageOutput() { CurrentPageData=new T[0] }; + return new PageOutput() { CurrentPageData = new T[0] }; } @@ -49,10 +51,10 @@ namespace IRaCIS.Core.Infrastructure.Extention } //单字段排序 异步 - public static async Task> ToPagedListAsync(this IQueryable source, int pageNumber, int pageSize, string defaultSortFiled = "Id", bool isAsc = true,bool isMultiSortFiled=false, string[] sortArray=default, CancellationToken cancellationToken = default) + public static async Task> ToPagedListAsync(this IQueryable source, int pageNumber, int pageSize, string defaultSortFiled = "Id", bool isAsc = true, bool isMultiSortFiled = false, string[] sortArray = default, CancellationToken cancellationToken = default) { - if (isMultiSortFiled&& sortArray==default) + if (isMultiSortFiled && sortArray == default) { throw new System.Exception("The sort field must be specified"); } @@ -83,7 +85,7 @@ namespace IRaCIS.Core.Infrastructure.Extention { var sortString = string.Join(',', sortArray); - source= source.OrderBy(sortString); + source = source.OrderBy(sortString); } source = source.Skip((pageNumber - 1) * pageSize); var items = await source @@ -102,8 +104,47 @@ namespace IRaCIS.Core.Infrastructure.Extention return pagedList; } + + 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; + } + //多字段排序 ["a asc", "b desc", "c asc"] - public static PageOutput ToPagedList(this IQueryable source, int pageIndex, int pageSize,string[] sortArray) + public static PageOutput ToPagedList(this IQueryable source, int pageIndex, int pageSize, string[] sortArray) { if (pageIndex <= 0) { @@ -180,5 +221,8 @@ namespace IRaCIS.Core.Infrastructure.Extention return pagedList; } + + + } }