修复在线设备数量问题
This commit is contained in:
@@ -342,16 +342,13 @@ public class DashboardController : ControllerBase
|
|||||||
{
|
{
|
||||||
private readonly DeviceManagementService _deviceManagementService;
|
private readonly DeviceManagementService _deviceManagementService;
|
||||||
private readonly ApplicationService _applicationService;
|
private readonly ApplicationService _applicationService;
|
||||||
private readonly ILogger<DashboardController> _logger;
|
|
||||||
|
|
||||||
public DashboardController(
|
public DashboardController(
|
||||||
DeviceManagementService deviceManagementService,
|
DeviceManagementService deviceManagementService,
|
||||||
ApplicationService applicationService,
|
ApplicationService applicationService)
|
||||||
ILogger<DashboardController> logger)
|
|
||||||
{
|
{
|
||||||
_deviceManagementService = deviceManagementService;
|
_deviceManagementService = deviceManagementService;
|
||||||
_applicationService = applicationService;
|
_applicationService = applicationService;
|
||||||
_logger = logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -365,24 +362,10 @@ public class DashboardController : ControllerBase
|
|||||||
|
|
||||||
// 在线设备:1分钟内有活动
|
// 在线设备:1分钟内有活动
|
||||||
var onlineThreshold = DateTime.UtcNow.AddMinutes(-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
|
var stats = new DashboardStatsDto
|
||||||
{
|
{
|
||||||
TotalDevices = devices.Data.Count,
|
TotalDevices = devices.Data.Count,
|
||||||
OnlineDevices = onlineCount,
|
OnlineDevices = devices.Data.Count(d => d.LastSeenAt.HasValue && d.LastSeenAt >= onlineThreshold),
|
||||||
TotalApplications = applications.Total
|
TotalApplications = applications.Total
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user