S8OrderFlowSubstepUnitSeedData.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using Admin.NET.Plugin.AiDOP.Entity.S8.OrderFlow;
  2. namespace Admin.NET.Plugin.AiDOP.SeedData;
  3. /// <summary>
  4. /// S8-ORDER-EXECUTION-ORDER-REVIEW-SUBSTEP-PERSIST-1:ORDER_REVIEW_PLAN_CALC 阶段 L3 责任单元种子。
  5. /// 20 单 × 5 L2 × N 责任单元(4+3+3+3+2 = 15 / 单)= 300 行;每条 L3 由父 L2 的 piHours / actualHours 按
  6. /// 部门权重严格回卷生成(合计 = 父 L2 同字段),actualHours 缺失时全部 pending。
  7. /// 责任单元仅使用既有真实业务部门:法律事务部 / 技术售前组 / 综合主计划 / 试验站 / 市场部 / 研发中心。
  8. /// </summary>
  9. [IncreSeed]
  10. public class S8OrderFlowSubstepUnitSeedData : ISqlSugarEntitySeedData<AdoS8OrderFlowSubstepUnit>
  11. {
  12. public IEnumerable<AdoS8OrderFlowSubstepUnit> HasData() => S8OrderFlowSubstepUnitDataset.BuildUnits();
  13. }
  14. internal static class S8OrderFlowSubstepUnitDataset
  15. {
  16. internal const long UnitIdBase = 1329909130000L;
  17. internal const string FlowCode = "ORDER_REVIEW_PLAN_CALC";
  18. /// <summary>L3 责任单元定义。</summary>
  19. internal readonly record struct UnitDef(string Code, string Name, decimal Weight);
  20. /// <summary>
  21. /// 5 个 L2 子节点的 L3 责任单元模板:每个 substep_code → 责任单元列表(含权重,合计 1.00)。
  22. /// UnitCode 既有 4 项(LEGAL / TECH_PRESALE / GENERAL_PLAN / LAB),新增 2 项(MARKETING / RND)。
  23. /// 部门名全部来自既有 stage-meta / 既有 seed,未引入新部门。
  24. /// </summary>
  25. internal static readonly Dictionary<string, UnitDef[]> L3Template = new()
  26. {
  27. ["OPINION_REVIEW"] = new[]
  28. {
  29. new UnitDef("LEGAL", "法律事务部", 0.30m),
  30. new UnitDef("TECH_PRESALE", "技术售前组", 0.35m),
  31. new UnitDef("GENERAL_PLAN", "综合主计划", 0.15m),
  32. new UnitDef("LAB", "试验站", 0.20m),
  33. },
  34. ["OPINION_FEEDBACK"] = new[]
  35. {
  36. new UnitDef("MARKETING", "市场部", 0.40m),
  37. new UnitDef("TECH_PRESALE", "技术售前组", 0.35m),
  38. new UnitDef("GENERAL_PLAN", "综合主计划", 0.25m),
  39. },
  40. ["SECOND_REVIEW"] = new[]
  41. {
  42. new UnitDef("TECH_PRESALE", "技术售前组", 0.40m),
  43. new UnitDef("RND", "研发中心", 0.35m),
  44. new UnitDef("GENERAL_PLAN", "综合主计划", 0.25m),
  45. },
  46. ["LEADER_REVIEW"] = new[]
  47. {
  48. new UnitDef("MARKETING", "市场部", 0.35m),
  49. new UnitDef("RND", "研发中心", 0.40m),
  50. new UnitDef("GENERAL_PLAN", "综合主计划", 0.25m),
  51. },
  52. ["CONTRACT_SEAL"] = new[]
  53. {
  54. new UnitDef("LEGAL", "法律事务部", 0.70m),
  55. new UnitDef("MARKETING", "市场部", 0.30m),
  56. },
  57. };
  58. public static IEnumerable<AdoS8OrderFlowSubstepUnit> BuildUnits()
  59. {
  60. long seq = 0;
  61. foreach (var spec in S8OrderFlowDataset.Specs)
  62. {
  63. var orderId = S8OrderFlowDataset.OrderIdBase + spec.Idx;
  64. var scenario = spec.OrderCode == "SO-2026-001" ? "PPT" : "DEMO";
  65. var l2Rows = S8OrderFlowSubstepDataset.BuildL2Rows(spec);
  66. for (var substepIdx = 0; substepIdx < S8OrderFlowSubstepDataset.L2Def.Length; substepIdx++)
  67. {
  68. var (substepCode, _, _) = S8OrderFlowSubstepDataset.L2Def[substepIdx];
  69. var template = L3Template[substepCode];
  70. var substepId = S8OrderFlowSubstepDataset.SubstepIdAt(spec.Idx, substepIdx);
  71. var l2Row = l2Rows[substepIdx];
  72. var weights = template.Select(u => u.Weight).ToArray();
  73. var piHoursArr = S8OrderFlowSubstepDataset.AllocateByWeight(l2Row.PiHours, weights);
  74. decimal[]? actualHoursArr = l2Row.ActualHours == null
  75. ? null
  76. : S8OrderFlowSubstepDataset.AllocateByWeight(l2Row.ActualHours.Value, weights);
  77. for (var i = 0; i < template.Length; i++)
  78. {
  79. var unit = template[i];
  80. var actual = actualHoursArr?[i];
  81. var status = actual == null
  82. ? "pending"
  83. : S8OrderFlowSubstepDataset.ClassifyByPi(actual.Value, piHoursArr[i]);
  84. yield return new AdoS8OrderFlowSubstepUnit
  85. {
  86. Id = UnitIdBase + (++seq),
  87. SubstepId = substepId,
  88. OrderId = orderId,
  89. OrderCode = spec.OrderCode,
  90. OrderFlowCode = FlowCode,
  91. SubstepCode = substepCode,
  92. UnitCode = unit.Code,
  93. UnitName = unit.Name,
  94. PiHours = piHoursArr[i],
  95. ActualHours = actual,
  96. Status = status,
  97. SortNo = i + 1,
  98. ScenarioCode = scenario,
  99. DataSource = "SEED",
  100. TenantId = 1,
  101. FactoryId = 1,
  102. CreatedAt = S8OrderFlowDataset.CreatedAt,
  103. UpdatedAt = null,
  104. IsDeleted = false,
  105. };
  106. }
  107. }
  108. }
  109. }
  110. }