using X1.Domain.Entities.TestCase;
using X1.Domain.Events;
namespace X1.Application.Features.TaskExecution.Events.NodeExecutionEvents;
///
/// 节点执行事件基类
/// 提供通用的事件属性和工厂方法,减少重复代码
///
public abstract class BaseNodeExecutionEvent : INodeExecutionEvent
{
///
/// 事件ID
///
public string EventId { get; set; } = Guid.NewGuid().ToString();
///
/// 任务执行ID
///
public string TaskExecutionId { get; set; } = null!;
///
/// 节点ID
///
public string NodeId { get; set; } = null!;
///
/// 步骤映射类型
///
public StepMapping StepMapping { get; set; }
///
/// 执行人/执行终端ID
///
public string ExecutorId { get; set; } = null!;
///
/// 蜂窝设备运行时编码
///
public string RuntimeCode { get; set; } = null!;
///
/// 测试场景编码
///
public string ScenarioCode { get; set; } = null!;
///
/// 测试场景ID
///
public string ScenarioId { get; set; } = null!;
///
/// 测试用例流程名称
///
public string FlowName { get; set; } = null!;
///
/// 测试用例流程ID
///
public string FlowId { get; set; } = null!;
///
/// 事件时间戳
///
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
///
/// 静态工厂方法:从 NodeExecutionStartedEvent 创建具体事件实例
///
/// 具体的事件类型
/// 原始事件通知
/// 具体事件实例
public static T CreateFrom(NodeExecutionStartedEvent notification) where T : BaseNodeExecutionEvent, new()
{
return new T
{
EventId = Guid.NewGuid().ToString(),
TaskExecutionId = notification.TaskExecutionId,
NodeId = notification.NodeId,
StepMapping = notification.StepMapping,
ExecutorId = notification.ExecutorId,
RuntimeCode = notification.RuntimeCode,
ScenarioCode = notification.ScenarioCode,
ScenarioId = notification.ScenarioId,
FlowName = notification.FlowName,
FlowId = notification.FlowId,
Timestamp = DateTime.UtcNow
};
}
}