using System.ComponentModel.DataAnnotations.Schema; using System.Text.Json; using System.Text.Json.Serialization; namespace MessageService.Domain.KeyObjects { public class MessageContent { // 兜底文本 [JsonPropertyName("fallback")] public string Fallback { get; init; } // 核心 Payload,反序列化时根据外层 MessageType 转换为具体子类 public string RawBody { get; init; } public string RawExt { get; set; } = string.Empty; [JsonPropertyName("body")] // 业务代码使用的对象 [NotMapped] public object Body => string.IsNullOrEmpty(RawBody) ? null : JsonSerializer.Deserialize(RawBody); [NotMapped] public Dictionary Ext => string.IsNullOrEmpty(RawExt) ? new() : JsonSerializer.Deserialize>(RawExt); // 引用信息 [JsonPropertyName("quote")] public QuoteInfo Quote { get; set; } = new(); private MessageContent() { } public MessageContent(string fallback, object body) { Fallback = fallback; RawBody = body == null ? null : JsonSerializer.Serialize(body); } } }