91 lines
4.6 KiB
C#
91 lines
4.6 KiB
C#
namespace MiGu.Server.Configs;
|
||
|
||
/// <summary>
|
||
/// 部署画像 —— 登录后「配置向导」的结果,对应 ConfigStore 的 <c>deployment</c> section
|
||
/// (持久化于 <c>data/config-deployment.json</c>)。
|
||
///
|
||
/// <para>它是「按选型裁剪」的单一事实来源:</para>
|
||
/// <list type="number">
|
||
/// <item><see cref="Configured"/>=false 时,登录返回 <c>NeedsWizard=true</c>,前端跳转配置向导;</item>
|
||
/// <item><see cref="NavigationKinds"/> 经 <see cref="ToActiveSceneIds"/> 映射为 SimpleLite 场景 id,
|
||
/// 由 Launcher 写入 <c>plugins/active-scenes.json</c> / 透传 <c>--scenes</c>,驱动内核「选择性加载」导航场景插件;</item>
|
||
/// <item><see cref="Modules"/> 驱动平台菜单与能力裁剪(PageCatalog 可见页)。</item>
|
||
/// </list>
|
||
/// </summary>
|
||
/// <param name="Configured">向导是否已完成。false = 登录后强制进入配置向导。</param>
|
||
/// <param name="PlatformType">平台主定位(仅用于 UI 标题/默认值),如 <c>standard</c> / <c>wcs</c> / <c>wms-wcs</c> / <c>custom</c>。</param>
|
||
/// <param name="Modules">启用的功能模块(多选),暂定 <c>wms</c> / <c>ptl</c>。</param>
|
||
/// <param name="NavigationKinds">导航方式(多选,一等维度),取值 <c>magnetic</c> / <c>qrcode</c> / <c>laser</c>,与 SimpleCore.NavKind 对齐。</param>
|
||
/// <param name="Scenarios">选用的业务场景模板 id(来自 ScenarioTemplateConfig),如 <c>tpl-sps</c> / <c>tpl-pack</c>。</param>
|
||
/// <param name="UpdatedBy">最近一次保存向导的用户名(审计用)。</param>
|
||
public record DeploymentProfile(
|
||
bool Configured,
|
||
string PlatformType,
|
||
List<string> Modules,
|
||
List<string> NavigationKinds,
|
||
List<string> Scenarios,
|
||
string UpdatedBy)
|
||
{
|
||
public static DeploymentProfile Default() => new(
|
||
Configured: false,
|
||
PlatformType: "standard",
|
||
Modules: new List<string>(),
|
||
NavigationKinds: new List<string>(),
|
||
Scenarios: new List<string>(),
|
||
UpdatedBy: "");
|
||
|
||
/// <summary>
|
||
/// 导航方式 → SimpleLite 场景 id 映射。与 <c>*.scene.json.id</c>、<c>SimpleCore.Navigation.NavKind</c>
|
||
/// 以及内核 <c>active-scenes.json.activeScenes</c> 一致;这是平台与内核之间「导航选型」的契约约定。
|
||
/// <para>两平台制(StandardScene 拆分落地):磁导航 → <c>scene.mag</c>;
|
||
/// 二维码与激光共用融合平台 <c>scene.qrlidar</c>(激光坐标导航 + 二维码按轨道逐段触发,可融合可单用)。</para>
|
||
/// </summary>
|
||
public static readonly IReadOnlyDictionary<string, string> NavKindToSceneId =
|
||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||
{
|
||
["magnetic"] = "scene.mag",
|
||
["qrcode"] = "scene.qrlidar",
|
||
["laser"] = "scene.qrlidar",
|
||
};
|
||
|
||
/// <summary>
|
||
/// 把已选 <see cref="NavigationKinds"/> 映射为 SimpleLite 激活场景 id 列表(去重、忽略未知项、保持选择顺序)。
|
||
/// 供 Launcher 写 <c>active-scenes.json</c> / 拼 <c>--scenes</c> 参数使用。
|
||
/// </summary>
|
||
public IReadOnlyList<string> ToActiveSceneIds()
|
||
{
|
||
var result = new List<string>();
|
||
if (NavigationKinds == null) return result;
|
||
foreach (var k in NavigationKinds)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(k)) continue;
|
||
if (NavKindToSceneId.TryGetValue(k.Trim(), out var sceneId) && !result.Contains(sceneId))
|
||
result.Add(sceneId);
|
||
}
|
||
return result;
|
||
}
|
||
|
||
/// <summary>信号交互场景 id(PLC 握手 + 磁条交管)。</summary>
|
||
public const string SignalSceneId = "scene.signal";
|
||
|
||
/// <summary>设备驱动场景 id(门/充电桩等,各类项目通用)。</summary>
|
||
public const string DeviceSceneId = "scene.device";
|
||
|
||
/// <summary>是否选了磁导航。</summary>
|
||
public bool UsesMagnetic() =>
|
||
NavigationKinds?.Any(k => string.Equals(k, "magnetic", StringComparison.OrdinalIgnoreCase)) == true;
|
||
|
||
/// <summary>
|
||
/// 写入 active-scenes.json 的完整场景集合:导航插件 + 磁导航时并入 scene.signal + scene.device。
|
||
/// </summary>
|
||
public IReadOnlyList<string> ToLauncherSceneIds()
|
||
{
|
||
var result = ToActiveSceneIds().ToList();
|
||
if (UsesMagnetic() && !result.Contains(SignalSceneId, StringComparer.OrdinalIgnoreCase))
|
||
result.Add(SignalSceneId);
|
||
if (!result.Contains(DeviceSceneId, StringComparer.OrdinalIgnoreCase))
|
||
result.Add(DeviceSceneId);
|
||
return result;
|
||
}
|
||
}
|