diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 22e9715f1..217ff1e8f 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -1519,7 +1519,7 @@ - Site 调研 每个项目 处理任务数 + Site 调研 每个项目 需要处理的审批统计 diff --git a/IRaCIS.Core.Application/Service/Document/DTO/SystemDocumentViewModel.cs b/IRaCIS.Core.Application/Service/Document/DTO/SystemDocumentViewModel.cs index 9d397184d..f5f4615c9 100644 --- a/IRaCIS.Core.Application/Service/Document/DTO/SystemDocumentViewModel.cs +++ b/IRaCIS.Core.Application/Service/Document/DTO/SystemDocumentViewModel.cs @@ -29,6 +29,8 @@ namespace IRaCIS.Core.Application.Contracts public bool IsSystemDoc { get; set; } + public string FileType { get; set; } = string.Empty; + } @@ -89,7 +91,7 @@ namespace IRaCIS.Core.Application.Contracts public Guid? SystemDocumentId { get; set; } - public string Type { get; set; } = string.Empty; + public Guid? FileTypeId { get; set; } public string Name { get; set; } = string.Empty; @@ -101,7 +103,7 @@ namespace IRaCIS.Core.Application.Contracts [NotDefault] public Guid TrialId { get; set; } - public string Type { get; set; } = string.Empty; + public Guid? FileTypeId { get; set; } public string Name { get; set; } = string.Empty; @@ -139,11 +141,11 @@ namespace IRaCIS.Core.Application.Contracts public class SystemDocumentAddOrEdit { public Guid? Id { get; set; } - public string Type { get; set; } = string.Empty; + public Guid FileTypeId { get; set; } public string Name { get; set; } = string.Empty; public string Path { get; set; } = string.Empty; - public bool IsAbandon { get; set; } + public bool IsDeleted { get; set; } public int SignViewMinimumMinutes { get; set; } diff --git a/IRaCIS.Core.Application/Service/Document/DTO/TrialDocumentViewModel.cs b/IRaCIS.Core.Application/Service/Document/DTO/TrialDocumentViewModel.cs index 761a6f52d..ba92a1fea 100644 --- a/IRaCIS.Core.Application/Service/Document/DTO/TrialDocumentViewModel.cs +++ b/IRaCIS.Core.Application/Service/Document/DTO/TrialDocumentViewModel.cs @@ -31,8 +31,8 @@ namespace IRaCIS.Core.Application.Contracts ///TrialDocumentQuery 列表查询参数模型 public class TrialDocumentQuery : PageInput { - - public string Type { get; set; } = String.Empty; + + public Guid? FileTypeId { get; set; } public string Name { get; set; } = String.Empty; @@ -47,12 +47,12 @@ namespace IRaCIS.Core.Application.Contracts public Guid? Id { get; set; } public Guid TrialId { get; set; } - public string Type { get; set; } = String.Empty; + public Guid FileTypeId { get; set; } public string Name { get; set; } = String.Empty; public string Path { get; set; } = String.Empty; public string Description { get; set; } = String.Empty; - public bool IsAbandon { get; set; } + public bool IsDeleted { get; set; } public int SignViewMinimumMinutes { get; set; } diff --git a/IRaCIS.Core.Application/Service/Document/SystemDocumentService.cs b/IRaCIS.Core.Application/Service/Document/SystemDocumentService.cs index 4af16b93a..04f05152c 100644 --- a/IRaCIS.Core.Application/Service/Document/SystemDocumentService.cs +++ b/IRaCIS.Core.Application/Service/Document/SystemDocumentService.cs @@ -39,9 +39,9 @@ namespace IRaCIS.Core.Application.Services [HttpPost] public async Task> GetSystemDocumentListAsync(SystemDocumentQuery querySystemDocument) { - var systemDocumentQueryable = _systemDocumentRepository + var systemDocumentQueryable = _systemDocumentRepository.AsQueryable(true) .WhereIf(!string.IsNullOrEmpty(querySystemDocument.Name), t => t.Name.Contains(querySystemDocument.Name)) - .WhereIf(!string.IsNullOrEmpty(querySystemDocument.Type), t => t.Type.Contains(querySystemDocument.Type)) + .WhereIf(querySystemDocument.FileTypeId != null, t => t.FileTypeId == querySystemDocument.FileTypeId) .ProjectTo(_mapper.ConfigurationProvider, new { token = _userInfo.UserToken, userId = _userInfo.Id }); return await systemDocumentQueryable.ToPagedListAsync(querySystemDocument.PageIndex, querySystemDocument.PageSize, querySystemDocument.SortField, querySystemDocument.Asc); @@ -54,7 +54,7 @@ namespace IRaCIS.Core.Application.Services var entity = _mapper.Map(addOrEditSystemDocument); - if (await _systemDocumentRepository.AnyAsync(t => t.Type == addOrEditSystemDocument.Type && t.Name == addOrEditSystemDocument.Name)) + if (await _systemDocumentRepository.AnyAsync(t => t.FileTypeId == addOrEditSystemDocument.FileTypeId && t.Name == addOrEditSystemDocument.Name,true)) { return ResponseOutput.NotOk("同类型已存在该文件名"); } @@ -66,24 +66,24 @@ namespace IRaCIS.Core.Application.Services } else { - var document = await _systemDocumentRepository.Where(t => t.Id == addOrEditSystemDocument.Id, true).Include(t => t.NeedConfirmedUserTypeList).FirstOrDefaultAsync(); + var document = await _systemDocumentRepository.Where(t => t.Id == addOrEditSystemDocument.Id, true,true).Include(t => t.NeedConfirmedUserTypeList).FirstOrDefaultAsync(); if (document == null) return Null404NotFound(document); - if (await _systemDocumentRepository.AnyAsync(t => t.Type == addOrEditSystemDocument.Type && t.Name == addOrEditSystemDocument.Name && t.Id != addOrEditSystemDocument.Id)) + if (await _systemDocumentRepository.AnyAsync(t => t.FileTypeId == addOrEditSystemDocument.FileTypeId && t.Name == addOrEditSystemDocument.Name && t.Id != addOrEditSystemDocument.Id,true)) { return ResponseOutput.NotOk("同类型已存在该文件名"); } - var dbDocumentType = document.Type; + _mapper.Map(addOrEditSystemDocument, document); - if (dbDocumentType != addOrEditSystemDocument.Type) + if (document.FileTypeId != addOrEditSystemDocument.FileTypeId) { var rootPath = Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\')).IfNullThrowException().FullName; var beforeFilePath = Path.Combine(rootPath, document.Path); - document.Path = document.Path.Replace(dbDocumentType, addOrEditSystemDocument.Type); + document.Path = document.Path.Replace(document.FileTypeId.ToString(), addOrEditSystemDocument.FileTypeId.ToString()); var nowPath = Path.Combine(rootPath, document.Path); @@ -128,7 +128,7 @@ namespace IRaCIS.Core.Application.Services { - var query = from sysDoc in _systemDocumentRepository.Where(t => t.NeedConfirmedUserTypeList.Any(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId)) + var query = from sysDoc in _systemDocumentRepository.Where(t => t.NeedConfirmedUserTypeList.Any(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId),true) join confirm in _repository.GetQueryable() on new { ConfirmUserId = _userInfo.Id, SystemDocumentId = sysDoc.Id } equals new { confirm.ConfirmUserId, confirm.SystemDocumentId } into cc from confirm in cc.DefaultIfEmpty() @@ -141,11 +141,11 @@ namespace IRaCIS.Core.Application.Services Id = sysDoc.Id, CreateTime = sysDoc.CreateTime, - IsAbandon = sysDoc.IsAbandon, + IsDeleted = sysDoc.IsDeleted, SignViewMinimumMinutes = sysDoc.SignViewMinimumMinutes, Name = sysDoc.Name, Path = sysDoc.Path, - Type = sysDoc.Type, + FileType = sysDoc.FileType.Value, UpdateTime = sysDoc.UpdateTime, FullFilePath = sysDoc.Path + "?access_token=" + _userInfo.UserToken, diff --git a/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs b/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs index de0f8a378..ed0143d74 100644 --- a/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs +++ b/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs @@ -24,13 +24,15 @@ namespace IRaCIS.Core.Application.Services private readonly IWebHostEnvironment _hostEnvironment; private readonly IRepository _trialDocumentRepository; private readonly IRepository _systemDocConfirmedUserRepository; + private readonly IRepository _systemDocumentRepository; public TrialDocumentService(IWebHostEnvironment hostEnvironment, IRepository trialDocumentRepository - , IRepository systemDocConfirmedUserRepository) + , IRepository systemDocConfirmedUserRepository,IRepository systemDocumentRepository) { _hostEnvironment = hostEnvironment; - this._trialDocumentRepository = trialDocumentRepository; - this._systemDocConfirmedUserRepository = systemDocConfirmedUserRepository; + _trialDocumentRepository = trialDocumentRepository; + _systemDocConfirmedUserRepository = systemDocConfirmedUserRepository; + _systemDocumentRepository = systemDocumentRepository; } /// @@ -42,9 +44,9 @@ namespace IRaCIS.Core.Application.Services public async Task> GetTrialDocumentList(TrialDocumentQuery queryTrialDocument) { - var trialDocumentQueryable = _trialDocumentRepository.Where(t => t.TrialId == queryTrialDocument.TrialId) + var trialDocumentQueryable = _trialDocumentRepository.AsQueryable(true).Where(t => t.TrialId == queryTrialDocument.TrialId) .WhereIf(!string.IsNullOrEmpty(queryTrialDocument.Name), t => t.Name.Contains(queryTrialDocument.Name)) - .WhereIf(!string.IsNullOrEmpty(queryTrialDocument.Type), t => t.Type.Contains(queryTrialDocument.Type)) + .WhereIf(queryTrialDocument.FileTypeId!=null, t => t.FileTypeId==queryTrialDocument.FileTypeId) .ProjectTo(_mapper.ConfigurationProvider, new { token = _userInfo.UserToken }); return await trialDocumentQueryable.ToPagedListAsync(queryTrialDocument.PageIndex, queryTrialDocument.PageSize, queryTrialDocument.SortField, queryTrialDocument.Asc); @@ -126,7 +128,7 @@ namespace IRaCIS.Core.Application.Services var systemDocumentQueryable = from needConfirmedUserType in _repository.Where(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId) //.Where(u => u.UserTypeRole.UserList.SelectMany(cc => cc.UserTrials.Where(t => t.TrialId == querySystemDocument.TrialId)).Any(e => e.Trial.TrialFinishedTime < u.SystemDocument.CreateTime)) .WhereIf(trialFininshedTime != null, u => u.SystemDocument.CreateTime < trialFininshedTime) - .WhereIf(!_userInfo.IsAdmin, t => t.SystemDocument.IsAbandon == false || (t.SystemDocument.IsAbandon == true && t.SystemDocument.SystemDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id))) + .WhereIf(!_userInfo.IsAdmin, t => t.SystemDocument.IsDeleted == false || (t.SystemDocument.IsDeleted == true && t.SystemDocument.SystemDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id))) join trialUser in _repository.Where(t => t.TrialId == querySystemDocument.TrialId && t.UserId == _userInfo.Id) on needConfirmedUserType.NeedConfirmUserTypeId equals trialUser.User.UserTypeId @@ -138,11 +140,11 @@ namespace IRaCIS.Core.Application.Services Id = needConfirmedUserType.SystemDocument.Id, CreateTime = needConfirmedUserType.SystemDocument.CreateTime, - IsAbandon = needConfirmedUserType.SystemDocument.IsAbandon, + IsDeleted = needConfirmedUserType.SystemDocument.IsDeleted, SignViewMinimumMinutes = needConfirmedUserType.SystemDocument.SignViewMinimumMinutes, Name = needConfirmedUserType.SystemDocument.Name, Path = needConfirmedUserType.SystemDocument.Path, - Type = needConfirmedUserType.SystemDocument.Type, + FileType = needConfirmedUserType.SystemDocument.FileType.Value, UpdateTime = needConfirmedUserType.SystemDocument.UpdateTime, FullFilePath = needConfirmedUserType.SystemDocument.Path + "?access_token=" + _userInfo.UserToken, @@ -155,9 +157,9 @@ namespace IRaCIS.Core.Application.Services }; //项目文档查询 - var trialDocQueryable = from trialDoc in _trialDocumentRepository.Where(t => t.TrialId == querySystemDocument.TrialId) + var trialDocQueryable = from trialDoc in _trialDocumentRepository.AsQueryable(true).Where(t => t.TrialId == querySystemDocument.TrialId) .WhereIf(!_userInfo.IsAdmin, t => t.NeedConfirmedUserTypeList.Any(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId)) - .WhereIf(!_userInfo.IsAdmin, t => t.IsAbandon == false || (t.IsAbandon == true && t.TrialDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id))) + .WhereIf(!_userInfo.IsAdmin, t => t.IsDeleted == false || (t.IsDeleted == true && t.TrialDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id))) join trialUser in _repository.Where(t => t.TrialId == querySystemDocument.TrialId && t.UserId == _userInfo.Id) on trialDoc.TrialId equals trialUser.TrialId join confirm in _repository.Where(t => t.TrialDocument.TrialId == querySystemDocument.TrialId) on @@ -169,10 +171,10 @@ namespace IRaCIS.Core.Application.Services IsSystemDoc = false, CreateTime = trialDoc.CreateTime, FullFilePath = trialDoc.Path + "?access_token=" + _userInfo.UserToken, - IsAbandon = trialDoc.IsAbandon, + IsDeleted = trialDoc.IsDeleted, Name = trialDoc.Name, Path = trialDoc.Path, - Type = trialDoc.Type, + FileType = trialDoc.FileType.Value, UpdateTime = trialDoc.UpdateTime, SignViewMinimumMinutes = trialDoc.SignViewMinimumMinutes, @@ -188,7 +190,7 @@ namespace IRaCIS.Core.Application.Services var unionQuery = systemDocumentQueryable.Union(trialDocQueryable) .WhereIf(!string.IsNullOrEmpty(querySystemDocument.Name), t => t.Name.Contains(querySystemDocument.Name)) - .WhereIf(!string.IsNullOrEmpty(querySystemDocument.Type), t => t.Type.Contains(querySystemDocument.Type)); + .WhereIf(querySystemDocument.FileTypeId!=null, t => t.FileTypeId==querySystemDocument.FileTypeId); return await unionQuery.ToPagedListAsync(querySystemDocument.PageIndex, querySystemDocument.PageSize, querySystemDocument.SortField, querySystemDocument.Asc); } @@ -208,7 +210,7 @@ namespace IRaCIS.Core.Application.Services var systemDocumentQueryable = from needConfirmedUserType in _repository.Where(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId) //.Where(u => u.UserTypeRole.UserList.SelectMany(cc => cc.UserTrials.Where(t => t.TrialId == querySystemDocument.TrialId)).Any(e => e.Trial.TrialFinishedTime < u.SystemDocument.CreateTime)) .WhereIf(trialFininshedTime != null, u => u.SystemDocument.CreateTime < trialFininshedTime) - .WhereIf(!_userInfo.IsAdmin, t => t.SystemDocument.IsAbandon == false || (t.SystemDocument.IsAbandon == true && t.SystemDocument.SystemDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id))) + .WhereIf(!_userInfo.IsAdmin, t => t.SystemDocument.IsDeleted == false || (t.SystemDocument.IsDeleted == true && t.SystemDocument.SystemDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id))) join trialUser in _repository.Where(t => t.TrialId == trialId && t.UserId == _userInfo.Id) on needConfirmedUserType.NeedConfirmUserTypeId equals trialUser.User.UserTypeId @@ -223,7 +225,7 @@ namespace IRaCIS.Core.Application.Services //项目文档查询 var trialDocQueryable = from trialDoc in _trialDocumentRepository.Where(t => t.TrialId == trialId) .WhereIf(!_userInfo.IsAdmin, t => t.NeedConfirmedUserTypeList.Any(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId)) - .WhereIf(!_userInfo.IsAdmin, t => t.IsAbandon == false || (t.IsAbandon == true && t.TrialDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id))) + .WhereIf(!_userInfo.IsAdmin, t => t.IsDeleted == false || (t.IsDeleted == true && t.TrialDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id))) join trialUser in _repository.Where(t => t.TrialId == trialId && t.UserId == _userInfo.Id) on trialDoc.TrialId equals trialUser.TrialId join confirm in _repository.Where(t => t.TrialDocument.TrialId == trialId) on @@ -303,11 +305,11 @@ namespace IRaCIS.Core.Application.Services Id = trialDocumentNeedConfirmedUserType.TrialDocument.Id, CreateTime = trialDocumentNeedConfirmedUserType.TrialDocument.CreateTime, - IsAbandon = trialDocumentNeedConfirmedUserType.TrialDocument.IsAbandon, + IsDeleted = trialDocumentNeedConfirmedUserType.TrialDocument.IsDeleted, SignViewMinimumMinutes = trialDocumentNeedConfirmedUserType.TrialDocument.SignViewMinimumMinutes, Name = trialDocumentNeedConfirmedUserType.TrialDocument.Name, Path = trialDocumentNeedConfirmedUserType.TrialDocument.Path, - Type = trialDocumentNeedConfirmedUserType.TrialDocument.Type, + FileType = trialDocumentNeedConfirmedUserType.TrialDocument.FileType.Value, UpdateTime = trialDocumentNeedConfirmedUserType.TrialDocument.UpdateTime, @@ -336,11 +338,11 @@ namespace IRaCIS.Core.Application.Services Id = needConfirmEdUserType.SystemDocument.Id, CreateTime = needConfirmEdUserType.SystemDocument.CreateTime, - IsAbandon = needConfirmEdUserType.SystemDocument.IsAbandon, + IsDeleted = needConfirmEdUserType.SystemDocument.IsDeleted, SignViewMinimumMinutes = needConfirmEdUserType.SystemDocument.SignViewMinimumMinutes, Name = needConfirmEdUserType.SystemDocument.Name, Path = needConfirmEdUserType.SystemDocument.Path, - Type = needConfirmEdUserType.SystemDocument.Type, + FileType = needConfirmEdUserType.SystemDocument.FileType.Value, UpdateTime = needConfirmEdUserType.SystemDocument.UpdateTime, @@ -355,7 +357,7 @@ namespace IRaCIS.Core.Application.Services var unionQuery = trialDocQuery.Union(systemDocQuery) .WhereIf(!string.IsNullOrEmpty(querySystemDocument.Name), t => t.Name.Contains(querySystemDocument.Name)) - .WhereIf(!string.IsNullOrEmpty(querySystemDocument.Type), t => t.Type.Contains(querySystemDocument.Type)); + .WhereIf(querySystemDocument.FileTypeId!=null, t => t.FileTypeId==querySystemDocument.FileTypeId); return await unionQuery.ToPagedListAsync(querySystemDocument.PageIndex, querySystemDocument.PageSize, querySystemDocument.SortField, querySystemDocument.Asc); } @@ -383,8 +385,8 @@ namespace IRaCIS.Core.Application.Services [HttpGet("{trialId:guid}")] public async Task> GetTrialDocAndSystemDocType(Guid trialId) { - return await _trialDocumentRepository.Where(t => t.TrialId == trialId).Select(t => t.Type) - .Union(_repository.GetQueryable().Select(t => t.Type)).Distinct() + return await _trialDocumentRepository.Where(t => t.TrialId == trialId).Select(t => t.FileType.Value) + .Union(_repository.GetQueryable().Select(t => t.FileType.Value)).Distinct() .ToListAsync(); } @@ -395,7 +397,7 @@ namespace IRaCIS.Core.Application.Services var entity = _mapper.Map(addOrEditTrialDocument); - if (await _trialDocumentRepository.AnyAsync(t => t.Type == addOrEditTrialDocument.Type && t.Name == addOrEditTrialDocument.Name && t.TrialId == addOrEditTrialDocument.TrialId)) + if (await _trialDocumentRepository.AnyAsync(t => t.FileTypeId == addOrEditTrialDocument.FileTypeId && t.Name == addOrEditTrialDocument.Name && t.TrialId == addOrEditTrialDocument.TrialId,true)) { return ResponseOutput.NotOk("同类型已存在该文件名"); } @@ -405,7 +407,7 @@ namespace IRaCIS.Core.Application.Services } else { - if (await _trialDocumentRepository.AnyAsync(t => t.Type == addOrEditTrialDocument.Type && t.Name == addOrEditTrialDocument.Name && t.Id != addOrEditTrialDocument.Id && t.TrialId == addOrEditTrialDocument.TrialId)) + 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("同类型已存在该文件名"); } @@ -414,18 +416,18 @@ namespace IRaCIS.Core.Application.Services if (document == null) return Null404NotFound(document); - var dbDocumentType = document.Type; + //var dbDocumentType = document.Type; _mapper.Map(addOrEditTrialDocument, document); - if (dbDocumentType != addOrEditTrialDocument.Type) + if (document.FileTypeId != addOrEditTrialDocument.FileTypeId) { var rootPath = Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\')).IfNullThrowException().FullName; var beforeFilePath = Path.Combine(rootPath, document.Path); - document.Path = document.Path.Replace(dbDocumentType, addOrEditTrialDocument.Type); + document.Path = document.Path.Replace(document.FileTypeId.ToString(), addOrEditTrialDocument.FileTypeId.ToString()); var nowPath = Path.Combine(rootPath, document.Path); @@ -453,7 +455,7 @@ namespace IRaCIS.Core.Application.Services [HttpDelete("{trialId:guid}/{trialDocumentId:guid}")] public async Task DeleteTrialDocument(Guid trialDocumentId, Guid trialId) { - if (await _trialDocumentRepository.Where(t => t.Id == trialDocumentId).AnyAsync(t => t.TrialDocConfirmedUserList.Any())) + if (await _trialDocumentRepository.AsQueryable(true).Where(t => t.Id == trialDocumentId).AnyAsync(t => t.TrialDocConfirmedUserList.Any())) { return ResponseOutput.NotOk("该文档,已有用户签名 不允许删除"); } @@ -479,14 +481,12 @@ namespace IRaCIS.Core.Application.Services if (isSystemDoc) { await _repository.AddAsync(new SystemDocConfirmedUser() { SystemDocumentId = documentId, SignFirstViewTime = DateTime.Now }); - //success = await _repository.UpdateFromQueryAsync(t => t.Id == documentId, d => new SystemDocConfirmedUser() { SignFirstViewTime = DateTime.Now }); } else { await _repository.AddAsync(new TrialDocUserTypeConfirmedUser() { TrialDocumentId = documentId, SignFirstViewTime = DateTime.Now }); - //success = await _repository.UpdateFromQueryAsync(t => t.Id == documentId , d => new TrialDocUserTypeConfirmedUser() { SignFirstViewTime = DateTime.Now }); } success= await _repository.SaveChangesAsync(); @@ -519,7 +519,7 @@ namespace IRaCIS.Core.Application.Services { return ResponseOutput.NotOk("该文档已经签名"); } - if (!await _repository.AnyAsync(t => t.Id == userConfirmCommand.DocumentId) || await _trialDocumentRepository.AnyAsync(t => t.Id == userConfirmCommand.DocumentId && t.IsAbandon)) + if (!await _systemDocumentRepository.AnyAsync(t => t.Id == userConfirmCommand.DocumentId) || await _trialDocumentRepository.AnyAsync(t => t.Id == userConfirmCommand.DocumentId && t.IsDeleted,true)) { return ResponseOutput.NotOk("文件已删除或者废除,签署失败!"); } @@ -533,7 +533,7 @@ namespace IRaCIS.Core.Application.Services return ResponseOutput.NotOk("该文档已经签名"); } - if (!await _trialDocumentRepository.AnyAsync(t => t.Id == userConfirmCommand.DocumentId) || await _repository.AnyAsync(t => t.Id == userConfirmCommand.DocumentId && t.IsAbandon)) + if (!await _trialDocumentRepository.AnyAsync(t => t.Id == userConfirmCommand.DocumentId) || await _repository.AnyAsync(t => t.Id == userConfirmCommand.DocumentId && t.IsDeleted,true)) { return ResponseOutput.NotOk("文件已删除或者废除,签署失败!"); } @@ -558,11 +558,11 @@ namespace IRaCIS.Core.Application.Services { if (isSystemDoc) { - await _repository.UpdateFromQueryAsync(t => t.Id == documentId, u => new SystemDocument() { IsAbandon = true }); + await _repository.UpdateFromQueryAsync(t => t.Id == documentId, u => new SystemDocument() { IsDeleted = true }); } else { - await _trialDocumentRepository.UpdateFromQueryAsync(t => t.Id == documentId, u => new TrialDocument() { IsAbandon = true }); + await _trialDocumentRepository.UpdateFromQueryAsync(t => t.Id == documentId, u => new TrialDocument() { IsDeleted = true }); } return ResponseOutput.Ok(); } @@ -606,17 +606,17 @@ namespace IRaCIS.Core.Application.Services public PageOutput GetTrialSystemDocumentList(DocumentTrialUnionQuery querySystemDocument) { var systemDocumentQueryable = _repository - .WhereIf(!_userInfo.IsAdmin, t => t.IsAbandon == false) + .WhereIf(!_userInfo.IsAdmin, t => t.IsDeleted == false) .Select(t => new DocumentUnionWithUserStatView() { Id = t.Id, IsSystemDoc = true, CreateTime = t.CreateTime, FullFilePath = t.Path + "?access_token=" + _userInfo.UserToken, - IsAbandon = t.IsAbandon, + IsDeleted = t.IsDeleted, Name = t.Name, Path = t.Path, - Type = t.Type, + FileType = t.FileType.Value, UpdateTime = t.UpdateTime, SignViewMinimumMinutes = t.SignViewMinimumMinutes, DocumentConfirmedUserCount = t.SystemDocConfirmedUserList.Count(), @@ -631,10 +631,10 @@ namespace IRaCIS.Core.Application.Services IsSystemDoc = false, CreateTime = t.CreateTime, FullFilePath = t.Path + "?access_token=" + _userInfo.UserToken, - IsAbandon = t.IsAbandon, + IsDeleted = t.IsDeleted, Name = t.Name, Path = t.Path, - Type = t.Type, + FileType = t.FileType.Value, UpdateTime = t.UpdateTime, SignViewMinimumMinutes = t.SignViewMinimumMinutes, @@ -645,7 +645,7 @@ namespace IRaCIS.Core.Application.Services var unionQuery = systemDocumentQueryable.Union(trialDocQueryable) .WhereIf(!string.IsNullOrEmpty(querySystemDocument.Name), t => t.Name.Contains(querySystemDocument.Name)) - .WhereIf(!string.IsNullOrEmpty(querySystemDocument.Type), t => t.Type.Contains(querySystemDocument.Type)); + .WhereIf(querySystemDocument.FileTypeId!=null, t => t.FileTypeId==querySystemDocument.FileTypeId); return unionQuery.ToPagedList(querySystemDocument.PageIndex, querySystemDocument.PageSize, querySystemDocument.SortField, querySystemDocument.Asc); } diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/DTO/TrialSiteSurveyViewModel.cs b/IRaCIS.Core.Application/Service/SiteSurvey/DTO/TrialSiteSurveyViewModel.cs index 0019dffc7..1ec1da3f1 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/DTO/TrialSiteSurveyViewModel.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/DTO/TrialSiteSurveyViewModel.cs @@ -96,7 +96,7 @@ namespace IRaCIS.Core.Application.Contracts public string TrialSiteAliasName { get; set; } = String.Empty; public string SiteName { get; set; } = string.Empty; - public bool IsAbandon { get; set; } + public bool IsDeleted { get; set; } public Guid Id { get; set; } public Guid TrialId { get; set; } public Guid SiteId { get; set; } @@ -255,7 +255,7 @@ namespace IRaCIS.Core.Application.Contracts public TrialSiteSurveyEnum? State { get; set; } - public bool? IsAbandon { get; set; } + public bool? IsDeleted { get; set; } public DateTime? UpdateTimeBegin { get; set; } diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs index cd795a2be..da50c9f09 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs @@ -364,7 +364,7 @@ namespace IRaCIS.Core.Application.Contracts { var trialSiteSurveyQueryable = _trialSiteSurveyRepository.Where(t => t.TrialId == surveyQueryDTO.TrialId).IgnoreQueryFilters() .WhereIf(surveyQueryDTO.SiteId != null, t => t.SiteId == surveyQueryDTO.SiteId) - .WhereIf(surveyQueryDTO.IsAbandon != null, t => t.IsAbandon == surveyQueryDTO.IsAbandon) + .WhereIf(surveyQueryDTO.IsDeleted != null, t => t.IsDeleted == surveyQueryDTO.IsDeleted) .WhereIf(!string.IsNullOrWhiteSpace(surveyQueryDTO.UserKeyInfo), t => t.UserName.Contains(surveyQueryDTO.UserKeyInfo) || t.Phone.Contains(surveyQueryDTO.UserKeyInfo) || t.Email.Contains(surveyQueryDTO.UserKeyInfo)) .WhereIf(surveyQueryDTO.State != null, t => t.State == surveyQueryDTO.State) .WhereIf(surveyQueryDTO.UpdateTimeBegin != null, t => t.UpdateTime >= surveyQueryDTO.UpdateTimeBegin) @@ -385,7 +385,7 @@ namespace IRaCIS.Core.Application.Contracts var groupSelectIdQuery = - _trialSiteSurveyRepository.Where(t => t.TrialId == queryParam.TrialId && t.IsAbandon == false) + _trialSiteSurveyRepository.Where(t => t.TrialId == queryParam.TrialId) .WhereIf(queryParam.SiteId != null, t => t.SiteId == queryParam.SiteId) .WhereIf(!string.IsNullOrEmpty(queryParam.FormWriterKeyInfo), t => (t.UserName).Contains(queryParam.FormWriterKeyInfo) || t.Email.Contains(queryParam.FormWriterKeyInfo) || t.Phone.Contains(queryParam.FormWriterKeyInfo)) .GroupBy(t => t.SiteId) @@ -624,14 +624,14 @@ namespace IRaCIS.Core.Application.Contracts [HttpPut("{trialId:guid}/{trialSiteSurveyId:guid}")] public async Task AbandonSiteSurvey(Guid trialSiteSurveyId) { - var survey = (await _trialSiteSurveyRepository.FirstOrDefaultAsync(t => t.Id == trialSiteSurveyId)).IfNullThrowConvertException(); + var survey = (await _trialSiteSurveyRepository.FirstOrDefaultAsync(t => t.Id == trialSiteSurveyId,true)).IfNullThrowConvertException(); if (survey.State != TrialSiteSurveyEnum.ToSubmit) { return ResponseOutput.NotOk("只允许废除未提交的记录"); } - survey.IsAbandon = true; + survey.IsDeleted = true; await _repository.SaveChangesAsync(); diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/PersonalWorkstation.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/PersonalWorkstation.cs index b3e7ec5f4..99aff527e 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/PersonalWorkstation.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/PersonalWorkstation.cs @@ -43,7 +43,7 @@ namespace IRaCIS.Core.Application TotalNeedSignTrialDocCount = _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SuperAdmin ? 0 : await _trialDocumentRepository - .Where(t => t.IsAbandon == false || (t.IsAbandon == true && + .Where(t => t.IsDeleted == false || (t.IsDeleted == true && t.TrialDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id))) .SelectMany(t => t.NeedConfirmedUserTypeList) @@ -60,7 +60,7 @@ namespace IRaCIS.Core.Application TotalNeedSignSystemDocCount = _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SuperAdmin ? 0 : await _systemDocumentRepository - .Where(t => t.IsAbandon == false || (t.IsAbandon == true && t.SystemDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id))) + .Where(t => t.IsDeleted == false || (t.IsDeleted == true && t.SystemDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id))) .SelectMany(t => t.NeedConfirmedUserTypeList) .CountAsync(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId), @@ -78,7 +78,7 @@ namespace IRaCIS.Core.Application /// - /// Site 调研 每个项目 处理任务数 + /// Site 调研 每个项目 需要处理的审批统计 /// /// /// diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs index a468b641a..c21ca4632 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs @@ -76,7 +76,7 @@ namespace IRaCIS.Core.Application.Services var data = await _trialRepository.Where(t => t.Id == trialId).IgnoreQueryFilters().ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync(); var groupSelectIdQuery = - _trialSiteSurveyRepository.Where(t => t.TrialId == trialId && t.IsAbandon == false) + _trialSiteSurveyRepository.Where(t => t.TrialId == trialId && t.IsDeleted == false) .GroupBy(t => t.SiteId) .Select(g => g.OrderByDescending(u => u.CreateTime).Select(t => t.Id).First()); diff --git a/IRaCIS.Core.Domain/Document/SystemDocument.cs b/IRaCIS.Core.Domain/Document/SystemDocument.cs index 0577b630f..803d50dc6 100644 --- a/IRaCIS.Core.Domain/Document/SystemDocument.cs +++ b/IRaCIS.Core.Domain/Document/SystemDocument.cs @@ -13,18 +13,22 @@ namespace IRaCIS.Core.Domain.Models ///SystemDocument /// [Table("SystemDocument")] - public class SystemDocument : Entity, IAuditUpdate, IAuditAdd + public class SystemDocument : Entity, IAuditUpdate, IAuditAdd,ISoftDelete { public List SystemDocConfirmedUserList { get; set; } public List NeedConfirmedUserTypeList { get; set; } - /// - /// Type - /// - [Required] - public string Type { get; set; } = string.Empty; + + + + [ForeignKey("FileTypeId")] + public Dictionary FileType { get; set; } + + + + public Guid FileTypeId { get; set; } /// /// Name @@ -33,7 +37,7 @@ namespace IRaCIS.Core.Domain.Models public string Name { get; set; } = string.Empty; - public bool IsAbandon { get; set; } + public int SignViewMinimumMinutes { get; set; } @@ -66,11 +70,12 @@ namespace IRaCIS.Core.Domain.Models /// [Required] public Guid UpdateUserId { get; set; } - + public DateTime? DeletedTime { get; set; } + public bool IsDeleted { get; set; } - } + } } diff --git a/IRaCIS.Core.Domain/Document/TrialDocument.cs b/IRaCIS.Core.Domain/Document/TrialDocument.cs index 2a8c92762..b65b1b293 100644 --- a/IRaCIS.Core.Domain/Document/TrialDocument.cs +++ b/IRaCIS.Core.Domain/Document/TrialDocument.cs @@ -25,13 +25,14 @@ namespace IRaCIS.Core.Domain.Models public Trial Trial { get; set; } - //public List TrialUserList { get; set; } + [ForeignKey("FileTypeId")] + public Dictionary FileType { get; set; } + + + + public Guid FileTypeId { get; set; } + - /// - /// Type - /// - [Required] - public string Type { get; set; } = string.Empty; /// /// Name @@ -58,7 +59,6 @@ namespace IRaCIS.Core.Domain.Models public string Description { get; set; } = string.Empty; - public bool IsAbandon { get; set; } public int SignViewMinimumMinutes { get; set; } @@ -85,8 +85,11 @@ namespace IRaCIS.Core.Domain.Models /// [Required] public Guid UpdateUserId { get; set; } - + public DateTime? DeletedTime { get; set; } + + + public bool IsDeleted { get; set; } } diff --git a/IRaCIS.Core.Domain/SiteSurvey/TrialSiteSurvey.cs b/IRaCIS.Core.Domain/SiteSurvey/TrialSiteSurvey.cs index b8d66a39b..87df58e9f 100644 --- a/IRaCIS.Core.Domain/SiteSurvey/TrialSiteSurvey.cs +++ b/IRaCIS.Core.Domain/SiteSurvey/TrialSiteSurvey.cs @@ -14,7 +14,7 @@ namespace IRaCIS.Core.Domain.Models ///TrialSiteSurvey /// [Table("TrialSiteSurvey")] - public class TrialSiteSurvey : Entity, IAuditUpdate, IAuditAdd + public class TrialSiteSurvey : Entity, IAuditUpdate, IAuditAdd,ISoftDelete { //public bool IsLocked { get; set; }=false; public TrialSiteSurveyEnum State { get; set; } = TrialSiteSurveyEnum.ToSubmit; @@ -32,7 +32,10 @@ namespace IRaCIS.Core.Domain.Models public Site Site { get; set; } - public bool IsAbandon { get; set; } + public DateTime? DeletedTime { get; set; } + + + public bool IsDeleted { get; set; } /// /// TrialId diff --git a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs index 13b9a930b..00c9034cf 100644 --- a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs +++ b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs @@ -53,7 +53,7 @@ namespace IRaCIS.Core.Infra.EFCore base.OnModelCreating(modelBuilder); modelBuilder.Entity() - .HasQueryFilter(t => t.IsAbandon == false); + .HasQueryFilter(t => t.IsDeleted == false); // 软删除配置 foreach (var entityType in modelBuilder.Model.GetEntityTypes()) diff --git a/IRaCIS.Core.Infra.EFCore/Repository/IRepository.cs b/IRaCIS.Core.Infra.EFCore/Repository/IRepository.cs index 15e6de642..8e7bdbba8 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/IRepository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/IRepository.cs @@ -37,12 +37,12 @@ namespace IRaCIS.Core.Infra.EFCore //Task InsertOrUpdateAsync(this DbSet dbset, TFrom from, bool autoSave = false, params EntityVerifyExp[] verify) where T : Entity; - Task AnyAsync(Expression> filter) where T : Entity; + Task AnyAsync(Expression> filter, bool ignoreQueryFilters = false) where T : Entity; - Task FirstOrDefaultAsync(Expression> exp = null) where T : Entity; - Task CountAsync(Expression> exp = null) where T : Entity; + Task FirstOrDefaultAsync(Expression> exp = null, bool ignoreQueryFilters = false) where T : Entity; + Task CountAsync(Expression> exp = null, bool ignoreQueryFilters = false) where T : Entity; - IQueryable Where(Expression> exp = null, bool isTraking = false) where T : Entity; + IQueryable Where(Expression> exp = null, bool isTraking = false, bool ignoreQueryFilters = false) where T : Entity; ValueTask FindAsync(Guid id) where T : Entity; @@ -167,14 +167,14 @@ namespace IRaCIS.Core.Infra.EFCore { if (verifyItem.verifyType == VerifyEnum.OnlyUpdate) { - if (await _dbContext.Set().AnyAsync(verifyItem.VerifyExp).ConfigureAwait(false)) + if (await _dbContext.Set().IgnoreQueryFilters().AnyAsync(verifyItem.VerifyExp).ConfigureAwait(false)) { throw new BusinessValidationFailedException(verifyItem.VerifyMsg); } } else if (verifyItem.verifyType == VerifyEnum.Both) { - if (await _dbContext.Set().AnyAsync(verifyItem.VerifyExp.And(t => t.Id != entity.Id)).ConfigureAwait(false)) + if (await _dbContext.Set().IgnoreQueryFilters().AnyAsync(verifyItem.VerifyExp.And(t => t.Id != entity.Id)).ConfigureAwait(false)) { throw new BusinessValidationFailedException(verifyItem.VerifyMsg); } @@ -200,9 +200,18 @@ namespace IRaCIS.Core.Infra.EFCore { return _dbContext.Entry(t); } - public async Task AnyAsync(Expression> filter) where T : Entity + public async Task AnyAsync(Expression> filter, bool ignoreQueryFilters = false) where T : Entity { - return await _dbContext.Set().AnyAsync(filter).ConfigureAwait(false); ; + + var query = _dbContext.Set().AsQueryable(); + + if (ignoreQueryFilters) + { + query = query.IgnoreQueryFilters(); + } + + return await query.AsNoTracking().AnyAsync(filter).ConfigureAwait(false); + } @@ -217,15 +226,40 @@ namespace IRaCIS.Core.Infra.EFCore /// /// /// - public async Task CountAsync(Expression> exp = null) where T : Entity + public async Task CountAsync(Expression> exp = null, bool ignoreQueryFilters = false) where T : Entity { - if (exp == null) return await _dbContext.Set().CountAsync().ConfigureAwait(false); - return await _dbContext.Set().CountAsync(exp).ConfigureAwait(false); + var query = _dbContext.Set().AsQueryable(); + + if (ignoreQueryFilters) + { + query = query.IgnoreQueryFilters(); + } + + if (exp != null) + { + query = query.Where(exp); + } + + return await query.CountAsync().ConfigureAwait(false); + + } - public async Task FirstOrDefaultAsync(Expression> exp = null) where T : Entity + public async Task FirstOrDefaultAsync(Expression> exp = null, bool ignoreQueryFilters = false) where T : Entity { - if (exp == null) return await _dbContext.Set().FirstOrDefaultAsync().ConfigureAwait(false); - return await _dbContext.Set().FirstOrDefaultAsync(exp).ConfigureAwait(false); + + var query = _dbContext.Set().AsQueryable(); + + if (ignoreQueryFilters) + { + query = query.IgnoreQueryFilters(); + } + + if (exp != null) + { + query = query.Where(exp); + } + + return await query.FirstOrDefaultAsync().ConfigureAwait(false); } /// @@ -235,10 +269,15 @@ namespace IRaCIS.Core.Infra.EFCore /// /// /// - public IQueryable Where(Expression> exp = null, bool isTraking = false) where T : Entity + public IQueryable Where(Expression> exp = null, bool isTraking = false, bool ignoreQueryFilters = false) where T : Entity { IQueryable query = _dbContext.Set(); + if (ignoreQueryFilters) + { + query = query.IgnoreQueryFilters(); + } + if (!isTraking) { query = query.AsNoTracking(); @@ -356,7 +395,7 @@ namespace IRaCIS.Core.Infra.EFCore { if (whereFilter == null) throw new ArgumentNullException(nameof(whereFilter)); - return await _dbContext.Set().AsNoTracking().Where(whereFilter).UpdateFromQueryAsync(updateFactory).ConfigureAwait(false) > 0; + return await _dbContext.Set().AsNoTracking().IgnoreQueryFilters().Where(whereFilter).UpdateFromQueryAsync(updateFactory).ConfigureAwait(false) > 0; } } diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index 905293a64..cce6fea06 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -252,7 +252,7 @@ namespace IRaCIS.Core.Infra.EFCore // Z.EntityFramework.Plus.EFCore public async Task DeleteFromQueryAsync(Expression> deleteFilter) { - return await _dbSet.Where(deleteFilter).DeleteFromQueryAsync() > 0; + return await _dbSet.IgnoreQueryFilters().Where(deleteFilter).DeleteFromQueryAsync() > 0; } public async Task UpdateFromQueryAsync(Expression> where, Expression> updateFactory)