IIqcReceiptStdReader.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using SqlSugar;
  2. namespace Admin.NET.Plugin.AiDOP.MaterialWarehouse.InventoryPosting.L0;
  3. /// <summary>
  4. /// IQC 收货标准层只读读取(L0,态①)。**只读 `mdp_std_iqc_receipt_state`**——不直连 dopdemorq、不读旧 InvMaster/PurOrd* raw。
  5. /// 双源边界:std 内容由入站/切源决定(本库 或 dopdemorq),读端只按 tenant+domain+fbillno 查,与 source 解耦。
  6. /// </summary>
  7. public interface IIqcReceiptStdReader
  8. {
  9. /// <summary>按 (tenant, domain, FBILLNO) 读标准层单行;不存在返回 null(Found=false)。</summary>
  10. Task<IqcReceiptStdRow> LoadRowAsync(long tenantId, string domainCode, string fbillno);
  11. }
  12. /// <summary>
  13. /// 生产实现:原生 SQL 读 `mdp_std_iqc_receipt_state`(运行时 DDL 表,非 SugarTable 实体,故走 Ado)。
  14. /// ⚠️ Phase 5B 未实库验证:标准层需先由 <see cref="IqcReceiptStateMdpSyncService"/> 贴源产出。
  15. /// </summary>
  16. public sealed class SqlSugarIqcReceiptStdReader : IIqcReceiptStdReader, ITransient
  17. {
  18. private readonly ISqlSugarClient _db;
  19. public SqlSugarIqcReceiptStdReader(ISqlSugarClient db) => _db = db;
  20. public async Task<IqcReceiptStdRow> LoadRowAsync(long tenantId, string domainCode, string fbillno)
  21. {
  22. var dt = await _db.Ado.GetDataTableAsync(
  23. """
  24. SELECT tenant_id, domain, fbillno, qc_nbr, item_num, location, lot_serial, rct_nbr,
  25. pur_ord, pur_line, potype, qty_ordered, received_cum_qty, returned_cum_qty,
  26. sample_qty, receipt_pending_qty, receivable_detail_count, sync_time
  27. FROM mdp_std_iqc_receipt_state
  28. WHERE tenant_id=@t AND domain=@d AND fbillno=@fb
  29. LIMIT 1
  30. """,
  31. new SugarParameter("@t", tenantId), new SugarParameter("@d", domainCode ?? ""), new SugarParameter("@fb", fbillno));
  32. if (dt.Rows.Count == 0) return null;
  33. var r = dt.Rows[0];
  34. decimal Dec(string c) => r[c] == DBNull.Value ? 0m : Convert.ToDecimal(r[c]);
  35. int Int(string c) => r[c] == DBNull.Value ? 0 : Convert.ToInt32(r[c]);
  36. string Str(string c) => r[c] == DBNull.Value ? "" : Convert.ToString(r[c]);
  37. return new IqcReceiptStdRow
  38. {
  39. TenantId = tenantId, Domain = domainCode ?? "", Fbillno = fbillno, QcNbr = Str("qc_nbr"),
  40. ItemNum = Str("item_num"), Location = Str("location"), LotSerial = Str("lot_serial"), RctNbr = Str("rct_nbr"),
  41. PurOrd = Str("pur_ord"), PurLine = Int("pur_line"), Potype = Str("potype"),
  42. OrderedQty = Dec("qty_ordered"), ReceivedCumQty = Dec("received_cum_qty"), ReturnedCumQty = Dec("returned_cum_qty"),
  43. SampleQty = Dec("sample_qty"), ReceiptPendingQty = Dec("receipt_pending_qty"), ReceivableDetailCount = Int("receivable_detail_count"),
  44. SourceSyncedAt = r["sync_time"] == DBNull.Value ? (DateTime?)null : Convert.ToDateTime(r["sync_time"]),
  45. };
  46. }
  47. }