You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.2 KiB
58 lines
2.2 KiB
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.Extensions.Logging;
|
|
using CellularManagement.Application.Features.ProtocolLogs.Queries.GetProtocolLogsByDevice;
|
|
using CellularManagement.Domain.Common;
|
|
using CellularManagement.Domain.Entities.Device;
|
|
using CellularManagement.Presentation.Abstractions;
|
|
using MediatR;
|
|
|
|
namespace CellularManagement.Presentation.Controllers;
|
|
|
|
/// <summary>
|
|
/// 协议日志控制器
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
[Authorize]
|
|
public class ProtocolLogsController : ApiController
|
|
{
|
|
private readonly ILogger<ProtocolLogsController> _logger;
|
|
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
/// <param name="mediator">中介者</param>
|
|
/// <param name="logger">日志记录器</param>
|
|
public ProtocolLogsController(IMediator mediator, ILogger<ProtocolLogsController> logger)
|
|
: base(mediator)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 获取协议日志
|
|
/// </summary>
|
|
/// <param name="query">查询请求</param>
|
|
/// <returns>协议日志列表</returns>
|
|
[HttpPost("logs")]
|
|
public async Task<OperationResult<GetProtocolLogsByDeviceResponse>> GetProtocolLogs(
|
|
[FromBody] GetProtocolLogsByDeviceQuery query)
|
|
{
|
|
_logger.LogInformation("开始获取协议日志,设备代码: {DeviceCode}, 开始时间戳: {StartTimestamp}, 结束时间戳: {EndTimestamp}, 协议层类型数量: {LayerTypesCount}, 运行时状态: {DeviceRuntimeStatus}, 运行时代码数量: {RuntimeCodesCount}, 运行时状态数量: {RuntimeStatusesCount}",
|
|
query.DeviceCode, query.StartTimestamp, query.EndTimestamp, query.LayerTypes?.Length ?? 0, query.DeviceRuntimeStatus, query.RuntimeCodes?.Length ?? 0, query.RuntimeStatuses?.Length ?? 0);
|
|
|
|
var result = await mediator.Send(query);
|
|
if (!result.IsSuccess)
|
|
{
|
|
_logger.LogWarning("获取协议日志失败: {Message}", result.ErrorMessages);
|
|
return result;
|
|
}
|
|
|
|
_logger.LogInformation("成功获取协议日志,共 {Count} 条记录",
|
|
result.Data?.Items?.Count ?? 0);
|
|
return result;
|
|
}
|
|
}
|