GetEnums 返回中英文对照:EnumItem{Name,ChineseName,Value} 替代 Dictionary<string,int>

- EnumMetadata 每个枚举从 Dictionary 改为 List<EnumItem>
- ScenarioService 内置中文翻译(与 ReportGenerator 统一)
- 250 测试全过
This commit is contained in:
tian 2026-06-19 21:24:51 +08:00
parent 2a062c07bd
commit 4b2677e224
4 changed files with 124 additions and 23 deletions

View File

@ -2,19 +2,27 @@ using System.Collections.Generic;
namespace CounterDrone.Core.Services
{
/// <summary>枚举元数据(前端下拉框数据源)</summary>
/// <summary>枚举条目(前端下拉框数据源)</summary>
public class EnumItem
{
public string Name { get; set; } = "";
public string ChineseName { get; set; } = "";
public int Value { get; set; }
}
/// <summary>枚举元数据(中英文对照)</summary>
public class EnumMetadata
{
public Dictionary<string, int> DroneType { get; set; } = new();
public Dictionary<string, int> PowerType { get; set; } = new();
public Dictionary<string, int> PlatformType { get; set; } = new();
public Dictionary<string, int> AerosolType { get; set; } = new();
public Dictionary<string, int> WeatherType { get; set; } = new();
public Dictionary<string, int> WindDirection { get; set; } = new();
public Dictionary<string, int> SceneType { get; set; } = new();
public Dictionary<string, int> FormationMode { get; set; } = new();
public Dictionary<string, int> TriggerMode { get; set; } = new();
public Dictionary<string, int> ReleaseMode { get; set; } = new();
public Dictionary<string, int> EquipmentRole { get; set; } = new();
public List<EnumItem> DroneType { get; set; } = new();
public List<EnumItem> PowerType { get; set; } = new();
public List<EnumItem> PlatformType { get; set; } = new();
public List<EnumItem> AerosolType { get; set; } = new();
public List<EnumItem> WeatherType { get; set; } = new();
public List<EnumItem> WindDirection { get; set; } = new();
public List<EnumItem> SceneType { get; set; } = new();
public List<EnumItem> FormationMode { get; set; } = new();
public List<EnumItem> TriggerMode { get; set; } = new();
public List<EnumItem> ReleaseMode { get; set; } = new();
public List<EnumItem> EquipmentRole { get; set; } = new();
}
}

View File

@ -234,20 +234,28 @@ namespace CounterDrone.Core.Services
{
return new EnumMetadata
{
DroneType = EnumToDict<Models.DroneType>(),
PowerType = EnumToDict<Models.PowerType>(),
PlatformType = EnumToDict<Models.PlatformType>(),
AerosolType = EnumToDict<Models.AerosolType>(),
WeatherType = EnumToDict<Models.WeatherType>(),
WindDirection = EnumToDict<Models.WindDirection>(),
SceneType = EnumToDict<Models.SceneType>(),
FormationMode = EnumToDict<Models.FormationMode>(),
TriggerMode = EnumToDict<Models.TriggerMode>(),
ReleaseMode = EnumToDict<Models.ReleaseMode>(),
EquipmentRole = EnumToDict<Models.EquipmentRole>(),
DroneType = EnumToList<Models.DroneType>(TranslateDrone),
PowerType = EnumToList<Models.PowerType>(TranslatePower),
PlatformType = EnumToList<Models.PlatformType>(TranslatePlatform),
AerosolType = EnumToList<Models.AerosolType>(TranslateAerosol),
WeatherType = EnumToList<Models.WeatherType>(TranslateWeather),
WindDirection = EnumToList<Models.WindDirection>(TranslateWindDirection),
SceneType = EnumToList<Models.SceneType>(TranslateScene),
FormationMode = EnumToList<Models.FormationMode>(TranslateFormation),
TriggerMode = EnumToList<Models.TriggerMode>(TranslateTrigger),
ReleaseMode = EnumToList<Models.ReleaseMode>(TranslateRelease),
EquipmentRole = EnumToList<Models.EquipmentRole>(TranslateEquipmentRole),
};
}
private static List<EnumItem> EnumToList<T>(Func<T, string> translate) where T : Enum
{
var list = new List<EnumItem>();
foreach (T v in Enum.GetValues(typeof(T)))
list.Add(new EnumItem { Name = v.ToString(), ChineseName = translate(v), Value = Convert.ToInt32(v) });
return list;
}
private static Dictionary<string, int> EnumToDict<T>() where T : Enum
{
var dict = new Dictionary<string, int>();
@ -256,6 +264,91 @@ namespace CounterDrone.Core.Services
return dict;
}
// ═══ 中文翻译 ═══
private static string TranslateDrone(Models.DroneType t) => t switch
{
Models.DroneType.Rotor => "旋翼",
Models.DroneType.FixedWing => "固定翼",
Models.DroneType.HighSpeed => "高速目标",
_ => t.ToString(),
};
private static string TranslatePower(Models.PowerType p) => p switch
{
Models.PowerType.Electric => "电推",
Models.PowerType.Piston => "活塞",
Models.PowerType.Jet => "喷气",
_ => p.ToString(),
};
private static string TranslatePlatform(Models.PlatformType p) => p switch
{
Models.PlatformType.AirBased => "空基",
Models.PlatformType.GroundBased => "地基",
_ => p.ToString(),
};
private static string TranslateAerosol(Models.AerosolType t) => t switch
{
Models.AerosolType.InertGas => "惰性气体(吸入式灭火)",
Models.AerosolType.ActiveMaterial => "活性材料(爆燃式)",
Models.AerosolType.ActiveFuel => "活性燃料(吸入式爆炸)",
_ => t.ToString(),
};
private static string TranslateWeather(Models.WeatherType w) => w switch
{
Models.WeatherType.Sunny => "晴天",
Models.WeatherType.Overcast => "阴天",
Models.WeatherType.Fog => "雾天",
Models.WeatherType.Rain => "雨天",
Models.WeatherType.Night => "夜间",
_ => w.ToString(),
};
private static string TranslateWindDirection(Models.WindDirection d) => d switch
{
Models.WindDirection.N => "北 (N)",
Models.WindDirection.NE => "东北 (NE)",
Models.WindDirection.E => "东 (E)",
Models.WindDirection.SE => "东南 (SE)",
Models.WindDirection.S => "南 (S)",
Models.WindDirection.SW => "西南 (SW)",
Models.WindDirection.W => "西 (W)",
Models.WindDirection.NW => "西北 (NW)",
_ => d.ToString(),
};
private static string TranslateScene(Models.SceneType s) => s switch
{
Models.SceneType.Urban => "城市",
Models.SceneType.Plain => "平原",
Models.SceneType.Mountain => "山区",
Models.SceneType.Coast => "海岸",
_ => s.ToString(),
};
private static string TranslateFormation(Models.FormationMode f) => f switch
{
Models.FormationMode.Single => "单机",
Models.FormationMode.Formation => "编队",
Models.FormationMode.Swarm => "蜂群",
_ => f.ToString(),
};
private static string TranslateTrigger(Models.TriggerMode t) => t switch
{
Models.TriggerMode.Time => "时间触发",
Models.TriggerMode.Area => "区域触发",
Models.TriggerMode.Manual => "手动触发",
_ => t.ToString(),
};
private static string TranslateRelease(Models.ReleaseMode r) => r switch
{
Models.ReleaseMode.Single => "单次",
Models.ReleaseMode.Continuous => "连续",
Models.ReleaseMode.Pulse => "脉冲",
_ => r.ToString(),
};
private static string TranslateEquipmentRole(Models.EquipmentRole r) => r switch
{
Models.EquipmentRole.Detection => "探测设备",
Models.EquipmentRole.LaunchPlatform => "发射平台",
_ => r.ToString(),
};
// ========== Scenario CRUD ==========
public Scenario UpdateScenario(Scenario scenario)

Binary file not shown.