namespace Admin.NET.Plugin.AiDOP.MaterialWarehouse.InventoryPosting.Inventory;
/// InvMaster 写(W1 首建 / W2 更新为 After)。
public sealed class InvMasterWrite
{
public long TenantId { get; set; }
public string DomainCode { get; set; }
public string ItemNum { get; set; }
public string Location { get; set; }
/// 聚合增量(生产实库用相对 UPDATE `set x=x+delta` 防 lost-update,与 LIVE 相对更新一致)。
public InventoryDeltas Delta { get; set; }
/// 计算后值(供 INSERT 新行 = 0+delta,及 Shadow 对账验证)。
public InventoryBalance After { get; set; }
/// 无 InvMaster 且组内含入库 → 首建后再置 After。
public bool InsertIfMissing { get; set; }
public string User { get; set; }
}
/// ItemMaster.Location 语义写(W3 → ado_item_location_state;仅当原默认库位为空、txn Location 非空)。
public sealed class ItemLocationWrite
{
public long TenantId { get; set; }
public string DomainCode { get; set; }
public string ItemNum { get; set; }
public string DefaultLocation { get; set; }
public string User { get; set; }
}
/// LocationDetail 写(W4 首建 / W5 更新为 After)。
public sealed class LocationDetailWrite
{
public long TenantId { get; set; }
public string DomainCode { get; set; }
public string ItemNum { get; set; }
public string Location { get; set; }
public string LotSerial { get; set; }
public string Refs { get; set; }
/// 聚合增量(生产实库用相对 UPDATE 防 lost-update)。
public InventoryDeltas Delta { get; set; }
/// 计算后值(供 INSERT / 对账)。
public InventoryBalance After { get; set; }
public bool InsertIfMissing { get; set; }
public decimal Cost { get; set; }
public string Curr { get; set; }
public string User { get; set; }
}
/// 库存流水行(W6 append,映射 ado_inventory_transaction)。
public sealed class InventoryTransactionRow
{
public long TenantId { get; set; }
public string DomainCode { get; set; }
public long PostingId { get; set; }
public long TransactionGroupId { get; set; }
public int Seq { get; set; }
public string ItemNum { get; set; }
public string Location { get; set; }
public string LotSerial { get; set; }
public string TransType { get; set; }
public decimal QtyChange { get; set; }
public decimal BeginBalance { get; set; }
public decimal FreezeQty { get; set; }
public decimal Assay { get; set; }
public decimal Amt { get; set; }
public string WorkOrd { get; set; }
public string ShipperNum { get; set; }
public string Fbillno { get; set; }
public string Receiver { get; set; }
public string RctQcNbr { get; set; }
public string Remark { get; set; }
public string User { get; set; }
}
/// 一次过账计算出的全部写(W1-W6);由 store 在单事务内落地。
public sealed class InventoryWriteSet
{
public List InvMasterWrites { get; } = new();
public List ItemLocationWrites { get; } = new();
public List LocationDetailWrites { get; } = new();
public List TransactionRows { get; } = new();
public int TotalWrites => InvMasterWrites.Count + ItemLocationWrites.Count + LocationDetailWrites.Count + TransactionRows.Count;
}
/// C5 过账结果类别。(Duplicate/Conflict 由上游 Phase 4 幂等层在 C5 之前判定,不在 C5 内。)
public enum InventoryPostingOutcome
{
Success = 1,
ValidationFailure = 2,
Error = 3,
}
/// C5 过账结果(结构化错误码 + 保留 LIVE ReturnMsg 语义供 Shadow 对账)。
public sealed class InventoryPostingResult
{
public InventoryPostingOutcome Outcome { get; set; }
public IReadOnlyList GuardErrors { get; set; } = System.Array.Empty();
public int WrittenRows { get; set; }
public string ErrorCode { get; set; }
public string ErrorMessage { get; set; }
/// LIVE ReturnMsg 语义映射("保存成功"/守卫消息/"保存失败,…")。
public string LegacyReturnMsg { get; set; }
}