irc-netcore-api/IRaCIS.Core.Application/Triggers/JudgeVisitTaskTrigger.cs

68 lines
3.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using EntityFrameworkCore.Triggered;
using IRaCIS.Core.Domain.Share;
namespace IRaCIS.Core.Application.Triggers
{
public class JudgeVisitTaskTrigger(
IRepository<VisitTask> _visitTaskRepository,
IRepository<ReadingJudgeInfo> _readingJudgeInfoRepository) : IBeforeSaveTrigger<VisitTask>, IAfterSaveTrigger<VisitTask>
{
/// <summary>
/// 因为维护状态先后顺序导致 裁判任务关联的 任务上的JudgeVisitTaskId==nulll 在这里需要重新设置下
///
/// 比如: 申请裁判任务重阅事务里面本来设置了任务上的裁判id,但是因为下面的逻辑,导致设置的值又被清理了,只能重新设置下
/// </summary>
/// <param name="context"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task AfterSave(ITriggerContext<VisitTask> context, CancellationToken cancellationToken)
{
var visitTask = context.Entity;
//裁判任务维护当裁判任务受到影响的时候需要清理任务上关联的裁判任务id
if (context.ChangeType == ChangeType.Added && visitTask.ReadingCategory == ReadingCategory.Judge && visitTask.TaskState == TaskState.Effect)
{
var find = _readingJudgeInfoRepository.Where(t => t.JudgeTaskId == visitTask.Id).FirstOrDefault();
if (find != null)
{
var ids = new Guid[] { find.TaskIdOne, find.TaskIdTwo };
await _visitTaskRepository.BatchUpdateNoTrackingAsync(t => ids.Contains(t.Id), u => new VisitTask() { JudgeVisitTaskId = visitTask.Id });
}
}
}
/// <summary>
/// 比如 两个任务产生了裁判然后其中一个人申请了重阅影响了裁判需要清理之前任务的上裁判id
///
///
/// 因为申请重阅,退回,里面分有序,无序,情况太多,所以不在那块逻辑修改,不然得加多个地方处理,在这里统一处理
/// </summary>
/// <param name="context"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task BeforeSave(ITriggerContext<VisitTask> context, CancellationToken cancellationToken)
{
var visitTask = context.Entity;
//裁判任务维护当裁判任务受到影响的时候需要清理任务上关联的裁判任务id
if (context.ChangeType == ChangeType.Modified)
{
if (visitTask.ReadingCategory == ReadingCategory.Judge && (visitTask.TaskState == TaskState.Adbandon || visitTask.TaskState == TaskState.HaveReturned))
{
var find = _readingJudgeInfoRepository.Where(t => t.JudgeTaskId == visitTask.Id).FirstOrDefault();
if (find != null)
{
var ids = new Guid[] { find.TaskIdOne, find.TaskIdTwo };
await _visitTaskRepository.BatchUpdateNoTrackingAsync(t => ids.Contains(t.Id), u => new VisitTask() { JudgeVisitTaskId = null });
}
}
}
}
}
}