using OrpaonVision.Core.LayerCompletion;
using OrpaonVision.Core.Results;
namespace OrpaonVision.Core.FinalJudgment;
///
/// 整机完成判定服务接口。
///
public interface IFinalJudgmentService
{
///
/// 执行整机完成判定。
///
/// 判定上下文。
/// 终判规则列表。
/// 取消令牌。
/// 终判结果。
Task> ExecuteFinalJudgmentAsync(FinalJudgmentContext judgmentContext, IReadOnlyList finalRules, CancellationToken cancellationToken = default);
///
/// 批量执行整机完成判定。
///
/// 判定上下文列表。
/// 终判规则列表。
/// 取消令牌。
/// 批量终判结果。
Task> BatchExecuteFinalJudgmentAsync(IReadOnlyList judgmentContexts, IReadOnlyList finalRules, CancellationToken cancellationToken = default);
///
/// 获取整机完成判定历史。
///
/// 开始时间。
/// 结束时间。
/// 取消令牌。
/// 判定历史。
Task>> GetJudgmentHistoryAsync(DateTime startTime, DateTime endTime, CancellationToken cancellationToken = default);
///
/// 获取整机完成判定统计信息。
///
/// 开始时间。
/// 结束时间。
/// 取消令牌。
/// 统计信息。
Task> GetJudgmentStatisticsAsync(DateTime startTime, DateTime endTime, CancellationToken cancellationToken = default);
///
/// 获取NG原因分析。
///
/// 开始时间。
/// 结束时间。
/// 取消令牌。
/// NG原因分析。
Task> GetNGCauseAnalysisAsync(DateTime startTime, DateTime endTime, CancellationToken cancellationToken = default);
///
/// 创建终判规则。
///
/// 终判规则。
/// 取消令牌。
/// 创建结果。
Task> CreateFinalRuleAsync(FinalJudgmentRule rule, CancellationToken cancellationToken = default);
///
/// 更新终判规则。
///
/// 终判规则。
/// 取消令牌。
/// 更新结果。
Task UpdateFinalRuleAsync(FinalJudgmentRule rule, CancellationToken cancellationToken = default);
///
/// 删除终判规则。
///
/// 规则ID。
/// 取消令牌。
/// 删除结果。
Task DeleteFinalRuleAsync(Guid ruleId, CancellationToken cancellationToken = default);
///
/// 获取终判规则列表。
///
/// 产品类型编码(可选)。
/// 规则类型(可选)。
/// 取消令牌。
/// 规则列表。
Task>> GetFinalRulesAsync(string? productTypeCode = null, FinalJudgmentRuleType? ruleType = null, CancellationToken cancellationToken = default);
///
/// 生成整机完成判定报告。
///
/// 判定ID。
/// 取消令牌。
/// 判定报告。
Task> GenerateJudgmentReportAsync(Guid judgmentId, CancellationToken cancellationToken = default);
}
///
/// 整机完成判定上下文。
///
public sealed class FinalJudgmentContext
{
///
/// 产品类型编码。
///
public string ProductTypeCode { get; init; } = string.Empty;
///
/// 会话ID。
///
public string SessionId { get; init; } = string.Empty;
///
/// 总层级数量。
///
public int TotalLayers { get; init; }
///
/// 已完成层级数量。
///
public int CompletedLayers { get; init; }
///
/// 失败层级数量。
///
public int FailedLayers { get; init; }
///
/// 层级完成判定结果列表。
///
public IReadOnlyList LayerCompletionResults { get; init; } = Array.Empty();
///
/// 整体完成度。
///
public double OverallCompletionPercentage => TotalLayers > 0 ? (double)CompletedLayers / TotalLayers * 100 : 0.0;
///
/// 判定开始时间。
///
public DateTime JudgmentStartTimeUtc { get; init; }
///
/// 判定结束时间。
///
public DateTime JudgmentEndTimeUtc { get; init; }
///
/// 总耗时(毫秒)。
///
public long TotalElapsedMs { 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 FinalJudgmentResult
{
///
/// 判定ID。
///
public Guid JudgmentId { get; init; }
///
/// 产品类型编码。
///
public string ProductTypeCode { get; init; } = string.Empty;
///
/// 会话ID。
///
public string SessionId { get; init; } = string.Empty;
///
/// 是否通过终判。
///
public bool IsPassed { get; init; }
///
/// 判定类型。
///
public FinalJudgmentType JudgmentType { get; init; }
///
/// 判定时间。
///
public DateTime JudgmentTimeUtc { get; init; }
///
/// 判定耗时(毫秒)。
///
public long JudgmentElapsedMs { get; init; }
///
/// 总体评分。
///
public double OverallScore { get; init; }
///
/// 判定质量。
///
public JudgmentQuality JudgmentQuality { get; init; }
///
/// 通过的规则列表。
///
public IReadOnlyList PassedRules { get; init; } = Array.Empty();
///
/// 失败的规则列表。
///
public IReadOnlyList FailedRules { get; init; } = Array.Empty();
///
/// NG原因列表。
///
public IReadOnlyList NGCauses { get; init; } = Array.Empty();
///
/// 证据链。
///
public EvidenceChain EvidenceChain { get; init; } = new();
///
/// 判定详情。
///
public string? Details { get; init; }
///
/// 判定建议。
///
public string? Recommendation { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 规则判定结果。
///
public sealed class RuleJudgmentResult
{
///
/// 规则ID。
///
public Guid RuleId { get; init; }
///
/// 规则名称。
///
public string RuleName { get; init; } = string.Empty;
///
/// 规则类型。
///
public FinalJudgmentRuleType RuleType { get; init; }
///
/// 是否通过规则。
///
public bool IsPassed { get; init; }
///
/// 规则评分。
///
public double RuleScore { get; init; }
///
/// 规则权重。
///
public double RuleWeight { get; init; }
///
/// 实际值。
///
public double ActualValue { get; init; }
///
/// 阈值。
///
public double Threshold { get; init; }
///
/// 判定详情。
///
public string? Details { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// NG原因。
///
public sealed class NGCause
{
///
/// 原因ID。
///
public Guid CauseId { get; init; }
///
/// 原因类型。
///
public NGCauseType CauseType { get; init; }
///
/// 原因级别。
///
public NGCauseLevel CauseLevel { get; init; }
///
/// 原因描述。
///
public string Description { get; init; } = string.Empty;
///
/// 相关层级。
///
public int? RelatedLayer { get; init; }
///
/// 相关部件。
///
public string? RelatedPart { get; init; }
///
/// 发生时间。
///
public DateTime OccurrenceTimeUtc { get; init; }
///
/// 修复建议。
///
public string? FixSuggestion { get; init; }
///
/// 影响程度。
///
public ImpactLevel ImpactLevel { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 证据链。
///
public sealed class EvidenceChain
{
///
/// 证据链ID。
///
public Guid ChainId { get; init; }
///
/// 创建时间。
///
public DateTime CreatedAtUtc { get; init; }
///
/// 证据节点列表。
///
public IReadOnlyList EvidenceNodes { get; init; } = Array.Empty();
///
/// 证据链完整性评分。
///
public double CompletenessScore { get; init; }
///
/// 证据链可信度评分。
///
public double CredibilityScore { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 证据节点。
///
public sealed class EvidenceNode
{
///
/// 节点ID。
///
public Guid NodeId { get; init; }
///
/// 节点类型。
///
public EvidenceNodeType NodeType { get; init; }
///
/// 节点名称。
///
public string NodeName { get; init; } = string.Empty;
///
/// 节点描述。
///
public string NodeDescription { get; init; } = string.Empty;
///
/// 发生时间。
///
public DateTime TimestampUtc { get; init; }
///
/// 相关层级。
///
public int? RelatedLayer { get; init; }
///
/// 数据内容。
///
public object? DataContent { get; init; }
///
/// 文件路径。
///
public string? FilePath { get; init; }
///
/// 证据权重。
///
public double EvidenceWeight { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 批量终判结果。
///
public sealed class BatchFinalJudgmentResult
{
///
/// 终判结果列表。
///
public IReadOnlyList JudgmentResults { get; init; } = Array.Empty();
///
/// 总判定数量。
///
public int TotalJudgments { get; init; }
///
/// 通过数量。
///
public int PassedCount { get; init; }
///
/// 失败数量。
///
public int FailedCount { get; init; }
///
/// 总体通过率。
///
public double OverallPassRate => TotalJudgments > 0 ? (double)PassedCount / TotalJudgments * 100 : 0.0;
///
/// 批量处理时间。
///
public DateTime BatchProcessingTimeUtc { get; init; }
///
/// 总耗时(毫秒)。
///
public long TotalElapsedMs { get; init; }
///
/// 判定详情。
///
public string? Details { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 整机完成判定历史。
///
public sealed class FinalJudgmentHistory
{
///
/// 判定ID。
///
public Guid JudgmentId { get; init; }
///
/// 产品类型编码。
///
public string ProductTypeCode { get; init; } = string.Empty;
///
/// 会话ID。
///
public string SessionId { get; init; } = string.Empty;
///
/// 判定类型。
///
public FinalJudgmentType JudgmentType { get; init; }
///
/// 判定时间。
///
public DateTime JudgmentTimeUtc { get; init; }
///
/// 是否通过。
///
public bool IsPassed { get; init; }
///
/// 总体评分。
///
public double OverallScore { get; init; }
///
/// 判定质量。
///
public JudgmentQuality JudgmentQuality { get; init; }
///
/// 操作用户。
///
public string OperatorUser { get; init; } = string.Empty;
///
/// NG原因数量。
///
public int NGCauseCount { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 整机完成判定统计信息。
///
public sealed class FinalJudgmentStatistics
{
///
/// 总判定次数。
///
public int TotalJudgments { get; init; }
///
/// 通过次数。
///
public int PassedCount { get; init; }
///
/// 失败次数。
///
public int FailedCount { get; init; }
///
/// 总体通过率。
///
public double OverallPassRate => TotalJudgments > 0 ? (double)PassedCount / TotalJudgments * 100 : 0.0;
///
/// 按判定类型分组的统计。
///
public Dictionary ByJudgmentType { get; init; } = new();
///
/// 按产品类型分组的统计。
///
public Dictionary ByProductType { get; init; } = new();
///
/// 按判定质量分组的统计。
///
public Dictionary ByQuality { get; init; } = new();
///
/// 平均评分。
///
public double AverageScore { get; init; }
///
/// 平均耗时(毫秒)。
///
public double AverageElapsedMs { get; init; }
///
/// 统计开始时间。
///
public DateTime StartTimeUtc { get; init; }
///
/// 统计结束时间。
///
public DateTime EndTimeUtc { get; init; }
}
///
/// 判定类型统计。
///
public sealed class JudgmentTypeStatistics
{
///
/// 判定类型。
///
public FinalJudgmentType JudgmentType { get; init; }
///
/// 判定次数。
///
public int JudgmentCount { get; init; }
///
/// 通过次数。
///
public int PassCount { get; init; }
///
/// 通过率。
///
public double PassRate => JudgmentCount > 0 ? (double)PassCount / JudgmentCount * 100 : 0.0;
///
/// 平均评分。
///
public double AverageScore { get; init; }
///
/// 平均耗时(毫秒)。
///
public double AverageElapsedMs { get; init; }
}
///
/// 产品类型判定统计。
///
public sealed class ProductTypeJudgmentStatistics
{
///
/// 产品类型编码。
///
public string ProductTypeCode { get; init; } = string.Empty;
///
/// 判定次数。
///
public int JudgmentCount { get; init; }
///
/// 通过次数。
///
public int PassCount { get; init; }
///
/// 通过率。
///
public double PassRate => JudgmentCount > 0 ? (double)PassCount / JudgmentCount * 100 : 0.0;
///
/// 平均评分。
///
public double AverageScore { get; init; }
///
/// 平均耗时(毫秒)。
///
public double AverageElapsedMs { get; init; }
}
///
/// 质量统计。
///
public sealed class QualityStatistics
{
///
/// 判定质量。
///
public JudgmentQuality Quality { get; init; }
///
/// 判定次数。
///
public int JudgmentCount { get; init; }
///
/// 占比。
///
public double Percentage => JudgmentCount > 0 ? (double)JudgmentCount / JudgmentCount * 100 : 0.0;
///
/// 平均评分。
///
public double AverageScore { get; init; }
}
///
/// NG原因分析。
///
public sealed class NGCauseAnalysis
{
///
/// 分析时间范围。
///
public DateTime StartTimeUtc { get; init; }
///
/// 分析时间范围。
///
public DateTime EndTimeUtc { get; init; }
///
/// 总NG数量。
///
public int TotalNGCount { get; init; }
///
/// 按原因类型分组的统计。
///
public Dictionary ByCauseType { get; init; } = new();
///
/// 按原因级别分组的统计。
///
public Dictionary ByCauseLevel { get; init; } = new();
///
/// 按影响程度分组的统计。
///
public Dictionary ByImpactLevel { get; init; } = new();
///
/// 按层级分组的统计。
///
public Dictionary ByLayer { get; init; } = new();
///
/// 热点NG原因列表。
///
public IReadOnlyList HotCauses { get; init; } = Array.Empty();
///
/// 趋势分析。
///
public NGCauseTrend Trend { get; init; } = new();
}
///
/// 原因类型统计。
///
public sealed class CauseTypeStatistics
{
///
/// 原因类型。
///
public NGCauseType CauseType { get; init; }
///
/// 发生次数。
///
public int OccurrenceCount { get; init; }
///
/// 占比。
///
public double Percentage => OccurrenceCount > 0 ? (double)OccurrenceCount / OccurrenceCount * 100 : 0.0;
///
/// 平均影响程度。
///
public double AverageImpactLevel { get; init; }
}
///
/// 原因级别统计。
///
public sealed class CauseLevelStatistics
{
///
/// 原因级别。
///
public NGCauseLevel CauseLevel { get; init; }
///
/// 发生次数。
///
public int OccurrenceCount { get; init; }
///
/// 占比。
///
public double Percentage => OccurrenceCount > 0 ? (double)OccurrenceCount / OccurrenceCount * 100 : 0.0;
}
///
/// 影响程度统计。
///
public sealed class ImpactStatistics
{
///
/// 影响程度。
///
public ImpactLevel ImpactLevel { get; init; }
///
/// 发生次数。
///
public int OccurrenceCount { get; init; }
///
/// 占比。
///
public double Percentage => OccurrenceCount > 0 ? (double)OccurrenceCount / OccurrenceCount * 100 : 0.0;
}
///
/// 层级NG统计。
///
public sealed class LayerNGStatistics
{
///
/// 层级编号。
///
public int LayerNumber { get; init; }
///
/// NG数量。
///
public int NGCount { get; init; }
///
/// 占比。
///
public double Percentage => NGCount > 0 ? (double)NGCount / NGCount * 100 : 0.0;
}
///
/// 热点NG原因。
///
public sealed class HotNGCause
{
///
/// 原因描述。
///
public string Description { get; init; } = string.Empty;
///
/// 发生次数。
///
public int OccurrenceCount { get; init; }
///
/// 排名。
///
public int Rank { get; init; }
///
/// 趋势。
///
public NGCauseTrendDirection Trend { get; init; }
}
///
/// NG原因趋势。
///
public sealed class NGCauseTrend
{
///
/// 趋势方向。
///
public NGCauseTrendDirection Direction { get; init; }
///
/// 变化率。
///
public double ChangeRate { get; init; }
///
/// 趋势描述。
///
public string TrendDescription { get; init; } = string.Empty;
}
///
/// 终判规则。
///
public sealed class FinalJudgmentRule
{
///
/// 规则ID。
///
public Guid RuleId { get; init; }
///
/// 规则名称。
///
public string RuleName { get; init; } = string.Empty;
///
/// 规则描述。
///
public string RuleDescription { get; init; } = string.Empty;
///
/// 产品类型编码。
///
public string ProductTypeCode { get; init; } = string.Empty;
///
/// 规则类型。
///
public FinalJudgmentRuleType RuleType { get; init; }
///
/// 规则权重。
///
public double RuleWeight { get; init; } = 1.0;
///
/// 阈值。
///
public double Threshold { get; init; }
///
/// 比较操作符。
///
public ComparisonOperator ComparisonOperator { get; init; }
///
/// 是否为必须满足的规则。
///
public bool IsMandatory { get; init; } = true;
///
/// 是否启用。
///
public bool IsEnabled { get; init; } = true;
///
/// 优先级。
///
public int Priority { get; init; } = 1;
///
/// 创建时间。
///
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 FinalJudgmentReport
{
///
/// 报告ID。
///
public Guid ReportId { get; init; }
///
/// 判定ID。
///
public Guid JudgmentId { get; init; }
///
/// 报告生成时间。
///
public DateTime GeneratedAtUtc { get; init; }
///
/// 报告类型。
///
public ReportType ReportType { get; init; }
///
/// 报告内容。
///
public string ReportContent { get; init; } = string.Empty;
///
/// 报告格式。
///
public ReportFormat ReportFormat { get; init; }
///
/// 文件路径。
///
public string? FilePath { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 整机完成判定类型枚举。
///
public enum FinalJudgmentType
{
///
/// 自动判定。
///
Automatic = 0,
///
/// 手动判定。
///
Manual = 1,
///
/// 复核判定。
///
Review = 2,
///
/// 仲裁判定。
///
Arbitration = 3
}
///
/// 终判规则类型枚举。
///
public enum FinalJudgmentRuleType
{
///
/// 完成度规则。
///
CompletionRate = 0,
///
/// 质量评分规则。
///
QualityScore = 1,
///
/// 错误率规则。
///
ErrorRate = 2,
///
/// 时间规则。
///
TimeConstraint = 3,
///
/// 自定义规则。
///
Custom = 4
}
///
/// 判定质量枚举。
///
public enum JudgmentQuality
{
///
/// 优秀。
///
Excellent = 0,
///
/// 良好。
///
Good = 1,
///
/// 一般。
///
Fair = 2,
///
/// 较差。
///
Poor = 3,
///
/// 不合格。
///
Unqualified = 4
}
///
/// NG原因类型枚举。
///
public enum NGCauseType
{
///
/// 部件缺失。
///
MissingPart = 0,
///
/// 部件错误。
///
WrongPart = 1,
///
/// 位置错误。
///
WrongPosition = 2,
///
/// 质量问题。
///
QualityIssue = 3,
///
/// 工艺问题。
///
ProcessIssue = 4,
///
/// 设备问题。
///
EquipmentIssue = 5,
///
/// 环境问题。
///
EnvironmentIssue = 6,
///
/// 人为因素。
///
HumanFactor = 7,
///
/// 其他原因。
///
Other = 8
}
///
/// NG原因级别枚举。
///
public enum NGCauseLevel
{
///
/// 轻微。
///
Minor = 0,
///
/// 一般。
///
Normal = 1,
///
/// 严重。
///
Serious = 2,
///
/// 致命。
///
Critical = 3
}
///
/// 影响程度枚举。
///
public enum ImpactLevel
{
///
/// 低影响。
///
Low = 0,
///
/// 中影响。
///
Medium = 1,
///
/// 高影响。
///
High = 2,
///
/// 严重影响。
///
Critical = 3
}
///
/// 证据节点类型枚举。
///
public enum EvidenceNodeType
{
///
/// 图像证据。
///
Image = 0,
///
/// 数据证据。
///
Data = 1,
///
/// 日志证据。
///
Log = 2,
///
/// 视频证据。
///
Video = 3,
///
/// 文档证据。
///
Document = 4,
///
/// 其他证据。
///
Other = 5
}
///
/// NG原因趋势方向枚举。
///
public enum NGCauseTrendDirection
{
///
/// 上升。
///
Increasing = 0,
///
/// 下降。
///
Decreasing = 1,
///
/// 稳定。
///
Stable = 2,
///
/// 波动。
///
Fluctuating = 3
}
///
/// 报告类型枚举。
///
public enum ReportType
{
///
/// 标准报告。
///
Standard = 0,
///
/// 详细报告。
///
Detailed = 1,
///
/// 摘要报告。
///
Summary = 2,
///
/// 统计报告。
///
Statistical = 3
}
///
/// 报告格式枚举。
///
public enum ReportFormat
{
///
/// 文本格式。
///
Text = 0,
///
/// HTML格式。
///
Html = 1,
///
/// PDF格式。
///
Pdf = 2,
///
/// Excel格式。
///
Excel = 3,
///
/// JSON格式。
///
Json = 4
}
///
/// 比较操作符枚举。
///
public enum ComparisonOperator
{
///
/// 等于。
///
Equal = 0,
///
/// 不等于。
///
NotEqual = 1,
///
/// 大于。
///
GreaterThan = 2,
///
/// 大于等于。
///
GreaterThanOrEqual = 3,
///
/// 小于。
///
LessThan = 4,
///
/// 小于等于。
///
LessThanOrEqual = 5
}