diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index 474d1343..4818fb29 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -241,24 +241,43 @@ public class DeviceService : IDeviceService public async Task GetDeviceNumberAsync() { var devices = await _dbContext.Queryable() - .Where(x => x.Type == DeviceTypeEnumType.Attendance) + .Where(x => x.Type == DeviceTypeEnumType.Attendance && x.Enable) .ToListAsync(); - var onlineNumber = devices.Where(x => x.Enable).Count(); - var offlineNumber = devices.Where(x => x.Enable == false).Count(); + + var offlineNumber = GetOfflineDevicesCount(devices).Count; + var res = new DeviceNumberResponse - { - OnlineNumber = onlineNumber, + { OfflineNumber = offlineNumber, - TotalNumber = devices.Count() + TotalNumber = devices.Count(), + OnlineNumber = devices.Count()- offlineNumber }; return res; } + /// + /// 获取离线设备 + /// + /// + /// + private List GetOfflineDevicesCount(List devices) + { + var list = new List(); + foreach (var device in devices) + { + TimeSpan timeDifference = DateTime.Now - device.ModifiedTime; + if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3)) + { + list.Add(device); + } + } + return list; + } public async Task> GetAttendanceTotalAsync(AttendanceTotalRequest request) { var page = await _dbContext.Queryable() .LeftJoin((d, dt) => d.TemplateCode == dt.Code) - .Where(d => d.Type == DeviceTypeEnumType.Attendance) + .Where(d => d.Type == DeviceTypeEnumType.Attendance && d.Enable) .Select((d, dt) => new DevicePageResponse { FuncsStr = d.Funcs.ToString(), @@ -273,9 +292,39 @@ public class DeviceService : IDeviceService public async Task> GetAttendanceOfflineAsync(DeviceOnlineAndofflineRequest request) { + var devices = await _dbContext.Queryable() + .Where(x => x.Type == DeviceTypeEnumType.Attendance && x.Enable) + .ToListAsync(); + + //离线 + var offDevices = GetOfflineDevicesCount(devices); + var offids = offDevices.Select(x => x.Id).ToList(); + + if (request.IsOnAndOff) + { + //离线 + var offpage = await _dbContext.Queryable() + .LeftJoin((d, dt) => d.TemplateCode == dt.Code) + .Where(d => d.Type == DeviceTypeEnumType.Attendance && d.Enable) + .Where(d => offids.Contains(d.Id)) + .Select((d, dt) => new DevicePageResponse + { + FuncsStr = d.Funcs.ToString(), + Brand = dt.Brand, + Type = d.Type, + + }, true) + .ToPageListAsync(request); + return offpage; + } + //在线 + var ids = devices.Select(x => x.Id).ToList(); + List onids = ids.Except(offids).ToList(); + var page = await _dbContext.Queryable() .LeftJoin((d, dt) => d.TemplateCode == dt.Code) - .Where(d => d.Type == DeviceTypeEnumType.Attendance && d.Enable == request.IsOnAndOff) + .Where(d => d.Type == DeviceTypeEnumType.Attendance && d.Enable) + .Where(d => onids.Contains(d.Id)) .Select((d, dt) => new DevicePageResponse { FuncsStr = d.Funcs.ToString(), diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index c6f5104a..e4e1e6f6 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -551,10 +551,10 @@ public class BalanceService : IBalanceService public async Task GetConsumeNumberAsync() { var devices = await _dbContext.Queryable() - .Where(x => x.Type == DeviceTypeEnumType.Meal) + .Where(x => x.Type == DeviceTypeEnumType.Meal && x.Enable) .ToListAsync(); - var offCount = devices.Where(x => x.Enable == false).Count(); + var offCount = GetOfflineDevicesCount(devices).Count; var places = await _dbContext.Queryable() .ToListAsync(); @@ -592,6 +592,26 @@ public class BalanceService : IBalanceService return res; } + + /// + /// 获取离线设备 + /// + /// + /// + private List GetOfflineDevicesCount(List devices) + { + var list = new List(); + foreach (var device in devices) + { + TimeSpan timeDifference = DateTime.Now - device.ModifiedTime; + if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3)) + { + list.Add(device); + } + } + return list; + } + private async Task> GetConsumptionTrendsAsync(ConsumptionTrendEnumType type) { var bs = await _dbContext.Queryable() diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs index 893859c7..4c7998ae 100644 --- a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs @@ -75,6 +75,7 @@ public class ApkFIileService : IApkFIileService .Where(x => x.ProductCode == productCode) .Select() .FirstAsync(); + info.ThrowIfNull($"产品{productCode}下没有apk存在"); var url =await RequestDownloadFile(info.Name); var host = Configuration["MinIO:Endpoint"];