Compare commits

..

2 Commits

Author SHA1 Message Date
he 27bdc95f6e Merge branch 'Test_IRC_Net8' of https://gitea.frp.extimaging.com/XCKJ/irc-netcore-api into Test_IRC_Net8
continuous-integration/drone/push Build is passing Details
2026-04-24 11:14:12 +08:00
he d74e3a9f60 删除关联问题答案 2026-04-24 11:14:03 +08:00
1 changed files with 44 additions and 0 deletions

View File

@ -31,6 +31,8 @@ public class SegmentationService(IRepository<Segmentation> _segmentationReposito
IRepository<ReadingTableAnswerRowInfo> _readingTableAnswerRowInfoRepository,
IRepository<ReadingTableQuestionAnswer> _readingTableQuestionAnswerRepository,
IRepository<Segment> _segmentRepository,
IRepository<ReadingQuestionTrial> _readingQuestionTrialRepository,
IRepository<ReadingTableQuestionTrial> _readingTableQuestionTrialRepository,
IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer): BaseService, ISegmentationService
{
@ -347,14 +349,20 @@ public class SegmentationService(IRepository<Segmentation> _segmentationReposito
foreach (var binding in bindings)
{
var visited = new HashSet<Guid>();
// 处理问题
if (binding.RowId != null && binding.TableQuestionId != null)
{
await _readingTableQuestionAnswerRepository.DeleteFromQueryAsync(x => x.VisitTaskId == binding.VisitTaskId && x.RowId == binding.RowId && x.TableQuestionId == binding.TableQuestionId);
await DeleteDependentAnswersAsync(binding.TableQuestionId.Value, binding.VisitTaskId, binding.RowId, visited);
}
else if (binding.QuestionId != null)
{
await _readingTaskQuestionAnswerRepository.DeleteFromQueryAsync(x => x.VisitTaskId == binding.VisitTaskId && x.ReadingQuestionTrialId == binding.QuestionId);
await DeleteDependentAnswersAsync(binding.QuestionId.Value, binding.VisitTaskId, null, visited);
}
}
@ -369,6 +377,42 @@ public class SegmentationService(IRepository<Segmentation> _segmentationReposito
}
}
/// <summary>
/// 递归清除依赖此问题的计算问题答案
/// </summary>
private async Task DeleteDependentAnswersAsync(Guid sourceQuestionId, Guid visitTaskId, Guid? rowId, HashSet<Guid> visited)
{
if (visited.Contains(sourceQuestionId)) return;
visited.Add(sourceQuestionId);
var sourceQuestionIdStr = sourceQuestionId.ToString();
var dependentTableQuestions = await _readingTableQuestionTrialRepository
.Where(x => x.DataSource == DataSources.Automatic && x.Type == "number" && x.CalculateQuestions.Contains(sourceQuestionIdStr))
.Select(x => x.Id)
.ToListAsync();
foreach (var tableQuestionId in dependentTableQuestions)
{
if (rowId != null)
{
await _readingTableQuestionAnswerRepository.DeleteFromQueryAsync(x => x.VisitTaskId == visitTaskId && x.RowId == rowId && x.TableQuestionId == tableQuestionId);
}
await DeleteDependentAnswersAsync(tableQuestionId, visitTaskId, rowId, visited);
}
var dependentTaskQuestions = await _readingQuestionTrialRepository
.Where(x => x.DataSource == DataSources.Automatic && x.Type == "number" && x.CalculateQuestions.Contains(sourceQuestionIdStr))
.Select(x => x.Id)
.ToListAsync();
foreach (var taskQuestionId in dependentTaskQuestions)
{
await _readingTaskQuestionAnswerRepository.DeleteFromQueryAsync(x => x.VisitTaskId == visitTaskId && x.ReadingQuestionTrialId == taskQuestionId);
await DeleteDependentAnswersAsync(taskQuestionId, visitTaskId, rowId, visited);
}
}
}