diff --git a/IRaCIS.Core.Application/Service/Reading/ReadModuleService.cs b/IRaCIS.Core.Application/Service/Reading/ReadModuleService.cs index bdee9d976..dfb016150 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadModuleService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadModuleService.cs @@ -14,6 +14,7 @@ using IRaCIS.Core.Infra.EFCore.Common; using System.Linq.Dynamic.Core; using IRaCIS.Core.Application.Service; using IRaCIS.Core.Application.ViewModel; +using IRaCIS.Core.Infrastructure; namespace IRaCIS.Application.Services { @@ -463,7 +464,21 @@ namespace IRaCIS.Application.Services [HttpDelete("{readModuleId:guid}")] public async Task DeleteReadModule(Guid readModuleId) { + + if (await _visitTaskRepository.AnyAsync(x => readModuleId==x.SouceReadModuleId && x.ReadingTaskState == ReadingTaskState.HaveSigned && x.TaskState == TaskState.Effect)) + { + throw new BusinessValidationFailedException("当前阅片已生成任务并且阅片完成,操作失败。"); + } + + + await _visitTaskRepository.BatchUpdateNoTrackingAsync(x => readModuleId==x.SouceReadModuleId, x => new VisitTask() + { + TaskState = TaskState.Adbandon + }); + + await _readModuleRepository.DeleteFromQueryAsync(t => t.Id == readModuleId, true); + await _readModuleRepository.SaveChangesAsync(); return ResponseOutput.Result(true); } diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingPeriodSetService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingPeriodSetService.cs index 0f1dc8cae..a2ff80f35 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingPeriodSetService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingPeriodSetService.cs @@ -13,6 +13,7 @@ using IRaCIS.Core.Infra.EFCore.Common; using IRaCIS.Core.Infrastructure.Extention; using IRaCIS.Core.Application.Service; using IRaCIS.Core.Application.ViewModel; +using IRaCIS.Core.Infrastructure; namespace IRaCIS.Application.Services { @@ -434,6 +435,18 @@ namespace IRaCIS.Application.Services } else { + + List readModuleIds = await _readModuleRepository.Where(x => x.ReadingPeriodSetId == indto.Id).Select(x => x.Id).ToListAsync(); + if (await _visitTaskRepository.AnyAsync(x => readModuleIds.Contains(x.SouceReadModuleId ?? default(Guid)) && x.ReadingTaskState == ReadingTaskState.HaveSigned && x.TaskState == TaskState.Effect)) + { + throw new BusinessValidationFailedException("当前阅片已生成任务并且阅片完成,撤销失败。"); + } + + + await _visitTaskRepository.BatchUpdateNoTrackingAsync(x => readModuleIds.Contains(x.SouceReadModuleId ?? default(Guid)), x => new VisitTask() + { + TaskState = TaskState.Adbandon + }); await _readModuleRepository.DeleteFromQueryAsync(x => x.ReadingPeriodSetId == indto.Id); }