diff --git a/IRaCIS.Core.Application/Service/Visit/SubjectService.cs b/IRaCIS.Core.Application/Service/Visit/SubjectService.cs index c2d3eb25f..8a38ca416 100644 --- a/IRaCIS.Core.Application/Service/Visit/SubjectService.cs +++ b/IRaCIS.Core.Application/Service/Visit/SubjectService.cs @@ -98,6 +98,7 @@ namespace IRaCIS.Application.Services [HttpDelete("{trialId:guid}/{id:guid}")] [TypeFilter(typeof(TrialResourceFilter))] + [UnitOfWork] public async Task DeleteSubject(Guid id) { @@ -106,12 +107,11 @@ namespace IRaCIS.Application.Services return ResponseOutput.NotOk("This subject has executed a visit with uploading study images,and couldn't be deleted."); } - await _subjectRepository.DeleteFromQueryAsync(u => u.Id == id); - await _subjectVisitRepository.DeleteFromQueryAsync(u => u.SubjectId == id); + await _subjectRepository.SoftDeleteFromQueryAsync(u => u.Id == id); + await _subjectVisitRepository.SoftDeleteFromQueryAsync(u => u.SubjectId == id); var isSuccess = await _subjectRepository.SaveChangesAsync(); - return ResponseOutput.Result(isSuccess); } diff --git a/IRaCIS.Core.Application/Service/Visit/VisitPlanService.cs b/IRaCIS.Core.Application/Service/Visit/VisitPlanService.cs index d7eae738c..d5cf6cb72 100644 --- a/IRaCIS.Core.Application/Service/Visit/VisitPlanService.cs +++ b/IRaCIS.Core.Application/Service/Visit/VisitPlanService.cs @@ -1,7 +1,6 @@ using IRaCIS.Core.Infrastructure.ExpressionExtend; using IRaCIS.Application.Interfaces; using IRaCIS.Application.Contracts; -using IRaCIS.Core.Infra.EFCore; using IRaCIS.Core.Application.Filter; using Microsoft.AspNetCore.Mvc; using IRaCIS.Core.Domain.Share; @@ -23,22 +22,16 @@ namespace IRaCIS.Application.Services private readonly IRepository _visitStageRepository; private readonly IRepository _trialRepository; private readonly IRepository _subjectVisitRepository; - private readonly IRepository _influnceStatRepository; private readonly IRepository _influnceRepository; - private readonly IInspectionService _inspectionService; public VisitPlanService(IRepository visitStageRepository, IRepository trialRepository, IRepository subjectVisitRepository, IRepository influnceStatRepository, - IRepository visitPlanInfluenceStudy, - - IInspectionService inspectionService) + IRepository visitPlanInfluenceStudy) { _visitStageRepository = visitStageRepository; _trialRepository = trialRepository; this._subjectVisitRepository = subjectVisitRepository; - this._influnceStatRepository = influnceStatRepository; this._influnceRepository = visitPlanInfluenceStudy; - this._inspectionService = inspectionService; } @@ -355,7 +348,7 @@ namespace IRaCIS.Application.Services //访视计划 整体状态变更为 确认 await _visitStageRepository.BatchUpdateNoTrackingAsync(u => u.TrialId == trialId, t => new VisitStage() { IsConfirmed = true, IsHaveFirstConfirmed = true }); - await _repository.SaveChangesAsync(); + await _visitStageRepository.SaveChangesAsync(); return ResponseOutput.Ok(); } @@ -389,6 +382,8 @@ namespace IRaCIS.Application.Services } + + /// 删除项目计划某一项 废弃 [HttpDelete("{id:guid}/{trialId:guid}")] [TrialAudit(AuditType.TrialAudit, AuditOptType.DeleteTrialVisitPlanItem)] diff --git a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs index ec94617d5..0154e2f6d 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs @@ -27,6 +27,8 @@ namespace IRaCIS.Core.Infra.EFCore /// 批量删除,EF跟踪方式(所有查询出来,再删除 浪费性能,但是稽查 或者触发某些操作时,需要知道数据库实体信息 不可避免用这种) Task> DeleteFromQueryAsync(Expression> deleteFilter, bool autoSave = false, bool ignoreQueryFilter = false); + Task> SoftDeleteFromQueryAsync(Expression> deleteFilter, bool autoSave = false, bool ignoreQueryFilter = false); + Task DeleteFromQueryAsync(Guid id, bool autoSave = false, bool ignoreQueryFilter = false); diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index 3381e575f..c803c5440 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -355,6 +355,24 @@ namespace IRaCIS.Core.Infra.EFCore } + public async Task> SoftDeleteFromQueryAsync(Expression> deleteFilter, bool autoSave = false, bool ignoreQueryFilter = false) + { + var query = ignoreQueryFilter ? _dbSet.IgnoreQueryFilters() : _dbSet; + var waitDeleteList = await query.Where(deleteFilter).ToListAsync(); + + foreach (var deleteItem in waitDeleteList) + { + if(deleteItem is ISoftDelete softDeleteItem) + { + softDeleteItem.IsDeleted = true; + } + } + + await SaveChangesAsync(autoSave); + + return waitDeleteList; + } + #endregion