diff --git a/src/Oms.Domain/ChannelsAggregate/Consts/IssueNotifyMethodCodes.cs b/src/Oms.Domain/ChannelsAggregate/Consts/IssueNotifyMethodCodes.cs index 3d495ec..887cf44 100644 --- a/src/Oms.Domain/ChannelsAggregate/Consts/IssueNotifyMethodCodes.cs +++ b/src/Oms.Domain/ChannelsAggregate/Consts/IssueNotifyMethodCodes.cs @@ -8,22 +8,22 @@ public static class IssueNotifyMethodCodes public const string Feishu = "feishu"; public const string Wechat = "wechat"; - public static readonly HashSet All = - [ + public static readonly HashSet All = new(StringComparer.OrdinalIgnoreCase) + { InApp, Email, Sms, Feishu, Wechat - ]; + }; public static string GetDisplayName(string? code) => code?.Trim().ToLowerInvariant() switch { - InApp => "站内信", - Email => "邮件", - Sms => "短信", - Feishu => "飞书", - Wechat => "微信", + "inapp" => "站内信", + "email" => "邮件", + "sms" => "短信", + "feishu" => "飞书", + "wechat" => "微信", _ => code ?? string.Empty }; @@ -36,8 +36,9 @@ public static class IssueNotifyMethodCodes var parts = raw .Split([',', ';', ' '], StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) - .Select(x => x.ToLowerInvariant()) - .Where(x => All.Contains(x)) + .Select(ToCanonical) + .Where(x => x != null) + .Cast() .Distinct(StringComparer.OrdinalIgnoreCase) .ToList(); @@ -54,4 +55,22 @@ public static class IssueNotifyMethodCodes return normalized.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).ToList(); } + + private static string? ToCanonical(string raw) + { + if (string.IsNullOrWhiteSpace(raw)) + { + return null; + } + + return raw.Trim().ToLowerInvariant() switch + { + "inapp" => InApp, + "email" => Email, + "sms" => Sms, + "feishu" => Feishu, + "wechat" => Wechat, + _ => null + }; + } }