NeutralRequiredColumns.cs 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. namespace Admin.NET.Plugin.AiDOP.DataPlatform;
  2. /// <summary>
  3. /// 中立层 KPI 必填列。某通道的投影 SQL 必须写出这些列,写不出的列登记在 <see cref="Gaps"/>。
  4. /// </summary>
  5. public static class NeutralRequiredColumns
  6. {
  7. public sealed record RequiredColumn(string Name, string? SemanticCode);
  8. public static IReadOnlyList<RequiredColumn> For(string? stdObject) =>
  9. string.Equals(stdObject, "INV_TRANS", StringComparison.OrdinalIgnoreCase)
  10. ?
  11. [
  12. new("location", "INV_LOCATION"),
  13. new("lot_serial", "INV_LOT"),
  14. new("create_user", "INV_CREATE_USER"),
  15. new("end_balance", "INV_END_BALANCE"),
  16. new("dimension1", null),
  17. new("eff_date", null),
  18. // S5_L1_001 物料上线周期、S7_L1_001 订单发货周期都以 approved_time 为唯一时间基准:
  19. // 该列整列为空时两个 KPI 只会算出 NO_DATA,且不会报错,故必须当必填列守住。
  20. new("approved_time", null),
  21. new("doc_qty", "DOC_QTY_CLOSE"),
  22. new("line_closed_flag", "DOC_QTY_CLOSE")
  23. ]
  24. : [];
  25. public static readonly string[] InvTrans =
  26. [
  27. "location", "lot_serial", "create_user", "end_balance", "dimension1", "eff_date", "approved_time", "doc_qty", "line_closed_flag"
  28. ];
  29. public sealed record Projection(string Channel, string RelativePath, string Marker, string[] Present, string[] Missing);
  30. public static readonly Projection[] Channels =
  31. [
  32. new("T8",
  33. Path.Combine("DataPlatform", "T8BaseInboundMdpSyncService.NeutralProjection.cs"),
  34. "ProjectInvTransSql",
  35. ["doc_qty", "eff_date", "approved_time", "dimension1", "line_closed_flag", "location", "lot_serial", "create_user", "end_balance"],
  36. []),
  37. new("PUSH",
  38. Path.Combine("DataPlatform", "T8BaseInboundMdpSyncService.NeutralProjection.cs"),
  39. "BuildProjectApiInvTransSql",
  40. ["location", "lot_serial", "create_user", "end_balance", "doc_qty", "line_closed_flag", "dimension1", "eff_date", "approved_time"],
  41. []),
  42. new("PULL",
  43. Path.Combine("DataPlatform", "T8BaseInboundMdpSyncService.NeutralProjection.cs"),
  44. "BuildProjectApiInvTransSql",
  45. ["location", "lot_serial", "create_user", "end_balance", "doc_qty", "line_closed_flag", "dimension1", "eff_date", "approved_time"],
  46. []),
  47. new("165",
  48. Path.Combine("MaterialWarehouse", "InventoryMdpSyncService.cs"),
  49. "MaterializeInvTransStdAsync",
  50. ["location", "lot_serial", "create_user", "end_balance", "doc_qty", "dimension1", "eff_date", "approved_time"],
  51. ["line_closed_flag"]),
  52. // 165 的销售发运走 ASN 明细单独一段投影(任务 A-3),是 mdp_std_inv_trans 的第二个写入口。
  53. // 它漏掉 approved_time 时 S7 三个指标会一起静默变成 NO_DATA,故必须单列为一个通道守住。
  54. new("165_ASN",
  55. Path.Combine("DataPlatform", "Wms", "ShipTransNeutralProjection.cs"),
  56. // 标记只写表名:带上 INSERT INTO 会被「中立层写入必须调用来源闸门」的守卫当成写入点。
  57. "mdp_std_inv_trans",
  58. ["location", "lot_serial", "create_user", "dimension1", "eff_date", "approved_time", "doc_qty"],
  59. ["end_balance", "line_closed_flag"]),
  60. // NATIVE 不写 mdp_std_inv_trans(自有数据只进工单、BOM、员工、销售订单行),
  61. // 故不参与库存流水必填列的覆盖断言,这里只记它自己的写入方标记。
  62. new("NATIVE",
  63. Path.Combine("DataPlatform", "NativeNeutralProjectionService.cs"),
  64. "AIDOP_NATIVE",
  65. ["written_by"],
  66. [])
  67. ];
  68. }