S8OrderFlowOrderSeedData.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 t2a:S8 订单执行链路主档种子(20 单)。
  5. /// SO-2026-001 = PPT 第 1 页真值;其余 19 单沿用旧 demo seed 的业务维度与派生规则,
  6. /// 但 ORDER_FLOW 编码统一从 lower 升为 UPPER node_code。
  7. /// 新表 ado_s8_order_flow_order 不保留 exception_count 预存字段,
  8. /// 异常数后续由 ado_s8_exception 实时聚合。
  9. /// </summary>
  10. [IncreSeed]
  11. public class S8OrderFlowOrderSeedData : ISqlSugarEntitySeedData<AdoS8OrderFlowOrder>
  12. {
  13. public IEnumerable<AdoS8OrderFlowOrder> HasData() => S8OrderFlowDataset.BuildOrders();
  14. }
  15. internal static class S8OrderFlowDataset
  16. {
  17. /// <summary>沿用旧 demo seed 的 release_at 基准。</summary>
  18. internal static readonly DateTime ReleaseBase = new(2026, 4, 15, 9, 0, 0);
  19. internal static readonly DateTime CreatedAt = DateTime.Parse("2026-05-12 00:00:00");
  20. /// <summary>OrderId 基址(与旧 demo OrderIdBase 不同号段,避免冲突)。</summary>
  21. internal const long OrderIdBase = 1329909100000L;
  22. internal const long StageIdBase = 1329909110000L;
  23. /// <summary>lower → UPPER 映射(旧 demo seed 编码 → ORDER_FLOW dimension node_code)。</summary>
  24. internal static string ToUpperFlow(string lowerKey) => lowerKey switch
  25. {
  26. "order_review" => "ORDER_REVIEW_PLAN_CALC",
  27. "product_design" => "PRODUCT_DESIGN",
  28. "material_procurement" => "MATERIAL_PURCHASE",
  29. "body_production" => "BODY_PRODUCTION",
  30. "final_assembly_shipping" => "FINAL_ASSEMBLY_DELIVERY",
  31. _ => throw new ArgumentException($"未知 lower flow key: {lowerKey}")
  32. };
  33. /// <summary>UPPER → 展示中文名。</summary>
  34. internal static string UpperFlowName(string upperCode) => upperCode switch
  35. {
  36. "ORDER_REVIEW_PLAN_CALC" => "评审/排产/测算",
  37. "PRODUCT_DESIGN" => "产品设计",
  38. "MATERIAL_PURCHASE" => "材料采购",
  39. "BODY_PRODUCTION" => "本体生产",
  40. "FINAL_ASSEMBLY_DELIVERY" => "总装发货",
  41. _ => upperCode
  42. };
  43. /// <summary>UPPER 顺序:5 阶段在 lifecycle / stage seed 中按此 sort_no 1~5。</summary>
  44. internal static readonly (string Upper, string Name, decimal Kpi)[] FlowDef =
  45. {
  46. ("ORDER_REVIEW_PLAN_CALC", "评审/排产/测算", 5m),
  47. ("PRODUCT_DESIGN", "产品设计", 3m),
  48. ("MATERIAL_PURCHASE", "材料采购", 14m),
  49. ("BODY_PRODUCTION", "本体生产", 6m),
  50. ("FINAL_ASSEMBLY_DELIVERY", "总装发货", 3m),
  51. };
  52. internal record OrderSpec(
  53. int Idx, string OrderCode, string ProductName,
  54. string CustomerName, string CustomerCode, string CustomerType,
  55. string ProductLine, string Region, string Priority,
  56. string WorkflowStatus, string CurrentNodeLower, string FocusNodeLower,
  57. int? ResponseMinutes, int? ProcessingMinutes, int? TotalLossMinutes);
  58. /// <summary>20 单 specs。与旧 S8DemoOrderFlowSeedData.Specs 业务维度一一对齐(除 ORDER_FLOW 编码升级 + 去掉 ExceptionCount)。</summary>
  59. internal static readonly OrderSpec[] Specs =
  60. {
  61. new(1, "SO-2026-001", "高压接线盒", "电气设备厂A", "C001", "KA", "A产品线", "华北", "P2", "completed", "final_assembly_shipping", "final_assembly_shipping", 2880, 1440, 4320),
  62. new(2, "SO-2026-002", "转向机总成", "电气设备厂B", "C002", "KA", "B产品线", "华东", "P3", "completed", "final_assembly_shipping", "material_procurement", 110, 850, 960),
  63. new(3, "SO-2026-003", "电池箱横梁", "电气设备厂C", "C003", "KA", "C产品线", "华南", "P2", "completed", "final_assembly_shipping", "body_production", 80, 720, 800),
  64. new(4, "SO-2026-004", "高压接线盒", "电气设备厂D", "C004", "SMB", "A产品线", "华北", "P3", "completed", "final_assembly_shipping", "product_design", 95, 680, 775),
  65. new(5, "SO-2026-005", "电池箱横梁", "电气设备厂E", "C005", "MICRO", "C产品线", "华南", "P2", "completed", "final_assembly_shipping", "product_design", 70, 610, 680),
  66. new(6, "SO-2026-006", "驱动总成支架", "电气设备厂A", "C001", "KA", "A产品线", "华北", "P2", "completed", "final_assembly_shipping", "material_procurement", 130, 1240, 2350),
  67. new(7, "SO-2026-007", "减速器壳体", "电气设备厂B", "C002", "KA", "B产品线", "华东", "P2", "completed", "final_assembly_shipping", "body_production", 145, 1080, 2210),
  68. new(8, "SO-2026-008", "项目定制骨架", "电气设备厂C", "C003", "KA", "C产品线", "华南", "P1", "completed", "final_assembly_shipping", "body_production", 165, 1320, 2640),
  69. new(9, "SO-2026-009", "控制器外壳", "电气设备厂D", "C004", "SMB", "A产品线", "华北", "P2", "completed", "final_assembly_shipping", "order_review", 60, 540, 600),
  70. new(10, "SO-2026-010", "试制急单件", "电气设备厂E", "C005", "MICRO", "C产品线", "华南", "P2", "completed", "final_assembly_shipping", "product_design", 88, 730, 818),
  71. new(11, "SO-2026-011", "冷却模块框架", "电气设备厂A", "C001", "KA", "B产品线", "华东", "P2", "completed", "final_assembly_shipping", "final_assembly_shipping", 50, 410, 460),
  72. new(12, "SO-2026-012", "动力舱隔板", "电气设备厂B", "C002", "KA", "B产品线", "华东", "P2", "completed", "final_assembly_shipping", "material_procurement", 100, 920, 1020),
  73. new(13, "SO-2026-013", "模组支架", "电气设备厂C", "C003", "KA", "C产品线", "华南", "P2", "completed", "final_assembly_shipping", "body_production", 92, 860, 952),
  74. new(14, "SO-2026-014", "一体化支撑件", "电气设备厂D", "C004", "SMB", "A产品线", "华北", "P3", "completed", "final_assembly_shipping", "material_procurement", 75, 700, 775),
  75. new(15, "SO-2026-015", "项目定制骨架", "电气设备厂E", "C005", "MICRO", "C产品线", "华南", "P2", "completed", "final_assembly_shipping", "order_review", 65, 580, 645),
  76. new(16, "SO-2026-016", "控制器外壳", "电气设备厂A", "C001", "KA", "A产品线", "华北", "P2", "in_progress", "order_review", "order_review", 90, null, null),
  77. new(17, "SO-2026-017", "转向机总成", "电气设备厂B", "C002", "KA", "B产品线", "华东", "P2", "in_progress", "product_design", "product_design", 105, null, null),
  78. new(18, "SO-2026-018", "项目定制骨架", "电气设备厂C", "C003", "KA", "C产品线", "华南", "P2", "in_progress", "material_procurement", "material_procurement", 120, null, null),
  79. new(19, "SO-2026-019", "驱动总成支架", "电气设备厂D", "C004", "SMB", "A产品线", "华北", "P1", "in_progress", "body_production", "body_production", 140, null, null),
  80. new(20, "SO-2026-020", "试制急单件", "电气设备厂E", "C005", "MICRO", "C产品线", "华南", "P1", "in_progress", "final_assembly_shipping", "final_assembly_shipping", 55, null, null),
  81. };
  82. public static IEnumerable<AdoS8OrderFlowOrder> BuildOrders()
  83. {
  84. var targetCycle = FlowDef.Sum(s => s.Kpi);
  85. foreach (var spec in Specs)
  86. {
  87. var lifecycle = S8OrderFlowStageDataset.BuildLifecycleValues(spec);
  88. decimal? actualCycleDays = null;
  89. if (spec.WorkflowStatus == "completed" && lifecycle[^1].actualEnd.HasValue)
  90. {
  91. var days = decimal.Round((decimal)(lifecycle[^1].actualEnd!.Value - ReleaseBase).TotalDays, 1);
  92. actualCycleDays = days;
  93. }
  94. yield return new AdoS8OrderFlowOrder
  95. {
  96. Id = OrderIdBase + spec.Idx,
  97. TenantId = 1,
  98. FactoryId = 1,
  99. OrderCode = spec.OrderCode,
  100. ProductName = spec.ProductName,
  101. ProductLine = spec.ProductLine,
  102. CustomerCode = spec.CustomerCode,
  103. CustomerName = spec.CustomerName,
  104. CustomerType = spec.CustomerType,
  105. Region = spec.Region,
  106. Priority = spec.Priority,
  107. WorkflowStatus = spec.WorkflowStatus,
  108. CurrentOrderFlowCode = ToUpperFlow(spec.CurrentNodeLower),
  109. ReleaseAt = ReleaseBase,
  110. TargetCycleDays = targetCycle,
  111. ActualCycleDays = actualCycleDays,
  112. ResponseMinutes = spec.ResponseMinutes,
  113. ProcessingMinutes = spec.ProcessingMinutes,
  114. TotalLossMinutes = spec.TotalLossMinutes,
  115. ScenarioCode = spec.OrderCode == "SO-2026-001" ? "PPT" : "DEMO",
  116. DataSource = "SEED",
  117. CreatedAt = CreatedAt,
  118. UpdatedAt = null,
  119. IsDeleted = false,
  120. };
  121. }
  122. }
  123. }