using Admin.NET.Plugin.AiDOP.Entity.S8.OrderFlow;
namespace Admin.NET.Plugin.AiDOP.SeedData;
///
/// ORDER-FLOW-S8-INTEGRATED-DOMAIN-RESET-1 t2b:OPINION_REVIEW 子节点下 L3 责任单元种子。
/// 20 单 × 4 责任单元 = 80 行,全部挂在 substep_code = OPINION_REVIEW;SO-2026-001 按 PPT 第 2 页真值,
/// 其余 19 单按 (orderIdx, unitIdx) 派生 multiplier,确定性、可重入。
///
[IncreSeed]
public class S8OrderFlowSubstepUnitSeedData : ISqlSugarEntitySeedData
{
public IEnumerable HasData() => S8OrderFlowSubstepUnitDataset.BuildUnits();
}
internal static class S8OrderFlowSubstepUnitDataset
{
internal const long UnitIdBase = 1329909130000L;
internal const string FlowCode = "ORDER_REVIEW_PLAN_CALC";
internal const string SubstepCode = "OPINION_REVIEW";
/// L3 四方责任单元固定顺序与 PI 基线工时。
internal static readonly (string Code, string Name, decimal PiHours)[] L3Def =
{
("LEGAL", "法律事务部", 2m),
("TECH_PRESALE", "技术售前组", 3m),
("GENERAL_PLAN", "综合主计划", 1m),
("LAB", "试验站", 2m),
};
/// SO-2026-001 PPT 第 2 页 L3 真值:actual_hours / status,与 L3Def 同序。
private static readonly (decimal Actual, string Status)[] Ppt001L3 =
{
(2.0m, "green"),
(9.2m, "red"),
(1.2m, "yellow"),
(2.0m, "green"),
};
///
/// 19 个非 PPT 单的 L3 派生 multiplier 桶。
/// bucketIdx = (idx - 2 + unitIdx) mod 4,对应 4 种 (multiplier, status) 组合。
/// status 满足:multiplier ≤ 1.00 = green;1.00 < multiplier ≤ 1.25 = yellow;> 1.25 = red。
///
private static readonly (decimal Mult, string Status)[] L3Buckets =
{
(0.95m, "green"),
(1.15m, "yellow"),
(1.35m, "red"),
(1.05m, "yellow"),
};
public static IEnumerable BuildUnits()
{
long seq = 0;
foreach (var spec in S8OrderFlowDataset.Specs)
{
var orderId = S8OrderFlowDataset.OrderIdBase + spec.Idx;
var substepId = S8OrderFlowSubstepDataset.OpinionReviewSubstepId(spec.Idx);
var isPpt = spec.OrderCode == "SO-2026-001";
var scenario = isPpt ? "PPT" : "DEMO";
for (var i = 0; i < L3Def.Length; i++)
{
var (code, name, piHours) = L3Def[i];
decimal actual;
string status;
if (isPpt)
{
actual = Ppt001L3[i].Actual;
status = Ppt001L3[i].Status;
}
else
{
var bucketIdx = ((spec.Idx - 2) + i) % L3Buckets.Length;
var bucket = L3Buckets[bucketIdx];
actual = decimal.Round(piHours * bucket.Mult, 1);
status = bucket.Status;
}
yield return new AdoS8OrderFlowSubstepUnit
{
Id = UnitIdBase + (++seq),
SubstepId = substepId,
OrderId = orderId,
OrderCode = spec.OrderCode,
OrderFlowCode = FlowCode,
SubstepCode = SubstepCode,
UnitCode = code,
UnitName = name,
PiHours = piHours,
ActualHours = actual,
Status = status,
SortNo = i + 1,
ScenarioCode = scenario,
DataSource = "SEED",
TenantId = 1,
FactoryId = 1,
CreatedAt = S8OrderFlowDataset.CreatedAt,
UpdatedAt = null,
IsDeleted = false,
};
}
}
}
}