From 5e29f013b8c248a1753bb92383328f0b890080aa Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Mon, 26 Feb 2024 10:14:36 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E6=94=B9=E7=A6=BB=E7=BA=BF?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/DeviceService.cs | 65 ++++++++++++++++--- .../Services/Implements/BalanceService.cs | 24 ++++++- .../Services/Implements/ApkFIileService.cs | 1 + 3 files changed, 80 insertions(+), 10 deletions(-) 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"];