You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
153 lines
5.6 KiB
153 lines
5.6 KiB
using Microsoft.AspNetCore.Mvc;
|
|
using LTEMvcApp.Models;
|
|
using LTEMvcApp.Services;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace LTEMvcApp.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 配置管理控制器 - 负责普通客户端配置管理
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class ConfigController : ControllerBase
|
|
{
|
|
private readonly WebSocketManagerService _webSocketManager;
|
|
private readonly ILogger<ConfigController> _logger;
|
|
|
|
public ConfigController(WebSocketManagerService webSocketManager, ILogger<ConfigController> logger)
|
|
{
|
|
_webSocketManager = webSocketManager;
|
|
_logger = logger;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取所有客户端配置
|
|
/// </summary>
|
|
/// <returns>客户端配置列表</returns>
|
|
[HttpGet]
|
|
public ActionResult<List<ClientConfig>> GetAllConfigs()
|
|
{
|
|
var configs = _webSocketManager.GetAllClientConfigs();
|
|
return Ok(configs);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取指定客户端的统计配置
|
|
/// </summary>
|
|
/// <param name="clientName">客户端名称</param>
|
|
/// <returns>统计配置</returns>
|
|
[HttpGet("statistics/{clientName}")]
|
|
public ActionResult<StatisticsConfig?> GetClientStatisticsConfig(string clientName)
|
|
{
|
|
try
|
|
{
|
|
var config = _webSocketManager.GetClientStatisticsConfig(clientName);
|
|
return Ok(new { success = true, data = config });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "获取客户端统计配置时出错: {ClientName}", clientName);
|
|
return BadRequest(new { success = false, message = ex.Message });
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置指定客户端的统计配置
|
|
/// </summary>
|
|
/// <param name="clientName">客户端名称</param>
|
|
/// <param name="config">统计配置</param>
|
|
/// <returns>操作结果</returns>
|
|
[HttpPost("statistics/{clientName}")]
|
|
public ActionResult SetClientStatisticsConfig(string clientName, [FromBody] StatisticsConfig config)
|
|
{
|
|
try
|
|
{
|
|
config.ClientName = clientName; // 确保客户端名称正确
|
|
_webSocketManager.SetClientStatisticsConfig(config);
|
|
return Ok(new { success = true, message = "客户端统计配置已更新" });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "设置客户端统计配置时出错: {ClientName}", clientName);
|
|
return BadRequest(new { success = false, message = ex.Message });
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新客户端的Samples参数
|
|
/// </summary>
|
|
/// <param name="clientName">客户端名称</param>
|
|
/// <param name="enableSamples">是否启用Samples</param>
|
|
/// <returns>操作结果</returns>
|
|
[HttpPost("statistics/{clientName}/samples")]
|
|
public ActionResult UpdateClientSamples(string clientName, [FromBody] bool enableSamples)
|
|
{
|
|
try
|
|
{
|
|
var config = _webSocketManager.GetClientStatisticsConfig(clientName);
|
|
if (config == null)
|
|
{
|
|
// 创建新配置
|
|
config = new StatisticsConfig
|
|
{
|
|
ClientName = clientName,
|
|
EnableSamples = enableSamples,
|
|
EnableRf = false,
|
|
IsEnabled = true
|
|
};
|
|
}
|
|
else
|
|
{
|
|
config.EnableSamples = enableSamples;
|
|
}
|
|
|
|
_webSocketManager.SetClientStatisticsConfig(config);
|
|
return Ok(new { success = true, message = "Samples参数已更新" });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "更新客户端Samples参数时出错: {ClientName}", clientName);
|
|
return BadRequest(new { success = false, message = ex.Message });
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新客户端的RF参数
|
|
/// </summary>
|
|
/// <param name="clientName">客户端名称</param>
|
|
/// <param name="enableRf">是否启用RF</param>
|
|
/// <returns>操作结果</returns>
|
|
[HttpPost("statistics/{clientName}/rf")]
|
|
public ActionResult UpdateClientRf(string clientName, [FromBody] bool enableRf)
|
|
{
|
|
try
|
|
{
|
|
var config = _webSocketManager.GetClientStatisticsConfig(clientName);
|
|
if (config == null)
|
|
{
|
|
// 创建新配置
|
|
config = new StatisticsConfig
|
|
{
|
|
ClientName = clientName,
|
|
EnableSamples = false,
|
|
EnableRf = enableRf,
|
|
IsEnabled = true
|
|
};
|
|
}
|
|
else
|
|
{
|
|
config.EnableRf = enableRf;
|
|
}
|
|
|
|
_webSocketManager.SetClientStatisticsConfig(config);
|
|
return Ok(new { success = true, message = "RF参数已更新" });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "更新客户端RF参数时出错: {ClientName}", clientName);
|
|
return BadRequest(new { success = false, message = ex.Message });
|
|
}
|
|
}
|
|
}
|
|
}
|