From 319cc7faf3884c723991fb1b43b56789aef7a8fc Mon Sep 17 00:00:00 2001 From: he <10978375@qq.com> Date: Tue, 28 Jun 2022 17:41:52 +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 --- .../IRaCIS.Core.Application.xml | 44 +++++++- .../Reading/Dto/ReadingQuestionViewModel.cs | 42 ++++++- .../Service/Reading/ReadingQuestionService.cs | 103 +++++++++++++++++- 3 files changed, 185 insertions(+), 4 deletions(-) diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index ce09ce537..8c64c8c84 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -1867,6 +1867,41 @@ 问题名称 + + + 父问题ID + + + + + 项目标准Id + + + + + 系统问题ID + + + + + 系统标准的ParentId + + + + + 答案分组 + + + + + 答案组合 + + + + + 裁判类型 + + 分组 @@ -4624,7 +4659,14 @@ - 更改项目标准 + 更改项目标准(老) + + + + + + + 更改项目标准(新) diff --git a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingQuestionViewModel.cs b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingQuestionViewModel.cs index b9353d91b..c6138f40f 100644 --- a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingQuestionViewModel.cs +++ b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingQuestionViewModel.cs @@ -1,4 +1,5 @@ -using System; +using IRaCIS.Core.Domain.Share; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; @@ -348,6 +349,45 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto public string QuestionName { get; set; } = string.Empty; } + public class TrialQuestion + { + public Guid Id { get; set; } + + /// + /// 父问题ID + /// + public Guid? ParentId { get; set; } + + /// + /// 项目标准Id + /// + public Guid ReadingQuestionCriterionTrialId { get; set; } + + /// + /// 系统问题ID + /// + public Guid? ReadingQuestionSystemId { get; set; } + + /// + /// 系统标准的ParentId + /// + public Guid? SystemParentId { get; set; } + + /// + /// 答案分组 + /// + public string AnswerGroup { get; set; } = string.Empty; + + /// + /// 答案组合 + /// + public string AnswerCombination { get; set; } = string.Empty; + + /// + /// 裁判类型 + /// + public JudgeTypeEnum JudgeType { get; set; } + } public class AddOrUpdateReadingQuestionSystemInDto { diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingQuestionService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingQuestionService.cs index ffe85b2bb..95939b255 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingQuestionService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingQuestionService.cs @@ -160,7 +160,7 @@ namespace IRaCIS.Application.Services if (inDto.IsCompleteConfig) { - await UpdateTrialCriterion(inDto.Id); + await SynchronizeSystemCriterion(inDto.Id); }else { await _readingQuestionCriterionTrialRepository.BatchUpdateNoTrackingAsync(x=>x.ReadingQuestionCriterionSystemId== inDto.Id, x => new ReadingQuestionCriterionTrial() @@ -174,7 +174,7 @@ namespace IRaCIS.Application.Services } /// - /// 更改项目标准 + /// 更改项目标准(老) /// /// /// @@ -201,6 +201,105 @@ namespace IRaCIS.Application.Services await _readingQuestionTrialRepository.AddRangeAsync(needAddQuestionList); } + + /// + /// 更改项目标准(新) + /// + /// + /// + private async Task SynchronizeSystemCriterion(Guid systemCriterionId) + { + var systemCriterion = await _readingQuestionCriterionSystemRepository.FirstOrDefaultAsync(x=>x.Id== systemCriterionId); + + var trialCriterionList = await _readingQuestionCriterionTrialRepository.Where(x => x.ReadingQuestionCriterionSystemId == systemCriterionId).Select(x => new { + x.Id, + x.TrialId, + }).ToListAsync(); + + var trialCriterionIds= trialCriterionList.Select(x => x.Id).ToList(); + var systemQuestionList = await _readingQuestionSystemRepository.Where(x => x.ReadingQuestionCriterionSystemId == systemCriterionId).ToListAsync(); + var trialQuestions = await _readingQuestionTrialRepository.Where(x => trialCriterionIds.Contains(x.ReadingQuestionCriterionTrialId)).Select(x => new TrialQuestion + { + AnswerCombination = x.AnswerCombination, + AnswerGroup = x.AnswerGroup, + Id = x.Id, + JudgeType = x.JudgeType, + ParentId = x.ParentId, + ReadingQuestionCriterionTrialId = x.ReadingQuestionCriterionTrialId, + ReadingQuestionSystemId = x.ReadingQuestionSystemId, + SystemParentId = x.SystemParentId + }).ToListAsync(); + + List trialQuestionList = new List(); + foreach (var item in trialCriterionList) + { + + var thistrialQuestions = trialQuestions.Where(x => x.ReadingQuestionCriterionTrialId == item.Id).ToList(); + + var query = systemQuestionList.GroupJoin(thistrialQuestions, a => a.Id, b => b.ReadingQuestionSystemId, (a, b) => new + { + a, + trialQuestion = b + }).SelectMany(a => a.trialQuestion, (m, n) => new ReadingQuestionTrial + { + Id=n.Id, + + }); + var needAddQuestionList = systemQuestionList.GroupJoin(thistrialQuestions, a => a.Id, b => b.ReadingQuestionSystemId, (x, y) => new { system = x, trial = y }) + .SelectMany( + a => a.trial.DefaultIfEmpty(), + (c,d) => new ReadingQuestionTrial + { + Id=(c.trial.FirstOrDefault()?.Id)??NewId.NextGuid(), + ShowOrder=c.system.ShowOrder, + SystemParentId=c.system.ParentId, + ReadingQuestionSystemId=c.system.Id, + AnswerCombination = (c.trial.FirstOrDefault()?.AnswerCombination)??string.Empty, + AnswerGroup= (c.trial.FirstOrDefault()?.AnswerGroup) ?? string.Empty, + GroupName=c.system.GroupName, + IsEnable=c.system.IsEnable, + IsJudgeQuestion=c.system.IsJudgeQuestion, + IsRequired=c.system.IsRequired, + JudgeType = (c.trial.FirstOrDefault()?.JudgeType)??JudgeTypeEnum.None, + ParentId = c.trial.FirstOrDefault()?.ParentId, + ParentTriggerValue=c.system.ParentTriggerValue, + QuestionName=c.system.QuestionName, + ReadingQuestionCriterionTrialId = item.Id, + Remark=c.system.Remark, + TrialId=item.TrialId, + Type=c.system.Type, + TypeValue=c.system.TypeValue, + }).ToList(); + var copydata = needAddQuestionList.Clone(); + needAddQuestionList.ForEach(x => + { + if (x.SystemParentId == null) + { + x.ParentId = null; + } + else + { + x.ParentId = copydata.FirstOrDefault(y => y.ReadingQuestionSystemId == x.SystemParentId).Id; + } + }); + + trialQuestionList.AddRange(needAddQuestionList); + } + await _readingQuestionTrialRepository.BatchDeleteNoTrackingAsync(x => trialCriterionIds.Contains(x.ReadingQuestionCriterionTrialId)); + await _readingQuestionCriterionTrialRepository.BatchUpdateNoTrackingAsync(x => trialCriterionIds.Contains(x.Id), x => new ReadingQuestionCriterionTrial() + { + IsEnable = systemCriterion.IsEnable, + CriterionName = systemCriterion.CriterionName, + ShowOrder = systemCriterion.ShowOrder, + IsCompleteConfig = systemCriterion.IsCompleteConfig, + + }); + + await _readingQuestionTrialRepository.AddRangeAsync(trialQuestionList); + await _readingQuestionTrialRepository.SaveChangesAsync(); + } + + /// /// 添加系统qc问题标准 ///