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.
139 lines
5.2 KiB
139 lines
5.2 KiB
using CellularManagement.Application.Features.AtOperations.Commands.CreateAtOperation;
|
|
using CellularManagement.Application.Features.AtOperations.Commands.DeleteAtOperation;
|
|
using CellularManagement.Application.Features.AtOperations.Commands.UpdateAtOperation;
|
|
using CellularManagement.Application.Features.AtOperations.Queries.GetAtOperationById;
|
|
using CellularManagement.Application.Features.AtOperations.Queries.GetAtOperations;
|
|
using CellularManagement.Domain.Common;
|
|
using CellularManagement.Presentation.Abstractions;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace CellularManagement.Presentation.Controllers
|
|
{
|
|
/// <summary>
|
|
/// AT操作管理控制器
|
|
/// </summary>
|
|
[Route("api/at-operations")]
|
|
[ApiController]
|
|
[Authorize]
|
|
public class AtOperationsController : ApiController
|
|
{
|
|
private readonly ILogger<AtOperationsController> _logger;
|
|
|
|
/// <summary>
|
|
/// 初始化AT操作控制器
|
|
/// </summary>
|
|
public AtOperationsController(IMediator mediator, ILogger<AtOperationsController> logger)
|
|
: base(mediator)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取AT操作列表
|
|
/// </summary>
|
|
[HttpGet]
|
|
public async Task<OperationResult<GetAtOperationsResponse>> GetAll([FromQuery] GetAtOperationsQuery query)
|
|
{
|
|
_logger.LogInformation("开始获取AT操作列表,页码: {PageNumber}, 每页数量: {PageSize}, 搜索关键词: {Keyword}, 设备ID: {DeviceId}",
|
|
query.PageNumber, query.PageSize, query.Keyword, query.DeviceId);
|
|
|
|
var result = await mediator.Send(query);
|
|
if (!result.IsSuccess)
|
|
{
|
|
_logger.LogWarning("获取AT操作列表失败: {Message}", result.ErrorMessages);
|
|
return result;
|
|
}
|
|
|
|
_logger.LogInformation("成功获取AT操作列表,共 {Count} 条记录", result.Data?.TotalCount ?? 0);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取AT操作详情
|
|
/// </summary>
|
|
[HttpGet("{id}")]
|
|
public async Task<OperationResult<GetAtOperationByIdResponse>> GetById(string id)
|
|
{
|
|
_logger.LogInformation("开始获取AT操作详情,操作ID: {OperationId}", id);
|
|
|
|
var query = new GetAtOperationByIdQuery { Id = id };
|
|
var result = await mediator.Send(query);
|
|
if (!result.IsSuccess)
|
|
{
|
|
_logger.LogWarning("获取AT操作详情失败: {Message}", result.ErrorMessages);
|
|
return result;
|
|
}
|
|
|
|
_logger.LogInformation("成功获取AT操作详情,操作ID: {OperationId}", id);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建AT操作
|
|
/// </summary>
|
|
[HttpPost]
|
|
public async Task<OperationResult<CreateAtOperationResponse>> Create([FromBody] CreateAtOperationCommand command)
|
|
{
|
|
_logger.LogInformation("开始创建AT操作,设备ID: {DeviceId}, 端口: {Port}, 命令: {Command}",
|
|
command.DeviceId, command.Port, command.Command);
|
|
|
|
var result = await mediator.Send(command);
|
|
if (!result.IsSuccess)
|
|
{
|
|
_logger.LogWarning("创建AT操作失败: {Message}", result.ErrorMessages);
|
|
return result;
|
|
}
|
|
|
|
_logger.LogInformation("成功创建AT操作,操作ID: {OperationId}", result.Data?.Id);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新AT操作
|
|
/// </summary>
|
|
[HttpPut("{id}")]
|
|
public async Task<OperationResult<UpdateAtOperationResponse>> Update(string id, [FromBody] UpdateAtOperationCommand command)
|
|
{
|
|
_logger.LogInformation("开始更新AT操作,操作ID: {OperationId}", id);
|
|
|
|
if (id != command.Id)
|
|
{
|
|
_logger.LogWarning("AT操作ID不匹配,路径ID: {PathId}, 命令ID: {CommandId}", id, command.Id);
|
|
return OperationResult<UpdateAtOperationResponse>.CreateFailure("AT操作ID不匹配");
|
|
}
|
|
|
|
var result = await mediator.Send(command);
|
|
if (!result.IsSuccess)
|
|
{
|
|
_logger.LogWarning("更新AT操作失败: {Message}", result.ErrorMessages);
|
|
return result;
|
|
}
|
|
|
|
_logger.LogInformation("成功更新AT操作,操作ID: {OperationId}", id);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除AT操作
|
|
/// </summary>
|
|
[HttpDelete("{id}")]
|
|
public async Task<OperationResult<bool>> Delete(string id)
|
|
{
|
|
_logger.LogInformation("开始删除AT操作,操作ID: {OperationId}", id);
|
|
|
|
var command = new DeleteAtOperationCommand { Id = id };
|
|
var result = await mediator.Send(command);
|
|
if (!result.IsSuccess)
|
|
{
|
|
_logger.LogWarning("删除AT操作失败: {Message}", result.ErrorMessages);
|
|
return result;
|
|
}
|
|
|
|
_logger.LogInformation("成功删除AT操作,操作ID: {OperationId}", id);
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
|