72 lines
2.4 KiB
C#
72 lines
2.4 KiB
C#
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.Aop;
|
|
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")]
|
|
[IgnoreTenant]
|
|
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,
|
|
DeployPlace = x.DeployPlace,
|
|
Type = x.Type,
|
|
HeartbeatInterval = x.HeartbeatInterval,
|
|
DirectionType = x.DeployDirection,
|
|
LastHeartbeatTime = xr.LastHeartbeatTime,
|
|
ConnectionInfo = x.ConnectionInfo
|
|
})
|
|
.ToListAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设备事件记录
|
|
/// </summary>
|
|
/// <param name="factory"></param>
|
|
/// <param name="time"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("event/records")]
|
|
[IgnoreTenant]
|
|
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)
|
|
.OrderByDescending(x => x.RaiseDateTime)
|
|
.Select(x => new DeviceRecordResponse
|
|
{
|
|
DeviceNo = x.DeviceUniqueNo,
|
|
Time = x.RaiseDateTime,
|
|
UserCode = x.UserUniqueNo,
|
|
Valid = x.Status,
|
|
SerialNo = x.SerialNo
|
|
})
|
|
.ToListAsync();
|
|
}
|
|
} |