feat: standalone detection equipment API + task detail includes detections
IScenarioService: AddDetection/DeleteDetection/GetDetections (independent of SaveDeployment overwrite). Repository: GetByTaskIdAndRole filters by equipment role. TaskFullConfig.Equipment already includes detections (GetTaskDetail.GetByTaskId returns all). Frontend filters by EquipmentRole.Detection or uses GetDetections. Tests: 4 detection CRUD tests. 212 total pass.
This commit is contained in:
parent
11f8cb2c79
commit
665747a846
@ -14,6 +14,14 @@ namespace CounterDrone.Core.Repository
|
||||
return Db.Table<EquipmentDeployment>().Where(e => e.TaskId == taskId).ToList();
|
||||
}
|
||||
|
||||
/// <summary>按任务和角色查询装备(EquipmentRole: 0=Detection, 1=LaunchPlatform)</summary>
|
||||
public List<EquipmentDeployment> GetByTaskIdAndRole(string taskId, int equipmentRole)
|
||||
{
|
||||
return Db.Table<EquipmentDeployment>()
|
||||
.Where(e => e.TaskId == taskId && e.EquipmentRole == equipmentRole)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public void DeleteByTaskId(string taskId)
|
||||
{
|
||||
var equips = GetByTaskId(taskId);
|
||||
|
||||
@ -15,6 +15,14 @@ namespace CounterDrone.Core.Services
|
||||
void SaveControlZones(string taskId, List<ControlZone> zones);
|
||||
void SaveTarget(string taskId, TargetConfig target);
|
||||
void SaveDeployment(string taskId, List<EquipmentDeployment> equips);
|
||||
|
||||
/// <summary>添加单个探测设备(独立于 SaveDeployment,不覆盖火力单元)</summary>
|
||||
void AddDetection(string taskId, EquipmentDeployment detection);
|
||||
/// <summary>删除探测设备</summary>
|
||||
void DeleteDetection(string detectionId);
|
||||
/// <summary>获取任务的所有探测设备(EquipmentRole.Detection)</summary>
|
||||
List<EquipmentDeployment> GetDetections(string taskId);
|
||||
|
||||
void SaveCloudDispersal(string taskId, CloudDispersal cloud);
|
||||
void SaveRoute(string taskId, string groupId, RoutePlan route, List<Waypoint> waypoints);
|
||||
void UpdateStep(string taskId, int step);
|
||||
|
||||
@ -158,6 +158,26 @@ namespace CounterDrone.Core.Services
|
||||
TouchTask(taskId);
|
||||
}
|
||||
|
||||
public void AddDetection(string taskId, EquipmentDeployment detection)
|
||||
{
|
||||
detection.TaskId = taskId;
|
||||
detection.EquipmentRole = (int)EquipmentRole.Detection;
|
||||
if (string.IsNullOrEmpty(detection.Id))
|
||||
detection.Id = Guid.NewGuid().ToString();
|
||||
_equipRepo.Insert(detection);
|
||||
TouchTask(taskId);
|
||||
}
|
||||
|
||||
public void DeleteDetection(string detectionId)
|
||||
{
|
||||
_equipRepo.Delete(detectionId);
|
||||
}
|
||||
|
||||
public List<EquipmentDeployment> GetDetections(string taskId)
|
||||
{
|
||||
return _equipRepo.GetByTaskIdAndRole(taskId, (int)EquipmentRole.Detection);
|
||||
}
|
||||
|
||||
public void SaveCloudDispersal(string taskId, CloudDispersal cloud)
|
||||
{
|
||||
cloud.TaskId = taskId;
|
||||
|
||||
@ -484,5 +484,81 @@ namespace CounterDrone.Core.Tests
|
||||
var searchResult = _service.SearchTasks("完整流程", null, null, 1, 10);
|
||||
Assert.Equal(1, searchResult.TotalCount);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════
|
||||
// 探测设备独立 CRUD
|
||||
// ═══════════════════════════════════════
|
||||
|
||||
[Fact]
|
||||
public void AddDetection_PersistsAndQueryable()
|
||||
{
|
||||
var task = _service.CreateTask("探测设备测试", "");
|
||||
_service.AddDetection(task.Id, new EquipmentDeployment
|
||||
{
|
||||
Quantity = 1,
|
||||
PositionX = 5000, PositionY = 0, PositionZ = 0,
|
||||
RadarRange = 8000, EORange = 4000, IRRange = 3000,
|
||||
DetectionAccuracy = 50,
|
||||
});
|
||||
|
||||
var detections = _service.GetDetections(task.Id);
|
||||
Assert.Single(detections);
|
||||
Assert.Equal((int)EquipmentRole.Detection, detections[0].EquipmentRole);
|
||||
Assert.Equal(8000.0, detections[0].RadarRange);
|
||||
Assert.Equal(50.0, detections[0].DetectionAccuracy);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDetections_FiltersOutLaunchPlatforms()
|
||||
{
|
||||
var task = _service.CreateTask("探测过滤测试", "");
|
||||
// 一个火力单元
|
||||
_service.SaveDeployment(task.Id, new List<EquipmentDeployment>
|
||||
{
|
||||
new EquipmentDeployment
|
||||
{
|
||||
EquipmentRole = (int)EquipmentRole.LaunchPlatform,
|
||||
Quantity = 1, PositionX = 1000,
|
||||
},
|
||||
});
|
||||
// 两个探测设备(独立添加)
|
||||
_service.AddDetection(task.Id, new EquipmentDeployment { RadarRange = 5000 });
|
||||
_service.AddDetection(task.Id, new EquipmentDeployment { EORange = 3000 });
|
||||
|
||||
var detections = _service.GetDetections(task.Id);
|
||||
Assert.Equal(2, detections.Count); // 只有探测设备,不含火力单元
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeleteDetection_RemovesOnlyOne()
|
||||
{
|
||||
var task = _service.CreateTask("探测删除测试", "");
|
||||
_service.AddDetection(task.Id, new EquipmentDeployment { RadarRange = 5000 });
|
||||
var det2 = new EquipmentDeployment { EORange = 3000 };
|
||||
_service.AddDetection(task.Id, det2);
|
||||
|
||||
_service.DeleteDetection(det2.Id);
|
||||
|
||||
var detections = _service.GetDetections(task.Id);
|
||||
Assert.Single(detections);
|
||||
Assert.Equal(5000.0, detections[0].RadarRange);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetTaskDetail_IncludesDetections()
|
||||
{
|
||||
var task = _service.CreateTask("想定含探测", "");
|
||||
_service.SaveDeployment(task.Id, new List<EquipmentDeployment>
|
||||
{
|
||||
new EquipmentDeployment { EquipmentRole = (int)EquipmentRole.LaunchPlatform, Quantity = 1 },
|
||||
});
|
||||
_service.AddDetection(task.Id, new EquipmentDeployment { RadarRange = 10000 });
|
||||
|
||||
var detail = _service.GetTaskDetail(task.Id);
|
||||
// Equipment 包含火力单元 + 探测设备
|
||||
Assert.Equal(2, detail.Equipment.Count);
|
||||
Assert.Contains(detail.Equipment, e => e.EquipmentRole == (int)EquipmentRole.Detection);
|
||||
Assert.Contains(detail.Equipment, e => e.EquipmentRole == (int)EquipmentRole.LaunchPlatform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user