using Newtonsoft.Json; namespace CoreAgent.Domain.Models.Protocol; /// /// 移动用户身份信息 /// 用于存储移动网络用户的基本身份和位置信息 /// 遵循DDD(领域驱动设计)原则,作为领域模型的一部分 /// public class MobileUserIdentity { /// /// 公共陆地移动网络标识 /// Public Land Mobile Network Identifier /// [JsonProperty("plmn")] public string? Plmn { get; set; } /// /// 旧的临时移动用户标识 /// Old Temporary Mobile Subscriber Identity /// [JsonProperty("oldTmsi")] public string? OldTmsi { get; set; } /// /// 临时移动用户标识 /// Temporary Mobile Subscriber Identity /// [JsonProperty("tmsi")] public string? Tmsi { get; set; } /// /// 国际移动用户标识 /// International Mobile Subscriber Identity /// [JsonProperty("imsi")] public string? Imsi { get; set; } /// /// 小区ID /// Cell Identifier /// [JsonProperty("cellId")] public int? CellId { get; set; } /// /// 用户设备ID /// User Equipment Identifier /// [JsonProperty("ueId")] public int? UeId { get; set; } /// /// 初始化移动用户身份信息的新实例 /// public MobileUserIdentity() { } /// /// 初始化移动用户身份信息的新实例 /// /// 公共陆地移动网络标识 /// 旧的临时移动用户标识 /// 临时移动用户标识 /// 国际移动用户标识 /// 小区ID /// 用户设备ID public MobileUserIdentity( string? plmn = null, string? oldTmsi = null, string? tmsi = null, string? imsi = null, int? cellId = null, int? ueId = null) { Plmn = plmn; OldTmsi = oldTmsi; Tmsi = tmsi; Imsi = imsi; CellId = cellId; UeId = ueId; } /// /// 检查是否包含有效的用户身份信息 /// /// 是否包含有效信息 public bool HasValidIdentity() { return !string.IsNullOrWhiteSpace(Imsi) || !string.IsNullOrWhiteSpace(Tmsi) || UeId.HasValue; } /// /// 检查是否包含位置信息 /// /// 是否包含位置信息 public bool HasLocationInfo() { return !string.IsNullOrWhiteSpace(Plmn) || CellId.HasValue; } /// /// 获取用户身份摘要信息 /// /// 摘要信息 public string GetIdentitySummary() { var parts = new List(); if (!string.IsNullOrWhiteSpace(Imsi)) parts.Add($"IMSI:{Imsi}"); if (!string.IsNullOrWhiteSpace(Tmsi)) parts.Add($"TMSI:{Tmsi}"); if (UeId.HasValue) parts.Add($"UE:{UeId}"); if (!string.IsNullOrWhiteSpace(Plmn)) parts.Add($"PLMN:{Plmn}"); if (CellId.HasValue) parts.Add($"Cell:{CellId}"); return parts.Count > 0 ? string.Join(" | ", parts) : "No Identity Info"; } /// /// 检查TMSI是否发生变化 /// /// TMSI是否发生变化 public bool HasTmsiChanged() { return !string.IsNullOrWhiteSpace(OldTmsi) && !string.IsNullOrWhiteSpace(Tmsi) && !OldTmsi.Equals(Tmsi, StringComparison.OrdinalIgnoreCase); } /// /// 创建身份信息的副本 /// /// 新的移动用户身份信息 public MobileUserIdentity Copy() { return new MobileUserIdentity { Plmn = Plmn, OldTmsi = OldTmsi, Tmsi = Tmsi, Imsi = Imsi, CellId = CellId, UeId = UeId }; } /// /// 更新TMSI信息 /// /// 新的TMSI public void UpdateTmsi(string? newTmsi) { if (!string.IsNullOrWhiteSpace(Tmsi)) { OldTmsi = Tmsi; } Tmsi = newTmsi; } /// /// 转换为JSON字符串 /// /// JSON字符串 public string ToJson() { return JsonConvert.SerializeObject(this, Formatting.Indented); } /// /// 从JSON字符串创建移动用户身份信息 /// /// JSON字符串 /// 移动用户身份信息 public static MobileUserIdentity FromJson(string json) { return JsonConvert.DeserializeObject(json) ?? new MobileUserIdentity(); } /// /// 重写ToString方法 /// /// 字符串表示 public override string ToString() { return GetIdentitySummary(); } }