diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs index 28bc2bdd..4801b8d9 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs @@ -188,20 +188,10 @@ public class DevicesController : ControllerBase /// 获取考勤在线/离线设备详情列表 /// /// - [HttpGet("attendancesoffline")] - public async Task> GetAttendanceOfflineAsync([FromQuery] DeviceOnlineAndOfflineRequest request) + [HttpGet("onlineStatus/page")] + public async Task> GetOnlineStatusPageAsync([FromQuery] DeviceOnlineAndOfflineRequest request) { - return await _deviceService.GetAttendanceOfflineAsync(request); - } - - /// - /// 获取门禁在线/离线设备详情列表 - /// - /// - [HttpGet("dooroffline")] - public async Task> GetDoorOfflineAsync([FromQuery] GetDoorOfflineRequest request) - { - return await _deviceService.GetDoorOfflineAsync(request); + return await _deviceService.GetOnlineStatusPageAsync(request); } /// diff --git a/Src/Dlhis.Basic/Device/Request/DeviceOnlineAndOfflineRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceOnlineAndOfflineRequest.cs new file mode 100644 index 00000000..7521326b --- /dev/null +++ b/Src/Dlhis.Basic/Device/Request/DeviceOnlineAndOfflineRequest.cs @@ -0,0 +1,19 @@ +using System.ComponentModel.DataAnnotations; +using Dlhis.Entity.Device.Enums; +using Kurisu.AspNetCore.DataAccess.Dto; + +namespace Dlhis.Basic.Device.Request; + +public class DeviceOnlineAndOfflineRequest : PageDto +{ + /// + /// 是否在线 + /// + public bool IsOnline { get; set; } + + /// + /// 设备类型 + /// + [EnumDataType(typeof(DeviceTypeEnumType))] + public DeviceTypeEnumType Type { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Basic/Device/Request/DeviceOnlineAndofflineRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceOnlineAndofflineRequest.cs deleted file mode 100644 index 82bdea8b..00000000 --- a/Src/Dlhis.Basic/Device/Request/DeviceOnlineAndofflineRequest.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Kurisu.AspNetCore.DataAccess.Dto; - -namespace Dlhis.Basic.Device.Request -{ - public class DeviceOnlineAndOfflineRequest : PageDto - { - public bool IsOnAndOff { get; set; } - } -} diff --git a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs index 5592e608..d941645d 100644 --- a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs @@ -18,9 +18,7 @@ public interface IDeviceService : IScopeDependency Task> GetAttendanceTotalAsync(AttendanceTotalRequest request); - Task> GetAttendanceOfflineAsync(DeviceOnlineAndOfflineRequest request); - - Task> GetDoorOfflineAsync(GetDoorOfflineRequest request); + Task> GetOnlineStatusPageAsync(DeviceOnlineAndOfflineRequest request); Task> GetRecentNumbersAsync(); diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index 967a1936..ba7201c9 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -180,12 +180,10 @@ public class DeviceService : IDeviceService /// /// /// - private async Task CheckTemplateExistsAsync(Guid templateCode) + private async Task CheckTemplateExistsAsync(Guid templateCode) { var entity = await _dbContext.Queryable().Where(x => x.Code == templateCode).FirstAsync(); entity.ThrowIfNull("设备模板不存在"); - - return entity; } /// @@ -246,6 +244,7 @@ public class DeviceService : IDeviceService } catch (Exception) { + //ignore } true.ThrowIfTrue($"设备已添加{factory}厂区"); @@ -360,18 +359,11 @@ public class DeviceService : IDeviceService return page; } - public async Task> GetAttendanceOfflineAsync(DeviceOnlineAndOfflineRequest request) + public async Task> GetOnlineStatusPageAsync(DeviceOnlineAndOfflineRequest request) { - return await GetDeviceStatusPageAsync(request.IsOnAndOff, request, DeviceTypeEnumType.Attendance); + return await GetDeviceStatusPageAsync(request.IsOnline, request, request.Type); } - - public async Task> GetDoorOfflineAsync(GetDoorOfflineRequest request) - { - return await GetDeviceStatusPageAsync(request.IsOnAndOff, request, DeviceTypeEnumType.Door); - } - - public async Task> GetRecentNumbersAsync() { //获取近30天并转化为"yyyy-MM-dd"集合 @@ -403,23 +395,22 @@ public class DeviceService : IDeviceService //************************************************************* help methods ************************************************************************ - private async Task> GetDeviceStatusPageAsync(bool isOnAndOff, PageDto pageDto, DeviceTypeEnumType deviceType) + private async Task> GetDeviceStatusPageAsync(bool isOnline, PageDto pageDto, DeviceTypeEnumType type) { - var devices = deviceType == DeviceTypeEnumType.Attendance - ? await _dbContext.Queryable().Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance)).ToListAsync() + var devices = type == DeviceTypeEnumType.Attendance + ? await _dbContext.Queryable().Where(x => x.Type == DeviceTypeEnumType.Attendance).ToListAsync() : await _dbContext.Queryable().Where(x => x.Type == DeviceTypeEnumType.Door).ToListAsync(); var offDevices = await GetOfflineDevicesCount(devices); //离线 var ids = offDevices.Select(x => x.Id).ToList(); - if (!isOnAndOff) + if (!isOnline) { ids = devices.Select(x => x.Id).Except(ids).ToList(); } return await _dbContext.Queryable() .LeftJoin((d, dt) => d.TemplateCode == dt.Code) - .Where(d => d.Type == DeviceTypeEnumType.Attendance) .Where(d => ids.Contains(d.Id)) .WhereIF(pageDto.Search.IsPresent(), d => d.UniqueNo == pageDto.Search || d.DeployPlace.Contains(pageDto.Search)) @@ -427,7 +418,7 @@ public class DeviceService : IDeviceService { FuncsStr = d.Funcs.ToString(), Brand = dt.Brand, - Type = d.Type, + Type = d.Type }, true) .ToPageListAsync(pageDto); }