S8OrderFlowSubstepUnitSeedData.cs 5.4 KB

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