using Quartz; using Microsoft.Extensions.DependencyInjection; namespace VolPro.Warehouse.Services; public class HeartbeatMonitorJob : IJob { public async Task Execute(IJobExecutionContext context) { var sp = (IServiceProvider)context.JobDetail.JobDataMap["ServiceProvider"]; var gwSvc = sp.GetService(); var devSvc = sp.GetService(); var timeout = DateTime.Now.AddSeconds(-30); var offlineNodes = await gwSvc.FindAsIQueryable(x => x.IsOnline == "在线" && x.LastHeartbeat < timeout) .ToListAsync(); foreach (var node in offlineNodes) { node.IsOnline = "离线"; await gwSvc.UpdateAsync(node); await devSvc.UpdateAsync(x => x.GatewayNodeId == node.NodeId, x => new base_device { IsOnline = "离线" }); } } }