S8SeverityCode.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. namespace Admin.NET.Plugin.AiDOP.Infrastructure.S8;
  2. /// <summary>
  3. /// S8-SEVERITY-FOLLOW-SERIOUS-STANDARDIZE-EXEC-1:S8 异常 severity 业务枚举。
  4. /// 当前阶段只保留 FOLLOW(关注)/ SERIOUS(严重)两档;
  5. /// 旧值 LOW/MEDIUM/HIGH/CRITICAL 仅作为 legacy 兼容输入,新写入必须落 FOLLOW/SERIOUS。
  6. /// </summary>
  7. public static class S8SeverityCode
  8. {
  9. public const string Follow = "FOLLOW";
  10. public const string Serious = "SERIOUS";
  11. /// <summary>归一化:旧值/空值/新值 -> FOLLOW / SERIOUS。空值默认 FOLLOW。</summary>
  12. public static string Normalize(string? code)
  13. {
  14. if (string.IsNullOrWhiteSpace(code)) return Follow;
  15. return code.Trim().ToUpperInvariant() switch
  16. {
  17. "FOLLOW" => Follow,
  18. "LOW" => Follow,
  19. "MEDIUM" => Follow,
  20. "SERIOUS" => Serious,
  21. "HIGH" => Serious,
  22. "CRITICAL" => Serious,
  23. _ => Follow,
  24. };
  25. }
  26. public static bool IsFollow(string? code) => Normalize(code) == Follow;
  27. public static bool IsSerious(string? code) => Normalize(code) == Serious;
  28. /// <summary>新值或旧值合法(用于 legacy 查询参数兼容)。</summary>
  29. public static bool IsValid(string? code)
  30. {
  31. if (string.IsNullOrWhiteSpace(code)) return false;
  32. return code.Trim().ToUpperInvariant() switch
  33. {
  34. "FOLLOW" or "SERIOUS" or "LOW" or "MEDIUM" or "HIGH" or "CRITICAL" => true,
  35. _ => false,
  36. };
  37. }
  38. public static string Label(string? code) => Normalize(code) switch
  39. {
  40. Serious => "严重",
  41. _ => "关注",
  42. };
  43. public static object[] Options() =>
  44. new[] { Follow, Serious }
  45. .Select(v => new { value = v, label = Label(v) })
  46. .ToArray<object>();
  47. }