IS8RuleEvaluator.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Admin.NET.Plugin.AiDOP.Entity.S8;
  2. namespace Admin.NET.Plugin.AiDOP.Service.S8.Rules;
  3. /// <summary>
  4. /// R2 规则 evaluator 抽象。每个 rule_type 对应一个实现,由 S8WatchSchedulerService 按 rule_type 分派。
  5. /// 首版仅 TIMEOUT;OUT_OF_RANGE 走 S8WatchSchedulerService 内既有兼容分支,不接入此抽象。
  6. /// 不做事件触发、不做 SLA 升级、不做严重度阶梯。
  7. /// </summary>
  8. public interface IS8RuleEvaluator
  9. {
  10. /// <summary>支持的 rule_type 字符串(TIMEOUT / SHORTAGE / OUT_OF_RANGE)。</summary>
  11. string RuleType { get; }
  12. /// <summary>评估一条 WatchRule,产出 0..N 条命中。不做去重、不建单。</summary>
  13. Task<List<S8RuleHit>> EvaluateAsync(
  14. long tenantId,
  15. long factoryId,
  16. AdoS8WatchRule rule,
  17. CancellationToken cancellationToken = default);
  18. }
  19. /// <summary>
  20. /// 内部命中模型。供 R2 evaluator 与 S8WatchSchedulerService 的 dedup/建单消费。
  21. /// 字段全部 nullable 以兼容 TIMEOUT / SHORTAGE / OUT_OF_RANGE 三类。R2 仅 TIMEOUT 路径写入。
  22. /// </summary>
  23. public sealed class S8RuleHit
  24. {
  25. public long SourceRuleId { get; set; }
  26. public string SourceRuleCode { get; set; } = string.Empty;
  27. public string SourceObjectType { get; set; } = string.Empty;
  28. public string SourceObjectId { get; set; } = string.Empty;
  29. public string RelatedObjectCode { get; set; } = string.Empty;
  30. public string ExceptionTypeCode { get; set; } = string.Empty;
  31. public string SceneCode { get; set; } = string.Empty;
  32. public string Severity { get; set; } = "FOLLOW";
  33. public string DedupKey { get; set; } = string.Empty;
  34. public string SourcePayload { get; set; } = "{}";
  35. public DateTime DetectedAt { get; set; } = DateTime.Now;
  36. public string Title { get; set; } = string.Empty;
  37. public long DataSourceId { get; set; }
  38. public long? OccurrenceDeptId { get; set; }
  39. public long? ResponsibleDeptId { get; set; }
  40. /// <summary>
  41. /// 命中归属模块码(S1-S7)。evaluator 可显式提供以覆盖 scene 默认派生;
  42. /// 留 null 时建单方按严格 S1-S7 派生:hit.SceneCode(仅 S1-S7)→ exception_type.scene_code。
  43. /// 不接受 legacy 复合 scene(S8-EXCEPTION-CREATION-MODULE-CODE-FIX-1)。
  44. /// </summary>
  45. public string? ModuleCode { get; set; }
  46. }