diff --git a/IRaCIS.Core.Application/Service/QC/DTO/QCQuestionConfigureViewModel.cs b/IRaCIS.Core.Application/Service/QC/DTO/QCQuestionConfigureViewModel.cs index de70c0e8..98cbf559 100644 --- a/IRaCIS.Core.Application/Service/QC/DTO/QCQuestionConfigureViewModel.cs +++ b/IRaCIS.Core.Application/Service/QC/DTO/QCQuestionConfigureViewModel.cs @@ -73,7 +73,9 @@ namespace IRaCIS.Core.Application.Contracts public bool? IsEnable { get; set; } - public Guid? TrialId { get; set; } + public bool IsDefeaultViewParent { get; set; } + + } diff --git a/IRaCIS.Core.Application/Service/QC/QCQuestionService.cs b/IRaCIS.Core.Application/Service/QC/QCQuestionService.cs index b4970f85..32c51fa3 100644 --- a/IRaCIS.Core.Application/Service/QC/QCQuestionService.cs +++ b/IRaCIS.Core.Application/Service/QC/QCQuestionService.cs @@ -95,6 +95,7 @@ namespace IRaCIS.Core.Application.Contracts .WhereIf(queryQCQuestionConfigure.IsEnable != null,x=>x.IsEnable== queryQCQuestionConfigure.IsEnable) .WhereIf(!string.IsNullOrWhiteSpace(queryQCQuestionConfigure.QuestionName), t => t.QuestionName.Contains(queryQCQuestionConfigure.QuestionName)) .WhereIf(!string.IsNullOrWhiteSpace(queryQCQuestionConfigure.Type), t => t.Type.Contains(queryQCQuestionConfigure.Type)) + .WhereIf(queryQCQuestionConfigure.IsDefeaultViewParent==true,t=>t.ParentId==null) .OrderBy(t=>t.ShowOrder) .ProjectTo(_mapper.ConfigurationProvider); diff --git a/IRaCIS.Core.Application/Service/QC/TrialQCQuestionService.cs b/IRaCIS.Core.Application/Service/QC/TrialQCQuestionService.cs index 99d39667..4edca22e 100644 --- a/IRaCIS.Core.Application/Service/QC/TrialQCQuestionService.cs +++ b/IRaCIS.Core.Application/Service/QC/TrialQCQuestionService.cs @@ -40,7 +40,7 @@ namespace IRaCIS.Core.Application.Contracts var trialQCQuestionQueryable = _trialQcQuestionRepository.Where(t => t.TrialId == queryTrialQCQuestionConfigure.TrialId) .WhereIf(!string.IsNullOrWhiteSpace(queryTrialQCQuestionConfigure.QuestionName), t => t.QuestionName.Contains(queryTrialQCQuestionConfigure.QuestionName)) .WhereIf(!string.IsNullOrWhiteSpace(queryTrialQCQuestionConfigure.Type), t => t.Type.Contains(queryTrialQCQuestionConfigure.Type)) - .WhereIf(queryTrialQCQuestionConfigure.IsEnable!=null, t => t.IsEnable== queryTrialQCQuestionConfigure.IsEnable) + .WhereIf(queryTrialQCQuestionConfigure.IsEnable != null, t => t.IsEnable == queryTrialQCQuestionConfigure.IsEnable) .WhereIf(queryTrialQCQuestionConfigure.IsRequired != null, t => t.IsRequired == queryTrialQCQuestionConfigure.IsRequired) @@ -139,49 +139,113 @@ namespace IRaCIS.Core.Application.Contracts { await VerifyIsQCConfirmedAsync(trialId); - var maxShowOrder = await _trialQcQuestionRepository.Where(x => x.TrialId == trialId).OrderByDescending(x=>x.ShowOrder).Select(x => x.ShowOrder).FirstOrDefaultAsync(); - batchList.ForEach(x => - { - maxShowOrder++; - x.ShowOrder= maxShowOrder; - x.SystemQuestionId = x.Id.Value; - x.Id = NewId.NextGuid(); - }); + var maxShowOrder = await _trialQcQuestionRepository.Where(x => x.TrialId == trialId).OrderByDescending(x => x.ShowOrder).Select(x => x.ShowOrder).FirstOrDefaultAsync(); + maxShowOrder++; - foreach (var item in batchList.Where(x=>x.ParentId!=null)) + #region OLd + //batchList.ForEach(x => + //{ + // maxShowOrder++; + // x.ShowOrder = maxShowOrder; + // x.SystemQuestionId = x.Id.Value; + // x.Id = NewId.NextGuid(); + + //}); + + //foreach (var item in batchList.Where(x => x.ParentId != null)) + //{ + // var parent = batchList.Where(x => x.SystemQuestionId == item.ParentId).FirstOrDefault(); + // if (parent == null) + // { + // item.ParentId = null; + // item.ParentTriggerValue = String.Empty; + // } + // else + // { + // item.ParentId = parent.Id; + // } + //} + + #endregion + + #region New + //查询所有的子问题 + var list = await _qCQuestionRepository.Where(t => t.ParentId != null).ToListAsync(); + + var mappedList = _mapper.Map>(list); + + var childList = new List(); + + //遍历父层级的问题 + var batchConfigList = _mapper.Map>(batchList.Where(t => t.ParentId == null)); + + foreach (var item in batchConfigList.Where(t=>t.ParentId==null).OrderBy(t => t.ShowOrder)) { - var parent = batchList.Where(x => x.SystemQuestionId == item.ParentId).FirstOrDefault(); - if (parent == null) + var oldParentId = item.Id; + item.Id = NewId.NextGuid(); + item.TrialId = trialId; + item.ShowOrder = maxShowOrder++; + + var findChildList = GetChildList(oldParentId, item.Id, mappedList); + + + foreach (var findChild in findChildList) { - item.ParentId = null; - item.ParentTriggerValue = String.Empty; - } - else - { - item.ParentId = parent.Id; + + findChild.TrialId = trialId; + + findChild.ShowOrder = maxShowOrder++; } + + childList.AddRange(findChildList); } - - var batchConfigList = _mapper.Map>(batchList); - batchConfigList.ForEach(t => t.TrialId = trialId); + #endregion + await _trialQcQuestionRepository.AddRangeAsync(batchConfigList); + await _trialQcQuestionRepository.AddRangeAsync(childList); + var success = await _repository.SaveChangesAsync(); return ResponseOutput.Result(success); } + + private List GetChildList(Guid parentId, Guid newParentId, List list) + { + var childList = new List(); + + var findlist = list.Where(t => t.ParentId == parentId).ToList(); + + foreach (var child in findlist) + { + var oldParentId = child.Id; + + child.Id = NewId.NextGuid(); + child.ParentId = newParentId; + + childList.Add(child); + + var findList = GetChildList(oldParentId, child.Id, list); + + childList.AddRange(findList); + + } + + return childList; + } + [Authorize(Policy = IRaCISPolicy.IQC)] public async Task AddOrUpdateTrialQCQuestionConfigure(TrialQCQuestionAddOrEdit addOrEditTrialQCQuestionConfigure) { - if (await _trialQcQuestionRepository.AnyAsync(x =>x.TrialId== addOrEditTrialQCQuestionConfigure.TrialId&& x.Id != addOrEditTrialQCQuestionConfigure.Id && x.ShowOrder == addOrEditTrialQCQuestionConfigure.ShowOrder)) + if (await _trialQcQuestionRepository.AnyAsync(x => x.TrialId == addOrEditTrialQCQuestionConfigure.TrialId && x.Id != addOrEditTrialQCQuestionConfigure.Id && x.ShowOrder == addOrEditTrialQCQuestionConfigure.ShowOrder)) { throw new BusinessValidationFailedException("序号重复,操作失败"); diff --git a/IRaCIS.Core.Application/Service/QC/_MapConfig.cs b/IRaCIS.Core.Application/Service/QC/_MapConfig.cs index 1e97e266..cfe2a531 100644 --- a/IRaCIS.Core.Application/Service/QC/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/QC/_MapConfig.cs @@ -225,6 +225,7 @@ namespace IRaCIS.Core.Application.Service CreateMap(); + CreateMap(); CreateMap(); CreateMap(); diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index 81b061fd..09671bbe 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -101,9 +101,13 @@ namespace IRaCIS.Application.Services //await _repository.BatchUpdateAsync(t => t.TrialId == Guid.Parse("40400000-3e2c-0016-239b-08da581f0e74") && t.EntityName== "ClinicalDataTrialSet", t => new DataInspection() { CreateTime= DateTime.Now.AddMonths(-2) } ); - await _visitTaskRepositoryy.UpdatePartialFromQueryAsync( Guid.Parse("78360000-3E2C-0016-9B53-08DA6A002040"), c => new VisitTask() { UpdateTime = DateTime.Now }); + //await _visitTaskRepositoryy.UpdatePartialFromQueryAsync( Guid.Parse("78360000-3E2C-0016-9B53-08DA6A002040"), c => new VisitTask() { UpdateTime = DateTime.Now }); - await _visitTaskRepositoryy.UpdatePartialFromQueryAsync( Guid.Parse("78360000-3E2C-0016-9B53-08DA6A002040"), c => new VisitTask() { UpdateTime = DateTime.Now.AddMinutes(1) }); + //await _visitTaskRepositoryy.UpdatePartialFromQueryAsync( Guid.Parse("78360000-3E2C-0016-9B53-08DA6A002040"), c => new VisitTask() { UpdateTime = DateTime.Now.AddMinutes(1) }); + + + var list1 = await _repository.Where().Select(t => t.TranslateValue(t.Value, t.ValueCN,true)).ToListAsync(); + var list2 = await _repository.Where().Select(t => t.TranslateValue(t.Value, t.ValueCN, false)).ToListAsync(); await _repository.SaveChangesAsync(); return _userInfo.LocalIp; diff --git a/IRaCIS.Core.Domain/Common/Dictionary.cs b/IRaCIS.Core.Domain/Common/Dictionary.cs index f169c9a7..6b518574 100644 --- a/IRaCIS.Core.Domain/Common/Dictionary.cs +++ b/IRaCIS.Core.Domain/Common/Dictionary.cs @@ -1,3 +1,4 @@ +using EntityFrameworkCore.Projectables; using IRaCIS.Core.Domain.Share; using System; using System.Collections.Generic; @@ -62,5 +63,9 @@ namespace IRaCIS.Core.Domain.Models public string MappedValue { get; set; } + [Projectable] + public string TranslateValue( string value, string valueCN,bool isCN) => isCN?valueCN:value; + + } }