diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs index a1f1f58b6..1ff683ceb 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs @@ -1505,6 +1505,20 @@ namespace IRaCIS.Application.Services [HttpPost] public async Task SubmitTableQuestion(SubmitTableQuestionInDto inDto) { + var tableQuestionIds = inDto.AnswerList.Select(x => x.TableQuestionId).ToList(); + var questions = await _readingTableQuestionTrialRepository.Where(x => tableQuestionIds.Contains(x.Id) && x.MaxRowCount != null).ToListAsync(); + + foreach (var item in questions) + { + var answer = inDto.AnswerList.Where(x => x.TableQuestionId == item.Id).Select(x => x.Answer).FirstOrDefault(); + if ((await _readingTableQuestionAnswerRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId && x.TableQuestionId == item.Id && x.Answer == answer).CountAsync()) > item.MaxRowCount.Value - 1) + { + throw new BusinessValidationFailedException($"问题{item.QuestionName}最大相同问题数为{item.MaxRowCount.Value},当前已超过!"); + } + } + + + await _readingTableQuestionAnswerRepository.BatchDeleteNoTrackingAsync(x => x.VisitTaskId == inDto.VisitTaskId && x.QuestionId == inDto.QuestionId && x.TrialId == inDto.TrialId && x.RowIndex == inDto.RowIndex); await _readingTableAnswerRowInfoRepository.BatchDeleteNoTrackingAsync(x => x.VisitTaskId == inDto.VisitTaskId && x.QuestionId == inDto.QuestionId && x.TrialId == inDto.TrialId && x.RowIndex == inDto.RowIndex); List answerList = inDto.AnswerList.Select(x => new ReadingTableQuestionAnswer()