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; } /// /// 设备列表 /// /// /// [HttpGet("list")] [IgnoreTenant] public async Task> GetDeviceAsync(string factory) { return await _dbContext.Queryable() .LeftJoin((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, HeartbeatInterval = x.HeartbeatInterval, DirectionType = x.DeployDirection, LastHeartbeatTime = xr.LastHeartbeatTime, }) .ToListAsync(); } /// /// 设备事件记录 /// /// /// /// [HttpGet("event/records")] [IgnoreTenant] public async Task> GetEventRecordPageAsync(string factory, DateTime time) { return await _dbContext.Queryable().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(); } }