From 6c362c0e8763b500bc0fbbf121b9e60a1ed1b511 Mon Sep 17 00:00:00 2001 From: Zhanghu Date: Tue, 13 Jan 2026 15:37:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=A8=E7=BA=BF=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ .../DevicesManagementController.cs | 23 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index faa0fa6..1e6b251 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ src/DRS9.Dashboard.Infrastructure/bin/ src/DRS9.Dashboard.Infrastructure/obj/ src/DRS9.Dashboard.Server/bin/ src/DRS9.Dashboard.Server/obj/ +src/DRS9.Dashboard.Server/dashboard.db-shm +src/DRS9.Dashboard.Server/dashboard.db-wal diff --git a/src/DRS9.Dashboard.Server/Controllers/DevicesManagementController.cs b/src/DRS9.Dashboard.Server/Controllers/DevicesManagementController.cs index 64f116e..cdf5d45 100644 --- a/src/DRS9.Dashboard.Server/Controllers/DevicesManagementController.cs +++ b/src/DRS9.Dashboard.Server/Controllers/DevicesManagementController.cs @@ -342,13 +342,16 @@ public class DashboardController : ControllerBase { private readonly DeviceManagementService _deviceManagementService; private readonly ApplicationService _applicationService; + private readonly ILogger _logger; public DashboardController( DeviceManagementService deviceManagementService, - ApplicationService applicationService) + ApplicationService applicationService, + ILogger logger) { _deviceManagementService = deviceManagementService; _applicationService = applicationService; + _logger = logger; } /// @@ -360,10 +363,26 @@ public class DashboardController : ControllerBase var devices = await _deviceManagementService.GetAllDevicesAsync(); var applications = await _applicationService.GetAllAsync(); + // 在线设备:1分钟内有活动 + var onlineThreshold = DateTime.UtcNow.AddMinutes(-1); + var onlineCount = devices.Data.Count(d => d.LastSeenAt.HasValue && d.LastSeenAt >= onlineThreshold); + + // 调试输出 + _logger.LogInformation("UTC Now: {Now}", DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss")); + _logger.LogInformation("Online Threshold: {Threshold}", onlineThreshold.ToString("yyyy-MM-dd HH:mm:ss")); + foreach (var d in devices.Data) + { + _logger.LogInformation("Device {Id}: LastSeenAt={LastSeenAt}, IsOnline={IsOnline}", + d.Id, + d.LastSeenAt?.ToString("yyyy-MM-dd HH:mm:ss") ?? "null", + d.LastSeenAt.HasValue && d.LastSeenAt >= onlineThreshold); + } + _logger.LogInformation("Online Count: {Count}", onlineCount); + var stats = new DashboardStatsDto { TotalDevices = devices.Data.Count, - OnlineDevices = devices.Data.Count(d => d.IsEnabled), + OnlineDevices = onlineCount, TotalApplications = applications.Total };