fix 添加判断逻辑
This commit is contained in:
@@ -244,13 +244,13 @@ public class DeviceService : IDeviceService
|
|||||||
.Where(x => x.Type == DeviceTypeEnumType.Attendance && x.Enable)
|
.Where(x => x.Type == DeviceTypeEnumType.Attendance && x.Enable)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
var offlineNumber = GetOfflineDevicesCount(devices).Count;
|
var offlineNumber = await GetOfflineDevicesCount(devices);
|
||||||
|
|
||||||
var res = new DeviceNumberResponse
|
var res = new DeviceNumberResponse
|
||||||
{
|
{
|
||||||
OfflineNumber = offlineNumber,
|
OfflineNumber = offlineNumber.Count,
|
||||||
TotalNumber = devices.Count(),
|
TotalNumber = devices.Count,
|
||||||
OnlineNumber = devices.Count()- offlineNumber
|
OnlineNumber = devices.Count- offlineNumber.Count
|
||||||
};
|
};
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -259,12 +259,22 @@ public class DeviceService : IDeviceService
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="devices"></param>
|
/// <param name="devices"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private List<DeviceEntity> GetOfflineDevicesCount(List<DeviceEntity> devices)
|
private async Task<List<DeviceEntity>> GetOfflineDevicesCount(List<DeviceEntity> devices)
|
||||||
{
|
{
|
||||||
|
var nos = devices.Select(x => x.UniqueNo).ToList();
|
||||||
|
var deviceRegistrys = await _dbContext.Queryable<DeviceRegistryEntity>()
|
||||||
|
.Where(x => nos.Contains(x.DeviceUniqueNo))
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
var list = new List<DeviceEntity>();
|
var list = new List<DeviceEntity>();
|
||||||
foreach (var device in devices)
|
foreach (var device in devices)
|
||||||
{
|
{
|
||||||
TimeSpan timeDifference = DateTime.Now - device.ModifiedTime;
|
var regis = deviceRegistrys.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo);
|
||||||
|
if (regis == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
TimeSpan timeDifference = DateTime.Now - regis.LastHeartbeatTime;
|
||||||
if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3))
|
if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3))
|
||||||
{
|
{
|
||||||
list.Add(device);
|
list.Add(device);
|
||||||
@@ -297,7 +307,7 @@ public class DeviceService : IDeviceService
|
|||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
//离线
|
//离线
|
||||||
var offDevices = GetOfflineDevicesCount(devices);
|
var offDevices =await GetOfflineDevicesCount(devices);
|
||||||
var offids = offDevices.Select(x => x.Id).ToList();
|
var offids = offDevices.Select(x => x.Id).ToList();
|
||||||
|
|
||||||
if (request.IsOnAndOff)
|
if (request.IsOnAndOff)
|
||||||
|
|||||||
@@ -554,7 +554,7 @@ public class BalanceService : IBalanceService
|
|||||||
.Where(x => x.Type == DeviceTypeEnumType.Meal && x.Enable)
|
.Where(x => x.Type == DeviceTypeEnumType.Meal && x.Enable)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
var offCount = GetOfflineDevicesCount(devices).Count;
|
var offCount = await GetOfflineDevicesCount(devices);
|
||||||
|
|
||||||
var places = await _dbContext.Queryable<BusinessPlaceEntity>()
|
var places = await _dbContext.Queryable<BusinessPlaceEntity>()
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
@@ -581,9 +581,9 @@ public class BalanceService : IBalanceService
|
|||||||
|
|
||||||
var res = new ConsumeNumberResponse
|
var res = new ConsumeNumberResponse
|
||||||
{
|
{
|
||||||
Total = devices.Count(),
|
Total = devices.Count,
|
||||||
OffNumber = offCount,
|
OffNumber = offCount.Count,
|
||||||
PlaceNumber = places.Count(),
|
PlaceNumber = places.Count,
|
||||||
ConsumerableNumber = consumerable,
|
ConsumerableNumber = consumerable,
|
||||||
DailyNumber = monthlyCount != 0 ? Math.Abs((int)Math.Ceiling(monthlySpending / monthlyCount)) : 0,
|
DailyNumber = monthlyCount != 0 ? Math.Abs((int)Math.Ceiling(monthlySpending / monthlyCount)) : 0,
|
||||||
Days = days,
|
Days = days,
|
||||||
@@ -598,12 +598,22 @@ public class BalanceService : IBalanceService
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="devices"></param>
|
/// <param name="devices"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private List<DeviceEntity> GetOfflineDevicesCount(List<DeviceEntity> devices)
|
private async Task<List<DeviceEntity>> GetOfflineDevicesCount(List<DeviceEntity> devices)
|
||||||
{
|
{
|
||||||
|
var nos = devices.Select(x => x.UniqueNo).ToList();
|
||||||
|
var deviceRegistrys = await _dbContext.Queryable<DeviceRegistryEntity>()
|
||||||
|
.Where(x => nos.Contains(x.DeviceUniqueNo))
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
var list = new List<DeviceEntity>();
|
var list = new List<DeviceEntity>();
|
||||||
foreach (var device in devices)
|
foreach (var device in devices)
|
||||||
{
|
{
|
||||||
TimeSpan timeDifference = DateTime.Now - device.ModifiedTime;
|
var regis = deviceRegistrys.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo);
|
||||||
|
if (regis == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
TimeSpan timeDifference = DateTime.Now - regis.LastHeartbeatTime;
|
||||||
if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3))
|
if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3))
|
||||||
{
|
{
|
||||||
list.Add(device);
|
list.Add(device);
|
||||||
|
|||||||
Reference in New Issue
Block a user