feat 接口通用处理

This commit is contained in:
2024-07-03 15:49:16 +08:00
parent 79e4e9a211
commit 16fe03edcb
5 changed files with 32 additions and 43 deletions

View File

@@ -188,20 +188,10 @@ public class DevicesController : ControllerBase
/// 获取考勤在线/离线设备详情列表
/// </summary>
/// <returns></returns>
[HttpGet("attendancesoffline")]
public async Task<Pagination<DevicePageResponse>> GetAttendanceOfflineAsync([FromQuery] DeviceOnlineAndOfflineRequest request)
[HttpGet("onlineStatus/page")]
public async Task<Pagination<DevicePageResponse>> GetOnlineStatusPageAsync([FromQuery] DeviceOnlineAndOfflineRequest request)
{
return await _deviceService.GetAttendanceOfflineAsync(request);
}
/// <summary>
/// 获取门禁在线/离线设备详情列表
/// </summary>
/// <returns></returns>
[HttpGet("dooroffline")]
public async Task<Pagination<DevicePageResponse>> GetDoorOfflineAsync([FromQuery] GetDoorOfflineRequest request)
{
return await _deviceService.GetDoorOfflineAsync(request);
return await _deviceService.GetOnlineStatusPageAsync(request);
}
/// <summary>

View File

@@ -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
{
/// <summary>
/// 是否在线
/// </summary>
public bool IsOnline { get; set; }
/// <summary>
/// 设备类型
/// </summary>
[EnumDataType(typeof(DeviceTypeEnumType))]
public DeviceTypeEnumType Type { get; set; }
}

View File

@@ -1,9 +0,0 @@
using Kurisu.AspNetCore.DataAccess.Dto;
namespace Dlhis.Basic.Device.Request
{
public class DeviceOnlineAndOfflineRequest : PageDto
{
public bool IsOnAndOff { get; set; }
}
}

View File

@@ -18,9 +18,7 @@ public interface IDeviceService : IScopeDependency
Task<Pagination<DevicePageResponse>> GetAttendanceTotalAsync(AttendanceTotalRequest request);
Task<Pagination<DevicePageResponse>> GetAttendanceOfflineAsync(DeviceOnlineAndOfflineRequest request);
Task<Pagination<DevicePageResponse>> GetDoorOfflineAsync(GetDoorOfflineRequest request);
Task<Pagination<DevicePageResponse>> GetOnlineStatusPageAsync(DeviceOnlineAndOfflineRequest request);
Task<List<RecentNumberResponse>> GetRecentNumbersAsync();

View File

@@ -180,12 +180,10 @@ public class DeviceService : IDeviceService
/// </summary>
/// <param name="templateCode"></param>
/// <returns></returns>
private async Task<DeviceTemplateEntity> CheckTemplateExistsAsync(Guid templateCode)
private async Task CheckTemplateExistsAsync(Guid templateCode)
{
var entity = await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => x.Code == templateCode).FirstAsync();
entity.ThrowIfNull("设备模板不存在");
return entity;
}
/// <summary>
@@ -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<Pagination<DevicePageResponse>> GetAttendanceOfflineAsync(DeviceOnlineAndOfflineRequest request)
public async Task<Pagination<DevicePageResponse>> GetOnlineStatusPageAsync(DeviceOnlineAndOfflineRequest request)
{
return await GetDeviceStatusPageAsync(request.IsOnAndOff, request, DeviceTypeEnumType.Attendance);
return await GetDeviceStatusPageAsync(request.IsOnline, request, request.Type);
}
public async Task<Pagination<DevicePageResponse>> GetDoorOfflineAsync(GetDoorOfflineRequest request)
{
return await GetDeviceStatusPageAsync(request.IsOnAndOff, request, DeviceTypeEnumType.Door);
}
public async Task<List<RecentNumberResponse>> GetRecentNumbersAsync()
{
//获取近30天并转化为"yyyy-MM-dd"集合
@@ -403,23 +395,22 @@ public class DeviceService : IDeviceService
//************************************************************* help methods ************************************************************************
private async Task<Pagination<DevicePageResponse>> GetDeviceStatusPageAsync(bool isOnAndOff, PageDto pageDto, DeviceTypeEnumType deviceType)
private async Task<Pagination<DevicePageResponse>> GetDeviceStatusPageAsync(bool isOnline, PageDto pageDto, DeviceTypeEnumType type)
{
var devices = deviceType == DeviceTypeEnumType.Attendance
? await _dbContext.Queryable<DeviceEntity>().Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance)).ToListAsync()
var devices = type == DeviceTypeEnumType.Attendance
? await _dbContext.Queryable<DeviceEntity>().Where(x => x.Type == DeviceTypeEnumType.Attendance).ToListAsync()
: await _dbContext.Queryable<DeviceEntity>().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<DeviceEntity>()
.LeftJoin<DeviceTemplateEntity>((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);
}