diff --git a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingQuestionViewModel.cs b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingQuestionViewModel.cs index 17abf130f..f19155a4e 100644 --- a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingQuestionViewModel.cs +++ b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingQuestionViewModel.cs @@ -13,6 +13,8 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto public Guid SourceSystemCriterionId { get; set; } public Guid NewSystemCriterionId { get; set; } + + public bool IsCopyQuestion { get; set; } } diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingQuestionService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingQuestionService.cs index 5c3e21ca4..737c2da4f 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingQuestionService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingQuestionService.cs @@ -34,6 +34,7 @@ namespace IRaCIS.Application.Services private readonly IRepository _readingTableQuestionTrialRepository; private readonly IRepository _readingCriterionPageRepository; private readonly IRepository _trialRepository; + private readonly IRepository _organInfoRepository; private readonly IRepository _readingTableQuestionSystemRepository; private readonly IRepository _readingTaskQuestionAnswer; private readonly IRepository _previousPDFRepository; @@ -47,11 +48,12 @@ namespace IRaCIS.Application.Services IRepository ClinicalDataTrialSetRepository, IRepository ClinicalDataSystemSetRepository, IRepository dictionaryRepository, - IRepository readingTableQuestionTrialRepository, - IRepository readingCriterionPageRepository, - IRepository trialRepository, - IRepository readingTableQuestionSystemRepository, - IRepository readingTaskQuestionAnswer, + IRepository readingTableQuestionTrialRepository, + IRepository readingCriterionPageRepository, + IRepository trialRepository, + IRepository organInfoRepository, + IRepository readingTableQuestionSystemRepository, + IRepository readingTaskQuestionAnswer, IRepository previousPDFRepository ) { @@ -66,6 +68,7 @@ namespace IRaCIS.Application.Services this._readingTableQuestionTrialRepository = readingTableQuestionTrialRepository; this._readingCriterionPageRepository = readingCriterionPageRepository; this._trialRepository = trialRepository; + this._organInfoRepository = organInfoRepository; this._readingTableQuestionSystemRepository = readingTableQuestionSystemRepository; this._readingTaskQuestionAnswer = readingTaskQuestionAnswer; this._previousPDFRepository = previousPDFRepository; @@ -79,59 +82,79 @@ namespace IRaCIS.Application.Services [HttpPost] public async Task CopySystemCriterionData(CopySystemCriterionDataInDto inDto) { - var newSystemQuestionList = await _readingQuestionSystemRepository.Where(x => x.ReadingQuestionCriterionSystemId == inDto.SourceSystemCriterionId) - .ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); - newSystemQuestionList.ForEach(x => + if (inDto.IsCopyQuestion) { - x.Id = NewId.NextGuid(); - x.ReadingQuestionCriterionSystemId = inDto.NewSystemCriterionId; - }); - var copyNewQuestionList = newSystemQuestionList.Clone(); - var needAddDatas = new List(); - foreach (var x in newSystemQuestionList) - { - var question = x.Clone(); - if (question.ParentId != null) + var newSystemQuestionList = await _readingQuestionSystemRepository.Where(x => x.ReadingQuestionCriterionSystemId == inDto.SourceSystemCriterionId) + .ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); + newSystemQuestionList.ForEach(x => { - question.ParentId = copyNewQuestionList.Where(y => x.ParentId == y.OriginalId).Select(y => y.Id).FirstOrDefault(); - } - if (question.RelevanceId != null) + x.Id = NewId.NextGuid(); + x.ReadingQuestionCriterionSystemId = inDto.NewSystemCriterionId; + }); + var copyNewQuestionList = newSystemQuestionList.Clone(); + var needAddDatas = new List(); + foreach (var x in newSystemQuestionList) { - question.RelevanceId = copyNewQuestionList.Where(y => x.RelevanceId == y.OriginalId).Select(y => y.Id).FirstOrDefault(); - } - needAddDatas.Add(question); - }; + var question = x.Clone(); + if (question.ParentId != null) + { + question.ParentId = copyNewQuestionList.Where(y => x.ParentId == y.OriginalId).Select(y => y.Id).FirstOrDefault(); + } + if (question.RelevanceId != null) + { + question.RelevanceId = copyNewQuestionList.Where(y => x.RelevanceId == y.OriginalId).Select(y => y.Id).FirstOrDefault(); + } + needAddDatas.Add(question); + }; - await _readingQuestionSystemRepository.BatchDeleteNoTrackingAsync(x => x.ReadingQuestionCriterionSystemId == inDto.NewSystemCriterionId); - await _readingQuestionSystemRepository.AddRangeAsync(needAddDatas); - - #region 表格问题 - var newSystemTableQuestionList = await _readingTableQuestionSystemRepository.Where(x => x.SystemCriterionId == inDto.SourceSystemCriterionId) - .ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); - var copeNewSystemTableQuestionList = newSystemTableQuestionList.Clone(); - var needAddTableDatas = new List(); - foreach (var x in newSystemTableQuestionList) - { - var tableQuestion = x.Clone(); - tableQuestion.SystemCriterionId =inDto.NewSystemCriterionId; - tableQuestion.Id = NewId.NextGuid(); - if (tableQuestion.ParentId != null) + await _readingQuestionSystemRepository.BatchDeleteNoTrackingAsync(x => x.ReadingQuestionCriterionSystemId == inDto.NewSystemCriterionId); + await _readingQuestionSystemRepository.AddRangeAsync(needAddDatas); + + #region 表格问题 + var newSystemTableQuestionList = await _readingTableQuestionSystemRepository.Where(x => x.SystemCriterionId == inDto.SourceSystemCriterionId) + .ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); + var copeNewSystemTableQuestionList = newSystemTableQuestionList.Clone(); + var needAddTableDatas = new List(); + foreach (var x in newSystemTableQuestionList) { - tableQuestion.ParentId = copeNewSystemTableQuestionList.Where(y => x.ParentId == y.OriginalId).Select(y => y.Id).FirstOrDefault(); + var tableQuestion = x.Clone(); + tableQuestion.SystemCriterionId = inDto.NewSystemCriterionId; + tableQuestion.Id = NewId.NextGuid(); + if (tableQuestion.ParentId != null) + { + tableQuestion.ParentId = copeNewSystemTableQuestionList.Where(y => x.ParentId == y.OriginalId).Select(y => y.Id).FirstOrDefault(); + } + if (tableQuestion.RelevanceId != null) + { + tableQuestion.RelevanceId = copeNewSystemTableQuestionList.Where(y => x.RelevanceId == y.OriginalId).Select(y => y.Id).FirstOrDefault(); + } + if (tableQuestion.DependParentId != null) + { + tableQuestion.DependParentId = copeNewSystemTableQuestionList.Where(y => x.DependParentId == y.OriginalId).Select(y => y.Id).FirstOrDefault(); + } + needAddTableDatas.Add(tableQuestion); } - if (tableQuestion.RelevanceId != null) - { - tableQuestion.RelevanceId = copeNewSystemTableQuestionList.Where(y => x.RelevanceId == y.OriginalId).Select(y => y.Id).FirstOrDefault(); - } - if (tableQuestion.DependParentId != null) - { - tableQuestion.DependParentId = copeNewSystemTableQuestionList.Where(y => x.DependParentId == y.OriginalId).Select(y => y.Id).FirstOrDefault(); - } - needAddTableDatas.Add(tableQuestion); + await _readingTableQuestionSystemRepository.BatchDeleteNoTrackingAsync(x => x.SystemCriterionId == inDto.NewSystemCriterionId); + await _readingTableQuestionSystemRepository.AddRangeAsync(needAddTableDatas); + #endregion + } - await _readingTableQuestionSystemRepository.BatchDeleteNoTrackingAsync(x => x.SystemCriterionId == inDto.NewSystemCriterionId); - await _readingTableQuestionSystemRepository.AddRangeAsync(needAddTableDatas); - #endregion + else + { + var organData = await _organInfoRepository.Where(x => x.SystemCriterionId == inDto.SourceSystemCriterionId).ToListAsync(); + + organData.ForEach(x => { + x.Id = NewId.NextGuid(); + x.SystemCriterionId = inDto.NewSystemCriterionId; + }); + await _organInfoRepository.BatchDeleteNoTrackingAsync(x => x.SystemCriterionId == inDto.NewSystemCriterionId); + await _organInfoRepository.AddRangeAsync(organData); + + } + + + + await _readingTableQuestionSystemRepository.SaveChangesAsync(); return ResponseOutput.Ok(); }