S8OrderFlowSubstepSeedData.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 t2b:ORDER_REVIEW_PLAN_CALC 阶段 L2 子节点种子。
  5. /// 20 单 × 5 子节点 = 100 行;SO-2026-001 按 PPT 第 2 页真值;其余 19 单按 (orderIdx, substepIdx)
  6. /// 派生 multiplier,确定性、可重入,无随机数 / DateTime.Now。
  7. /// </summary>
  8. [IncreSeed]
  9. public class S8OrderFlowSubstepSeedData : ISqlSugarEntitySeedData<AdoS8OrderFlowSubstep>
  10. {
  11. public IEnumerable<AdoS8OrderFlowSubstep> HasData() => S8OrderFlowSubstepDataset.BuildSubsteps();
  12. }
  13. internal static class S8OrderFlowSubstepDataset
  14. {
  15. internal const long SubstepIdBase = 1329909120000L;
  16. internal const string FlowCode = "ORDER_REVIEW_PLAN_CALC";
  17. /// <summary>L2 五子节点固定顺序与 PI 基线工时。</summary>
  18. internal static readonly (string Code, string Name, decimal PiHours)[] L2Def =
  19. {
  20. ("OPINION_REVIEW", "意见评审", 8m),
  21. ("OPINION_FEEDBACK", "意见反馈", 12m),
  22. ("SECOND_REVIEW", "二次评审", 8m),
  23. ("LEADER_REVIEW", "领导意见", 10m),
  24. ("CONTRACT_SEAL", "合同盖章", 2m),
  25. };
  26. /// <summary>SO-2026-001 PPT 第 2 页 L2 真值:actual_hours / status,与 L2Def 同序。</summary>
  27. private static readonly (decimal Actual, string Status)[] Ppt001L2 =
  28. {
  29. (14.4m, "red"),
  30. (14.2m, "yellow"),
  31. ( 7.0m, "green"),
  32. (12.0m, "yellow"),
  33. ( 2.0m, "green"),
  34. };
  35. /// <summary>
  36. /// 19 个非 PPT 单的 L2 派生 multiplier 桶。
  37. /// bucketIdx = (idx - 2 + substepIdx) mod 5,对应 5 种 (multiplier, status) 组合。
  38. /// status 满足:multiplier ≤ 1.00 = green;1.00 &lt; multiplier ≤ 1.25 = yellow;&gt; 1.25 = red。
  39. /// </summary>
  40. private static readonly (decimal Mult, string Status)[] L2Buckets =
  41. {
  42. (0.90m, "green"),
  43. (1.10m, "yellow"),
  44. (1.40m, "red"),
  45. (1.00m, "green"),
  46. (1.20m, "yellow"),
  47. };
  48. public static IEnumerable<AdoS8OrderFlowSubstep> BuildSubsteps()
  49. {
  50. long seq = 0;
  51. foreach (var spec in S8OrderFlowDataset.Specs)
  52. {
  53. var orderId = S8OrderFlowDataset.OrderIdBase + spec.Idx;
  54. var isPpt = spec.OrderCode == "SO-2026-001";
  55. var scenario = isPpt ? "PPT" : "DEMO";
  56. for (var i = 0; i < L2Def.Length; i++)
  57. {
  58. var (code, name, piHours) = L2Def[i];
  59. decimal actual;
  60. string status;
  61. if (isPpt)
  62. {
  63. actual = Ppt001L2[i].Actual;
  64. status = Ppt001L2[i].Status;
  65. }
  66. else
  67. {
  68. var bucketIdx = ((spec.Idx - 2) + i) % L2Buckets.Length;
  69. var bucket = L2Buckets[bucketIdx];
  70. actual = decimal.Round(piHours * bucket.Mult, 1);
  71. status = bucket.Status;
  72. }
  73. yield return new AdoS8OrderFlowSubstep
  74. {
  75. Id = SubstepIdBase + (++seq),
  76. OrderId = orderId,
  77. OrderCode = spec.OrderCode,
  78. OrderFlowCode = FlowCode,
  79. SubstepCode = code,
  80. SubstepName = name,
  81. PiHours = piHours,
  82. ActualHours = actual,
  83. Status = status,
  84. SortNo = i + 1,
  85. ScenarioCode = scenario,
  86. DataSource = "SEED",
  87. TenantId = 1,
  88. FactoryId = 1,
  89. CreatedAt = S8OrderFlowDataset.CreatedAt,
  90. UpdatedAt = null,
  91. IsDeleted = false,
  92. };
  93. }
  94. }
  95. }
  96. /// <summary>OPINION_REVIEW 在 100 行 substep 中的全局 substep_id(供 unit seed 反查 FK)。</summary>
  97. public static long OpinionReviewSubstepId(int orderIdx)
  98. {
  99. // 每单 5 个 substep,OPINION_REVIEW 是第 1 个(sort_no=1)。
  100. // seq 顺序:(idx=1 的 5 个) → (idx=2 的 5 个) → ...
  101. // 第 idx 单的 OPINION_REVIEW seq = (idx - 1) * 5 + 1。
  102. return SubstepIdBase + (orderIdx - 1) * 5L + 1L;
  103. }
  104. }