删除分割删除对应的绑定和答案
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
61c4d79fa1
commit
751121e878
|
|
@ -12,6 +12,8 @@ using IRaCIS.Core.Infrastructure.Extention;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using IRaCIS.Core.Infra.EFCore;
|
using IRaCIS.Core.Infra.EFCore;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace IRaCIS.Core.Application.Service;
|
namespace IRaCIS.Core.Application.Service;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -85,6 +87,7 @@ public class SegmentationService(IRepository<Segmentation> _segmentationReposito
|
||||||
[HttpDelete("{segmentationId:guid}")]
|
[HttpDelete("{segmentationId:guid}")]
|
||||||
public async Task<IResponseOutput> DeleteSegmentation(Guid segmentationId)
|
public async Task<IResponseOutput> DeleteSegmentation(Guid segmentationId)
|
||||||
{
|
{
|
||||||
|
await DeleteBindingsAndAnswersAsync(segmentationId, null);
|
||||||
var success = await _segmentationRepository.DeleteFromQueryAsync(t => t.Id == segmentationId,true);
|
var success = await _segmentationRepository.DeleteFromQueryAsync(t => t.Id == segmentationId,true);
|
||||||
return ResponseOutput.Ok();
|
return ResponseOutput.Ok();
|
||||||
}
|
}
|
||||||
|
|
@ -138,6 +141,7 @@ public class SegmentationService(IRepository<Segmentation> _segmentationReposito
|
||||||
[HttpDelete("{segmentId:guid}")]
|
[HttpDelete("{segmentId:guid}")]
|
||||||
public async Task<IResponseOutput> DeleteSegment(Guid segmentId)
|
public async Task<IResponseOutput> DeleteSegment(Guid segmentId)
|
||||||
{
|
{
|
||||||
|
await DeleteBindingsAndAnswersAsync(null, segmentId);
|
||||||
var success = await _segmentRepository.DeleteFromQueryAsync(t => t.Id == segmentId, true);
|
var success = await _segmentRepository.DeleteFromQueryAsync(t => t.Id == segmentId, true);
|
||||||
return ResponseOutput.Ok();
|
return ResponseOutput.Ok();
|
||||||
}
|
}
|
||||||
|
|
@ -309,6 +313,44 @@ public class SegmentationService(IRepository<Segmentation> _segmentationReposito
|
||||||
return ResponseOutput.Ok();
|
return ResponseOutput.Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除分割组和分割时的关联数据删除逻辑
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="segmentationId"></param>
|
||||||
|
/// <param name="segmentId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task DeleteBindingsAndAnswersAsync(Guid? segmentationId, Guid? segmentId)
|
||||||
|
{
|
||||||
|
var bindingsQuery = _segmentBindingRepository
|
||||||
|
.WhereIf(segmentationId != null, x => x.SegmentationId == segmentationId)
|
||||||
|
.WhereIf(segmentId != null, x => x.SegmentId == segmentId);
|
||||||
|
|
||||||
|
var bindings = await bindingsQuery.ToListAsync();
|
||||||
|
|
||||||
|
foreach (var binding in bindings)
|
||||||
|
{
|
||||||
|
// 处理问题
|
||||||
|
if (binding.RowId != null && binding.TableQuestionId != null)
|
||||||
|
{
|
||||||
|
await _readingTableQuestionAnswerRepository.DeleteFromQueryAsync(x => x.VisitTaskId == binding.VisitTaskId && x.RowId == binding.RowId && x.TableQuestionId == binding.TableQuestionId);
|
||||||
|
}
|
||||||
|
else if (binding.QuestionId != null)
|
||||||
|
{
|
||||||
|
await _readingTaskQuestionAnswerRepository.DeleteFromQueryAsync(x => x.VisitTaskId == binding.VisitTaskId && x.ReadingQuestionTrialId == binding.QuestionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理绑定关系
|
||||||
|
if (segmentationId != null)
|
||||||
|
{
|
||||||
|
await _segmentBindingRepository.DeleteFromQueryAsync(x => x.SegmentationId == segmentationId);
|
||||||
|
}
|
||||||
|
else if (segmentId != null)
|
||||||
|
{
|
||||||
|
await _segmentBindingRepository.DeleteFromQueryAsync(x => x.SegmentId == segmentId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue