using OrpaonVision.Core.LayerRecognition;
using OrpaonVision.Core.PartRecognition;
using OrpaonVision.Core.Results;
namespace OrpaonVision.Core.QuantityValidation;
///
/// 数量校验服务接口。
///
public interface IQuantityValidationService
{
///
/// 校验精确数量。
///
/// 部件列表。
/// 期望数量。
/// 部件类型(可选)。
/// 取消令牌。
/// 精确数量校验结果。
Task> ValidateExactQuantityAsync(IReadOnlyList parts, int expectedCount, PartType? partType = null, CancellationToken cancellationToken = default);
///
/// 校验最少数量。
///
/// 部件列表。
/// 最少数量。
/// 部件类型(可选)。
/// 取消令牌。
/// 最少数量校验结果。
Task> ValidateMinimumQuantityAsync(IReadOnlyList parts, int minCount, PartType? partType = null, CancellationToken cancellationToken = default);
///
/// 校验范围数量。
///
/// 部件列表。
/// 最小数量。
/// 最大数量。
/// 部件类型(可选)。
/// 取消令牌。
/// 范围数量校验结果。
Task> ValidateRangeQuantityAsync(IReadOnlyList parts, int minCount, int maxCount, PartType? partType = null, CancellationToken cancellationToken = default);
///
/// 校验唯一数量。
///
/// 部件列表。
/// 唯一属性名。
/// 期望唯一数量。
/// 部件类型(可选)。
/// 取消令牌。
/// 唯一数量校验结果。
Task> ValidateUniqueQuantityAsync(IReadOnlyList parts, string uniqueProperty, int expectedUniqueCount, PartType? partType = null, CancellationToken cancellationToken = default);
///
/// 批量数量校验。
///
/// 部件列表。
/// 校验规则列表。
/// 取消令牌。
/// 批量校验结果。
Task> BatchValidateQuantityAsync(IReadOnlyList parts, IReadOnlyList validationRules, CancellationToken cancellationToken = default);
///
/// 获取数量校验统计信息。
///
/// 开始时间。
/// 结束时间。
/// 取消令牌。
/// 统计信息。
Task> GetValidationStatisticsAsync(DateTime startTime, DateTime endTime, CancellationToken cancellationToken = default);
///
/// 创建数量校验规则。
///
/// 校验规则。
/// 取消令牌。
/// 创建结果。
Task> CreateValidationRuleAsync(QuantityValidationRule rule, CancellationToken cancellationToken = default);
///
/// 更新数量校验规则。
///
/// 校验规则。
/// 取消令牌。
/// 更新结果。
Task UpdateValidationRuleAsync(QuantityValidationRule rule, CancellationToken cancellationToken = default);
///
/// 删除数量校验规则。
///
/// 规则ID。
/// 取消令牌。
/// 删除结果。
Task DeleteValidationRuleAsync(Guid ruleId, CancellationToken cancellationToken = default);
///
/// 获取数量校验规则列表。
///
/// 产品类型编码(可选)。
/// 层级编号(可选)。
/// 部件类型(可选)。
/// 取消令牌。
/// 规则列表。
Task>> GetValidationRulesAsync(string? productTypeCode = null, int? layerNumber = null, PartType? partType = null, CancellationToken cancellationToken = default);
}
///
/// 精确数量校验结果。
///
public sealed class ExactQuantityValidationResult
{
///
/// 是否通过校验。
///
public bool IsValid { get; init; }
///
/// 实际数量。
///
public int ActualCount { get; init; }
///
/// 期望数量。
///
public int ExpectedCount { get; init; }
///
/// 数量偏差。
///
public int Deviation => ActualCount - ExpectedCount;
///
/// 部件类型(如果指定)。
///
public PartType? PartType { get; init; }
///
/// 匹配的部件列表。
///
public IReadOnlyList MatchedParts { get; init; } = Array.Empty();
///
/// 校验时间。
///
public DateTime ValidationTimeUtc { get; init; }
///
/// 详细信息。
///
public string? Details { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 最少数量校验结果。
///
public sealed class MinimumQuantityValidationResult
{
///
/// 是否通过校验。
///
public bool IsValid { get; init; }
///
/// 实际数量。
///
public int ActualCount { get; init; }
///
/// 最少数量。
///
public int MinimumCount { get; init; }
///
/// 超出数量。
///
public int ExcessCount => Math.Max(0, ActualCount - MinimumCount);
///
/// 部件类型(如果指定)。
///
public PartType? PartType { get; init; }
///
/// 匹配的部件列表。
///
public IReadOnlyList MatchedParts { get; init; } = Array.Empty();
///
/// 校验时间。
///
public DateTime ValidationTimeUtc { get; init; }
///
/// 详细信息。
///
public string? Details { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 范围数量校验结果。
///
public sealed class RangeQuantityValidationResult
{
///
/// 是否通过校验。
///
public bool IsValid { get; init; }
///
/// 实际数量。
///
public int ActualCount { get; init; }
///
/// 最小数量。
///
public int MinimumCount { get; init; }
///
/// 最大数量。
///
public int MaximumCount { get; init; }
///
/// 是否低于最小值。
///
public bool IsBelowMinimum => ActualCount < MinimumCount;
///
/// 是否高于最大值。
///
public bool IsAboveMaximum => ActualCount > MaximumCount;
///
/// 部件类型(如果指定)。
///
public PartType? PartType { get; init; }
///
/// 匹配的部件列表。
///
public IReadOnlyList MatchedParts { get; init; } = Array.Empty();
///
/// 校验时间。
///
public DateTime ValidationTimeUtc { get; init; }
///
/// 详细信息。
///
public string? Details { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 唯一数量校验结果。
///
public sealed class UniqueQuantityValidationResult
{
///
/// 是否通过校验。
///
public bool IsValid { get; init; }
///
/// 实际唯一数量。
///
public int ActualUniqueCount { get; init; }
///
/// 期望唯一数量。
///
public int ExpectedUniqueCount { get; init; }
///
/// 唯一属性名。
///
public string UniqueProperty { get; init; } = string.Empty;
///
/// 唯一值列表。
///
public IReadOnlyList