using OrpaonVision.Core.Results; namespace OrpaonVision.Core.LayerTransition; /// /// 层级转换服务接口。 /// public interface ILayerTransitionService { /// /// 检查是否可以前进到下一层。 /// /// 当前层级。 /// 转换上下文。 /// 取消令牌。 /// 检查结果。 Task> CheckCanMoveForwardAsync(int currentLayer, LayerTransitionContext transitionContext, CancellationToken cancellationToken = default); /// /// 检查是否可以后退到上一层。 /// /// 当前层级。 /// 转换上下文。 /// 取消令牌。 /// 检查结果。 Task> CheckCanMoveBackwardAsync(int currentLayer, LayerTransitionContext transitionContext, CancellationToken cancellationToken = default); /// /// 执行层级转换。 /// /// 转换请求。 /// 取消令牌。 /// 转换结果。 Task> ExecuteTransitionAsync(LayerTransitionRequest transitionRequest, CancellationToken cancellationToken = default); /// /// 回滚层级转换。 /// /// 回滚请求。 /// 取消令牌。 /// 回滚结果。 Task> RollbackTransitionAsync(LayerTransitionRollbackRequest rollbackRequest, CancellationToken cancellationToken = default); /// /// 获取层级转换保护配置。 /// /// 产品类型编码。 /// 层级编号。 /// 取消令牌。 /// 保护配置。 Task> GetProtectionConfigAsync(string productTypeCode, int layerNumber, CancellationToken cancellationToken = default); /// /// 更新层级转换保护配置。 /// /// 保护配置。 /// 取消令牌。 /// 更新结果。 Task UpdateProtectionConfigAsync(LayerTransitionProtectionConfig config, CancellationToken cancellationToken = default); /// /// 获取层级转换历史。 /// /// 开始时间。 /// 结束时间。 /// 取消令牌。 /// 转换历史。 Task>> GetTransitionHistoryAsync(DateTime startTime, DateTime endTime, CancellationToken cancellationToken = default); /// /// 获取层级转换统计信息。 /// /// 开始时间。 /// 结束时间。 /// 取消令牌。 /// 统计信息。 Task> GetTransitionStatisticsAsync(DateTime startTime, DateTime endTime, CancellationToken cancellationToken = default); } /// /// 层级转换上下文。 /// public sealed class LayerTransitionContext { /// /// 产品类型编码。 /// public string ProductTypeCode { get; init; } = string.Empty; /// /// 会话ID。 /// public string SessionId { get; init; } = string.Empty; /// /// 当前层级完成状态。 /// public bool IsCurrentLayerCompleted { get; init; } /// /// 层级完成度。 /// public double CompletionPercentage { get; init; } /// /// 层级完成时间。 /// public DateTime? LayerCompletionTimeUtc { get; init; } /// /// 是否存在错误。 /// public bool HasErrors { get; init; } /// /// 错误信息。 /// public IReadOnlyList ErrorMessages { get; init; } = Array.Empty(); /// /// 是否需要人工干预。 /// public bool RequiresManualIntervention { get; init; } /// /// 人工干预原因。 /// public string? ManualInterventionReason { get; init; } /// /// 扩展属性。 /// public Dictionary ExtendedProperties { get; init; } = new(); } /// /// 层级转换检查结果。 /// public sealed class LayerTransitionCheckResult { /// /// 是否允许转换。 /// public bool CanTransition { get; init; } /// /// 转换类型。 /// public LayerTransitionType TransitionType { get; init; } /// /// 检查时间。 /// public DateTime CheckTimeUtc { get; init; } /// /// 允许转换的原因。 /// public string? AllowReason { get; init; } /// /// 拒绝转换的原因。 /// public string? DenyReason { get; init; } /// /// 保护策略。 /// public LayerTransitionProtectionStrategy ProtectionStrategy { get; init; } /// /// 保护条件检查结果。 /// public IReadOnlyList ProtectionConditionChecks { get; init; } = Array.Empty(); /// /// 建议等待时间(秒)。 /// public int SuggestedWaitTimeSeconds { get; init; } /// /// 扩展属性。 /// public Dictionary ExtendedProperties { get; init; } = new(); } /// /// 保护条件检查结果。 /// public sealed class ProtectionConditionCheckResult { /// /// 条件名称。 /// public string ConditionName { get; init; } = string.Empty; /// /// 是否满足条件。 /// public bool IsConditionMet { get; init; } /// /// 条件类型。 /// public ProtectionConditionType ConditionType { get; init; } /// /// 实际值。 /// public double ActualValue { get; init; } /// /// 阈值。 /// public double Threshold { get; init; } /// /// 检查详情。 /// public string? Details { get; init; } /// /// 扩展属性。 /// public Dictionary ExtendedProperties { get; init; } = new(); } /// /// 层级转换请求。 /// public sealed class LayerTransitionRequest { /// /// 请求ID。 /// public Guid RequestId { get; init; } /// /// 产品类型编码。 /// public string ProductTypeCode { get; init; } = string.Empty; /// /// 会话ID。 /// public string SessionId { get; init; } = string.Empty; /// /// 当前层级。 /// public int CurrentLayer { get; init; } /// /// 目标层级。 /// public int TargetLayer { get; init; } /// /// 转换类型。 /// public LayerTransitionType TransitionType { get; init; } /// /// 转换原因。 /// public string Reason { get; init; } = string.Empty; /// /// 请求用户。 /// public string RequestUser { get; init; } = string.Empty; /// /// 是否强制转换(忽略保护策略)。 /// public bool IsForced { get; init; } /// /// 强制转换原因。 /// public string? ForceReason { get; init; } /// /// 请求时间。 /// public DateTime RequestTimeUtc { get; init; } /// /// 扩展属性。 /// public Dictionary ExtendedProperties { get; init; } = new(); } /// /// 层级转换结果。 /// public sealed class LayerTransitionResult { /// /// 转换是否成功。 /// public bool IsSuccess { get; init; } /// /// 转换ID。 /// public Guid TransitionId { get; init; } /// /// 请求ID。 /// public Guid RequestId { get; init; } /// /// 转换类型。 /// public LayerTransitionType TransitionType { get; init; } /// /// 源层级。 /// public int SourceLayer { get; init; } /// /// 目标层级。 /// public int TargetLayer { get; init; } /// /// 转换时间。 /// public DateTime TransitionTimeUtc { get; init; } /// /// 转换耗时(毫秒)。 /// public long TransitionElapsedMs { get; init; } /// /// 转换结果描述。 /// public string? ResultDescription { get; init; } /// /// 是否触发了保护策略。 /// public bool ProtectionTriggered { get; init; } /// /// 触发的保护策略。 /// public LayerTransitionProtectionStrategy TriggeredProtectionStrategy { get; init; } /// /// 回滚信息。 /// public LayerTransitionRollbackInfo? RollbackInfo { get; init; } /// /// 扩展属性。 /// public Dictionary ExtendedProperties { get; init; } = new(); } /// /// 层级转换回滚请求。 /// public sealed class LayerTransitionRollbackRequest { /// /// 请求ID。 /// public Guid RequestId { get; init; } /// /// 原转换ID。 /// public Guid OriginalTransitionId { get; init; } /// /// 产品类型编码。 /// public string ProductTypeCode { get; init; } = string.Empty; /// /// 会话ID。 /// public string SessionId { get; init; } = string.Empty; /// /// 当前层级。 /// public int CurrentLayer { get; init; } /// /// 回滚目标层级。 /// public int RollbackTargetLayer { get; init; } /// /// 回滚原因。 /// public string Reason { get; init; } = string.Empty; /// /// 回滚用户。 /// public string RollbackUser { get; init; } = string.Empty; /// /// 回滚时间。 /// public DateTime RollbackTimeUtc { get; init; } /// /// 扩展属性。 /// public Dictionary ExtendedProperties { get; init; } = new(); } /// /// 层级转换回滚信息。 /// public sealed class LayerTransitionRollbackInfo { /// /// 回滚ID。 /// public Guid RollbackId { get; init; } /// /// 原转换ID。 /// public Guid OriginalTransitionId { get; init; } /// /// 回滚时间。 /// public DateTime RollbackTimeUtc { get; init; } /// /// 回滚原因。 /// public string RollbackReason { get; init; } = string.Empty; /// /// 回滚用户。 /// public string RollbackUser { get; init; } = string.Empty; /// /// 扩展属性。 /// public Dictionary ExtendedProperties { get; init; } = new(); } /// /// 层级转换保护配置。 /// public sealed class LayerTransitionProtectionConfig { /// /// 配置ID。 /// public Guid ConfigId { get; init; } /// /// 产品类型编码。 /// public string ProductTypeCode { get; init; } = string.Empty; /// /// 层级编号。 /// public int LayerNumber { get; init; } /// /// 保护策略。 /// public LayerTransitionProtectionStrategy ProtectionStrategy { get; init; } /// /// 最小停留时间(秒)。 /// public int MinimumStayTimeSeconds { get; init; } /// /// 最大停留时间(秒)。 /// public int MaximumStayTimeSeconds { get; init; } /// /// 完成度阈值(百分比)。 /// public double CompletionThreshold { get; init; } /// /// 是否允许强制转换。 /// public bool AllowForceTransition { get; init; } /// /// 强制转换所需权限。 /// public string RequiredPermissionForForce { get; init; } = string.Empty; /// /// 是否启用自动回滚。 /// public bool EnableAutoRollback { get; init; } /// /// 自动回滚条件。 /// public IReadOnlyList AutoRollbackConditions { get; init; } = Array.Empty(); /// /// 保护条件列表。 /// public IReadOnlyList ProtectionConditions { get; init; } = Array.Empty(); /// /// 是否启用。 /// public bool IsEnabled { get; init; } = true; /// /// 创建时间。 /// public DateTime CreatedAtUtc { get; init; } /// /// 更新时间。 /// public DateTime UpdatedAtUtc { get; init; } /// /// 版本号。 /// public string Version { get; init; } = "1.0"; /// /// 扩展属性。 /// public Dictionary ExtendedProperties { get; init; } = new(); } /// /// 保护条件。 /// public sealed class ProtectionCondition { /// /// 条件ID。 /// public Guid ConditionId { get; init; } /// /// 条件名称。 /// public string ConditionName { get; init; } = string.Empty; /// /// 条件类型。 /// public ProtectionConditionType ConditionType { get; init; } /// /// 是否为必须满足的条件。 /// public bool IsMandatory { get; init; } = true; /// /// 阈值。 /// public double Threshold { get; init; } /// /// 比较操作符。 /// public ComparisonOperator ComparisonOperator { get; init; } /// /// 条件描述。 /// public string? Description { get; init; } /// /// 扩展属性。 /// public Dictionary ExtendedProperties { get; init; } = new(); } /// /// 自动回滚条件。 /// public sealed class AutoRollbackCondition { /// /// 条件ID。 /// public Guid ConditionId { get; init; } /// /// 条件名称。 /// public string ConditionName { get; init; } = string.Empty; /// /// 条件类型。 /// public AutoRollbackConditionType ConditionType { get; init; } /// /// 阈值。 /// public double Threshold { get; init; } /// /// 检查间隔(秒)。 /// public int CheckIntervalSeconds { get; init; } /// /// 连续失败次数阈值。 /// public int ConsecutiveFailuresThreshold { get; init; } /// /// 条件描述。 /// public string? Description { get; init; } /// /// 扩展属性。 /// public Dictionary ExtendedProperties { get; init; } = new(); } /// /// 层级转换历史。 /// public sealed class LayerTransitionHistory { /// /// 转换ID。 /// public Guid TransitionId { get; init; } /// /// 产品类型编码。 /// public string ProductTypeCode { get; init; } = string.Empty; /// /// 会话ID。 /// public string SessionId { get; init; } = string.Empty; /// /// 转换类型。 /// public LayerTransitionType TransitionType { get; init; } /// /// 源层级。 /// public int SourceLayer { get; init; } /// /// 目标层级。 /// public int TargetLayer { get; init; } /// /// 转换时间。 /// public DateTime TransitionTimeUtc { get; init; } /// /// 转换是否成功。 /// public bool IsSuccess { get; init; } /// /// 转换原因。 /// public string Reason { get; init; } = string.Empty; /// /// 操作用户。 /// public string OperatorUser { get; init; } = string.Empty; /// /// 是否强制转换。 /// public bool IsForced { get; init; } /// /// 保护策略是否触发。 /// public bool ProtectionTriggered { get; init; } /// /// 回滚信息。 /// public LayerTransitionRollbackInfo? RollbackInfo { get; init; } /// /// 扩展属性。 /// public Dictionary ExtendedProperties { get; init; } = new(); } /// /// 层级转换统计信息。 /// public sealed class LayerTransitionStatistics { /// /// 总转换次数。 /// public int TotalTransitions { get; init; } /// /// 成功转换次数。 /// public int SuccessfulTransitions { get; init; } /// /// 失败转换次数。 /// public int FailedTransitions { get; init; } /// /// 总体成功率。 /// public double OverallSuccessRate => TotalTransitions > 0 ? (double)SuccessfulTransitions / TotalTransitions * 100 : 0.0; /// /// 按转换类型分组的统计。 /// public Dictionary ByTransitionType { get; init; } = new(); /// /// 按产品类型分组的统计。 /// public Dictionary ByProductType { get; init; } = new(); /// /// 按层级分组的统计。 /// public Dictionary ByLayer { get; init; } = new(); /// /// 强制转换统计。 /// public ForceTransitionStatistics ForceTransitions { get; init; } = new(); /// /// 保护触发统计。 /// public ProtectionTriggerStatistics ProtectionTriggers { get; init; } = new(); /// /// 统计开始时间。 /// public DateTime StartTimeUtc { get; init; } /// /// 统计结束时间。 /// public DateTime EndTimeUtc { get; init; } } /// /// 转换类型统计。 /// public sealed class TransitionTypeStatistics { /// /// 转换类型。 /// public LayerTransitionType TransitionType { get; init; } /// /// 转换次数。 /// public int TransitionCount { get; init; } /// /// 成功次数。 /// public int SuccessCount { get; init; } /// /// 成功率。 /// public double SuccessRate => TransitionCount > 0 ? (double)SuccessCount / TransitionCount * 100 : 0.0; /// /// 平均耗时(毫秒)。 /// public double AverageElapsedMs { get; init; } } /// /// 产品类型转换统计。 /// public sealed class ProductTypeTransitionStatistics { /// /// 产品类型编码。 /// public string ProductTypeCode { get; init; } = string.Empty; /// /// 转换次数。 /// public int TransitionCount { get; init; } /// /// 成功次数。 /// public int SuccessCount { get; init; } /// /// 成功率。 /// public double SuccessRate => TransitionCount > 0 ? (double)SuccessCount / TransitionCount * 100 : 0.0; /// /// 平均耗时(毫秒)。 /// public double AverageElapsedMs { get; init; } } /// /// 按层级分组的转换统计。 /// public sealed class LayerTransitionStatisticsByLayer { /// /// 层级编号。 /// public int LayerNumber { get; init; } /// /// 转换次数。 /// public int TransitionCount { get; init; } /// /// 成功次数。 /// public int SuccessCount { get; init; } /// /// 成功率。 /// public double SuccessRate => TransitionCount > 0 ? (double)SuccessCount / TransitionCount * 100 : 0.0; /// /// 平均停留时间(秒)。 /// public double AverageStayTimeSeconds { get; init; } } /// /// 强制转换统计。 /// public sealed class ForceTransitionStatistics { /// /// 强制转换次数。 /// public int ForceTransitionCount { get; init; } /// /// 成功次数。 /// public int SuccessCount { get; init; } /// /// 成功率。 /// public double SuccessRate => ForceTransitionCount > 0 ? (double)SuccessCount / ForceTransitionCount * 100 : 0.0; /// /// 按用户分组的统计。 /// public Dictionary ByUser { get; init; } = new(); } /// /// 保护触发统计。 /// public sealed class ProtectionTriggerStatistics { /// /// 保护触发次数。 /// public int ProtectionTriggerCount { get; init; } /// /// 转换被阻止次数。 /// public int TransitionBlockedCount { get; init; } /// /// 强制转换成功次数。 /// public int ForceSuccessCount { get; init; } /// /// 按保护策略分组的统计。 /// public Dictionary ByStrategy { get; init; } = new(); } /// /// 层级转换类型枚举。 /// public enum LayerTransitionType { /// /// 前进转换。 /// Forward = 0, /// /// 后退转换。 /// Backward = 1, /// /// 跳转转换。 /// Jump = 2, /// /// 重置转换。 /// Reset = 3 } /// /// 层级转换保护策略枚举。 /// public enum LayerTransitionProtectionStrategy { /// /// 无保护。 /// None = 0, /// /// 时间保护。 /// TimeProtection = 1, /// /// 完成度保护。 /// CompletionProtection = 2, /// /// 综合保护。 /// Comprehensive = 3, /// /// 严格保护。 /// Strict = 4 } /// /// 保护条件类型枚举。 /// public enum ProtectionConditionType { /// /// 停留时间条件。 /// StayTime = 0, /// /// 完成度条件。 /// Completion = 1, /// /// 错误状态条件。 /// ErrorStatus = 2, /// /// 人工干预条件。 /// ManualIntervention = 3, /// /// 系统状态条件。 /// SystemStatus = 4 } /// /// 自动回滚条件类型枚举。 /// public enum AutoRollbackConditionType { /// /// 错误率条件。 /// ErrorRate = 0, /// /// 性能条件。 /// Performance = 1, /// /// 超时条件。 /// Timeout = 2, /// /// 资源条件。 /// Resource = 3 } /// /// 比较操作符枚举。 /// public enum ComparisonOperator { /// /// 等于。 /// Equal = 0, /// /// 不等于。 /// NotEqual = 1, /// /// 大于。 /// GreaterThan = 2, /// /// 大于等于。 /// GreaterThanOrEqual = 3, /// /// 小于。 /// LessThan = 4, /// /// 小于等于。 /// LessThanOrEqual = 5 }