diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index b4f988272..f30170f59 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -9644,6 +9644,13 @@ + + + 同步系统标准 + + + + 同步标准到项目新(2022-08-10) diff --git a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingQuestionViewModel.cs b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingQuestionViewModel.cs index c74cfbc3e..2ca6c12b9 100644 --- a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingQuestionViewModel.cs +++ b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingQuestionViewModel.cs @@ -565,6 +565,14 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto { public Guid OriginalId { get; set; } } + + + public class SynchronizeSystemCriterionInDto + { + public Guid FromSystemCriterionId { get; set; } + public Guid ToSystemCriterionId { get; set; } + } + public class SynchronizeCriterionInDto { [NotDefault] diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingCriterion/ReadingQuestionService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingCriterion/ReadingQuestionService.cs index ea4523b69..52d8c1e5e 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingCriterion/ReadingQuestionService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingCriterion/ReadingQuestionService.cs @@ -827,6 +827,94 @@ namespace IRaCIS.Application.Services return ResponseOutput.Ok(); } + /// + /// 同步系统标准 + /// + /// + /// + [HttpPost] + public async Task SynchronizeSystemCriterionQuestion(SynchronizeSystemCriterionInDto inDto) + { + // 先找到项目系统问题Id和项目问题Id的对应关系 + var questionRelation = _readingQuestionSystemRepository.Where(x => x.ReadingQuestionCriterionSystemId == inDto.FromSystemCriterionId).ToDictionary( + x => x.Id, + x => NewId.NextGuid() + ); + + + var newQuestionList = await _readingQuestionSystemRepository.Where(x => x.ReadingQuestionCriterionSystemId == inDto.FromSystemCriterionId).ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); + var copyNewQuestionList = newQuestionList.Clone(); + + var needAddDatas = new List(); + + foreach (var x in newQuestionList) + { + var question = x.Clone(); + question.ReadingQuestionCriterionSystemId = inDto.ToSystemCriterionId; + question.Id = questionRelation[question.Id.Value]; + if (question.ParentId != null) + { + question.ParentId = questionRelation[question.ParentId ?? default(Guid)]; + } + if (question.GroupId != null) + { + question.GroupId = questionRelation[question.GroupId ?? default(Guid)]; + } + if (question.RelevanceId != null) + { + question.RelevanceId = questionRelation[question.RelevanceId ?? default(Guid)]; + } + needAddDatas.Add(_mapper.Map(question)); + }; + + await _readingQuestionSystemRepository.BatchDeleteNoTrackingAsync(x => x.ReadingQuestionCriterionSystemId == inDto.ToSystemCriterionId); + await _readingQuestionSystemRepository.AddRangeAsync(needAddDatas); + + + var tableQuestionRelation = _readingTableQuestionSystemRepository.Where(x => x.SystemCriterionId == inDto.FromSystemCriterionId).ToDictionary( + x => x.Id, + x => NewId.NextGuid() + ); + + + var newtableQuestion =await _readingTableQuestionSystemRepository.Where(x => x.SystemCriterionId == inDto.FromSystemCriterionId).ToListAsync(); + + + var copyNewTableQuestionList = newtableQuestion.Clone(); + + var needAddTableDatas = new List(); + foreach (var x in newtableQuestion) + { + var tableQuestion = x.Clone(); + + + tableQuestion.SystemCriterionId = inDto.ToSystemCriterionId; + tableQuestion.Id = tableQuestionRelation[tableQuestion.Id]; + tableQuestion.ReadingQuestionId = questionRelation[tableQuestion.ReadingQuestionId]; + if (tableQuestion.ParentId != null) + { + tableQuestion.ParentId = tableQuestionRelation[tableQuestion.ParentId.Value]; + } + if (tableQuestion.RelevanceId != null) + { + tableQuestion.RelevanceId = tableQuestionRelation[tableQuestion.RelevanceId.Value]; ; + } + + if (tableQuestion.DependParentId != null) + { + tableQuestion.DependParentId = tableQuestionRelation[tableQuestion.DependParentId.Value]; ; + } + + needAddTableDatas.Add(tableQuestion); + } + + + await _readingTableQuestionSystemRepository.BatchDeleteNoTrackingAsync(x => x.SystemCriterionId == inDto.ToSystemCriterionId); + await _readingTableQuestionSystemRepository.AddRangeAsync(needAddTableDatas); + await _readingTableQuestionSystemRepository.SaveChangesAsync(); + + } + /// /// 同步标准到项目新(2022-08-10) /// diff --git a/IRaCIS.Core.Application/Service/Reading/_MapConfig.cs b/IRaCIS.Core.Application/Service/Reading/_MapConfig.cs index ed751f17f..d954b9f32 100644 --- a/IRaCIS.Core.Application/Service/Reading/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Reading/_MapConfig.cs @@ -169,10 +169,10 @@ namespace IRaCIS.Core.Application.Service CreateMap(); CreateMap() .ForMember(d => d.QuestionCount, u => u.MapFrom(s => s.ReadingQuestionSystemList.Count())); - //.ForMember(d => d.IsEnable, u => u.MapFrom(s => s.Dictionary.IsEnable)) - //.ForMember(d => d.ShowOrder, u => u.MapFrom(s => s.Dictionary.ShowOrder)); - + //.ForMember(d => d.IsEnable, u => u.MapFrom(s => s.Dictionary.IsEnable)) + //.ForMember(d => d.ShowOrder, u => u.MapFrom(s => s.Dictionary.ShowOrder)); + CreateMap(); CreateMap(); CreateMap() .ForMember(d => d.GroupName, u => u.MapFrom(s => s.GroupInfo==null?s.GroupName:s.GroupInfo.GroupName))