fix deviceRegister修复
This commit is contained in:
@@ -74,7 +74,7 @@ public class DeviceService : IDeviceService
|
||||
entity.Code = Guid.NewGuid();
|
||||
await _dbContext.InsertAsync(entity);
|
||||
//同时保存注册信息
|
||||
var registry = await _dbContext.Queryable<DeviceRegistryEntity>().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync();
|
||||
var registry = await _dbContext.Queryable<DeviceRegistryEntity>().Where(x => x.DeviceUniqueNo == request.UniqueNo).SingleAsync();
|
||||
if (registry == null)
|
||||
{
|
||||
registry = new DeviceRegistryEntity
|
||||
@@ -106,6 +106,20 @@ public class DeviceService : IDeviceService
|
||||
|
||||
request.Adapt(entity);
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
|
||||
var registry = await _dbContext.Queryable<DeviceRegistryEntity>().Where(x => x.DeviceUniqueNo == request.UniqueNo).SingleAsync();
|
||||
if (registry == null)
|
||||
{
|
||||
registry = new DeviceRegistryEntity
|
||||
{
|
||||
DeviceUniqueNo = request.UniqueNo,
|
||||
LastHeartbeatTime = DateTime.Now,
|
||||
RegisterTime = DateTime.Now,
|
||||
BusinessPlaceCode = null,
|
||||
};
|
||||
|
||||
await _dbContext.InsertAsync(registry);
|
||||
}
|
||||
}
|
||||
|
||||
await GenerateUploadRecordLogForBeginTimeAsync(entity);
|
||||
@@ -271,19 +285,25 @@ public class DeviceService : IDeviceService
|
||||
var deviceUniqueNos = devices.Select(x => x.UniqueNo).ToList();
|
||||
|
||||
var deviceRegistries = await _dbContext.Queryable<DeviceRegistryEntity>()
|
||||
.LeftJoin<DeviceEntity>((x, d) => x.DeviceUniqueNo == d.UniqueNo)
|
||||
.Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo))
|
||||
.Select((x, d) => new
|
||||
.Select(x => new
|
||||
{
|
||||
d.UniqueNo,
|
||||
d.HeartbeatInterval,
|
||||
x.DeviceUniqueNo,
|
||||
x.LastHeartbeatTime
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var offlineUniqueNos = deviceRegistries
|
||||
.Where(x => x.HeartbeatInterval > 0 && x.LastHeartbeatTime.AddSeconds(x.HeartbeatInterval) < now)
|
||||
.Select(x => x.UniqueNo);
|
||||
var offlineUniqueNos = devices.Where(x =>
|
||||
{
|
||||
var item = deviceRegistries.FirstOrDefault(p => p.DeviceUniqueNo == x.UniqueNo);
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return x.HeartbeatInterval > 0 && item.LastHeartbeatTime.AddSeconds(x.HeartbeatInterval) < now;
|
||||
}).Select(x => x.UniqueNo);
|
||||
|
||||
return devices.Where(x => offlineUniqueNos.Contains(x.UniqueNo)).Select(x => x.Id).ToList();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user