保存分割绑定和答案
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
c84fed8af1
commit
7a8ec6221f
|
|
@ -18,6 +18,16 @@ public class SegmentBindingView : SegmentBindingAddOrEdit
|
|||
|
||||
}
|
||||
|
||||
public class SaveSegmentBindingAndAnswerInDto
|
||||
{
|
||||
public Guid VisitTaskId { get; set; }
|
||||
public List<SaveSegmentBindingDto> BindingList { get; set; }
|
||||
}
|
||||
|
||||
public class SaveSegmentBindingDto : SegmentBindingAddOrEdit
|
||||
{
|
||||
public string Answer { get; set; }
|
||||
}
|
||||
|
||||
public class SegmentBindingAddOrEdit
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@ namespace IRaCIS.Core.Application.Service;
|
|||
[ ApiExplorerSettings(GroupName = "Reading")]
|
||||
public class SegmentationService(IRepository<Segmentation> _segmentationRepository,
|
||||
IRepository<SegmentBinding> _segmentBindingRepository,
|
||||
IRepository<ReadingTaskQuestionAnswer> _readingTaskQuestionAnswerRepository,
|
||||
IRepository<VisitTask> _visitTaskRepository,
|
||||
IRepository<ReadingTableAnswerRowInfo> _readingTableAnswerRowInfoRepository,
|
||||
IRepository<ReadingTableQuestionAnswer> _readingTableQuestionAnswerRepository,
|
||||
IRepository<Segment> _segmentRepository,
|
||||
IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer): BaseService, ISegmentationService
|
||||
{
|
||||
|
|
@ -146,15 +150,13 @@ public class SegmentationService(IRepository<Segmentation> _segmentationReposito
|
|||
{
|
||||
|
||||
var segmentBindingQueryable = _segmentBindingRepository
|
||||
.WhereIf(inQuery.QuestionId != null, x => x.QuestionId == inQuery.QuestionId)
|
||||
.WhereIf(inQuery.RowId != null, x => x.RowId == inQuery.RowId)
|
||||
.WhereIf(inQuery.SegmentId != null, x => x.SegmentId == inQuery.SegmentId)
|
||||
.WhereIf(inQuery.SegmentationId != null, x => x.SegmentationId == inQuery.SegmentationId)
|
||||
.WhereIf(inQuery.TableQuestionId != null, x => x.TableQuestionId == inQuery.TableQuestionId)
|
||||
|
||||
.WhereIf(inQuery.VisitTaskId != null, x => x.VisitTaskId == inQuery.VisitTaskId)
|
||||
|
||||
.ProjectTo<SegmentBindingView>(_mapper.ConfigurationProvider);
|
||||
.WhereIf(inQuery.QuestionId != null, x => x.QuestionId == inQuery.QuestionId)
|
||||
.WhereIf(inQuery.RowId != null, x => x.RowId == inQuery.RowId)
|
||||
.WhereIf(inQuery.SegmentId != null, x => x.SegmentId == inQuery.SegmentId)
|
||||
.WhereIf(inQuery.SegmentationId != null, x => x.SegmentationId == inQuery.SegmentationId)
|
||||
.WhereIf(inQuery.TableQuestionId != null, x => x.TableQuestionId == inQuery.TableQuestionId)
|
||||
.WhereIf(inQuery.VisitTaskId != null, x => x.VisitTaskId == inQuery.VisitTaskId)
|
||||
.ProjectTo<SegmentBindingView>(_mapper.ConfigurationProvider);
|
||||
|
||||
var pageList = await segmentBindingQueryable.ToPagedListAsync(inQuery);
|
||||
|
||||
|
|
@ -190,6 +192,107 @@ public class SegmentationService(IRepository<Segmentation> _segmentationReposito
|
|||
return ResponseOutput.Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存分割绑定和答案
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IResponseOutput> SaveSegmentBindingAndAnswer(SaveSegmentBindingAndAnswerInDto inDto)
|
||||
{
|
||||
|
||||
var taskinfo = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId)
|
||||
.FirstNotNullAsync();
|
||||
foreach (var item in inDto.BindingList)
|
||||
{
|
||||
// 处理绑定关系
|
||||
var binding = await _segmentBindingRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId && x.QuestionId == item.QuestionId && x.RowId == item.RowId && x.TableQuestionId == item.TableQuestionId)
|
||||
.FirstOrDefaultAsync();
|
||||
if (binding == null)
|
||||
{
|
||||
await _segmentBindingRepository.InsertFromDTOAsync(new SegmentBinding
|
||||
{
|
||||
VisitTaskId = inDto.VisitTaskId,
|
||||
QuestionId = item.QuestionId,
|
||||
RowId = item.RowId,
|
||||
TableQuestionId = item.TableQuestionId,
|
||||
SegmentId = item.SegmentId,
|
||||
SegmentationId = item.SegmentationId,
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
await _segmentBindingRepository.UpdatePartialFromQueryAsync(x => x.Id == binding.Id, t => new SegmentBinding
|
||||
{
|
||||
SegmentId = item.SegmentId,
|
||||
SegmentationId = item.SegmentationId,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 处理问题
|
||||
if (item.RowId != null && item.TableQuestionId != null)
|
||||
{
|
||||
var answer = await _readingTableQuestionAnswerRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId && x.RowId == item.VisitTaskId && x.TableQuestionId == item.TableQuestionId)
|
||||
.FirstOrDefaultAsync();
|
||||
var rowinfo= await _readingTableAnswerRowInfoRepository.Where(x => x.Id==item.RowId)
|
||||
.Include(x=>x.VisitTask)
|
||||
.FirstNotNullAsync();
|
||||
if (answer != null)
|
||||
{
|
||||
await _readingTableQuestionAnswerRepository.UpdatePartialFromQueryAsync(x => x.Id == answer.Id, t => new ReadingTableQuestionAnswer
|
||||
{
|
||||
Answer = item.Answer
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
await _readingTableQuestionAnswerRepository.InsertFromDTOAsync(new ReadingTableQuestionAnswer
|
||||
{
|
||||
VisitTaskId = inDto.VisitTaskId,
|
||||
RowId = item.RowId.Value,
|
||||
TableQuestionId = item.TableQuestionId.Value,
|
||||
Answer = item.Answer,
|
||||
TrialId= rowinfo.VisitTask.TrialId,
|
||||
RowIndex= rowinfo.RowIndex,
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var answer = await _readingTaskQuestionAnswerRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId &&x.ReadingQuestionTrialId==item.QuestionId)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (answer != null)
|
||||
{
|
||||
await _readingTaskQuestionAnswerRepository.UpdatePartialFromQueryAsync(x => x.Id == answer.Id, t => new ReadingTaskQuestionAnswer
|
||||
{
|
||||
Answer = item.Answer
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
await _readingTaskQuestionAnswerRepository.InsertFromDTOAsync(new ReadingTaskQuestionAnswer
|
||||
{
|
||||
ReadingQuestionTrialId= item.QuestionId.Value,
|
||||
ReadingQuestionCriterionTrialId=taskinfo.TrialReadingCriterionId,
|
||||
TrialId= taskinfo.TrialId,
|
||||
SubjectId= taskinfo.SubjectId,
|
||||
VisitTaskId = inDto.VisitTaskId,
|
||||
Answer=item.Answer,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
await _segmentationRepository.SaveChangesAsync();
|
||||
return ResponseOutput.Ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue