fix 逻辑修正
This commit is contained in:
@@ -11,6 +11,7 @@ using Kurisu.Core.DataAccess.Dto;
|
|||||||
using Kurisu.SqlSugar.Extensions;
|
using Kurisu.SqlSugar.Extensions;
|
||||||
using Kurisu.SqlSugar.Services;
|
using Kurisu.SqlSugar.Services;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
|
using MySqlX.XDevAPI.Relational;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
@@ -269,10 +270,8 @@ public class DeviceService : IDeviceService
|
|||||||
|
|
||||||
public async Task<DeviceNumberResponse> GetDeviceNumberAsync()
|
public async Task<DeviceNumberResponse> GetDeviceNumberAsync()
|
||||||
{
|
{
|
||||||
var devices = await _dbContext.Queryable<DeviceEntity>()
|
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance)).ToListAsync();
|
||||||
.Where(x => x.Type == DeviceTypeEnumType.Attendance && x.Enable)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
var offlineNumber = await GetOfflineDevicesCount(devices);
|
var offlineNumber = await GetOfflineDevicesCount(devices);
|
||||||
|
|
||||||
var res = new DeviceNumberResponse
|
var res = new DeviceNumberResponse
|
||||||
@@ -286,32 +285,48 @@ public class DeviceService : IDeviceService
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取离线设备
|
/// 获取离线设备
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="devices"></param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private async Task<List<DeviceEntity>> GetOfflineDevicesCount(List<DeviceEntity> devices)
|
private async Task<List<DeviceEntity>> GetOfflineDevicesCount(List<DeviceEntity> devices)
|
||||||
{
|
{
|
||||||
var nos = devices.Select(x => x.UniqueNo).ToList();
|
var now = DateTime.Now;
|
||||||
var deviceRegistrys = await _dbContext.Queryable<DeviceRegistryEntity>()
|
|
||||||
.Where(x => nos.Contains(x.DeviceUniqueNo))
|
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
|
||||||
|
{
|
||||||
|
UniqueNo = d.UniqueNo,
|
||||||
|
d.HeartbeatInterval,
|
||||||
|
x.LastHeartbeatTime
|
||||||
|
})
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
var list = new List<DeviceEntity>();
|
var OnlineDevices = deviceRegistries
|
||||||
foreach (var device in devices)
|
.Where(x =>
|
||||||
{
|
|
||||||
var regis = deviceRegistrys.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo);
|
|
||||||
if (regis == null || device.HeartbeatInterval == 0)
|
|
||||||
{
|
{
|
||||||
continue;
|
if (x.HeartbeatInterval <= 0)
|
||||||
}
|
{
|
||||||
TimeSpan timeDifference = DateTime.Now - regis.LastHeartbeatTime;
|
return true;
|
||||||
if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3))
|
}
|
||||||
|
|
||||||
|
return x.LastHeartbeatTime.AddSeconds(x.HeartbeatInterval * 3) >= now;
|
||||||
|
|
||||||
|
})
|
||||||
|
.Select(x => new
|
||||||
{
|
{
|
||||||
list.Add(device);
|
UniqueNo = x.UniqueNo,
|
||||||
}
|
})
|
||||||
|
.ToList();
|
||||||
}
|
var onlineUniqueNos = new List<string>();
|
||||||
|
OnlineDevices.ForEach(x => onlineUniqueNos.Add(x.UniqueNo));
|
||||||
|
|
||||||
|
var offUniqueNos = deviceUniqueNos.Except(onlineUniqueNos).ToList();
|
||||||
|
var list = devices.Where(x => offUniqueNos.Contains(x.UniqueNo)).ToList();
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<Pagination<DevicePageResponse>> GetAttendanceTotalAsync(AttendanceTotalRequest request)
|
public async Task<Pagination<DevicePageResponse>> GetAttendanceTotalAsync(AttendanceTotalRequest request)
|
||||||
{
|
{
|
||||||
@@ -332,9 +347,7 @@ public class DeviceService : IDeviceService
|
|||||||
|
|
||||||
public async Task<Pagination<DevicePageResponse>> GetAttendanceOfflineAsync(DeviceOnlineAndofflineRequest request)
|
public async Task<Pagination<DevicePageResponse>> GetAttendanceOfflineAsync(DeviceOnlineAndofflineRequest request)
|
||||||
{
|
{
|
||||||
var devices = await _dbContext.Queryable<DeviceEntity>()
|
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance)).ToListAsync();
|
||||||
.Where(x => x.Type == DeviceTypeEnumType.Attendance && x.Enable)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
//离线
|
//离线
|
||||||
var offDevices = await GetOfflineDevicesCount(devices);
|
var offDevices = await GetOfflineDevicesCount(devices);
|
||||||
|
|||||||
Reference in New Issue
Block a user