From e2421a0b49984660678e285b8f38011fbf3425c1 Mon Sep 17 00:00:00 2001 From: root <295172551@qq.com> Date: Sat, 28 Jun 2025 20:02:31 +0800 Subject: [PATCH] 1231311 --- LTEMvcApp/Controllers/ConfigController.cs | 138 +++-- LTEMvcApp/Controllers/StatisticsController.cs | 98 +-- .../README_StatisticsConfig_Implementation.md | 57 +- LTEMvcApp/Views/Home/StatisticsTest.cshtml | 353 ----------- LTEMvcApp/Views/Shared/_Layout.cshtml | 3 + LTEMvcApp/Views/Statistics/Config.cshtml | 564 ++++++++++++++++++ LTEMvcApp/Views/Statistics/Index.cshtml | 252 -------- LTEMvcApp/statistics_config.json | 25 +- 8 files changed, 728 insertions(+), 762 deletions(-) delete mode 100644 LTEMvcApp/Views/Home/StatisticsTest.cshtml create mode 100644 LTEMvcApp/Views/Statistics/Config.cshtml diff --git a/LTEMvcApp/Controllers/ConfigController.cs b/LTEMvcApp/Controllers/ConfigController.cs index b11f7d9..db0e8ed 100644 --- a/LTEMvcApp/Controllers/ConfigController.cs +++ b/LTEMvcApp/Controllers/ConfigController.cs @@ -21,21 +21,6 @@ namespace LTEMvcApp.Controllers _logger = logger; } - /// - /// 获取客户端配置 - /// - /// 客户端名称 - /// 客户端配置 - [HttpGet("{clientName}")] - public ActionResult GetClientConfig(string clientName) - { - var config = _webSocketManager.GetClientConfig(clientName); - if (config == null) - return NotFound($"客户端 '{clientName}' 不存在"); - - return Ok(config); - } - /// /// 获取所有客户端配置 /// @@ -48,36 +33,121 @@ namespace LTEMvcApp.Controllers } /// - /// 添加客户端配置 + /// 获取指定客户端的统计配置 + /// + /// 客户端名称 + /// 统计配置 + [HttpGet("statistics/{clientName}")] + public ActionResult GetClientStatisticsConfig(string clientName) + { + try + { + var config = _webSocketManager.GetClientStatisticsConfig(clientName); + return Json(new { success = true, data = config }); + } + catch (Exception ex) + { + _logger.LogError(ex, "获取客户端统计配置时出错: {ClientName}", clientName); + return Json(new { success = false, message = ex.Message }); + } + } + + /// + /// 设置指定客户端的统计配置 /// - /// 客户端配置 + /// 客户端名称 + /// 统计配置 /// 操作结果 - [HttpPost] - public ActionResult AddClientConfig([FromBody] ClientConfig config) + [HttpPost("statistics/{clientName}")] + public ActionResult SetClientStatisticsConfig(string clientName, [FromBody] StatisticsConfig config) { - if (string.IsNullOrEmpty(config.Name)) - return BadRequest("客户端名称不能为空"); + try + { + config.ClientName = clientName; // 确保客户端名称正确 + _webSocketManager.SetClientStatisticsConfig(config); + return Json(new { success = true, message = "客户端统计配置已更新" }); + } + catch (Exception ex) + { + _logger.LogError(ex, "设置客户端统计配置时出错: {ClientName}", clientName); + return Json(new { success = false, message = ex.Message }); + } + } - var success = _webSocketManager.AddClientConfig(config); - if (success) - return Ok(new { message = $"客户端 '{config.Name}' 配置已添加" }); - else - return BadRequest("添加客户端配置失败"); + /// + /// 更新客户端的Samples参数 + /// + /// 客户端名称 + /// 是否启用Samples + /// 操作结果 + [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 Json(new { success = true, message = "Samples参数已更新" }); + } + catch (Exception ex) + { + _logger.LogError(ex, "更新客户端Samples参数时出错: {ClientName}", clientName); + return Json(new { success = false, message = ex.Message }); + } } /// - /// 移除客户端配置 + /// 更新客户端的RF参数 /// /// 客户端名称 + /// 是否启用RF /// 操作结果 - [HttpDelete("{clientName}")] - public ActionResult RemoveClientConfig(string clientName) + [HttpPost("statistics/{clientName}/rf")] + public ActionResult UpdateClientRf(string clientName, [FromBody] bool enableRf) { - var success = _webSocketManager.RemoveClientConfig(clientName); - if (success) - return Ok(new { message = $"客户端 '{clientName}' 配置已移除" }); - else - return BadRequest($"移除客户端 '{clientName}' 配置失败"); + 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 Json(new { success = true, message = "RF参数已更新" }); + } + catch (Exception ex) + { + _logger.LogError(ex, "更新客户端RF参数时出错: {ClientName}", clientName); + return Json(new { success = false, message = ex.Message }); + } } } } \ No newline at end of file diff --git a/LTEMvcApp/Controllers/StatisticsController.cs b/LTEMvcApp/Controllers/StatisticsController.cs index f830080..ce2f3dc 100644 --- a/LTEMvcApp/Controllers/StatisticsController.cs +++ b/LTEMvcApp/Controllers/StatisticsController.cs @@ -161,96 +161,6 @@ namespace LTEMvcApp.Controllers } } - /// - /// 获取全局统计配置 - /// - [HttpGet] - public IActionResult GetGlobalStatisticsConfig() - { - try - { - var config = _webSocketManager.GetGlobalStatisticsConfig(); - return Json(new { success = true, data = config }); - } - catch (Exception ex) - { - _logger.LogError(ex, "获取全局统计配置时出错"); - return Json(new { success = false, message = ex.Message }); - } - } - - /// - /// 设置全局统计配置 - /// - [HttpPost] - public IActionResult SetGlobalStatisticsConfig([FromBody] GlobalStatisticsConfig config) - { - try - { - _webSocketManager.SetGlobalStatisticsConfig(config); - return Json(new { success = true, message = "全局统计配置已更新" }); - } - catch (Exception ex) - { - _logger.LogError(ex, "设置全局统计配置时出错"); - return Json(new { success = false, message = ex.Message }); - } - } - - /// - /// 获取指定客户端的统计配置 - /// - [HttpGet] - public IActionResult GetClientStatisticsConfig(string clientName) - { - try - { - var config = _webSocketManager.GetClientStatisticsConfig(clientName); - return Json(new { success = true, data = config }); - } - catch (Exception ex) - { - _logger.LogError(ex, "获取客户端统计配置时出错: {ClientName}", clientName); - return Json(new { success = false, message = ex.Message }); - } - } - - /// - /// 设置指定客户端的统计配置 - /// - [HttpPost] - public IActionResult SetClientStatisticsConfig([FromBody] StatisticsConfig config) - { - try - { - _webSocketManager.SetClientStatisticsConfig(config); - return Json(new { success = true, message = "客户端统计配置已更新" }); - } - catch (Exception ex) - { - _logger.LogError(ex, "设置客户端统计配置时出错: {ClientName}", config.ClientName); - return Json(new { success = false, message = ex.Message }); - } - } - - /// - /// 根据IP地址获取统计配置 - /// - [HttpGet] - public IActionResult GetStatisticsConfigByIp(string ipAddress) - { - try - { - var config = _webSocketManager.GetStatisticsConfigByIp(ipAddress); - return Json(new { success = true, data = config }); - } - catch (Exception ex) - { - _logger.LogError(ex, "根据IP获取统计配置时出错: {IpAddress}", ipAddress); - return Json(new { success = false, message = ex.Message }); - } - } - /// /// 获取所有客户端的统计配置 /// @@ -269,6 +179,14 @@ namespace LTEMvcApp.Controllers } } + /// + /// 统计配置管理页面 + /// + public IActionResult Config() + { + return View(); + } + /// /// SSE推送 - 所有统计数据 /// diff --git a/LTEMvcApp/README_StatisticsConfig_Implementation.md b/LTEMvcApp/README_StatisticsConfig_Implementation.md index 458f51f..cac3aee 100644 --- a/LTEMvcApp/README_StatisticsConfig_Implementation.md +++ b/LTEMvcApp/README_StatisticsConfig_Implementation.md @@ -19,18 +19,35 @@ - 通过Web界面实时修改配置 - 配置自动保存到`statistics_config.json`文件 - 支持配置列表查看和编辑 +- 支持配置导入/导出功能 + +## 页面结构 + +### 两个独立页面: +1. **`Statistics/Index.cshtml`** - 统计数据监控页面 + - 实时统计数据展示 + - 客户端状态监控 + - SSE实时数据推送 + - 小区详细信息查看 + +2. **`Statistics/Config.cshtml`** - 统计配置管理页面 + - 全局配置管理 + - 客户端特定配置 + - 配置列表管理 + - 配置导入/导出 ## 文件结构 ### 新增文件 - `Models/StatisticsConfig.cs` - 统计配置模型 - `statistics_config.json` - 统计配置文件 +- `Views/Statistics/Config.cshtml` - 统计配置管理页面 ### 修改文件 - `Services/LTEClientWebSocket.cs` - 添加统计配置支持 - `Services/WebSocketManagerService.cs` - 添加配置管理功能 -- `Controllers/StatisticsController.cs` - 添加配置管理API -- `Views/Home/StatisticsTest.cshtml` - 添加配置管理界面 +- `Controllers/StatisticsController.cs` - 添加配置管理API和Config方法 +- `Views/Shared/_Layout.cshtml` - 添加导航菜单链接 ## 核心实现 @@ -111,25 +128,32 @@ private void UpdateAllClientsStatisticsConfig() [HttpPost] SetClientStatisticsConfig([FromBody] StatisticsConfig config) [HttpGet] GetStatisticsConfigByIp(string ipAddress) [HttpGet] GetAllClientStatisticsConfigs() +public IActionResult Config() // 配置管理页面 ``` ## 使用方法 -### 1. 访问配置界面 -访问 `/Home/StatisticsTest` 页面,可以看到统计配置管理界面。 +### 1. 访问统计数据页面 +- 通过导航菜单点击"统计数据"或访问 `/Statistics/Index` +- 查看实时统计数据、客户端状态、小区信息等 -### 2. 设置全局配置 -- 在"全局统计配置"区域设置默认的samples和rf值 +### 2. 访问配置管理页面 +- 通过导航菜单点击"统计配置"或访问 `/Statistics/Config` +- 管理全局配置和客户端特定配置 + +### 3. 设置全局配置 +- 在"全局统计配置"部分设置默认的samples和rf值 - 点击"保存配置"按钮保存 -### 3. 设置客户端特定配置 -- 在"客户端特定配置"区域输入客户端信息 +### 4. 设置客户端特定配置 +- 在"客户端特定配置"部分输入客户端信息 - 设置特定的samples和rf值 - 点击"保存配置"按钮保存 -### 4. 查看配置列表 -- 在"配置列表"区域可以看到所有已配置的客户端 +### 5. 查看配置列表 +- 在"配置列表"部分可以看到所有已配置的客户端 - 点击"编辑"按钮可以修改现有配置 +- 支持配置导入/导出功能 ## 配置优先级 @@ -156,18 +180,27 @@ private void UpdateAllClientsStatisticsConfig() } ``` +## 页面优势 + +### 拆分的好处: +1. **职责分离** - 数据监控和配置管理各司其职 +2. **用户体验** - 每个页面功能专注,界面简洁 +3. **维护性** - 代码结构清晰,易于维护和扩展 +4. **性能** - 避免单个页面过于复杂,加载更快 + ## 注意事项 1. 配置修改后会自动应用到所有已连接的客户端 2. 新连接的客户端会自动应用相应的配置 3. 配置文件会在应用启动时自动加载 4. 配置修改会实时保存到文件,重启应用后配置仍然有效 +5. 两个页面功能独立,用户可以根据需要分别访问 ## 扩展功能 可以根据需要扩展以下功能: - 配置模板管理 -- 配置导入/导出 - 配置版本控制 - 配置变更日志 -- 批量配置操作 \ No newline at end of file +- 批量配置操作 +- 配置验证和测试 \ No newline at end of file diff --git a/LTEMvcApp/Views/Home/StatisticsTest.cshtml b/LTEMvcApp/Views/Home/StatisticsTest.cshtml deleted file mode 100644 index 2ad5d33..0000000 --- a/LTEMvcApp/Views/Home/StatisticsTest.cshtml +++ /dev/null @@ -1,353 +0,0 @@ -@{ - ViewData["Title"] = "统计测试"; -} - - - - - - - 统计功能测试 - - - - - API测试 - 获取所有统计数据 - 获取最新统计数据 - 获取统计摘要 - 清空统计数据 - - - SSE测试 - 测试SSE连接 - 停止SSE - - - - - - 统计配置管理 - - - - - 全局统计配置 - - - - 默认Samples: - - - 启用Samples - - - - 默认RF: - - - 启用RF - - - 加载配置 - 保存配置 - - - - - - - 客户端特定配置 - - - - 客户端名称: - - - - IP地址: - - - - 配置选项: - - - 启用Samples - - - - 启用RF - - - - 启用配置 - - - - 描述: - - - 加载配置 - 保存配置 - - - - - - - - - - 配置列表 - 刷新配置列表 - - - - - 客户端名称 - IP地址 - Samples - RF - 启用 - 描述 - 操作 - - - - - - - - - - - - 测试结果 - - - - - - - - - -@section Scripts { - -} \ No newline at end of file diff --git a/LTEMvcApp/Views/Shared/_Layout.cshtml b/LTEMvcApp/Views/Shared/_Layout.cshtml index af3ca29..b9ff3c7 100644 --- a/LTEMvcApp/Views/Shared/_Layout.cshtml +++ b/LTEMvcApp/Views/Shared/_Layout.cshtml @@ -236,6 +236,9 @@ 统计数据 + + 统计配置 + 测试客户端配置 diff --git a/LTEMvcApp/Views/Statistics/Config.cshtml b/LTEMvcApp/Views/Statistics/Config.cshtml new file mode 100644 index 0000000..88751ce --- /dev/null +++ b/LTEMvcApp/Views/Statistics/Config.cshtml @@ -0,0 +1,564 @@ +@{ + ViewData["Title"] = "统计配置管理"; +} + + + + + + + + + + 统计配置管理 + + + + + + + + + + + + 客户端统计配置 + + + + + + 0 个客户端 + + + 重新加载客户端 + + + + + + + 客户端名称 + IP地址 + Samples + RF + 状态 + 描述 + 操作 + + + + + + + + + + + + + + + + + + + 配置说明 + + + + + + 配置优先级: + + 客户端特定配置 - 如果客户端有特定的配置且启用,则使用该配置 + 系统默认值 - 如果客户端没有特定配置,则使用系统默认值(samples=false, rf=false) + + + + 参数说明: + + Samples - 控制是否收集详细的采样数据,可能影响性能 + RF - 控制是否收集射频相关数据,包含信号质量等信息 + 启用配置 - 控制该客户端配置是否生效 + + + + + + + + + + + + + + + +@section Scripts { + +} \ No newline at end of file diff --git a/LTEMvcApp/Views/Statistics/Index.cshtml b/LTEMvcApp/Views/Statistics/Index.cshtml index 7abd2ed..c787f0d 100644 --- a/LTEMvcApp/Views/Statistics/Index.cshtml +++ b/LTEMvcApp/Views/Statistics/Index.cshtml @@ -137,108 +137,6 @@ - - - - - - - 统计配置管理 - - - - - - - 全局统计配置 - - - - 默认Samples: - - - 启用Samples - - - - 默认RF: - - - 启用RF - - - 加载配置 - 保存配置 - - - - - - - 客户端特定配置 - - - - 客户端名称: - - - - IP地址: - - - - 配置选项: - - - 启用Samples - - - - 启用RF - - - - 启用配置 - - - - 描述: - - - 加载配置 - 保存配置 - - - - - - - - 配置列表 - 刷新配置列表 - - - - - 客户端名称 - IP地址 - Samples - RF - 启用 - 描述 - 操作 - - - - - - - - - - - - @section Scripts { @@ -252,10 +150,6 @@ loadSummary(); loadAllStats(); startRefreshTimer(); - - // 新增的配置管理初始化 - loadGlobalConfig(); - loadAllClientConfigs(); }); // 加载统计摘要 @@ -446,151 +340,5 @@ clearInterval(refreshTimer); } }); - - // 统计配置管理相关函数 - function loadGlobalConfig() { - console.log('加载全局统计配置...'); - $.get('/Statistics/GetGlobalStatisticsConfig', function(response) { - if (response.success) { - const config = response.data; - document.getElementById('globalSamples').checked = config.defaultSamples; - document.getElementById('globalRf').checked = config.defaultRf; - console.log('全局配置已加载:', config); - } else { - console.error('加载全局配置失败:', response.message); - } - }).fail(function(xhr, status, error) { - console.error('加载全局配置错误:', error); - }); - } - - function saveGlobalConfig() { - const config = { - defaultSamples: document.getElementById('globalSamples').checked, - defaultRf: document.getElementById('globalRf').checked, - clientConfigs: [] - }; - - console.log('保存全局统计配置...'); - $.ajax({ - url: '/Statistics/SetGlobalStatisticsConfig', - type: 'POST', - contentType: 'application/json', - data: JSON.stringify(config), - success: function(response) { - console.log('全局配置保存响应:', response); - if (response.success) { - alert('全局配置已保存'); - } else { - alert('保存失败: ' + response.message); - } - }, - error: function(xhr, status, error) { - console.error('保存全局配置错误:', error); - alert('保存失败: ' + error); - } - }); - } - - function loadClientConfig() { - const clientName = document.getElementById('clientName').value; - if (!clientName) { - alert('请输入客户端名称'); - return; - } - - console.log('加载客户端统计配置:', clientName); - $.get('/Statistics/GetClientStatisticsConfig', { clientName: clientName }, function(response) { - if (response.success && response.data) { - const config = response.data; - document.getElementById('clientName').value = config.clientName; - document.getElementById('clientIp').value = config.ipAddress; - document.getElementById('clientSamples').checked = config.enableSamples; - document.getElementById('clientRf').checked = config.enableRf; - document.getElementById('clientEnabled').checked = config.isEnabled; - document.getElementById('clientDescription').value = config.description; - console.log('客户端配置已加载:', config); - } else { - console.log('客户端配置未找到或加载失败'); - } - }).fail(function(xhr, status, error) { - console.error('加载客户端配置错误:', error); - }); - } - - function saveClientConfig() { - const config = { - clientName: document.getElementById('clientName').value, - ipAddress: document.getElementById('clientIp').value, - enableSamples: document.getElementById('clientSamples').checked, - enableRf: document.getElementById('clientRf').checked, - isEnabled: document.getElementById('clientEnabled').checked, - description: document.getElementById('clientDescription').value - }; - - if (!config.clientName) { - alert('请输入客户端名称'); - return; - } - - console.log('保存客户端统计配置...'); - $.ajax({ - url: '/Statistics/SetClientStatisticsConfig', - type: 'POST', - contentType: 'application/json', - data: JSON.stringify(config), - success: function(response) { - console.log('客户端配置保存响应:', response); - if (response.success) { - alert('客户端配置已保存'); - loadAllClientConfigs(); // 刷新配置列表 - } else { - alert('保存失败: ' + response.message); - } - }, - error: function(xhr, status, error) { - console.error('保存客户端配置错误:', error); - alert('保存失败: ' + error); - } - }); - } - - function loadAllClientConfigs() { - console.log('加载所有客户端配置...'); - $.get('/Statistics/GetAllClientStatisticsConfigs', function(response) { - if (response.success) { - const configs = response.data; - const tbody = document.getElementById('configTableBody'); - tbody.innerHTML = ''; - - configs.forEach(function(config) { - const row = document.createElement('tr'); - row.innerHTML = ` - ${config.clientName} - ${config.ipAddress} - ${config.enableSamples ? '是' : '否'} - ${config.enableRf ? '是' : '否'} - ${config.isEnabled ? '是' : '否'} - ${config.description} - - 编辑 - - `; - tbody.appendChild(row); - }); - - console.log('配置列表已更新,共', configs.length, '个配置'); - } else { - console.error('加载配置列表失败:', response.message); - } - }).fail(function(xhr, status, error) { - console.error('加载配置列表错误:', error); - }); - } - - function editConfig(clientName) { - document.getElementById('clientName').value = clientName; - loadClientConfig(); - } } \ No newline at end of file diff --git a/LTEMvcApp/statistics_config.json b/LTEMvcApp/statistics_config.json index 54bf085..4681647 100644 --- a/LTEMvcApp/statistics_config.json +++ b/LTEMvcApp/statistics_config.json @@ -1,22 +1,5 @@ { - "defaultSamples": false, - "defaultRf": false, - "clientConfigs": [ - { - "ipAddress": "192.168.13.12", - "clientName": "TestClient1", - "enableSamples": true, - "enableRf": false, - "isEnabled": true, - "description": "测试客户端1 - 启用samples" - }, - { - "ipAddress": "192.168.13.13", - "clientName": "TestClient2", - "enableSamples": false, - "enableRf": true, - "isEnabled": true, - "description": "测试客户端2 - 启用rf" - } - ] -} \ No newline at end of file + "defaultSamples": true, + "defaultRf": true, + "clientConfigs": [] +} \ No newline at end of file