namespace Admin.NET.Plugin.AiDOP.Infrastructure.S8;
///
/// S8 异常场景码常量(双轨)。
///
/// 新单模块 scene(S1-S7)与旧复合 scene(S1S7_DELIVERY 等)共存:
/// - 新代码请使用 S1-S7 单模块 scene;
/// - 旧复合常量保留向下兼容, /
/// / 等仍可识别。
///
/// 迁移轨道:S8-SCENE-MIGRATE-CODE-DUALRAIL-1(本轮,仅代码双轨,不动 DB)。
/// 后续 S8-SCENE-MIGRATE-CONFIG-S1S7-1 才迁移 scene_config / exception_type / watch_rule。
///
public static class S8SceneCode
{
// ─────────────── 新单模块 scene_code(S1-S7) ──────────────────────────────
/// S1 产销协同
public const string S1 = "S1";
/// S2 制造协同
public const string S2 = "S2";
/// S3 供应协同
public const string S3 = "S3";
/// S4 采购执行
public const string S4 = "S4";
/// S5 物料仓储
public const string S5 = "S5";
/// S6 生产执行
public const string S6 = "S6";
/// S7 成品仓储
public const string S7 = "S7";
// ─────────────── 旧复合 scene_code(保留兼容;新代码请勿使用) ─────────────
/// 交付异常(S1 订单评审变更 + S7 成品出库交期)— 旧复合 scene,保留兼容。
public const string S1S7Delivery = "S1S7_DELIVERY";
/// 生产异常(S2 工单开工 + S6 完工/质量)— 旧复合 scene,保留兼容。
public const string S2S6Production = "S2S6_PRODUCTION";
/// 供应异常(S3 MRP套料 + S5 IQC/库存)— 旧复合 scene,保留兼容。
public const string S3S5Supply = "S3S5_SUPPLY";
/// 采购执行异常(S4 PO跟单/收货/退货)— 旧复合 scene,保留兼容。
public const string S4Purchase = "S4_PURCHASE";
// 注:S2S6_QUALITY 是 dev DB 中存在但 C# 常量未定义的旧场景(demo rule 12 引用);
// 通过 Label() / Modules() 字面值识别保留兼容,不新增常量以免被新代码引用。
/// scene_code → 中文名称(双轨:S1-S7 业务名 + 旧复合保留)
public static string Label(string sceneCode) => sceneCode switch
{
S1 => "S1 产销协同",
S2 => "S2 制造协同",
S3 => "S3 供应协同",
S4 => "S4 采购执行",
S5 => "S5 物料仓储",
S6 => "S6 生产执行",
S7 => "S7 成品仓储",
S1S7Delivery => "交付异常",
S2S6Production => "生产异常",
"S2S6_QUALITY" => "质量异常",
S3S5Supply => "供应异常",
S4Purchase => "采购执行异常",
_ => sceneCode
};
///
/// scene_code → 所属模块列表(双轨)。
/// 新单模块 scene 1:1 自映射;旧复合 scene 沿用历史映射。
///
public static string[] Modules(string sceneCode) => sceneCode switch
{
S1 => new[] { S1 },
S2 => new[] { S2 },
S3 => new[] { S3 },
S4 => new[] { S4 },
S5 => new[] { S5 },
S6 => new[] { S6 },
S7 => new[] { S7 },
S1S7Delivery => new[] { "S1", "S7" },
S2S6Production => new[] { "S2", "S6" },
"S2S6_QUALITY" => new[] { "S2", "S6" },
S3S5Supply => new[] { "S3", "S5" },
S4Purchase => new[] { "S4" },
_ => Array.Empty()
};
/// 新单模块 scene_code 列表(S1-S7)。新代码请使用此清单。
public static readonly string[] ModuleSceneCodes = { S1, S2, S3, S4, S5, S6, S7 };
/// 旧复合 scene_code 列表(保留兼容;新代码请勿使用)。
public static readonly string[] LegacyCompositeSceneCodes =
{
S1S7Delivery,
S2S6Production,
S3S5Supply,
S4Purchase
};
///
/// 历史 scene_code 有序列表(仅含旧复合,保兼容外部遍历调用);
/// 新代码请改用 。
///
public static readonly string[] All =
{
S1S7Delivery,
S2S6Production,
S3S5Supply,
S4Purchase
};
}
///
/// S8 模块码常量(对应 S1-S7 业务模块)。
///
public static class S8ModuleCode
{
public const string S1 = "S1";
public const string S2 = "S2";
public const string S3 = "S3";
public const string S4 = "S4";
public const string S5 = "S5";
public const string S6 = "S6";
public const string S7 = "S7";
/// module_code → 业务名称(与侧栏菜单 S{N} 看板标题对齐,统一字面)
public static string Label(string moduleCode) => moduleCode switch
{
S1 => "S1 产销协同",
S2 => "S2 制造协同",
S3 => "S3 供应协同",
S4 => "S4 采购执行",
S5 => "S5 物料仓储",
S6 => "S6 生产执行",
S7 => "S7 成品仓储",
_ => moduleCode
};
///
/// module_code → 所属 scene_code。
/// S8-SCENE-MIGRATE-CODE-DUALRAIL-1 起:优先返回 S1-S7 单模块 scene,
/// 不再返回旧复合 scene;如需旧复合归属请直接引用 等常量。
///
public static string SceneOf(string moduleCode) => moduleCode switch
{
S1 => S8SceneCode.S1,
S2 => S8SceneCode.S2,
S3 => S8SceneCode.S3,
S4 => S8SceneCode.S4,
S5 => S8SceneCode.S5,
S6 => S8SceneCode.S6,
S7 => S8SceneCode.S7,
_ => string.Empty
};
/// 所有模块码有序列表
public static readonly string[] All = { S1, S2, S3, S4, S5, S6, S7 };
///
/// S8-EXCEPTION-CREATION-MODULE-CODE-FIX-1:合法 module_code 校验。
/// 仅 S1-S7 完全匹配返回 true;空值 / 任何非 S1-S7 字符串(含 legacy 复合 scene)返回 false。
///
public static bool IsValid(string? code) =>
!string.IsNullOrWhiteSpace(code) && Array.IndexOf(All, code!) >= 0;
///
/// 输入归一化:合法 S1-S7 原样返回,非法(含 legacy 复合 scene 字面量)返回 null。
/// 用于建单链路,caller 可链式优先级派生 module_code。
///
public static string? Normalize(string? code) => IsValid(code) ? code : null;
///
/// S8-EXCEPTION-CREATION-MODULE-CODE-FIX-1:严格按 single-module scene 派生 module_code。
/// 仅当 sceneCode ∈ {S1..S7} 时返回该值;
/// 不接受 legacy 复合 scene(S1S7_DELIVERY / S2S6_PRODUCTION / S2S6_QUALITY / S3S5_SUPPLY / S4_PURCHASE)。
/// 用于新建异常的 module_code 派生;与 区别在于不做 legacy 映射。
///
public static string? FromCanonicalScene(string? sceneCode) => Normalize(sceneCode);
///
/// 场景码 → 代表模块码(双轨)。
/// - 新 S1-S7 scene:返回自身( 1:1 自映射);
/// - 旧复合 scene:返回代表模块(取 首项),保留历史行为;
/// 用于历史 process_node 等非 module_code 派生场景;新建异常 module_code 请改用
/// (严格版,禁止 legacy 映射)。
/// 未识别 scene 返回 null(caller 自决:留空或兜底)。
///
public static string? FromScene(string? sceneCode)
{
if (string.IsNullOrWhiteSpace(sceneCode)) return null;
var modules = S8SceneCode.Modules(sceneCode);
return modules.Length == 0 ? null : modules[0];
}
}