diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs new file mode 100644 index 00000000..908ec2ad --- /dev/null +++ b/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs @@ -0,0 +1,42 @@ +using System.Net; +using System.Net.Sockets; +using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Device.Entities; +using Kurisu.SqlSugar.Services; +using Newtonsoft.Json; + +namespace Dlhis.ScheduledTask.CommonJobs; + +public class HeartbeatJob +{ + private readonly IDbContext _dbContext; + private readonly ILogger _logger; + + public HeartbeatJob(IDbContext dbContext, ILogger logger) + { + _dbContext = dbContext; + _logger = logger; + } + + public async Task RunAsync() + { + var devices = await _dbContext.Queryable().Where(x => x.Enable).ToListAsync(); + foreach (var device in devices) + { + try + { + var ipInfo = JsonConvert.DeserializeObject(device.ConnectionInfo); + + await new TcpClient().ConnectAsync(IPAddress.Parse(ipInfo.IP), ipInfo.Port); + await _dbContext.Updateable().SetColumns(x => x.LastHeartbeatTime == DateTime.Now) + .Where(x => x.DeviceUniqueNo == device.UniqueNo).ExecuteCommandAsync(); + + _logger.LogInformation("心跳设备:{no}成功", device.UniqueNo); + } + catch (Exception ex) + { + _logger.LogError(ex, "心跳设备失败:{message}", ex.Message); + } + } + } +} diff --git a/Src/Dlhis.ScheduledTask/IPPortDto.cs b/Src/Dlhis.ScheduledTask/IPPortDto.cs new file mode 100644 index 00000000..6a1bbd8a --- /dev/null +++ b/Src/Dlhis.ScheduledTask/IPPortDto.cs @@ -0,0 +1,8 @@ +namespace Dlhis.ScheduledTask +{ + public class IPPortDto + { + public string IP { get; set; } + public int Port { get; set; } + } +} diff --git a/Src/Dlhis.ScheduledTask/Packs/JobPack.cs b/Src/Dlhis.ScheduledTask/Packs/JobPack.cs index 5bccbd46..2a09eefb 100644 --- a/Src/Dlhis.ScheduledTask/Packs/JobPack.cs +++ b/Src/Dlhis.ScheduledTask/Packs/JobPack.cs @@ -41,5 +41,11 @@ public class JobPack : BaseAppPack { TimeZone = TimeZoneInfo.Local }); + + //心跳 + RecurringJob.AddOrUpdate("Heartbeat", s => s.RunAsync(), "10 * * * * ?", new RecurringJobOptions + { + TimeZone = TimeZoneInfo.Local + }); } } diff --git a/Src/Dlhis.ScheduledTask/SyncSapInfo/Comparers/SapOrgComparer.cs b/Src/Dlhis.ScheduledTask/SyncSapInfo/Comparers/SapOrgComparer.cs deleted file mode 100644 index da2ef800..00000000 --- a/Src/Dlhis.ScheduledTask/SyncSapInfo/Comparers/SapOrgComparer.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Dlhis.ScheduledTask.SyncSapInfo.Dto; - -namespace Dlhis.ScheduledTask.SyncSapInfo.Comparers; - -/// -/// 机构数据比较器 -/// -public class SapOrganizationComparer : IEqualityComparer -{ - public bool Equals(SapOrganizationItem x, SapOrganizationItem y) - { - if (ReferenceEquals(x, y)) return true; - if (ReferenceEquals(x, null) || ReferenceEquals(y, null)) return false; - if (x.GetType() != y.GetType()) return false; - - return x.BEGDA == y.BEGDA - && x.ENDDA == y.ENDDA - && x.LANGU == y.LANGU - && x.OBJID == y.OBJID - && x.STEXT == y.STEXT - && x.SOBID == y.SOBID - && x.ORGID01 == y.ORGID01 - && x.ORGID02 == y.ORGID02; - } - - public int GetHashCode(SapOrganizationItem obj) - { - return obj.BEGDA.SafeGetHashCode() ^ obj.ENDDA.SafeGetHashCode() - ^ obj.LANGU.SafeGetHashCode() ^ obj.OBJID.SafeGetHashCode() - ^ obj.STEXT.SafeGetHashCode() ^ obj.SOBID.SafeGetHashCode() - ^ obj.ORGID01.SafeGetHashCode() ^ obj.ORGID02.SafeGetHashCode(); - } -} diff --git a/Src/Dlhis.ScheduledTask/SyncSapInfo/Comparers/SapPositionComparer.cs b/Src/Dlhis.ScheduledTask/SyncSapInfo/Comparers/SapPositionComparer.cs deleted file mode 100644 index 2f6a04b2..00000000 --- a/Src/Dlhis.ScheduledTask/SyncSapInfo/Comparers/SapPositionComparer.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Dlhis.ScheduledTask.SyncSapInfo.Dto; - -namespace Dlhis.ScheduledTask.SyncSapInfo.Comparers; - -/// -/// 岗位信息比较器 -/// -public class SapPositionComparer : IEqualityComparer -{ - public bool Equals(SapPositionItem x, SapPositionItem y) - { - if (ReferenceEquals(x, y)) return true; - if (ReferenceEquals(x, null) || ReferenceEquals(y, null)) return false; - if (x.GetType() != y.GetType()) return false; - - return x.BEGDA == y.BEGDA - && x.ENDDA == y.ENDDA - && x.LANGU == y.LANGU - && x.ZJOBID == y.ZJOBID - && x.ZJOBNAME == y.ZJOBNAME - && x.ZZWID == y.ZZWID - && x.ZDEPID == y.ZDEPID; - } - - public int GetHashCode(SapPositionItem obj) - { - return obj.BEGDA.SafeGetHashCode() ^ obj.ENDDA.SafeGetHashCode() - ^ obj.LANGU.SafeGetHashCode() ^ obj.ZJOBID.SafeGetHashCode() - ^ obj.ZJOBNAME.SafeGetHashCode() ^ obj.ZZWID.SafeGetHashCode() - ^ obj.ZDEPID.SafeGetHashCode(); - } -}