Browse Source
- 优化CellularDevice仓储接口,移除未使用的方法 - 为ProtocolVersion实体添加工厂方法和更新方法 - 创建ProtocolVersion仓储接口和实现类 - 实现ProtocolVersion完整的CQRS命令和查询 - 创建ProtocolVersionsController,统一使用OperationResult返回 - 更新数据库配置和依赖注入 - 添加HTTP测试文件feature/x1-owen-debug
42 changed files with 1434 additions and 780 deletions
@ -0,0 +1,52 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.ProtocolVersions.Commands.CreateProtocolVersion; |
|||
|
|||
/// <summary>
|
|||
/// 创建协议版本命令
|
|||
/// </summary>
|
|||
public class CreateProtocolVersionCommand : IRequest<OperationResult<CreateProtocolVersionResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 版本名称
|
|||
/// </summary>
|
|||
[Required] |
|||
[MaxLength(50)] |
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 版本号
|
|||
/// </summary>
|
|||
[Required] |
|||
[MaxLength(20)] |
|||
public string Version { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 版本描述
|
|||
/// </summary>
|
|||
[MaxLength(500)] |
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否启用
|
|||
/// </summary>
|
|||
public bool IsEnabled { get; set; } = true; |
|||
|
|||
/// <summary>
|
|||
/// 发布日期
|
|||
/// </summary>
|
|||
public DateTime? ReleaseDate { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否强制更新
|
|||
/// </summary>
|
|||
public bool IsForceUpdate { get; set; } = false; |
|||
|
|||
/// <summary>
|
|||
/// 最低支持版本
|
|||
/// </summary>
|
|||
[MaxLength(20)] |
|||
public string? MinimumSupportedVersion { get; set; } |
|||
} |
@ -0,0 +1,83 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Entities.Device; |
|||
using CellularManagement.Domain.Repositories.Device; |
|||
|
|||
namespace CellularManagement.Application.Features.ProtocolVersions.Commands.CreateProtocolVersion; |
|||
|
|||
/// <summary>
|
|||
/// 创建协议版本命令处理器
|
|||
/// </summary>
|
|||
public class CreateProtocolVersionCommandHandler : IRequestHandler<CreateProtocolVersionCommand, OperationResult<CreateProtocolVersionResponse>> |
|||
{ |
|||
private readonly IProtocolVersionRepository _protocolVersionRepository; |
|||
private readonly ILogger<CreateProtocolVersionCommandHandler> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 初始化命令处理器
|
|||
/// </summary>
|
|||
public CreateProtocolVersionCommandHandler( |
|||
IProtocolVersionRepository protocolVersionRepository, |
|||
ILogger<CreateProtocolVersionCommandHandler> logger) |
|||
{ |
|||
_protocolVersionRepository = protocolVersionRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理创建协议版本命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<CreateProtocolVersionResponse>> Handle(CreateProtocolVersionCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始创建协议版本,版本名称: {Name}, 版本号: {Version}", |
|||
request.Name, request.Version); |
|||
|
|||
// 检查版本号是否已存在
|
|||
if (await _protocolVersionRepository.VersionExistsAsync(request.Version, cancellationToken)) |
|||
{ |
|||
_logger.LogWarning("协议版本号已存在: {Version}", request.Version); |
|||
return OperationResult<CreateProtocolVersionResponse>.CreateFailure($"协议版本号 {request.Version} 已存在"); |
|||
} |
|||
|
|||
// 创建协议版本实体
|
|||
var protocolVersion = ProtocolVersion.Create( |
|||
name: request.Name, |
|||
version: request.Version, |
|||
description: request.Description, |
|||
isEnabled: request.IsEnabled, |
|||
releaseDate: request.ReleaseDate, |
|||
isForceUpdate: request.IsForceUpdate, |
|||
minimumSupportedVersion: request.MinimumSupportedVersion); |
|||
|
|||
// 保存协议版本
|
|||
await _protocolVersionRepository.AddProtocolVersionAsync(protocolVersion, cancellationToken); |
|||
|
|||
// 构建响应
|
|||
var response = new CreateProtocolVersionResponse |
|||
{ |
|||
ProtocolVersionId = protocolVersion.Id, |
|||
Name = protocolVersion.Name, |
|||
Version = protocolVersion.Version, |
|||
Description = protocolVersion.Description, |
|||
IsEnabled = protocolVersion.IsEnabled, |
|||
ReleaseDate = protocolVersion.ReleaseDate, |
|||
IsForceUpdate = protocolVersion.IsForceUpdate, |
|||
MinimumSupportedVersion = protocolVersion.MinimumSupportedVersion, |
|||
CreatedAt = protocolVersion.CreatedAt |
|||
}; |
|||
|
|||
_logger.LogInformation("协议版本创建成功,版本ID: {ProtocolVersionId}, 版本名称: {Name}, 版本号: {Version}", |
|||
protocolVersion.Id, protocolVersion.Name, protocolVersion.Version); |
|||
return OperationResult<CreateProtocolVersionResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "创建协议版本时发生错误,版本名称: {Name}, 版本号: {Version}", |
|||
request.Name, request.Version); |
|||
return OperationResult<CreateProtocolVersionResponse>.CreateFailure($"创建协议版本时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,52 @@ |
|||
namespace CellularManagement.Application.Features.ProtocolVersions.Commands.CreateProtocolVersion; |
|||
|
|||
/// <summary>
|
|||
/// 创建协议版本响应
|
|||
/// </summary>
|
|||
public class CreateProtocolVersionResponse |
|||
{ |
|||
/// <summary>
|
|||
/// 协议版本ID
|
|||
/// </summary>
|
|||
public string ProtocolVersionId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 版本名称
|
|||
/// </summary>
|
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 版本号
|
|||
/// </summary>
|
|||
public string Version { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 版本描述
|
|||
/// </summary>
|
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否启用
|
|||
/// </summary>
|
|||
public bool IsEnabled { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 发布日期
|
|||
/// </summary>
|
|||
public DateTime? ReleaseDate { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否强制更新
|
|||
/// </summary>
|
|||
public bool IsForceUpdate { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 最低支持版本
|
|||
/// </summary>
|
|||
public string? MinimumSupportedVersion { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 创建时间
|
|||
/// </summary>
|
|||
public DateTime CreatedAt { get; set; } |
|||
} |
@ -0,0 +1,17 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.ProtocolVersions.Commands.DeleteProtocolVersion; |
|||
|
|||
/// <summary>
|
|||
/// 删除协议版本命令
|
|||
/// </summary>
|
|||
public class DeleteProtocolVersionCommand : IRequest<OperationResult<bool>> |
|||
{ |
|||
/// <summary>
|
|||
/// 协议版本ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string ProtocolVersionId { get; set; } = null!; |
|||
} |
@ -0,0 +1,56 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.Device; |
|||
|
|||
namespace CellularManagement.Application.Features.ProtocolVersions.Commands.DeleteProtocolVersion; |
|||
|
|||
/// <summary>
|
|||
/// 删除协议版本命令处理器
|
|||
/// </summary>
|
|||
public class DeleteProtocolVersionCommandHandler : IRequestHandler<DeleteProtocolVersionCommand, OperationResult<bool>> |
|||
{ |
|||
private readonly IProtocolVersionRepository _protocolVersionRepository; |
|||
private readonly ILogger<DeleteProtocolVersionCommandHandler> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 初始化删除协议版本命令处理器
|
|||
/// </summary>
|
|||
public DeleteProtocolVersionCommandHandler( |
|||
IProtocolVersionRepository protocolVersionRepository, |
|||
ILogger<DeleteProtocolVersionCommandHandler> logger) |
|||
{ |
|||
_protocolVersionRepository = protocolVersionRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理删除协议版本命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<bool>> Handle(DeleteProtocolVersionCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始处理删除协议版本命令,版本ID: {ProtocolVersionId}", request.ProtocolVersionId); |
|||
|
|||
// 检查协议版本是否存在
|
|||
var protocolVersion = await _protocolVersionRepository.GetProtocolVersionByIdAsync(request.ProtocolVersionId, cancellationToken); |
|||
if (protocolVersion == null) |
|||
{ |
|||
_logger.LogWarning("未找到协议版本,版本ID: {ProtocolVersionId}", request.ProtocolVersionId); |
|||
return OperationResult<bool>.CreateFailure($"未找到ID为 {request.ProtocolVersionId} 的协议版本"); |
|||
} |
|||
|
|||
// 删除协议版本
|
|||
await _protocolVersionRepository.DeleteProtocolVersionAsync(request.ProtocolVersionId, cancellationToken); |
|||
|
|||
_logger.LogInformation("协议版本删除成功,版本ID: {ProtocolVersionId}", request.ProtocolVersionId); |
|||
return OperationResult<bool>.CreateSuccess("协议版本删除成功", true); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "删除协议版本时发生错误,版本ID: {ProtocolVersionId}", request.ProtocolVersionId); |
|||
return OperationResult<bool>.CreateFailure($"删除协议版本时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,58 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.ProtocolVersions.Commands.UpdateProtocolVersion; |
|||
|
|||
/// <summary>
|
|||
/// 更新协议版本命令
|
|||
/// </summary>
|
|||
public class UpdateProtocolVersionCommand : IRequest<OperationResult<UpdateProtocolVersionResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 协议版本ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string ProtocolVersionId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 版本名称
|
|||
/// </summary>
|
|||
[Required] |
|||
[MaxLength(50)] |
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 版本号
|
|||
/// </summary>
|
|||
[Required] |
|||
[MaxLength(20)] |
|||
public string Version { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 版本描述
|
|||
/// </summary>
|
|||
[MaxLength(500)] |
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否启用
|
|||
/// </summary>
|
|||
public bool IsEnabled { get; set; } = true; |
|||
|
|||
/// <summary>
|
|||
/// 发布日期
|
|||
/// </summary>
|
|||
public DateTime? ReleaseDate { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否强制更新
|
|||
/// </summary>
|
|||
public bool IsForceUpdate { get; set; } = false; |
|||
|
|||
/// <summary>
|
|||
/// 最低支持版本
|
|||
/// </summary>
|
|||
[MaxLength(20)] |
|||
public string? MinimumSupportedVersion { get; set; } |
|||
} |
@ -0,0 +1,93 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Entities.Device; |
|||
using CellularManagement.Domain.Repositories.Device; |
|||
|
|||
namespace CellularManagement.Application.Features.ProtocolVersions.Commands.UpdateProtocolVersion; |
|||
|
|||
/// <summary>
|
|||
/// 更新协议版本命令处理器
|
|||
/// </summary>
|
|||
public class UpdateProtocolVersionCommandHandler : IRequestHandler<UpdateProtocolVersionCommand, OperationResult<UpdateProtocolVersionResponse>> |
|||
{ |
|||
private readonly IProtocolVersionRepository _protocolVersionRepository; |
|||
private readonly ILogger<UpdateProtocolVersionCommandHandler> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 初始化命令处理器
|
|||
/// </summary>
|
|||
public UpdateProtocolVersionCommandHandler( |
|||
IProtocolVersionRepository protocolVersionRepository, |
|||
ILogger<UpdateProtocolVersionCommandHandler> logger) |
|||
{ |
|||
_protocolVersionRepository = protocolVersionRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理更新协议版本命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<UpdateProtocolVersionResponse>> Handle(UpdateProtocolVersionCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始更新协议版本,版本ID: {ProtocolVersionId}, 版本名称: {Name}", |
|||
request.ProtocolVersionId, request.Name); |
|||
|
|||
// 检查协议版本是否存在
|
|||
var existingProtocolVersion = await _protocolVersionRepository.GetProtocolVersionByIdAsync(request.ProtocolVersionId, cancellationToken); |
|||
if (existingProtocolVersion == null) |
|||
{ |
|||
_logger.LogWarning("未找到协议版本,版本ID: {ProtocolVersionId}", request.ProtocolVersionId); |
|||
return OperationResult<UpdateProtocolVersionResponse>.CreateFailure($"未找到ID为 {request.ProtocolVersionId} 的协议版本"); |
|||
} |
|||
|
|||
// 如果版本号发生变化,检查新版本号是否已存在
|
|||
if (existingProtocolVersion.Version != request.Version) |
|||
{ |
|||
if (await _protocolVersionRepository.VersionExistsAsync(request.Version, cancellationToken)) |
|||
{ |
|||
_logger.LogWarning("协议版本号已存在: {Version}", request.Version); |
|||
return OperationResult<UpdateProtocolVersionResponse>.CreateFailure($"协议版本号 {request.Version} 已存在"); |
|||
} |
|||
} |
|||
|
|||
// 更新协议版本属性
|
|||
existingProtocolVersion.Update( |
|||
name: request.Name, |
|||
version: request.Version, |
|||
description: request.Description, |
|||
isEnabled: request.IsEnabled, |
|||
releaseDate: request.ReleaseDate, |
|||
isForceUpdate: request.IsForceUpdate, |
|||
minimumSupportedVersion: request.MinimumSupportedVersion); |
|||
|
|||
_protocolVersionRepository.UpdateProtocolVersion(existingProtocolVersion); |
|||
|
|||
// 构建响应
|
|||
var response = new UpdateProtocolVersionResponse |
|||
{ |
|||
ProtocolVersionId = existingProtocolVersion.Id, |
|||
Name = existingProtocolVersion.Name, |
|||
Version = existingProtocolVersion.Version, |
|||
Description = existingProtocolVersion.Description, |
|||
IsEnabled = existingProtocolVersion.IsEnabled, |
|||
ReleaseDate = existingProtocolVersion.ReleaseDate, |
|||
IsForceUpdate = existingProtocolVersion.IsForceUpdate, |
|||
MinimumSupportedVersion = existingProtocolVersion.MinimumSupportedVersion, |
|||
UpdatedAt = DateTime.UtcNow |
|||
}; |
|||
|
|||
_logger.LogInformation("协议版本更新成功,版本ID: {ProtocolVersionId}, 版本名称: {Name}", |
|||
existingProtocolVersion.Id, existingProtocolVersion.Name); |
|||
return OperationResult<UpdateProtocolVersionResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "更新协议版本时发生错误,版本ID: {ProtocolVersionId}, 版本名称: {Name}", |
|||
request.ProtocolVersionId, request.Name); |
|||
return OperationResult<UpdateProtocolVersionResponse>.CreateFailure($"更新协议版本时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,52 @@ |
|||
namespace CellularManagement.Application.Features.ProtocolVersions.Commands.UpdateProtocolVersion; |
|||
|
|||
/// <summary>
|
|||
/// 更新协议版本响应
|
|||
/// </summary>
|
|||
public class UpdateProtocolVersionResponse |
|||
{ |
|||
/// <summary>
|
|||
/// 协议版本ID
|
|||
/// </summary>
|
|||
public string ProtocolVersionId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 版本名称
|
|||
/// </summary>
|
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 版本号
|
|||
/// </summary>
|
|||
public string Version { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 版本描述
|
|||
/// </summary>
|
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否启用
|
|||
/// </summary>
|
|||
public bool IsEnabled { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 发布日期
|
|||
/// </summary>
|
|||
public DateTime? ReleaseDate { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否强制更新
|
|||
/// </summary>
|
|||
public bool IsForceUpdate { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 最低支持版本
|
|||
/// </summary>
|
|||
public string? MinimumSupportedVersion { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 更新时间
|
|||
/// </summary>
|
|||
public DateTime UpdatedAt { get; set; } |
|||
} |
@ -0,0 +1,17 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersionById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取协议版本查询
|
|||
/// </summary>
|
|||
public class GetProtocolVersionByIdQuery : IRequest<OperationResult<GetProtocolVersionByIdResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 协议版本ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string ProtocolVersionId { get; set; } = null!; |
|||
} |
@ -0,0 +1,68 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Entities.Device; |
|||
using CellularManagement.Domain.Repositories.Device; |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersionById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取协议版本查询处理器
|
|||
/// </summary>
|
|||
public class GetProtocolVersionByIdQueryHandler : IRequestHandler<GetProtocolVersionByIdQuery, OperationResult<GetProtocolVersionByIdResponse>> |
|||
{ |
|||
private readonly IProtocolVersionRepository _protocolVersionRepository; |
|||
private readonly ILogger<GetProtocolVersionByIdQueryHandler> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 初始化查询处理器
|
|||
/// </summary>
|
|||
public GetProtocolVersionByIdQueryHandler( |
|||
IProtocolVersionRepository protocolVersionRepository, |
|||
ILogger<GetProtocolVersionByIdQueryHandler> logger) |
|||
{ |
|||
_protocolVersionRepository = protocolVersionRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理查询请求
|
|||
/// </summary>
|
|||
public async Task<OperationResult<GetProtocolVersionByIdResponse>> Handle(GetProtocolVersionByIdQuery request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始查询协议版本,版本ID: {ProtocolVersionId}", request.ProtocolVersionId); |
|||
|
|||
var protocolVersion = await _protocolVersionRepository.GetProtocolVersionByIdAsync(request.ProtocolVersionId, cancellationToken); |
|||
|
|||
if (protocolVersion == null) |
|||
{ |
|||
_logger.LogWarning("未找到协议版本,版本ID: {ProtocolVersionId}", request.ProtocolVersionId); |
|||
return OperationResult<GetProtocolVersionByIdResponse>.CreateFailure($"未找到ID为 {request.ProtocolVersionId} 的协议版本"); |
|||
} |
|||
|
|||
var response = new GetProtocolVersionByIdResponse |
|||
{ |
|||
ProtocolVersionId = protocolVersion.Id, |
|||
Name = protocolVersion.Name, |
|||
Version = protocolVersion.Version, |
|||
Description = protocolVersion.Description, |
|||
IsEnabled = protocolVersion.IsEnabled, |
|||
ReleaseDate = protocolVersion.ReleaseDate, |
|||
IsForceUpdate = protocolVersion.IsForceUpdate, |
|||
MinimumSupportedVersion = protocolVersion.MinimumSupportedVersion, |
|||
CreatedAt = protocolVersion.CreatedAt, |
|||
UpdatedAt = protocolVersion.UpdatedAt |
|||
}; |
|||
|
|||
_logger.LogInformation("成功查询到协议版本,版本ID: {ProtocolVersionId}", request.ProtocolVersionId); |
|||
return OperationResult<GetProtocolVersionByIdResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "查询协议版本时发生错误,版本ID: {ProtocolVersionId}", request.ProtocolVersionId); |
|||
return OperationResult<GetProtocolVersionByIdResponse>.CreateFailure($"查询协议版本时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,57 @@ |
|||
namespace CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersionById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取协议版本响应
|
|||
/// </summary>
|
|||
public class GetProtocolVersionByIdResponse |
|||
{ |
|||
/// <summary>
|
|||
/// 协议版本ID
|
|||
/// </summary>
|
|||
public string ProtocolVersionId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 版本名称
|
|||
/// </summary>
|
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 版本号
|
|||
/// </summary>
|
|||
public string Version { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 版本描述
|
|||
/// </summary>
|
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否启用
|
|||
/// </summary>
|
|||
public bool IsEnabled { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 发布日期
|
|||
/// </summary>
|
|||
public DateTime? ReleaseDate { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否强制更新
|
|||
/// </summary>
|
|||
public bool IsForceUpdate { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 最低支持版本
|
|||
/// </summary>
|
|||
public string? MinimumSupportedVersion { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 创建时间
|
|||
/// </summary>
|
|||
public DateTime CreatedAt { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 更新时间
|
|||
/// </summary>
|
|||
public DateTime? UpdatedAt { get; set; } |
|||
} |
@ -0,0 +1,34 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersions; |
|||
|
|||
/// <summary>
|
|||
/// 获取协议版本列表查询
|
|||
/// </summary>
|
|||
public class GetProtocolVersionsQuery : IRequest<OperationResult<GetProtocolVersionsResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 页码
|
|||
/// </summary>
|
|||
[Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")] |
|||
public int PageNumber { get; set; } = 1; |
|||
|
|||
/// <summary>
|
|||
/// 每页数量
|
|||
/// </summary>
|
|||
[Range(1, 100, ErrorMessage = "每页数量必须在1-100之间")] |
|||
public int PageSize { get; set; } = 10; |
|||
|
|||
/// <summary>
|
|||
/// 搜索关键词
|
|||
/// </summary>
|
|||
[MaxLength(100)] |
|||
public string? SearchTerm { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否只获取启用的版本
|
|||
/// </summary>
|
|||
public bool? IsEnabled { get; set; } |
|||
} |
@ -0,0 +1,103 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Entities.Device; |
|||
using CellularManagement.Domain.Repositories; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using System.Linq; |
|||
using CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersionById; |
|||
using CellularManagement.Domain.Repositories.Device; |
|||
|
|||
namespace CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersions; |
|||
|
|||
/// <summary>
|
|||
/// 获取协议版本列表查询处理器
|
|||
/// </summary>
|
|||
public class GetProtocolVersionsQueryHandler : IRequestHandler<GetProtocolVersionsQuery, OperationResult<GetProtocolVersionsResponse>> |
|||
{ |
|||
private readonly IProtocolVersionRepository _protocolVersionRepository; |
|||
private readonly ILogger<GetProtocolVersionsQueryHandler> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 初始化查询处理器
|
|||
/// </summary>
|
|||
public GetProtocolVersionsQueryHandler( |
|||
IProtocolVersionRepository protocolVersionRepository, |
|||
ILogger<GetProtocolVersionsQueryHandler> logger) |
|||
{ |
|||
_protocolVersionRepository = protocolVersionRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理获取协议版本列表查询
|
|||
/// </summary>
|
|||
public async Task<OperationResult<GetProtocolVersionsResponse>> Handle(GetProtocolVersionsQuery request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
// 验证请求参数
|
|||
var validationContext = new ValidationContext(request); |
|||
var validationResults = new List<ValidationResult>(); |
|||
if (!Validator.TryValidateObject(request, validationContext, validationResults, true)) |
|||
{ |
|||
var errorMessages = validationResults.Select(r => r.ErrorMessage).ToList(); |
|||
_logger.LogWarning("请求参数无效: {Errors}", string.Join(", ", errorMessages)); |
|||
return OperationResult<GetProtocolVersionsResponse>.CreateFailure(errorMessages); |
|||
} |
|||
|
|||
_logger.LogInformation("开始获取协议版本列表,页码: {PageNumber}, 每页数量: {PageSize}, 搜索关键词: {SearchTerm}, 是否启用: {IsEnabled}", |
|||
request.PageNumber, request.PageSize, request.SearchTerm, request.IsEnabled); |
|||
|
|||
// 获取协议版本数据
|
|||
var protocolVersions = await _protocolVersionRepository.SearchProtocolVersionsAsync( |
|||
request.SearchTerm, |
|||
cancellationToken); |
|||
|
|||
// 如果指定了启用状态过滤
|
|||
if (request.IsEnabled.HasValue) |
|||
{ |
|||
protocolVersions = protocolVersions.Where(pv => pv.IsEnabled == request.IsEnabled.Value).ToList(); |
|||
} |
|||
|
|||
// 计算分页
|
|||
int totalCount = protocolVersions.Count(); |
|||
var items = protocolVersions |
|||
.Skip((request.PageNumber - 1) * request.PageSize) |
|||
.Take(request.PageSize) |
|||
.ToList(); |
|||
|
|||
// 构建响应
|
|||
var response = new GetProtocolVersionsResponse |
|||
{ |
|||
TotalCount = totalCount, |
|||
PageNumber = request.PageNumber, |
|||
PageSize = request.PageSize, |
|||
TotalPages = (int)Math.Ceiling(totalCount / (double)request.PageSize), |
|||
HasPreviousPage = request.PageNumber > 1, |
|||
HasNextPage = request.PageNumber < (int)Math.Ceiling(totalCount / (double)request.PageSize), |
|||
Items = items.Select(pv => new GetProtocolVersionByIdResponse |
|||
{ |
|||
ProtocolVersionId = pv.Id, |
|||
Name = pv.Name, |
|||
Version = pv.Version, |
|||
Description = pv.Description, |
|||
IsEnabled = pv.IsEnabled, |
|||
ReleaseDate = pv.ReleaseDate, |
|||
IsForceUpdate = pv.IsForceUpdate, |
|||
MinimumSupportedVersion = pv.MinimumSupportedVersion, |
|||
CreatedAt = pv.CreatedAt, |
|||
UpdatedAt = pv.UpdatedAt |
|||
}).ToList() |
|||
}; |
|||
|
|||
_logger.LogInformation("成功获取协议版本列表,共 {Count} 条记录", items.Count); |
|||
return OperationResult<GetProtocolVersionsResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "获取协议版本列表时发生错误"); |
|||
return OperationResult<GetProtocolVersionsResponse>.CreateFailure($"获取协议版本列表时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,44 @@ |
|||
using CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersionById; |
|||
|
|||
namespace CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersions; |
|||
|
|||
/// <summary>
|
|||
/// 获取协议版本列表响应
|
|||
/// </summary>
|
|||
public class GetProtocolVersionsResponse |
|||
{ |
|||
/// <summary>
|
|||
/// 总数量
|
|||
/// </summary>
|
|||
public int TotalCount { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 当前页码
|
|||
/// </summary>
|
|||
public int PageNumber { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 每页数量
|
|||
/// </summary>
|
|||
public int PageSize { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 总页数
|
|||
/// </summary>
|
|||
public int TotalPages { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否有上一页
|
|||
/// </summary>
|
|||
public bool HasPreviousPage { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否有下一页
|
|||
/// </summary>
|
|||
public bool HasNextPage { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 协议版本列表
|
|||
/// </summary>
|
|||
public List<GetProtocolVersionByIdResponse> Items { get; set; } = new(); |
|||
} |
@ -1,46 +0,0 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using CellularManagement.Domain.Entities.Common; |
|||
|
|||
namespace CellularManagement.Domain.Entities.Device; |
|||
|
|||
/// <summary>
|
|||
/// 设备状态实体
|
|||
/// </summary>
|
|||
public class DeviceStatus : AuditableEntity |
|||
{ |
|||
/// <summary>
|
|||
/// 状态名称
|
|||
/// </summary>
|
|||
[Required] |
|||
[MaxLength(50)] |
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 状态代码
|
|||
/// </summary>
|
|||
[Required] |
|||
[MaxLength(20)] |
|||
public string Code { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 状态描述
|
|||
/// </summary>
|
|||
[MaxLength(200)] |
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 状态颜色
|
|||
/// </summary>
|
|||
[MaxLength(20)] |
|||
public string? Color { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否启用
|
|||
/// </summary>
|
|||
public bool IsEnabled { get; set; } = true; |
|||
|
|||
/// <summary>
|
|||
/// 排序号
|
|||
/// </summary>
|
|||
public int SortOrder { get; set; } |
|||
} |
@ -1,40 +0,0 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using CellularManagement.Domain.Entities.Common; |
|||
|
|||
namespace CellularManagement.Domain.Entities.Device; |
|||
|
|||
/// <summary>
|
|||
/// 设备类型实体
|
|||
/// </summary>
|
|||
public class DeviceType : AuditableEntity |
|||
{ |
|||
/// <summary>
|
|||
/// 类型名称
|
|||
/// </summary>
|
|||
[Required] |
|||
[MaxLength(50)] |
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 类型代码
|
|||
/// </summary>
|
|||
[Required] |
|||
[MaxLength(20)] |
|||
public string Code { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 类型描述
|
|||
/// </summary>
|
|||
[MaxLength(200)] |
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否启用
|
|||
/// </summary>
|
|||
public bool IsEnabled { get; set; } = true; |
|||
|
|||
/// <summary>
|
|||
/// 排序号
|
|||
/// </summary>
|
|||
public int SortOrder { get; set; } |
|||
} |
@ -0,0 +1,63 @@ |
|||
using CellularManagement.Domain.Entities; |
|||
using CellularManagement.Domain.Entities.Device; |
|||
using CellularManagement.Domain.Repositories.Base; |
|||
|
|||
namespace CellularManagement.Domain.Repositories.Device; |
|||
|
|||
/// <summary>
|
|||
/// 协议版本仓储接口
|
|||
/// </summary>
|
|||
public interface IProtocolVersionRepository : IBaseRepository<ProtocolVersion> |
|||
{ |
|||
/// <summary>
|
|||
/// 添加协议版本
|
|||
/// </summary>
|
|||
Task<ProtocolVersion> AddProtocolVersionAsync(ProtocolVersion protocolVersion, CancellationToken cancellationToken = default); |
|||
|
|||
/// <summary>
|
|||
/// 更新协议版本
|
|||
/// </summary>
|
|||
void UpdateProtocolVersion(ProtocolVersion protocolVersion); |
|||
|
|||
/// <summary>
|
|||
/// 删除协议版本
|
|||
/// </summary>
|
|||
Task DeleteProtocolVersionAsync(string id, CancellationToken cancellationToken = default); |
|||
|
|||
/// <summary>
|
|||
/// 获取所有协议版本
|
|||
/// </summary>
|
|||
Task<IList<ProtocolVersion>> GetAllProtocolVersionsAsync(CancellationToken cancellationToken = default); |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取协议版本
|
|||
/// </summary>
|
|||
Task<ProtocolVersion?> GetProtocolVersionByIdAsync(string id, CancellationToken cancellationToken = default); |
|||
|
|||
/// <summary>
|
|||
/// 根据版本号获取协议版本
|
|||
/// </summary>
|
|||
Task<ProtocolVersion?> GetProtocolVersionByVersionAsync(string version, CancellationToken cancellationToken = default); |
|||
|
|||
/// <summary>
|
|||
/// 搜索协议版本
|
|||
/// </summary>
|
|||
Task<IList<ProtocolVersion>> SearchProtocolVersionsAsync( |
|||
string? keyword, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
/// <summary>
|
|||
/// 检查协议版本是否存在
|
|||
/// </summary>
|
|||
Task<bool> ExistsAsync(string id, CancellationToken cancellationToken = default); |
|||
|
|||
/// <summary>
|
|||
/// 检查版本号是否存在
|
|||
/// </summary>
|
|||
Task<bool> VersionExistsAsync(string version, CancellationToken cancellationToken = default); |
|||
|
|||
/// <summary>
|
|||
/// 获取启用的协议版本
|
|||
/// </summary>
|
|||
Task<IList<ProtocolVersion>> GetEnabledProtocolVersionsAsync(CancellationToken cancellationToken = default); |
|||
} |
@ -1,21 +0,0 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
|||
using CellularManagement.Domain.Entities.Device; |
|||
|
|||
namespace CellularManagement.Infrastructure.Configurations.Device; |
|||
|
|||
public class DeviceStatusConfiguration : IEntityTypeConfiguration<DeviceStatus> |
|||
{ |
|||
public void Configure(EntityTypeBuilder<DeviceStatus> builder) |
|||
{ |
|||
builder.ToTable("DeviceStatuses", t => t.HasComment("设备状态表")); |
|||
builder.HasKey(s => s.Id); |
|||
|
|||
// 配置属性
|
|||
builder.Property(s => s.Id).HasComment("状态ID"); |
|||
builder.Property(s => s.Name).IsRequired().HasMaxLength(50).HasComment("状态名称"); |
|||
builder.Property(s => s.Description).HasMaxLength(200).HasComment("状态描述"); |
|||
builder.Property(s => s.CreatedAt).IsRequired().HasComment("创建时间"); |
|||
builder.Property(s => s.UpdatedAt).IsRequired().HasComment("更新时间"); |
|||
} |
|||
} |
@ -1,21 +0,0 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
|||
using CellularManagement.Domain.Entities.Device; |
|||
|
|||
namespace CellularManagement.Infrastructure.Configurations.Device; |
|||
|
|||
public class DeviceTypeConfiguration : IEntityTypeConfiguration<DeviceType> |
|||
{ |
|||
public void Configure(EntityTypeBuilder<DeviceType> builder) |
|||
{ |
|||
builder.ToTable("DeviceTypes", t => t.HasComment("设备类型表")); |
|||
builder.HasKey(t => t.Id); |
|||
|
|||
// 配置属性
|
|||
builder.Property(t => t.Id).HasComment("类型ID"); |
|||
builder.Property(t => t.Name).IsRequired().HasMaxLength(50).HasComment("类型名称"); |
|||
builder.Property(t => t.Description).HasMaxLength(200).HasComment("类型描述"); |
|||
builder.Property(t => t.CreatedAt).IsRequired().HasComment("创建时间"); |
|||
builder.Property(t => t.UpdatedAt).IsRequired().HasComment("更新时间"); |
|||
} |
|||
} |
@ -0,0 +1,129 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using System.Linq; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Entities; |
|||
using CellularManagement.Domain.Repositories; |
|||
using CellularManagement.Infrastructure.Repositories.Base; |
|||
using CellularManagement.Domain.Entities.Device; |
|||
using CellularManagement.Domain.Repositories.Base; |
|||
using CellularManagement.Domain.Repositories.Device; |
|||
|
|||
namespace CellularManagement.Infrastructure.Repositories.Device; |
|||
|
|||
/// <summary>
|
|||
/// 协议版本仓储实现类
|
|||
/// </summary>
|
|||
public class ProtocolVersionRepository : BaseRepository<ProtocolVersion>, IProtocolVersionRepository |
|||
{ |
|||
private readonly ILogger<ProtocolVersionRepository> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 初始化仓储
|
|||
/// </summary>
|
|||
public ProtocolVersionRepository( |
|||
ICommandRepository<ProtocolVersion> commandRepository, |
|||
IQueryRepository<ProtocolVersion> queryRepository, |
|||
ILogger<ProtocolVersionRepository> logger) |
|||
: base(commandRepository, queryRepository, logger) |
|||
{ |
|||
_logger = logger; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 添加协议版本
|
|||
/// </summary>
|
|||
public async Task<ProtocolVersion> AddProtocolVersionAsync(ProtocolVersion protocolVersion, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await CommandRepository.AddAsync(protocolVersion, cancellationToken); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 更新协议版本
|
|||
/// </summary>
|
|||
public void UpdateProtocolVersion(ProtocolVersion protocolVersion) |
|||
{ |
|||
CommandRepository.Update(protocolVersion); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 删除协议版本
|
|||
/// </summary>
|
|||
public async Task DeleteProtocolVersionAsync(string id, CancellationToken cancellationToken = default) |
|||
{ |
|||
await CommandRepository.DeleteByIdAsync(id, cancellationToken); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取所有协议版本
|
|||
/// </summary>
|
|||
public async Task<IList<ProtocolVersion>> GetAllProtocolVersionsAsync(CancellationToken cancellationToken = default) |
|||
{ |
|||
var protocolVersions = await QueryRepository.GetAllAsync(cancellationToken); |
|||
return protocolVersions.ToList(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取协议版本
|
|||
/// </summary>
|
|||
public async Task<ProtocolVersion?> GetProtocolVersionByIdAsync(string id, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await QueryRepository.GetByIdAsync(id, cancellationToken); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 根据版本号获取协议版本
|
|||
/// </summary>
|
|||
public async Task<ProtocolVersion?> GetProtocolVersionByVersionAsync(string version, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await QueryRepository.FirstOrDefaultAsync(pv => pv.Version == version, cancellationToken); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 搜索协议版本
|
|||
/// </summary>
|
|||
public async Task<IList<ProtocolVersion>> SearchProtocolVersionsAsync( |
|||
string? keyword, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var query = await QueryRepository.FindAsync(pv => true, cancellationToken); |
|||
|
|||
if (!string.IsNullOrWhiteSpace(keyword)) |
|||
{ |
|||
query = query.Where(pv => |
|||
pv.Name.Contains(keyword) || |
|||
pv.Version.Contains(keyword) || |
|||
pv.Description.Contains(keyword)); |
|||
} |
|||
|
|||
var protocolVersions = query; |
|||
return protocolVersions.ToList(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 检查协议版本是否存在
|
|||
/// </summary>
|
|||
public async Task<bool> ExistsAsync(string id, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await QueryRepository.AnyAsync(pv => pv.Id == id, cancellationToken); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 检查版本号是否存在
|
|||
/// </summary>
|
|||
public async Task<bool> VersionExistsAsync(string version, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await QueryRepository.AnyAsync(pv => pv.Version == version, cancellationToken); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取启用的协议版本
|
|||
/// </summary>
|
|||
public async Task<IList<ProtocolVersion>> GetEnabledProtocolVersionsAsync(CancellationToken cancellationToken = default) |
|||
{ |
|||
var protocolVersions = await QueryRepository.FindAsync(pv => pv.IsEnabled, cancellationToken); |
|||
return protocolVersions.ToList(); |
|||
} |
|||
} |
@ -0,0 +1,135 @@ |
|||
using CellularManagement.Application.Features.ProtocolVersions.Commands.CreateProtocolVersion; |
|||
using CellularManagement.Application.Features.ProtocolVersions.Commands.DeleteProtocolVersion; |
|||
using CellularManagement.Application.Features.ProtocolVersions.Commands.UpdateProtocolVersion; |
|||
using CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersionById; |
|||
using CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersions; |
|||
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>
|
|||
/// 协议版本管理控制器
|
|||
/// </summary>
|
|||
[Route("api/protocolversions")] |
|||
[ApiController] |
|||
[Authorize] |
|||
public class ProtocolVersionsController : ApiController |
|||
{ |
|||
private readonly ILogger<ProtocolVersionsController> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 初始化协议版本控制器
|
|||
/// </summary>
|
|||
public ProtocolVersionsController(IMediator mediator, ILogger<ProtocolVersionsController> logger) |
|||
: base(mediator) |
|||
{ |
|||
_logger = logger; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取协议版本列表
|
|||
/// </summary>
|
|||
[HttpGet] |
|||
public async Task<OperationResult<GetProtocolVersionsResponse>> GetAll([FromQuery] GetProtocolVersionsQuery query) |
|||
{ |
|||
_logger.LogInformation("开始获取协议版本列表,页码: {PageNumber}, 每页数量: {PageSize}, 搜索关键词: {SearchTerm}, 是否启用: {IsEnabled}", |
|||
query.PageNumber, query.PageSize, query.SearchTerm, query.IsEnabled); |
|||
|
|||
var result = await mediator.Send(query); |
|||
if (!result.IsSuccess) |
|||
{ |
|||
_logger.LogWarning("获取协议版本列表失败: {Message}", result.ErrorMessages); |
|||
return result; |
|||
} |
|||
|
|||
_logger.LogInformation("成功获取协议版本列表,共 {Count} 条记录", result.Data?.TotalCount ?? 0); |
|||
return result; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取协议版本详情
|
|||
/// </summary>
|
|||
[HttpGet("{id}")] |
|||
public async Task<OperationResult<GetProtocolVersionByIdResponse>> GetById(string id) |
|||
{ |
|||
_logger.LogInformation("开始获取协议版本详情,版本ID: {ProtocolVersionId}", id); |
|||
|
|||
var result = await mediator.Send(new GetProtocolVersionByIdQuery { ProtocolVersionId = id }); |
|||
if (!result.IsSuccess) |
|||
{ |
|||
_logger.LogWarning("获取协议版本详情失败: {Message}", result.ErrorMessages); |
|||
return result; |
|||
} |
|||
|
|||
_logger.LogInformation("成功获取协议版本详情,版本ID: {ProtocolVersionId}", id); |
|||
return result; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 创建协议版本
|
|||
/// </summary>
|
|||
[HttpPost] |
|||
public async Task<OperationResult<CreateProtocolVersionResponse>> Create([FromBody] CreateProtocolVersionCommand command) |
|||
{ |
|||
_logger.LogInformation("开始创建协议版本,版本名称: {Name}, 版本号: {Version}", command.Name, command.Version); |
|||
|
|||
var result = await mediator.Send(command); |
|||
if (!result.IsSuccess) |
|||
{ |
|||
_logger.LogWarning("创建协议版本失败: {Message}", result.ErrorMessages); |
|||
return result; |
|||
} |
|||
|
|||
_logger.LogInformation("成功创建协议版本,版本ID: {ProtocolVersionId}", result.Data.ProtocolVersionId); |
|||
return result; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 更新协议版本
|
|||
/// </summary>
|
|||
[HttpPut("{id}")] |
|||
public async Task<OperationResult<UpdateProtocolVersionResponse>> Update(string id, [FromBody] UpdateProtocolVersionCommand command) |
|||
{ |
|||
_logger.LogInformation("开始更新协议版本,版本ID: {ProtocolVersionId}", id); |
|||
|
|||
if (id != command.ProtocolVersionId) |
|||
{ |
|||
_logger.LogWarning("协议版本ID不匹配,路径ID: {PathId}, 命令ID: {CommandId}", id, command.ProtocolVersionId); |
|||
return OperationResult<UpdateProtocolVersionResponse>.CreateFailure("协议版本ID不匹配"); |
|||
} |
|||
|
|||
var result = await mediator.Send(command); |
|||
if (!result.IsSuccess) |
|||
{ |
|||
_logger.LogWarning("更新协议版本失败: {Message}", result.ErrorMessages); |
|||
return result; |
|||
} |
|||
|
|||
_logger.LogInformation("成功更新协议版本,版本ID: {ProtocolVersionId}", id); |
|||
return result; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 删除协议版本
|
|||
/// </summary>
|
|||
[HttpDelete("{id}")] |
|||
public async Task<OperationResult<bool>> Delete(string id) |
|||
{ |
|||
_logger.LogInformation("开始删除协议版本,版本ID: {ProtocolVersionId}", id); |
|||
|
|||
var result = await mediator.Send(new DeleteProtocolVersionCommand { ProtocolVersionId = id }); |
|||
if (!result.IsSuccess) |
|||
{ |
|||
_logger.LogWarning("删除协议版本失败: {Message}", result.ErrorMessages); |
|||
return result; |
|||
} |
|||
|
|||
_logger.LogInformation("成功删除协议版本,版本ID: {ProtocolVersionId}", id); |
|||
return result; |
|||
} |
|||
} |
@ -0,0 +1,73 @@ |
|||
### 协议版本 CRUD API 测试 |
|||
|
|||
### 1. 创建协议版本 |
|||
POST {{baseUrl}}/api/protocolversions |
|||
Content-Type: application/json |
|||
Authorization: Bearer {{token}} |
|||
|
|||
{ |
|||
"name": "HTTP/1.1", |
|||
"version": "1.1.0", |
|||
"description": "HTTP协议1.1版本", |
|||
"isEnabled": true, |
|||
"releaseDate": "1997-01-01T00:00:00Z", |
|||
"isForceUpdate": false, |
|||
"minimumSupportedVersion": "1.0.0" |
|||
} |
|||
|
|||
### 2. 创建另一个协议版本 |
|||
POST {{baseUrl}}/api/protocolversions |
|||
Content-Type: application/json |
|||
Authorization: Bearer {{token}} |
|||
|
|||
{ |
|||
"name": "HTTP/2.0", |
|||
"version": "2.0.0", |
|||
"description": "HTTP协议2.0版本", |
|||
"isEnabled": true, |
|||
"releaseDate": "2015-05-14T00:00:00Z", |
|||
"isForceUpdate": true, |
|||
"minimumSupportedVersion": "1.1.0" |
|||
} |
|||
|
|||
### 3. 获取协议版本列表 |
|||
GET {{baseUrl}}/api/protocolversions?pageNumber=1&pageSize=10 |
|||
Authorization: Bearer {{token}} |
|||
|
|||
### 4. 搜索协议版本 |
|||
GET {{baseUrl}}/api/protocolversions?searchTerm=HTTP&pageNumber=1&pageSize=10 |
|||
Authorization: Bearer {{token}} |
|||
|
|||
### 5. 获取启用的协议版本 |
|||
GET {{baseUrl}}/api/protocolversions?isEnabled=true&pageNumber=1&pageSize=10 |
|||
Authorization: Bearer {{token}} |
|||
|
|||
### 6. 根据ID获取协议版本 |
|||
GET {{baseUrl}}/api/protocolversions/{{protocolVersionId}} |
|||
Authorization: Bearer {{token}} |
|||
|
|||
### 7. 更新协议版本 |
|||
PUT {{baseUrl}}/api/protocolversions/{{protocolVersionId}} |
|||
Content-Type: application/json |
|||
Authorization: Bearer {{token}} |
|||
|
|||
{ |
|||
"protocolVersionId": "{{protocolVersionId}}", |
|||
"name": "HTTP/1.1 Updated", |
|||
"version": "1.1.1", |
|||
"description": "HTTP协议1.1版本(已更新)", |
|||
"isEnabled": true, |
|||
"releaseDate": "1997-01-01T00:00:00Z", |
|||
"isForceUpdate": true, |
|||
"minimumSupportedVersion": "1.0.0" |
|||
} |
|||
|
|||
### 8. 删除协议版本 |
|||
DELETE {{baseUrl}}/api/protocolversions/{{protocolVersionId}} |
|||
Authorization: Bearer {{token}} |
|||
|
|||
### 环境变量设置 |
|||
# 在 VS Code 的 REST Client 扩展中设置以下变量: |
|||
# baseUrl: http://localhost:5000 |
|||
# token: 你的JWT令牌 |
|||
# protocolVersionId: 从创建响应中获取的协议版本ID |
Loading…
Reference in new issue