fix 任务根据设备心跳状态获取
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using Dlhis.Basic.Device.Dtos;
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
@@ -9,6 +10,7 @@ using Kurisu.AspNetCore.CustomClass;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Mapster;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services.Implements;
|
||||
|
||||
@@ -71,7 +73,7 @@ public class DeviceConnectService : IDeviceConnectService
|
||||
if (request.BusinessPlaceCode.HasValue)
|
||||
{
|
||||
var businessPlace = await _dbContext.Queryable<BusinessPlaceEntity>().Where(x => x.Code == request.BusinessPlaceCode).FirstAsync();
|
||||
businessPlace.ThrowIfNull("营业点不存在,无法设置到设备注册信息中");
|
||||
businessPlace.ThrowIfNull("营业点不存在,无法设置到设备注册信息中");
|
||||
}
|
||||
|
||||
//更新营业点信息
|
||||
@@ -81,13 +83,12 @@ public class DeviceConnectService : IDeviceConnectService
|
||||
}
|
||||
|
||||
|
||||
public async Task HeartbeatAsync(DeviceHeartbeatRequest request)
|
||||
public async Task<int> HeartbeatAsync(DeviceHeartbeatRequest request)
|
||||
{
|
||||
var registry = await _dbContext.Queryable<DeviceRegistryEntity>().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync();
|
||||
registry.ThrowIfNull($"注册信息不存在,无法发起心跳");
|
||||
|
||||
registry.LastHeartbeatTime = DateTime.Now;
|
||||
await _dbContext.UpdateAsync(registry);
|
||||
return await _dbContext.Updateable<DeviceRegistryEntity>()
|
||||
.SetColumns(x => x.LastHeartbeatTime == DateTime.Now)
|
||||
.Where(x => x.DeviceUniqueNo == request.UniqueNo)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -110,6 +111,20 @@ public class DeviceConnectService : IDeviceConnectService
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<DeviceUniqueWithConnectionInfoDto>> GetOnlineDeviceUniqueInfoAsync()
|
||||
{
|
||||
return await _dbContext.Queryable<DeviceEntity>()
|
||||
.LeftJoin<DeviceRegistryEntity>((d, dr) => d.UniqueNo == dr.DeviceUniqueNo)
|
||||
.Where((d, dr) => d.Enable && SqlFunc.DateAdd(dr.LastHeartbeatTime, SqlFunc.IIF(d.HeartbeatInterval == 0, 30, 30), DateType.Second) > DateTime.Now)
|
||||
.Select((d, dr) => new DeviceUniqueWithConnectionInfoDto
|
||||
{
|
||||
DeviceUnique = d.UniqueNo,
|
||||
ConnectionInfo = d.ConnectionInfo
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
//******************************************************** help methods **********************************************************
|
||||
|
||||
/// <summary>
|
||||
@@ -123,8 +138,8 @@ public class DeviceConnectService : IDeviceConnectService
|
||||
private async Task<DeviceEntity> GetEnableDeviceAsync(string uniqueNo, bool checkExists = true, string deployPlace = "", string tenantId = "")
|
||||
{
|
||||
var device = await _dbContext.Queryable<DeviceEntity>()
|
||||
.Where(x => x.UniqueNo == uniqueNo)
|
||||
.FirstAsync();
|
||||
.Where(x => x.UniqueNo == uniqueNo)
|
||||
.FirstAsync();
|
||||
|
||||
if (checkExists)
|
||||
{
|
||||
@@ -165,4 +180,4 @@ public class DeviceConnectService : IDeviceConnectService
|
||||
|
||||
return device;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user