修改QC问题

This commit is contained in:
2023-01-03 13:32:22 +08:00
parent 55d2ec2dd7
commit b8e21e5265
6 changed files with 102 additions and 25 deletions
@@ -73,7 +73,9 @@ namespace IRaCIS.Core.Application.Contracts
public bool? IsEnable { get; set; }
public Guid? TrialId { get; set; }
public bool IsDefeaultViewParent { get; set; }
}
@@ -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<QCQuestionConfigureView>(_mapper.ConfigurationProvider);
@@ -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<TrialQCQuestion>>(list);
var childList = new List<TrialQCQuestion>();
//遍历父层级的问题
var batchConfigList = _mapper.Map<List<TrialQCQuestion>>(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<List<TrialQCQuestion>>(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<TrialQCQuestion> GetChildList(Guid parentId, Guid newParentId, List<TrialQCQuestion> list)
{
var childList = new List<TrialQCQuestion>();
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<IResponseOutput> 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("序号重复,操作失败");
@@ -225,6 +225,7 @@ namespace IRaCIS.Core.Application.Service
CreateMap<QCQuestionAddOrEdit, QCQuestion>();
CreateMap<QCQuestion, TrialQCQuestion>();
CreateMap<TrialQCQuestionAddOrEdit, TrialQCQuestion>();
CreateMap<TrialQCQuestionConfigureBatchAdd, TrialQCQuestion>();