feai 北明接口
This commit is contained in:
65
Src/Dlhis.External/OpenApi/Controllers/DeviceController.cs
Normal file
65
Src/Dlhis.External/OpenApi/Controllers/DeviceController.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.External.OpenApi.Response;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.External.OpenApi.Controllers;
|
||||
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class DevicesController : ControllerBase
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public DevicesController(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设备列表
|
||||
/// </summary>
|
||||
/// <param name="factory"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
public async Task<List<DeviceResponse>> GetDeviceAsync(string factory)
|
||||
{
|
||||
return await _dbContext.Queryable<DeviceEntity>()
|
||||
.LeftJoin<DeviceRegistryEntity>((x, xr) => x.UniqueNo == xr.DeviceUniqueNo)
|
||||
.Where(x => x.TenantId == factory && (x.Type == DeviceTypeEnumType.Attendance || x.Type == DeviceTypeEnumType.Door))
|
||||
.Select((x, xr) => new DeviceResponse
|
||||
{
|
||||
DeviceNo = x.UniqueNo,
|
||||
HeartbeatInterval = x.HeartbeatInterval,
|
||||
DirectionType = x.DeployDirection,
|
||||
LastHeartbeatTime = xr.LastHeartbeatTime,
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设备事件记录
|
||||
/// </summary>
|
||||
/// <param name="factory"></param>
|
||||
/// <param name="time"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("event/records")]
|
||||
public async Task<List<DeviceRecordResponse>> GetEventRecordPageAsync(string factory, DateTime time)
|
||||
{
|
||||
return await _dbContext.Queryable<DeviceUploadLogEntity>().Where(x => x.RaiseDateTime >= time)
|
||||
.Where(x => x.TenantId == factory)
|
||||
.Select(x => new DeviceRecordResponse
|
||||
{
|
||||
DeviceNo = x.DeviceUniqueNo,
|
||||
Time = x.RaiseDateTime,
|
||||
UserCode = x.UserUniqueNo,
|
||||
Valid = x.Status,
|
||||
SerialNo = x.SerialNo
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user