From 310c526c8e47111990052e5fd86364a0cd41cb8d Mon Sep 17 00:00:00 2001 From: he <10978375@qq.com> Date: Tue, 14 Jun 2022 11:18:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Reading/ReadingQuestionService.cs | 98 +++++++++++++++++-- 1 file changed, 88 insertions(+), 10 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingQuestionService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingQuestionService.cs index ee3ad558..c0939a86 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingQuestionService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingQuestionService.cs @@ -186,6 +186,10 @@ namespace IRaCIS.Application.Services [HttpDelete("{readingQuestionSystemId:guid}")] public async Task DeleteReadingQuestionSystem(Guid readingQuestionSystemId) { + if (await _readingQuestionSystemRepository.AnyAsync(x => x.ParentId == readingQuestionSystemId)) + { + return ResponseOutput.NotOk("此问题存在子问题,请先删除子问题"); + } await _readingQuestionSystemRepository.DeleteFromQueryAsync(t => t.Id == readingQuestionSystemId); var success = await _readingQuestionSystemRepository.SaveChangesAsync(); return ResponseOutput.Result(success); @@ -218,8 +222,56 @@ namespace IRaCIS.Application.Services List systemQuestionList = x.ReadingQuestionSystemList.Clone(); + List readingQuestionTrialList = new List(); + + SetChildParentQuestion(criterion.Id, trialId, systemQuestionList, readingQuestionTrialList); + needAddCriterionList.Add(criterion); + + needAddQuestionList.AddRange(readingQuestionTrialList); + + }); + + + await _readingQuestionCriterionTrialRepository.AddRangeAsync(needAddCriterionList); + + await _readingQuestionTrialRepository.AddRangeAsync(needAddQuestionList); + + await _readingQuestionTrialRepository.SaveChangesAsync(); + } + + /// + /// 设置父子关系 + /// + /// 项目标准ID + /// 项目Id + /// 系统问题 + /// 需要添加list + private void SetChildParentQuestion(Guid ReadingQuestionCriterionTrialId, Guid trialId, List systemQuesitonList,List needQuestionList) + { + var parentIdIsNullList = systemQuesitonList.Where(x => x.ParentId == null).ToList(); + + parentIdIsNullList.ForEach(x => + { + var quesiton = x.Clone(); + var oldId = quesiton.Id; + var newId = NewId.NextGuid(); + needQuestionList.Add(new ReadingQuestionTrial() + { + Id = newId, + ShowOrder = quesiton.ShowOrder, + IsEnable = quesiton.IsEnable, + IsRequired = quesiton.IsRequired, + ParentTriggerValue = quesiton.ParentTriggerValue, + QuestionName = quesiton.QuestionName, + ReadingQuestionCriterionTrialId = ReadingQuestionCriterionTrialId, + TrialId = trialId, + Type = quesiton.Type, + TypeValue = quesiton.TypeValue, + }); + + CreateQuestionRelation(ReadingQuestionCriterionTrialId, trialId, oldId, newId, systemQuesitonList, needQuestionList); }); @@ -227,23 +279,44 @@ namespace IRaCIS.Application.Services } /// - /// 递归处理父子问题关系 + /// 递归处理父子关系 /// - private async Task SetChildParentQuestion(Guid trialId, List systemQuesitonList,List needQuestionList) + /// + /// + /// + /// + /// + /// + public void CreateQuestionRelation(Guid ReadingQuestionCriterionTrialId, Guid trialId,Guid oldParentId,Guid newParentId, List systemQuesitonList, List needQuestionList) { - var parentIdIsNullList = systemQuesitonList.Where(x => x.ParentId == null).ToList(); - - //parentIdIsNullList.ForEach(x => { - // var oldId = x.Id.Clone();` - - - //}) - + var childList = systemQuesitonList.Where(x => x.ParentId == oldParentId).ToList(); + childList.ForEach(x => + { + var quesiton = x.Clone(); + var oldId = quesiton.Id; + var newId = NewId.NextGuid(); + needQuestionList.Add(new ReadingQuestionTrial() + { + Id = newId, + ShowOrder = quesiton.ShowOrder, + IsEnable = quesiton.IsEnable, + IsRequired = quesiton.IsRequired, + ParentId = newParentId, + ParentTriggerValue = quesiton.ParentTriggerValue, + QuestionName = quesiton.QuestionName, + ReadingQuestionCriterionTrialId = ReadingQuestionCriterionTrialId, + TrialId = trialId, + Type = quesiton.Type, + TypeValue = quesiton.TypeValue, + }); + CreateQuestionRelation(ReadingQuestionCriterionTrialId, trialId, oldId, newId, systemQuesitonList, needQuestionList); + }); } + /// /// 新增修改项目问题标准(项目) /// @@ -263,6 +336,7 @@ namespace IRaCIS.Application.Services [HttpPost] public async Task> GetReadingQuestionCriterionTrialList(ReadingQuestionCriterionTrialViewInDto inDto) { + await AddSystemDataToTrila(inDto.TrialId); var query = _readingQuestionCriterionTrialRepository.AsQueryable() .Where(x=>x.TrialId==inDto.TrialId) .WhereIf(!inDto.CriterionName.IsNullOrEmpty(), x => x.CriterionName.Contains(inDto.CriterionName)) @@ -322,6 +396,10 @@ namespace IRaCIS.Application.Services [HttpDelete("{readingQuestionTrialId:guid}")] public async Task DeleteReadingQuestionTrial(Guid readingQuestionTrialId) { + if (await _readingQuestionTrialRepository.AnyAsync(x => x.ParentId == readingQuestionTrialId)) + { + return ResponseOutput.NotOk("此问题存在子问题,请先删除子问题"); + } await _readingQuestionTrialRepository.DeleteFromQueryAsync(t => t.Id == readingQuestionTrialId); var success = await _readingQuestionTrialRepository.SaveChangesAsync(); return ResponseOutput.Result(success);