针对界面显示的优化
This commit is contained in:
@@ -8,27 +8,50 @@ namespace SHH.CameraSdk;
|
||||
/// 核心功能:提供相机设备遥测数据查询、单设备详情查询、系统日志查询
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/monitor")] // [建议] 显式指定路由为小写,确保与前端 ${API}/monitor/... 匹配
|
||||
[Route("api/[controller]")]
|
||||
public class MonitorController : ControllerBase
|
||||
{
|
||||
#region --- 依赖注入 (Dependency Injection) ---
|
||||
|
||||
private readonly CameraManager _cameraManager;
|
||||
private readonly IStorageService _storage; // [新增] 存储服务引用
|
||||
private readonly ProcessingConfigManager _configManager;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数:注入 CameraManager 和 IStorageService
|
||||
/// </summary>
|
||||
public MonitorController(CameraManager cameraManager, IStorageService storage)
|
||||
public MonitorController(CameraManager cameraManager, IStorageService storage, ProcessingConfigManager configManager)
|
||||
{
|
||||
_cameraManager = cameraManager;
|
||||
_storage = storage;
|
||||
_configManager = configManager;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- API 接口定义 (API Endpoints) ---
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有设备及配置 (对应前端 /api/Monitor/all)
|
||||
/// </summary>
|
||||
[HttpGet("all")] // <--- 必须明确写上 "all",否则前端找不到
|
||||
public IActionResult GetAll()
|
||||
{
|
||||
var cameras = _cameraManager.GetAllDevices();
|
||||
var list = cameras.Select(c => new {
|
||||
c.Id,
|
||||
Status = c.Status.ToString(),
|
||||
c.IsPhysicalOnline,
|
||||
c.RealFps,
|
||||
c.TotalFrames,
|
||||
c.Config.Name,
|
||||
c.Config.IpAddress,
|
||||
// 务必包含配置信息,供前端回显
|
||||
ProcessingOptions = _configManager.GetOptions(c.Id)
|
||||
});
|
||||
return Ok(list);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取全量相机实时遥测数据快照
|
||||
/// 适用场景:监控大屏首页数据看板
|
||||
@@ -52,12 +75,18 @@ public class MonitorController : ControllerBase
|
||||
return Ok(new
|
||||
{
|
||||
device.Id,
|
||||
device.Status,
|
||||
Status = device.Status.ToString(),
|
||||
device.IsOnline,
|
||||
device.RealFps,
|
||||
device.TotalFrames,
|
||||
device.Config.Name,
|
||||
device.Config.IpAddress
|
||||
device.Config.IpAddress,
|
||||
// --- 新增:将内存中的订阅需求列表传给前端 ---
|
||||
Requirements = device.Controller.GetCurrentRequirements().Select(r => new {
|
||||
r.AppId,
|
||||
r.TargetFps,
|
||||
r.LastActive
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
@@ -129,4 +158,27 @@ public class MonitorController : ControllerBase
|
||||
|
||||
return Ok(logs);
|
||||
}
|
||||
|
||||
[HttpPost("update-processing")]
|
||||
public IActionResult UpdateProcessing([FromBody] UpdateProcessingRequest request)
|
||||
{
|
||||
// 1. 验证设备是否存在 (可选)
|
||||
|
||||
// 2. 构造配置对象
|
||||
var options = new ProcessingOptions
|
||||
{
|
||||
EnableShrink = request.EnableShrink,
|
||||
EnableExpand = request.EnableExpand,
|
||||
TargetWidth = request.TargetWidth,
|
||||
TargetHeight = request.TargetHeight,
|
||||
EnableEnhance = request.EnableEnhance,
|
||||
BrightnessLevel = request.BrightnessLevel
|
||||
};
|
||||
|
||||
// 3. 提交给配置管理器 (实时生效)
|
||||
// 这里的 _configManager 是通过构造函数注入的单例
|
||||
_configManager.UpdateOptions(request.DeviceId, options);
|
||||
|
||||
return Ok(new { msg = $"设备 {request.DeviceId} 配置已更新", time = DateTime.Now });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user