diff --git a/LTEMvcApp/Controllers/ConfigController.cs b/LTEMvcApp/Controllers/ConfigController.cs index b553f52..95cfedc 100644 --- a/LTEMvcApp/Controllers/ConfigController.cs +++ b/LTEMvcApp/Controllers/ConfigController.cs @@ -35,19 +35,19 @@ namespace LTEMvcApp.Controllers /// /// 获取指定客户端的统计配置 /// - /// 客户端名称 + /// 客户端IP地址 /// 统计配置 - [HttpGet("statistics/{clientName}")] - public ActionResult GetClientStatisticsConfig(string clientName) + [HttpGet("statistics/{ipAddress}")] + public ActionResult GetClientStatisticsConfig(string ipAddress) { try { - var config = _webSocketManager.GetClientStatisticsConfig(clientName); + var config = _webSocketManager.GetClientStatisticsConfig(ipAddress); return Ok(new { success = true, data = config }); } catch (Exception ex) { - _logger.LogError(ex, "获取客户端统计配置时出错: {ClientName}", clientName); + _logger.LogError(ex, "获取客户端统计配置时出错: {IpAddress}", ipAddress); return BadRequest(new { success = false, message = ex.Message }); } } @@ -55,21 +55,21 @@ namespace LTEMvcApp.Controllers /// /// 设置指定客户端的统计配置 /// - /// 客户端名称 + /// 客户端IP地址 /// 统计配置 /// 操作结果 - [HttpPost("statistics/{clientName}")] - public ActionResult SetClientStatisticsConfig(string clientName, [FromBody] StatisticsConfig config) + [HttpPost("statistics/{ipAddress}")] + public ActionResult SetClientStatisticsConfig(string ipAddress, [FromBody] StatisticsConfig config) { try { - config.ClientName = clientName; // 确保客户端名称正确 + config.IpAddress = ipAddress; // 确保IP地址正确 _webSocketManager.SetClientStatisticsConfig(config); return Ok(new { success = true, message = "客户端统计配置已更新" }); } catch (Exception ex) { - _logger.LogError(ex, "设置客户端统计配置时出错: {ClientName}", clientName); + _logger.LogError(ex, "设置客户端统计配置时出错: {IpAddress}", ipAddress); return BadRequest(new { success = false, message = ex.Message }); } } @@ -77,21 +77,21 @@ namespace LTEMvcApp.Controllers /// /// 更新客户端的Samples参数 /// - /// 客户端名称 + /// 客户端IP地址 /// 是否启用Samples /// 操作结果 - [HttpPost("statistics/{clientName}/samples")] - public ActionResult UpdateClientSamples(string clientName, [FromBody] bool enableSamples) + [HttpPost("statistics/{ipAddress}/samples")] + public ActionResult UpdateClientSamples(string ipAddress, [FromBody] bool enableSamples) { try { - var config = _webSocketManager.GetClientStatisticsConfig(clientName); + var config = _webSocketManager.GetClientStatisticsConfig(ipAddress); if (config == null) { // 创建新配置 config = new StatisticsConfig { - ClientName = clientName, + IpAddress = ipAddress, EnableSamples = enableSamples, EnableRf = false, IsEnabled = true @@ -107,7 +107,7 @@ namespace LTEMvcApp.Controllers } catch (Exception ex) { - _logger.LogError(ex, "更新客户端Samples参数时出错: {ClientName}", clientName); + _logger.LogError(ex, "更新客户端Samples参数时出错: {IpAddress}", ipAddress); return BadRequest(new { success = false, message = ex.Message }); } } @@ -115,21 +115,21 @@ namespace LTEMvcApp.Controllers /// /// 更新客户端的RF参数 /// - /// 客户端名称 + /// 客户端IP地址 /// 是否启用RF /// 操作结果 - [HttpPost("statistics/{clientName}/rf")] - public ActionResult UpdateClientRf(string clientName, [FromBody] bool enableRf) + [HttpPost("statistics/{ipAddress}/rf")] + public ActionResult UpdateClientRf(string ipAddress, [FromBody] bool enableRf) { try { - var config = _webSocketManager.GetClientStatisticsConfig(clientName); + var config = _webSocketManager.GetClientStatisticsConfig(ipAddress); if (config == null) { // 创建新配置 config = new StatisticsConfig { - ClientName = clientName, + IpAddress = ipAddress, EnableSamples = false, EnableRf = enableRf, IsEnabled = true @@ -145,7 +145,7 @@ namespace LTEMvcApp.Controllers } catch (Exception ex) { - _logger.LogError(ex, "更新客户端RF参数时出错: {ClientName}", clientName); + _logger.LogError(ex, "更新客户端RF参数时出错: {IpAddress}", ipAddress); return BadRequest(new { success = false, message = ex.Message }); } } diff --git a/LTEMvcApp/Services/WebSocketManagerService.cs b/LTEMvcApp/Services/WebSocketManagerService.cs index 30858c9..ce9009c 100644 --- a/LTEMvcApp/Services/WebSocketManagerService.cs +++ b/LTEMvcApp/Services/WebSocketManagerService.cs @@ -215,8 +215,8 @@ namespace LTEMvcApp.Services client.Start(); _clients[address] = client; - // 应用统计配置 - UpdateClientStatisticsConfig(config.Name); + // 应用统计配置 - 使用IP地址 + UpdateClientStatisticsConfig(address); return true; } @@ -852,11 +852,11 @@ namespace LTEMvcApp.Services /// /// 获取指定客户端的统计配置 /// - /// 客户端名称 + /// 客户端IP地址 /// 统计配置 - public StatisticsConfig? GetClientStatisticsConfig(string clientName) + public StatisticsConfig? GetClientStatisticsConfig(string ipAddress) { - return _globalStatisticsConfig.ClientConfigs.FirstOrDefault(c => c.ClientName == clientName); + return _globalStatisticsConfig.ClientConfigs.FirstOrDefault(c => c.IpAddress == ipAddress); } /// @@ -865,7 +865,7 @@ namespace LTEMvcApp.Services /// 统计配置 public void SetClientStatisticsConfig(StatisticsConfig config) { - var existingConfig = _globalStatisticsConfig.ClientConfigs.FirstOrDefault(c => c.ClientName == config.ClientName); + var existingConfig = _globalStatisticsConfig.ClientConfigs.FirstOrDefault(c => c.IpAddress == config.IpAddress); if (existingConfig != null) { _globalStatisticsConfig.ClientConfigs.Remove(existingConfig); @@ -873,8 +873,8 @@ namespace LTEMvcApp.Services _globalStatisticsConfig.ClientConfigs.Add(config); SaveStatisticsConfig(); - // 更新指定客户端的统计配置 - UpdateClientStatisticsConfig(config.ClientName); + // 更新指定客户端的统计配置 - 使用IP地址作为键 + UpdateClientStatisticsConfig(config.IpAddress); } /// @@ -894,19 +894,19 @@ namespace LTEMvcApp.Services { foreach (var client in _clients.Values) { - UpdateClientStatisticsConfig(client.Config.Name); + UpdateClientStatisticsConfig(client.Config.Address); } } /// /// 更新指定客户端的统计配置 /// - /// 客户端名称 - private void UpdateClientStatisticsConfig(string clientName) + /// 客户端IP地址 + private void UpdateClientStatisticsConfig(string ipAddress) { - if (_clients.TryGetValue(clientName, out var client)) + if (_clients.TryGetValue(ipAddress, out var client)) { - var config = GetClientStatisticsConfig(clientName); + var config = GetStatisticsConfigByIp(ipAddress); if (config != null && config.IsEnabled) { client.SetStatisticsConfig(config.EnableSamples, config.EnableRf); diff --git a/LTEMvcApp/Views/Statistics/Config.cshtml b/LTEMvcApp/Views/Statistics/Config.cshtml index 40226a7..11858da 100644 --- a/LTEMvcApp/Views/Statistics/Config.cshtml +++ b/LTEMvcApp/Views/Statistics/Config.cshtml @@ -322,25 +322,25 @@ ${client.address}
- +
- +
- +
-
@@ -365,19 +365,19 @@ } // 更新配置(实时保存到服务器) - function updateConfig(clientName, field, value) { - console.log(`更新配置: ${clientName} - ${field} = ${value}`); + function updateConfig(ipAddress, field, value) { + console.log(`更新配置: ${ipAddress} - ${field} = ${value}`); if (field === 'samples') { // 更新Samples参数 $.ajax({ - url: `/api/config/statistics/${encodeURIComponent(clientName)}/samples`, + url: `/api/config/statistics/${encodeURIComponent(ipAddress)}/samples`, type: 'POST', contentType: 'application/json', data: JSON.stringify(value), success: function(response) { if (response.success) { - console.log(`客户端 ${clientName} Samples参数已更新`); + console.log(`客户端 ${ipAddress} Samples参数已更新`); } else { console.error('更新Samples参数失败:', response.message); showAlert('danger', `更新Samples参数失败: ${response.message}`); @@ -391,13 +391,13 @@ } else if (field === 'rf') { // 更新RF参数 $.ajax({ - url: `/api/config/statistics/${encodeURIComponent(clientName)}/rf`, + url: `/api/config/statistics/${encodeURIComponent(ipAddress)}/rf`, type: 'POST', contentType: 'application/json', data: JSON.stringify(value), success: function(response) { if (response.success) { - console.log(`客户端 ${clientName} RF参数已更新`); + console.log(`客户端 ${ipAddress} RF参数已更新`); } else { console.error('更新RF参数失败:', response.message); showAlert('danger', `更新RF参数失败: ${response.message}`); @@ -410,29 +410,28 @@ }); } else if (field === 'enabled') { // 更新启用状态 - saveClientConfig(clientName); + saveClientConfig(ipAddress); } } // 保存客户端配置 - function saveClientConfig(clientName) { + function saveClientConfig(ipAddress) { const config = { - clientName: clientName, - ipAddress: '', // 将从客户端列表获取 - enableSamples: document.getElementById(`samples_${clientName}`).checked, - enableRf: document.getElementById(`rf_${clientName}`).checked, - isEnabled: document.getElementById(`enabled_${clientName}`).checked + ipAddress: ipAddress, + enableSamples: document.getElementById(`samples_${ipAddress}`).checked, + enableRf: document.getElementById(`rf_${ipAddress}`).checked, + isEnabled: document.getElementById(`enabled_${ipAddress}`).checked }; - // 从已加载的客户端列表中获取IP地址 + // 从已加载的客户端列表中获取客户端名称 const tbody = document.getElementById('clientConfigTableBody'); const rows = tbody.getElementsByTagName('tr'); for (let row of rows) { - const nameCell = row.querySelector('td:first-child strong'); - if (nameCell && nameCell.textContent === clientName) { - const ipCell = row.querySelector('td:nth-child(2) code'); - if (ipCell) { - config.ipAddress = ipCell.textContent; + const ipCell = row.querySelector('td:nth-child(2) code'); + if (ipCell && ipCell.textContent === ipAddress) { + const nameCell = row.querySelector('td:first-child strong'); + if (nameCell) { + config.clientName = nameCell.textContent; } break; } @@ -440,14 +439,14 @@ console.log('保存客户端统计配置:', config); $.ajax({ - url: `/api/config/statistics/${encodeURIComponent(clientName)}`, + url: `/api/config/statistics/${encodeURIComponent(ipAddress)}`, type: 'POST', contentType: 'application/json', data: JSON.stringify(config), success: function(response) { console.log('客户端配置保存响应:', response); if (response.success) { - showAlert('success', `客户端 ${clientName} 配置已保存`); + showAlert('success', `客户端 ${ipAddress} 配置已保存`); } else { showAlert('danger', `保存失败: ${response.message}`); } @@ -470,7 +469,7 @@ // 将配置转换为字典,方便查找 configs.forEach(function(config) { - configDict[config.clientName] = config; + configDict[config.ipAddress] = config; }); // 更新表格中的配置 @@ -478,15 +477,15 @@ const rows = tbody.getElementsByTagName('tr'); for (let row of rows) { - const nameCell = row.querySelector('td:first-child strong'); - if (nameCell) { - const clientName = nameCell.textContent; - const config = configDict[clientName]; + const ipCell = row.querySelector('td:nth-child(2) code'); + if (ipCell) { + const ipAddress = ipCell.textContent; + const config = configDict[ipAddress]; if (config) { - row.querySelector(`#samples_${clientName}`).checked = config.enableSamples; - row.querySelector(`#rf_${clientName}`).checked = config.enableRf; - row.querySelector(`#enabled_${clientName}`).checked = config.isEnabled; + row.querySelector(`#samples_${ipAddress}`).checked = config.enableSamples; + row.querySelector(`#rf_${ipAddress}`).checked = config.enableRf; + row.querySelector(`#enabled_${ipAddress}`).checked = config.isEnabled; } } }