S8OrderFlowProcurementPivotSeedData.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using Admin.NET.Plugin.AiDOP.Entity.S8.OrderFlow;
  2. namespace Admin.NET.Plugin.AiDOP.SeedData;
  3. /// <summary>
  4. /// ORDER-FLOW-S8-INTEGRATED-DOMAIN-RESET-1 t2c:S8 订单执行链路材料采购透视表 baseline 种子。
  5. /// 3 materials (XX/YY/ZZ) × 4 suppliers (A/B/C/TOTAL) × 4 specs (L4.5*11.2/MT2*6.3/MT1*5.4/TOTAL) = 48 行。
  6. /// YY 16 单元为 PPT 第 4 页真值;XX/ZZ 16 单元各自按确定性 multiplier 派生(无随机 / 无 Now)。
  7. /// status 在 seed 时确定,不允许 service/前端动态重判;按 cycle_days 三档阈值固化(≤15 green / 15..20 yellow / &gt;20 red)。
  8. /// order_id / order_code 全部 NULL(baseline 行)。
  9. /// </summary>
  10. [IncreSeed]
  11. public class S8OrderFlowProcurementPivotSeedData : ISqlSugarEntitySeedData<AdoS8OrderFlowProcurementPivot>
  12. {
  13. public IEnumerable<AdoS8OrderFlowProcurementPivot> HasData() => S8OrderFlowProcurementPivotDataset.BuildRows();
  14. }
  15. internal static class S8OrderFlowProcurementPivotDataset
  16. {
  17. internal const long PivotIdBase = 1329909140000L;
  18. internal static readonly string[] Suppliers = { "A", "B", "C", "TOTAL" };
  19. internal static readonly string[] Specs = { "L4.5*11.2", "MT2*6.3", "MT1*5.4", "TOTAL" };
  20. /// <summary>YY (PPT 第 4 页) 真值矩阵 [supplierIdx, specIdx];保留 3 位小数精度。</summary>
  21. private static readonly decimal[,] YyCycleDays =
  22. {
  23. // L4.5*11.2 | MT2*6.3 | MT1*5.4 | TOTAL
  24. { 14.800m, 11.000m, 11.000m, 13.000m }, // A
  25. { 14.050m, 17.150m, 17.150m, 15.600m }, // B
  26. { 14.050m, 23.925m, 23.850m, 20.100m }, // C
  27. { 14.500m, 17.400m, 14.800m, 15.300m }, // TOTAL
  28. };
  29. /// <summary>派生 XX / ZZ 单元值的 multiplier。XX 偏低、ZZ 偏高,便于 DEMO 拉开差异。</summary>
  30. private const decimal XxMultiplier = 0.85m;
  31. private const decimal ZzMultiplier = 1.10m;
  32. /// <summary>
  33. /// BASELINE_PPT 关键材料 grand 单元的"影响台次 / 准时齐套率"业务基线。
  34. /// 仅在 supplier_code=TOTAL && spec_code=TOTAL 行写入,其余 45 行保持 NULL。
  35. /// </summary>
  36. private static readonly Dictionary<string, (int ImpactCount, decimal KitRate)> GrandUnitBaseline = new()
  37. {
  38. ["XX"] = (55, 0.8500m),
  39. ["YY"] = (23, 0.8400m),
  40. ["ZZ"] = (10, 0.9700m),
  41. };
  42. public static IEnumerable<AdoS8OrderFlowProcurementPivot> BuildRows()
  43. {
  44. long seq = 0;
  45. foreach (var (material, scenario, mult) in new[]
  46. {
  47. ("XX", "DEMO", XxMultiplier),
  48. ("YY", "PPT", 1.0m),
  49. ("ZZ", "DEMO", ZzMultiplier),
  50. })
  51. {
  52. for (var s = 0; s < Suppliers.Length; s++)
  53. {
  54. for (var p = 0; p < Specs.Length; p++)
  55. {
  56. var rawCycle = YyCycleDays[s, p];
  57. var cycleDays = material == "YY"
  58. ? rawCycle
  59. : decimal.Round(rawCycle * mult, 3);
  60. var isGrand = Suppliers[s] == "TOTAL" && Specs[p] == "TOTAL";
  61. int? impactCount = null;
  62. decimal? kitRate = null;
  63. if (isGrand && GrandUnitBaseline.TryGetValue(material, out var baseline))
  64. {
  65. impactCount = baseline.ImpactCount;
  66. kitRate = baseline.KitRate;
  67. }
  68. yield return new AdoS8OrderFlowProcurementPivot
  69. {
  70. Id = PivotIdBase + (++seq),
  71. OrderId = null,
  72. OrderCode = null,
  73. MaterialCode = material,
  74. SupplierCode = Suppliers[s],
  75. SpecCode = Specs[p],
  76. CycleDays = cycleDays,
  77. Status = ClassifyStatus(cycleDays),
  78. ImpactCount = impactCount,
  79. KitRate = kitRate,
  80. ScenarioCode = scenario,
  81. DataSource = "SEED",
  82. TenantId = 1,
  83. FactoryId = 1,
  84. CreatedAt = S8OrderFlowDataset.CreatedAt,
  85. UpdatedAt = null,
  86. IsDeleted = false,
  87. };
  88. }
  89. }
  90. }
  91. }
  92. /// <summary>fixture 级 status 分类(seed-time once),运行期不再重算。</summary>
  93. private static string ClassifyStatus(decimal cycleDays)
  94. {
  95. if (cycleDays <= 15.0m) return "green";
  96. if (cycleDays <= 20.0m) return "yellow";
  97. return "red";
  98. }
  99. }