fix 增加心跳任务
This commit is contained in:
42
Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs
Normal file
42
Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs
Normal file
@@ -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<HeartbeatJob> _logger;
|
||||
|
||||
public HeartbeatJob(IDbContext dbContext, ILogger<HeartbeatJob> logger)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task RunAsync()
|
||||
{
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Enable).ToListAsync();
|
||||
foreach (var device in devices)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ipInfo = JsonConvert.DeserializeObject<IPPortDto>(device.ConnectionInfo);
|
||||
|
||||
await new TcpClient().ConnectAsync(IPAddress.Parse(ipInfo.IP), ipInfo.Port);
|
||||
await _dbContext.Updateable<DeviceRegistryEntity>().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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
Src/Dlhis.ScheduledTask/IPPortDto.cs
Normal file
8
Src/Dlhis.ScheduledTask/IPPortDto.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Dlhis.ScheduledTask
|
||||
{
|
||||
public class IPPortDto
|
||||
{
|
||||
public string IP { get; set; }
|
||||
public int Port { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -41,5 +41,11 @@ public class JobPack : BaseAppPack
|
||||
{
|
||||
TimeZone = TimeZoneInfo.Local
|
||||
});
|
||||
|
||||
//心跳
|
||||
RecurringJob.AddOrUpdate<HeartbeatJob>("Heartbeat", s => s.RunAsync(), "10 * * * * ?", new RecurringJobOptions
|
||||
{
|
||||
TimeZone = TimeZoneInfo.Local
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
using Dlhis.ScheduledTask.SyncSapInfo.Dto;
|
||||
|
||||
namespace Dlhis.ScheduledTask.SyncSapInfo.Comparers;
|
||||
|
||||
/// <summary>
|
||||
/// 机构数据比较器
|
||||
/// </summary>
|
||||
public class SapOrganizationComparer : IEqualityComparer<SapOrganizationItem>
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
using Dlhis.ScheduledTask.SyncSapInfo.Dto;
|
||||
|
||||
namespace Dlhis.ScheduledTask.SyncSapInfo.Comparers;
|
||||
|
||||
/// <summary>
|
||||
/// 岗位信息比较器
|
||||
/// </summary>
|
||||
public class SapPositionComparer : IEqualityComparer<SapPositionItem>
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user