MdpInboundModels.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System.Text.Encodings.Web;
  2. using System.Text.Json;
  3. using System.Text.Json.Serialization;
  4. namespace Admin.NET.Plugin.AiDOP.DataPlatform.Inbound;
  5. internal static class MdpInboundJson
  6. {
  7. public static readonly JsonSerializerOptions Options = new()
  8. {
  9. PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
  10. DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
  11. Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
  12. };
  13. }
  14. public sealed class MdpInboundReceiveArgs
  15. {
  16. public string EntityCode { get; init; } = string.Empty;
  17. public byte[] RawBody { get; init; } = [];
  18. public string AccessKey { get; init; } = string.Empty;
  19. public long TenantId { get; init; }
  20. public string IdempotencyKey { get; init; } = string.Empty;
  21. public string ClientIp { get; init; } = string.Empty;
  22. public string Path { get; init; } = string.Empty;
  23. public IReadOnlyDictionary<string, string> Headers { get; init; }
  24. = new Dictionary<string, string>();
  25. }
  26. public sealed class MdpInboundOutcome
  27. {
  28. public int HttpStatus { get; init; }
  29. public object Body { get; init; }
  30. }
  31. public sealed class MdpInboundReceiptData
  32. {
  33. public string EntityCode { get; set; } = string.Empty;
  34. public int Accepted { get; set; }
  35. public int Rejected { get; set; }
  36. public List<MdpInboundRejectedRow> RejectedRows { get; set; } = [];
  37. public bool IdempotentReplay { get; set; }
  38. public string SyncBatchId { get; set; } = string.Empty;
  39. public long RequestId { get; set; }
  40. public bool TransformEnqueued { get; set; }
  41. public int StaleRejected { get; set; }
  42. public int EqualTsOverride { get; set; }
  43. }
  44. public sealed class MdpInboundRejectedRow
  45. {
  46. public string BizKey { get; set; }
  47. public string Reason { get; set; } = string.Empty;
  48. }
  49. public sealed class MdpInboundSchemaField
  50. {
  51. public string Name { get; set; } = string.Empty;
  52. public string RawKey { get; set; } = string.Empty;
  53. public bool Required { get; set; }
  54. }
  55. public sealed class MdpInboundSchemaData
  56. {
  57. public string EntityCode { get; set; } = string.Empty;
  58. public string BizKeyExpr { get; set; }
  59. public List<MdpInboundSchemaField> Fields { get; set; } = [];
  60. }
  61. internal sealed class MdpInboundParsedBatch
  62. {
  63. public List<JsonElement> Rows { get; init; } = [];
  64. public string SnapshotId { get; init; }
  65. public int? Seq { get; init; }
  66. }
  67. public sealed class MdpInboundPreparedRow
  68. {
  69. public Dictionary<string, object?> Dict { get; init; } = new(StringComparer.OrdinalIgnoreCase);
  70. public string RawJson { get; init; } = string.Empty;
  71. public string BizKey { get; init; } = string.Empty;
  72. public string SourceUpdatedAt { get; init; }
  73. public string SourceVersion { get; init; }
  74. }
  75. internal sealed class MdpInboundStgGuardRow
  76. {
  77. public long Id { get; set; }
  78. public string SourceSystem { get; set; }
  79. public string SourceRowId { get; set; }
  80. public string SourceUpdatedAt { get; set; }
  81. public string SourceVersion { get; set; }
  82. public string RawData { get; set; }
  83. }
  84. internal sealed class MdpInboundBatchException : Exception
  85. {
  86. public int HttpStatus { get; }
  87. public string ErrorCode { get; }
  88. public MdpInboundBatchException(int httpStatus, string message, string errorCode = null)
  89. : base(message)
  90. {
  91. HttpStatus = httpStatus;
  92. ErrorCode = errorCode ?? message;
  93. }
  94. }