| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using System.Text.Json;
- using System.Text.Json.Serialization;
- namespace Admin.NET.Plugin.AiDOP.DataPlatform.Core;
- public sealed record PurchaseHandoffLine(
- Guid RawEventId,
- string PoNo,
- string PoLine,
- string ItemCode,
- decimal OrderQty,
- string? SupplierCode,
- DateTime? OrderDate,
- DateTime? DueDate,
- string? Status,
- string SourceUpdatedAt)
- {
- public string BusinessKey => $"{PoNo}#{PoLine}";
- }
- public sealed record PurchaseHandoffPackage(
- Guid BatchId,
- string LeaseToken,
- [property: JsonNumberHandling(JsonNumberHandling.WriteAsString | JsonNumberHandling.AllowReadingFromString)] long TenantId,
- [property: JsonNumberHandling(JsonNumberHandling.WriteAsString | JsonNumberHandling.AllowReadingFromString)] long FactoryId,
- long SourceId,
- long DatasetId,
- string DatasetKey,
- string SourceCode,
- string PackageVersion,
- string SourceSchemaVersion,
- string MappingVersion,
- IReadOnlyList<PurchaseHandoffLine> Items)
- {
- public const string Version = "1.0.0";
- private static readonly JsonSerializerOptions DigestJson = new(JsonSerializerDefaults.Web);
- public string PackageCode => "MDP-PO-001";
- public string ObjectCode => "PURCHASE_ORDER";
- public string ComputeDigest()
- {
- var bytes = JsonSerializer.SerializeToUtf8Bytes(this with { LeaseToken = string.Empty }, DigestJson);
- return PurchaseOrderSchemaRegistry.ComputeSha256(bytes);
- }
- }
- public sealed record PurchaseQuarantine(Guid RawEventId, string Field, string Reason);
- public sealed record PurchaseHandoffReceipt(Guid BatchId, int AcceptedCount, IReadOnlyList<PurchaseQuarantine> Conflicts)
- {
- public bool Matches(Guid expectedBatch, IReadOnlySet<Guid> events)
- {
- if (BatchId != expectedBatch || Conflicts is null || AcceptedCount < 0 || AcceptedCount != events.Count - Conflicts.Count)
- return false;
- var seen = new HashSet<Guid>();
- return Conflicts.All(conflict => conflict is not null && events.Contains(conflict.RawEventId) && seen.Add(conflict.RawEventId));
- }
- }
- public sealed record PurchaseBatchProcessingResult(PurchaseHandoffPackage Package, IReadOnlyList<PurchaseQuarantine> Quarantines);
- public interface IAidopPackageHandoff
- {
- Task<PurchaseHandoffReceipt?> FindReceiptAsync(Guid batch, string digest, CancellationToken cancellationToken);
- Task<PurchaseHandoffReceipt> SubmitAsync(PurchaseHandoffPackage package, CancellationToken cancellationToken);
- }
|