Browse Source
- 重构 NetworkConfigs 为 CoreNetworkConfigs,避免命名冲突 - 新增 IMSConfiguration Features 实现 - 新增 NetworkStackConfigs Features 实现 - 新增 StackCoreIMSBindings Features 实现 - 新增 RANConfiguration Features 实现 - 创建对应的控制器:CoreNetworkConfigsController, IMSConfigurationController, NetworkStackConfigsController, StackCoreIMSBindingsController, RANConfigurationController - 更新数据库上下文和依赖注入配置 - 添加完整的仓储接口和实现 - 添加 EF Core 配置类 - 修复 Devices Features 中的命名问题feature/x1-web-request
141 changed files with 6838 additions and 2002 deletions
@ -0,0 +1,35 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.CoreNetworkConfigs.Commands.CreateCoreNetworkConfig; |
|||
|
|||
/// <summary>
|
|||
/// 创建核心网配置命令
|
|||
/// </summary>
|
|||
public class CreateCoreNetworkConfigCommand : IRequest<OperationResult<CreateCoreNetworkConfigResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "配置名称不能为空")] |
|||
[MaxLength(100, ErrorMessage = "配置名称不能超过100个字符")] |
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置内容(JSON格式)
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "配置内容不能为空")] |
|||
public string ConfigContent { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置描述
|
|||
/// </summary>
|
|||
[MaxLength(500, ErrorMessage = "配置描述不能超过500个字符")] |
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否禁用
|
|||
/// </summary>
|
|||
public bool IsDisabled { get; set; } = false; |
|||
} |
@ -0,0 +1,95 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories.Base; |
|||
using CellularManagement.Domain.Services; |
|||
using CellularManagement.Domain.Entities.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.CoreNetworkConfigs.Commands.CreateCoreNetworkConfig; |
|||
|
|||
/// <summary>
|
|||
/// 创建核心网配置命令处理器
|
|||
/// </summary>
|
|||
public class CreateCoreNetworkConfigCommandHandler : IRequestHandler<CreateCoreNetworkConfigCommand, OperationResult<CreateCoreNetworkConfigResponse>> |
|||
{ |
|||
private readonly ICoreNetworkConfigRepository _coreNetworkConfigRepository; |
|||
private readonly ILogger<CreateCoreNetworkConfigCommandHandler> _logger; |
|||
private readonly IUnitOfWork _unitOfWork; |
|||
private readonly ICurrentUserService _currentUserService; |
|||
|
|||
/// <summary>
|
|||
/// 初始化命令处理器
|
|||
/// </summary>
|
|||
public CreateCoreNetworkConfigCommandHandler( |
|||
ICoreNetworkConfigRepository coreNetworkConfigRepository, |
|||
ILogger<CreateCoreNetworkConfigCommandHandler> logger, |
|||
IUnitOfWork unitOfWork, |
|||
ICurrentUserService currentUserService) |
|||
{ |
|||
_coreNetworkConfigRepository = coreNetworkConfigRepository; |
|||
_logger = logger; |
|||
_unitOfWork = unitOfWork; |
|||
_currentUserService = currentUserService; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理创建核心网配置命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<CreateCoreNetworkConfigResponse>> Handle(CreateCoreNetworkConfigCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始创建核心网配置,配置名称: {Name}", request.Name); |
|||
|
|||
// 检查配置名称是否已存在
|
|||
if (await _coreNetworkConfigRepository.NameExistsAsync(request.Name, cancellationToken)) |
|||
{ |
|||
_logger.LogWarning("核心网配置名称已存在: {Name}", request.Name); |
|||
return OperationResult<CreateCoreNetworkConfigResponse>.CreateFailure($"核心网配置名称 {request.Name} 已存在"); |
|||
} |
|||
|
|||
// 获取当前用户ID
|
|||
var currentUserId = _currentUserService.GetCurrentUserId(); |
|||
if (string.IsNullOrEmpty(currentUserId)) |
|||
{ |
|||
_logger.LogError("无法获取当前用户ID,用户可能未认证"); |
|||
return OperationResult<CreateCoreNetworkConfigResponse>.CreateFailure("用户未认证,无法创建核心网配置"); |
|||
} |
|||
|
|||
// 创建核心网配置实体
|
|||
var coreNetworkConfig = CoreNetworkConfig.Create( |
|||
name: request.Name, |
|||
configContent: request.ConfigContent, |
|||
createdBy: currentUserId, |
|||
description: request.Description, |
|||
isDisabled: request.IsDisabled); |
|||
|
|||
// 保存核心网配置
|
|||
await _coreNetworkConfigRepository.AddCoreNetworkConfigAsync(coreNetworkConfig, cancellationToken); |
|||
|
|||
// 保存更改到数据库
|
|||
await _unitOfWork.SaveChangesAsync(cancellationToken); |
|||
|
|||
// 构建响应
|
|||
var response = new CreateCoreNetworkConfigResponse |
|||
{ |
|||
CoreNetworkConfigId = coreNetworkConfig.Id, |
|||
Name = coreNetworkConfig.Name, |
|||
ConfigContent = coreNetworkConfig.ConfigContent, |
|||
Description = coreNetworkConfig.Description, |
|||
IsDisabled = coreNetworkConfig.IsDisabled, |
|||
CreatedAt = coreNetworkConfig.CreatedAt |
|||
}; |
|||
|
|||
_logger.LogInformation("核心网配置创建成功,配置ID: {CoreNetworkConfigId}, 配置名称: {Name}", |
|||
coreNetworkConfig.Id, coreNetworkConfig.Name); |
|||
return OperationResult<CreateCoreNetworkConfigResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "创建核心网配置时发生错误,配置名称: {Name}", request.Name); |
|||
return OperationResult<CreateCoreNetworkConfigResponse>.CreateFailure($"创建核心网配置时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
namespace CellularManagement.Application.Features.CoreNetworkConfigs.Commands.CreateCoreNetworkConfig; |
|||
|
|||
/// <summary>
|
|||
/// 创建核心网配置响应
|
|||
/// </summary>
|
|||
public class CreateCoreNetworkConfigResponse |
|||
{ |
|||
/// <summary>
|
|||
/// 核心网配置ID
|
|||
/// </summary>
|
|||
public string CoreNetworkConfigId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置内容(JSON格式)
|
|||
/// </summary>
|
|||
public string ConfigContent { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置描述
|
|||
/// </summary>
|
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否禁用
|
|||
/// </summary>
|
|||
public bool IsDisabled { 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.CoreNetworkConfigs.Commands.DeleteCoreNetworkConfig; |
|||
|
|||
/// <summary>
|
|||
/// 删除核心网配置命令
|
|||
/// </summary>
|
|||
public class DeleteCoreNetworkConfigCommand : IRequest<OperationResult<bool>> |
|||
{ |
|||
/// <summary>
|
|||
/// 核心网配置ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string CoreNetworkConfigId { get; set; } = null!; |
|||
} |
@ -0,0 +1,64 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories.Base; |
|||
|
|||
namespace CellularManagement.Application.Features.CoreNetworkConfigs.Commands.DeleteCoreNetworkConfig; |
|||
|
|||
/// <summary>
|
|||
/// 删除核心网配置命令处理器
|
|||
/// </summary>
|
|||
public class DeleteCoreNetworkConfigCommandHandler : IRequestHandler<DeleteCoreNetworkConfigCommand, OperationResult<bool>> |
|||
{ |
|||
private readonly ICoreNetworkConfigRepository _coreNetworkConfigRepository; |
|||
private readonly ILogger<DeleteCoreNetworkConfigCommandHandler> _logger; |
|||
private readonly IUnitOfWork _unitOfWork; |
|||
|
|||
/// <summary>
|
|||
/// 初始化命令处理器
|
|||
/// </summary>
|
|||
public DeleteCoreNetworkConfigCommandHandler( |
|||
ICoreNetworkConfigRepository coreNetworkConfigRepository, |
|||
ILogger<DeleteCoreNetworkConfigCommandHandler> logger, |
|||
IUnitOfWork unitOfWork) |
|||
{ |
|||
_coreNetworkConfigRepository = coreNetworkConfigRepository; |
|||
_logger = logger; |
|||
_unitOfWork = unitOfWork; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理删除核心网配置命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<bool>> Handle(DeleteCoreNetworkConfigCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始删除核心网配置,配置ID: {CoreNetworkConfigId}", request.CoreNetworkConfigId); |
|||
|
|||
// 检查核心网配置是否存在
|
|||
var existingConfig = await _coreNetworkConfigRepository.GetCoreNetworkConfigByIdAsync(request.CoreNetworkConfigId, cancellationToken); |
|||
if (existingConfig == null) |
|||
{ |
|||
_logger.LogWarning("核心网配置不存在: {CoreNetworkConfigId}", request.CoreNetworkConfigId); |
|||
return OperationResult<bool>.CreateFailure($"核心网配置 {request.CoreNetworkConfigId} 不存在"); |
|||
} |
|||
|
|||
// 删除核心网配置
|
|||
await _coreNetworkConfigRepository.DeleteCoreNetworkConfigAsync(request.CoreNetworkConfigId, cancellationToken); |
|||
|
|||
// 保存更改到数据库
|
|||
await _unitOfWork.SaveChangesAsync(cancellationToken); |
|||
|
|||
_logger.LogInformation("核心网配置删除成功,配置ID: {CoreNetworkConfigId}, 配置名称: {Name}", |
|||
request.CoreNetworkConfigId, existingConfig.Name); |
|||
return OperationResult<bool>.CreateSuccess(true); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "删除核心网配置时发生错误,配置ID: {CoreNetworkConfigId}", request.CoreNetworkConfigId); |
|||
return OperationResult<bool>.CreateFailure($"删除核心网配置时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,41 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.CoreNetworkConfigs.Commands.UpdateCoreNetworkConfig; |
|||
|
|||
/// <summary>
|
|||
/// 更新核心网配置命令
|
|||
/// </summary>
|
|||
public class UpdateCoreNetworkConfigCommand : IRequest<OperationResult<UpdateCoreNetworkConfigResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 核心网配置ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string CoreNetworkConfigId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "配置名称不能为空")] |
|||
[MaxLength(100, ErrorMessage = "配置名称不能超过100个字符")] |
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置内容(JSON格式)
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "配置内容不能为空")] |
|||
public string ConfigContent { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置描述
|
|||
/// </summary>
|
|||
[MaxLength(500, ErrorMessage = "配置描述不能超过500个字符")] |
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否禁用
|
|||
/// </summary>
|
|||
public bool IsDisabled { get; set; } = false; |
|||
} |
@ -0,0 +1,102 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories.Base; |
|||
using CellularManagement.Domain.Services; |
|||
using CellularManagement.Domain.Entities.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.CoreNetworkConfigs.Commands.UpdateCoreNetworkConfig; |
|||
|
|||
/// <summary>
|
|||
/// 更新核心网配置命令处理器
|
|||
/// </summary>
|
|||
public class UpdateCoreNetworkConfigCommandHandler : IRequestHandler<UpdateCoreNetworkConfigCommand, OperationResult<UpdateCoreNetworkConfigResponse>> |
|||
{ |
|||
private readonly ICoreNetworkConfigRepository _coreNetworkConfigRepository; |
|||
private readonly ILogger<UpdateCoreNetworkConfigCommandHandler> _logger; |
|||
private readonly IUnitOfWork _unitOfWork; |
|||
private readonly ICurrentUserService _currentUserService; |
|||
|
|||
/// <summary>
|
|||
/// 初始化命令处理器
|
|||
/// </summary>
|
|||
public UpdateCoreNetworkConfigCommandHandler( |
|||
ICoreNetworkConfigRepository coreNetworkConfigRepository, |
|||
ILogger<UpdateCoreNetworkConfigCommandHandler> logger, |
|||
IUnitOfWork unitOfWork, |
|||
ICurrentUserService currentUserService) |
|||
{ |
|||
_coreNetworkConfigRepository = coreNetworkConfigRepository; |
|||
_logger = logger; |
|||
_unitOfWork = unitOfWork; |
|||
_currentUserService = currentUserService; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理更新核心网配置命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<UpdateCoreNetworkConfigResponse>> Handle(UpdateCoreNetworkConfigCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始更新核心网配置,配置ID: {CoreNetworkConfigId}", request.CoreNetworkConfigId); |
|||
|
|||
// 检查核心网配置是否存在
|
|||
var existingConfig = await _coreNetworkConfigRepository.GetCoreNetworkConfigByIdAsync(request.CoreNetworkConfigId, cancellationToken); |
|||
if (existingConfig == null) |
|||
{ |
|||
_logger.LogWarning("核心网配置不存在: {CoreNetworkConfigId}", request.CoreNetworkConfigId); |
|||
return OperationResult<UpdateCoreNetworkConfigResponse>.CreateFailure($"核心网配置 {request.CoreNetworkConfigId} 不存在"); |
|||
} |
|||
|
|||
// 检查新名称是否与其他配置冲突
|
|||
var configWithSameName = await _coreNetworkConfigRepository.GetCoreNetworkConfigByNameAsync(request.Name, cancellationToken); |
|||
if (configWithSameName != null && configWithSameName.Id != request.CoreNetworkConfigId) |
|||
{ |
|||
_logger.LogWarning("核心网配置名称已存在: {Name}", request.Name); |
|||
return OperationResult<UpdateCoreNetworkConfigResponse>.CreateFailure($"核心网配置名称 {request.Name} 已存在"); |
|||
} |
|||
|
|||
// 获取当前用户ID
|
|||
var currentUserId = _currentUserService.GetCurrentUserId(); |
|||
if (string.IsNullOrEmpty(currentUserId)) |
|||
{ |
|||
_logger.LogError("无法获取当前用户ID,用户可能未认证"); |
|||
return OperationResult<UpdateCoreNetworkConfigResponse>.CreateFailure("用户未认证,无法更新核心网配置"); |
|||
} |
|||
|
|||
// 更新核心网配置
|
|||
existingConfig.Update( |
|||
name: request.Name, |
|||
configContent: request.ConfigContent, |
|||
updatedBy: currentUserId, |
|||
description: request.Description, |
|||
isDisabled: request.IsDisabled); |
|||
|
|||
// 保存更改
|
|||
_coreNetworkConfigRepository.UpdateCoreNetworkConfig(existingConfig); |
|||
await _unitOfWork.SaveChangesAsync(cancellationToken); |
|||
|
|||
// 构建响应
|
|||
var response = new UpdateCoreNetworkConfigResponse |
|||
{ |
|||
CoreNetworkConfigId = existingConfig.Id, |
|||
Name = existingConfig.Name, |
|||
ConfigContent = existingConfig.ConfigContent, |
|||
Description = existingConfig.Description, |
|||
IsDisabled = existingConfig.IsDisabled, |
|||
UpdatedAt = existingConfig.UpdatedAt |
|||
}; |
|||
|
|||
_logger.LogInformation("核心网配置更新成功,配置ID: {CoreNetworkConfigId}, 配置名称: {Name}", |
|||
existingConfig.Id, existingConfig.Name); |
|||
return OperationResult<UpdateCoreNetworkConfigResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "更新核心网配置时发生错误,配置ID: {CoreNetworkConfigId}", request.CoreNetworkConfigId); |
|||
return OperationResult<UpdateCoreNetworkConfigResponse>.CreateFailure($"更新核心网配置时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
namespace CellularManagement.Application.Features.CoreNetworkConfigs.Commands.UpdateCoreNetworkConfig; |
|||
|
|||
/// <summary>
|
|||
/// 更新核心网配置响应
|
|||
/// </summary>
|
|||
public class UpdateCoreNetworkConfigResponse |
|||
{ |
|||
/// <summary>
|
|||
/// 核心网配置ID
|
|||
/// </summary>
|
|||
public string CoreNetworkConfigId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置内容(JSON格式)
|
|||
/// </summary>
|
|||
public string ConfigContent { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置描述
|
|||
/// </summary>
|
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否禁用
|
|||
/// </summary>
|
|||
public bool IsDisabled { 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.CoreNetworkConfigs.Queries.GetCoreNetworkConfigById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取核心网配置查询
|
|||
/// </summary>
|
|||
public class GetCoreNetworkConfigByIdQuery : IRequest<OperationResult<GetCoreNetworkConfigByIdResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 核心网配置ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string CoreNetworkConfigId { get; set; } = null!; |
|||
} |
@ -0,0 +1,68 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.CoreNetworkConfigs.Queries.GetCoreNetworkConfigById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取核心网配置查询处理器
|
|||
/// </summary>
|
|||
public class GetCoreNetworkConfigByIdQueryHandler : IRequestHandler<GetCoreNetworkConfigByIdQuery, OperationResult<GetCoreNetworkConfigByIdResponse>> |
|||
{ |
|||
private readonly ICoreNetworkConfigRepository _coreNetworkConfigRepository; |
|||
private readonly ILogger<GetCoreNetworkConfigByIdQueryHandler> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 初始化查询处理器
|
|||
/// </summary>
|
|||
public GetCoreNetworkConfigByIdQueryHandler( |
|||
ICoreNetworkConfigRepository coreNetworkConfigRepository, |
|||
ILogger<GetCoreNetworkConfigByIdQueryHandler> logger) |
|||
{ |
|||
_coreNetworkConfigRepository = coreNetworkConfigRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理根据ID获取核心网配置查询
|
|||
/// </summary>
|
|||
public async Task<OperationResult<GetCoreNetworkConfigByIdResponse>> Handle(GetCoreNetworkConfigByIdQuery request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始获取核心网配置,配置ID: {CoreNetworkConfigId}", request.CoreNetworkConfigId); |
|||
|
|||
// 获取核心网配置
|
|||
var coreNetworkConfig = await _coreNetworkConfigRepository.GetCoreNetworkConfigByIdAsync(request.CoreNetworkConfigId, cancellationToken); |
|||
if (coreNetworkConfig == null) |
|||
{ |
|||
_logger.LogWarning("核心网配置不存在: {CoreNetworkConfigId}", request.CoreNetworkConfigId); |
|||
return OperationResult<GetCoreNetworkConfigByIdResponse>.CreateFailure($"核心网配置 {request.CoreNetworkConfigId} 不存在"); |
|||
} |
|||
|
|||
// 构建响应
|
|||
var response = new GetCoreNetworkConfigByIdResponse |
|||
{ |
|||
CoreNetworkConfigId = coreNetworkConfig.Id, |
|||
Name = coreNetworkConfig.Name, |
|||
ConfigContent = coreNetworkConfig.ConfigContent, |
|||
Description = coreNetworkConfig.Description, |
|||
IsDisabled = coreNetworkConfig.IsDisabled, |
|||
CreatedAt = coreNetworkConfig.CreatedAt, |
|||
UpdatedAt = coreNetworkConfig.UpdatedAt, |
|||
CreatedBy = coreNetworkConfig.CreatedBy, |
|||
UpdatedBy = coreNetworkConfig.UpdatedBy |
|||
}; |
|||
|
|||
_logger.LogInformation("成功获取核心网配置,配置ID: {CoreNetworkConfigId}, 配置名称: {Name}", |
|||
coreNetworkConfig.Id, coreNetworkConfig.Name); |
|||
return OperationResult<GetCoreNetworkConfigByIdResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "获取核心网配置时发生错误,配置ID: {CoreNetworkConfigId}", request.CoreNetworkConfigId); |
|||
return OperationResult<GetCoreNetworkConfigByIdResponse>.CreateFailure($"获取核心网配置时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,34 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.CoreNetworkConfigs.Queries.GetCoreNetworkConfigs; |
|||
|
|||
/// <summary>
|
|||
/// 获取核心网配置列表查询
|
|||
/// </summary>
|
|||
public class GetCoreNetworkConfigsQuery : IRequest<OperationResult<GetCoreNetworkConfigsResponse>> |
|||
{ |
|||
/// <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? IsDisabled { get; set; } |
|||
} |
@ -0,0 +1,78 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.CoreNetworkConfigs.Queries.GetCoreNetworkConfigs; |
|||
|
|||
/// <summary>
|
|||
/// 获取核心网配置列表查询处理器
|
|||
/// </summary>
|
|||
public class GetCoreNetworkConfigsQueryHandler : IRequestHandler<GetCoreNetworkConfigsQuery, OperationResult<GetCoreNetworkConfigsResponse>> |
|||
{ |
|||
private readonly ICoreNetworkConfigRepository _coreNetworkConfigRepository; |
|||
private readonly ILogger<GetCoreNetworkConfigsQueryHandler> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 初始化查询处理器
|
|||
/// </summary>
|
|||
public GetCoreNetworkConfigsQueryHandler( |
|||
ICoreNetworkConfigRepository coreNetworkConfigRepository, |
|||
ILogger<GetCoreNetworkConfigsQueryHandler> logger) |
|||
{ |
|||
_coreNetworkConfigRepository = coreNetworkConfigRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理获取核心网配置列表查询
|
|||
/// </summary>
|
|||
public async Task<OperationResult<GetCoreNetworkConfigsResponse>> Handle(GetCoreNetworkConfigsQuery request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始获取核心网配置列表,页码: {PageNumber}, 每页数量: {PageSize}, 搜索关键词: {SearchTerm}", |
|||
request.PageNumber, request.PageSize, request.SearchTerm ?? "无"); |
|||
|
|||
// 获取核心网配置列表
|
|||
var (totalCount, items) = await _coreNetworkConfigRepository.SearchCoreNetworkConfigsAsync( |
|||
request.SearchTerm, |
|||
request.PageNumber, |
|||
request.PageSize, |
|||
cancellationToken); |
|||
|
|||
// 计算总页数
|
|||
var totalPages = (int)Math.Ceiling((double)totalCount / request.PageSize); |
|||
|
|||
// 构建响应
|
|||
var response = new GetCoreNetworkConfigsResponse |
|||
{ |
|||
TotalCount = totalCount, |
|||
PageNumber = request.PageNumber, |
|||
PageSize = request.PageSize, |
|||
TotalPages = totalPages, |
|||
Items = items.Select(item => new CoreNetworkConfigDto |
|||
{ |
|||
CoreNetworkConfigId = item.Id, |
|||
Name = item.Name, |
|||
ConfigContent = item.ConfigContent, |
|||
Description = item.Description, |
|||
IsDisabled = item.IsDisabled, |
|||
CreatedAt = item.CreatedAt, |
|||
UpdatedAt = item.UpdatedAt, |
|||
CreatedBy = item.CreatedBy, |
|||
UpdatedBy = item.UpdatedBy |
|||
}).ToList() |
|||
}; |
|||
|
|||
_logger.LogInformation("成功获取核心网配置列表,总数量: {TotalCount}, 当前页数量: {ItemCount}", |
|||
totalCount, items.Count); |
|||
return OperationResult<GetCoreNetworkConfigsResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "获取核心网配置列表时发生错误"); |
|||
return OperationResult<GetCoreNetworkConfigsResponse>.CreateFailure($"获取核心网配置列表时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,35 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.IMSConfiguration.Commands.CreateIMS_Configuration; |
|||
|
|||
/// <summary>
|
|||
/// 创建IMS配置命令
|
|||
/// </summary>
|
|||
public class CreateIMS_ConfigurationCommand : IRequest<OperationResult<CreateIMS_ConfigurationResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "配置名称不能为空")] |
|||
[MaxLength(100, ErrorMessage = "配置名称不能超过100个字符")] |
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置内容(JSON格式)
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "配置内容不能为空")] |
|||
public string ConfigContent { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置描述
|
|||
/// </summary>
|
|||
[MaxLength(500, ErrorMessage = "配置描述不能超过500个字符")] |
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否禁用
|
|||
/// </summary>
|
|||
public bool IsDisabled { get; set; } = false; |
|||
} |
@ -0,0 +1,95 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories.Base; |
|||
using CellularManagement.Domain.Services; |
|||
using CellularManagement.Domain.Entities.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.IMSConfiguration.Commands.CreateIMS_Configuration; |
|||
|
|||
/// <summary>
|
|||
/// 创建IMS配置命令处理器
|
|||
/// </summary>
|
|||
public class CreateIMS_ConfigurationCommandHandler : IRequestHandler<CreateIMS_ConfigurationCommand, OperationResult<CreateIMS_ConfigurationResponse>> |
|||
{ |
|||
private readonly IIMS_ConfigurationRepository _imsConfigurationRepository; |
|||
private readonly ILogger<CreateIMS_ConfigurationCommandHandler> _logger; |
|||
private readonly IUnitOfWork _unitOfWork; |
|||
private readonly ICurrentUserService _currentUserService; |
|||
|
|||
/// <summary>
|
|||
/// 初始化命令处理器
|
|||
/// </summary>
|
|||
public CreateIMS_ConfigurationCommandHandler( |
|||
IIMS_ConfigurationRepository imsConfigurationRepository, |
|||
ILogger<CreateIMS_ConfigurationCommandHandler> logger, |
|||
IUnitOfWork unitOfWork, |
|||
ICurrentUserService currentUserService) |
|||
{ |
|||
_imsConfigurationRepository = imsConfigurationRepository; |
|||
_logger = logger; |
|||
_unitOfWork = unitOfWork; |
|||
_currentUserService = currentUserService; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理创建IMS配置命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<CreateIMS_ConfigurationResponse>> Handle(CreateIMS_ConfigurationCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始创建IMS配置,配置名称: {Name}", request.Name); |
|||
|
|||
// 检查配置名称是否已存在
|
|||
if (await _imsConfigurationRepository.NameExistsAsync(request.Name, cancellationToken)) |
|||
{ |
|||
_logger.LogWarning("IMS配置名称已存在: {Name}", request.Name); |
|||
return OperationResult<CreateIMS_ConfigurationResponse>.CreateFailure($"IMS配置名称 {request.Name} 已存在"); |
|||
} |
|||
|
|||
// 获取当前用户ID
|
|||
var currentUserId = _currentUserService.GetCurrentUserId(); |
|||
if (string.IsNullOrEmpty(currentUserId)) |
|||
{ |
|||
_logger.LogError("无法获取当前用户ID,用户可能未认证"); |
|||
return OperationResult<CreateIMS_ConfigurationResponse>.CreateFailure("用户未认证,无法创建IMS配置"); |
|||
} |
|||
|
|||
// 创建IMS配置实体
|
|||
var imsConfiguration = IMS_Configuration.Create( |
|||
name: request.Name, |
|||
configContent: request.ConfigContent, |
|||
createdBy: currentUserId, |
|||
description: request.Description, |
|||
isDisabled: request.IsDisabled); |
|||
|
|||
// 保存IMS配置
|
|||
await _imsConfigurationRepository.AddIMS_ConfigurationAsync(imsConfiguration, cancellationToken); |
|||
|
|||
// 保存更改到数据库
|
|||
await _unitOfWork.SaveChangesAsync(cancellationToken); |
|||
|
|||
// 构建响应
|
|||
var response = new CreateIMS_ConfigurationResponse |
|||
{ |
|||
IMS_ConfigurationId = imsConfiguration.Id, |
|||
Name = imsConfiguration.Name, |
|||
ConfigContent = imsConfiguration.ConfigContent, |
|||
Description = imsConfiguration.Description, |
|||
IsDisabled = imsConfiguration.IsDisabled, |
|||
CreatedAt = imsConfiguration.CreatedAt |
|||
}; |
|||
|
|||
_logger.LogInformation("IMS配置创建成功,配置ID: {IMS_ConfigurationId}, 配置名称: {Name}", |
|||
imsConfiguration.Id, imsConfiguration.Name); |
|||
return OperationResult<CreateIMS_ConfigurationResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "创建IMS配置时发生错误,配置名称: {Name}", request.Name); |
|||
return OperationResult<CreateIMS_ConfigurationResponse>.CreateFailure($"创建IMS配置时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
namespace CellularManagement.Application.Features.IMSConfiguration.Commands.CreateIMS_Configuration; |
|||
|
|||
/// <summary>
|
|||
/// 创建IMS配置响应
|
|||
/// </summary>
|
|||
public class CreateIMS_ConfigurationResponse |
|||
{ |
|||
/// <summary>
|
|||
/// IMS配置ID
|
|||
/// </summary>
|
|||
public string IMS_ConfigurationId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置内容(JSON格式)
|
|||
/// </summary>
|
|||
public string ConfigContent { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置描述
|
|||
/// </summary>
|
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否禁用
|
|||
/// </summary>
|
|||
public bool IsDisabled { 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.IMSConfiguration.Commands.DeleteIMS_Configuration; |
|||
|
|||
/// <summary>
|
|||
/// 删除IMS配置命令
|
|||
/// </summary>
|
|||
public class DeleteIMS_ConfigurationCommand : IRequest<OperationResult<bool>> |
|||
{ |
|||
/// <summary>
|
|||
/// IMS配置ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string IMS_ConfigurationId { get; set; } = null!; |
|||
} |
@ -0,0 +1,64 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories.Base; |
|||
|
|||
namespace CellularManagement.Application.Features.IMSConfiguration.Commands.DeleteIMS_Configuration; |
|||
|
|||
/// <summary>
|
|||
/// 删除IMS配置命令处理器
|
|||
/// </summary>
|
|||
public class DeleteIMS_ConfigurationCommandHandler : IRequestHandler<DeleteIMS_ConfigurationCommand, OperationResult<bool>> |
|||
{ |
|||
private readonly IIMS_ConfigurationRepository _imsConfigurationRepository; |
|||
private readonly ILogger<DeleteIMS_ConfigurationCommandHandler> _logger; |
|||
private readonly IUnitOfWork _unitOfWork; |
|||
|
|||
/// <summary>
|
|||
/// 初始化命令处理器
|
|||
/// </summary>
|
|||
public DeleteIMS_ConfigurationCommandHandler( |
|||
IIMS_ConfigurationRepository imsConfigurationRepository, |
|||
ILogger<DeleteIMS_ConfigurationCommandHandler> logger, |
|||
IUnitOfWork unitOfWork) |
|||
{ |
|||
_imsConfigurationRepository = imsConfigurationRepository; |
|||
_logger = logger; |
|||
_unitOfWork = unitOfWork; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理删除IMS配置命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<bool>> Handle(DeleteIMS_ConfigurationCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始删除IMS配置,配置ID: {IMS_ConfigurationId}", request.IMS_ConfigurationId); |
|||
|
|||
// 检查IMS配置是否存在
|
|||
var existingConfig = await _imsConfigurationRepository.GetIMS_ConfigurationByIdAsync(request.IMS_ConfigurationId, cancellationToken); |
|||
if (existingConfig == null) |
|||
{ |
|||
_logger.LogWarning("IMS配置不存在: {IMS_ConfigurationId}", request.IMS_ConfigurationId); |
|||
return OperationResult<bool>.CreateFailure($"IMS配置 {request.IMS_ConfigurationId} 不存在"); |
|||
} |
|||
|
|||
// 删除IMS配置
|
|||
await _imsConfigurationRepository.DeleteIMS_ConfigurationAsync(request.IMS_ConfigurationId, cancellationToken); |
|||
|
|||
// 保存更改到数据库
|
|||
await _unitOfWork.SaveChangesAsync(cancellationToken); |
|||
|
|||
_logger.LogInformation("IMS配置删除成功,配置ID: {IMS_ConfigurationId}, 配置名称: {Name}", |
|||
request.IMS_ConfigurationId, existingConfig.Name); |
|||
return OperationResult<bool>.CreateSuccess(true); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "删除IMS配置时发生错误,配置ID: {IMS_ConfigurationId}", request.IMS_ConfigurationId); |
|||
return OperationResult<bool>.CreateFailure($"删除IMS配置时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -1,43 +1,37 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using CellularManagement.Domain.Entities.Device; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkConfigs.Commands.CreateNetworkConfig; |
|||
namespace CellularManagement.Application.Features.IMSConfiguration.Commands.UpdateIMS_Configuration; |
|||
|
|||
/// <summary>
|
|||
/// 创建网络配置命令
|
|||
/// 更新IMS配置命令
|
|||
/// </summary>
|
|||
public class CreateNetworkConfigCommand : IRequest<OperationResult<CreateNetworkConfigResponse>> |
|||
public class UpdateIMS_ConfigurationCommand : IRequest<OperationResult<UpdateIMS_ConfigurationResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 配置类型
|
|||
/// IMS配置ID
|
|||
/// </summary>
|
|||
public NetworkConfigType ConfigType { get; set; } |
|||
[Required] |
|||
public string IMS_ConfigurationId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
[Required] |
|||
[MaxLength(100)] |
|||
[Required(ErrorMessage = "配置名称不能为空")] |
|||
[MaxLength(100, ErrorMessage = "配置名称不能超过100个字符")] |
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// PLMN字段(移动国家代码+移动网络代码)
|
|||
/// </summary>
|
|||
[MaxLength(10)] |
|||
public string? Plmn { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 配置内容(JSON格式)
|
|||
/// </summary>
|
|||
[Required] |
|||
[Required(ErrorMessage = "配置内容不能为空")] |
|||
public string ConfigContent { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置说明
|
|||
/// 配置描述
|
|||
/// </summary>
|
|||
[MaxLength(500)] |
|||
[MaxLength(500, ErrorMessage = "配置描述不能超过500个字符")] |
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
@ -0,0 +1,102 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories.Base; |
|||
using CellularManagement.Domain.Services; |
|||
using CellularManagement.Domain.Entities.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.IMSConfiguration.Commands.UpdateIMS_Configuration; |
|||
|
|||
/// <summary>
|
|||
/// 更新IMS配置命令处理器
|
|||
/// </summary>
|
|||
public class UpdateIMS_ConfigurationCommandHandler : IRequestHandler<UpdateIMS_ConfigurationCommand, OperationResult<UpdateIMS_ConfigurationResponse>> |
|||
{ |
|||
private readonly IIMS_ConfigurationRepository _imsConfigurationRepository; |
|||
private readonly ILogger<UpdateIMS_ConfigurationCommandHandler> _logger; |
|||
private readonly IUnitOfWork _unitOfWork; |
|||
private readonly ICurrentUserService _currentUserService; |
|||
|
|||
/// <summary>
|
|||
/// 初始化命令处理器
|
|||
/// </summary>
|
|||
public UpdateIMS_ConfigurationCommandHandler( |
|||
IIMS_ConfigurationRepository imsConfigurationRepository, |
|||
ILogger<UpdateIMS_ConfigurationCommandHandler> logger, |
|||
IUnitOfWork unitOfWork, |
|||
ICurrentUserService currentUserService) |
|||
{ |
|||
_imsConfigurationRepository = imsConfigurationRepository; |
|||
_logger = logger; |
|||
_unitOfWork = unitOfWork; |
|||
_currentUserService = currentUserService; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理更新IMS配置命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<UpdateIMS_ConfigurationResponse>> Handle(UpdateIMS_ConfigurationCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始更新IMS配置,配置ID: {IMS_ConfigurationId}", request.IMS_ConfigurationId); |
|||
|
|||
// 检查IMS配置是否存在
|
|||
var existingConfig = await _imsConfigurationRepository.GetIMS_ConfigurationByIdAsync(request.IMS_ConfigurationId, cancellationToken); |
|||
if (existingConfig == null) |
|||
{ |
|||
_logger.LogWarning("IMS配置不存在: {IMS_ConfigurationId}", request.IMS_ConfigurationId); |
|||
return OperationResult<UpdateIMS_ConfigurationResponse>.CreateFailure($"IMS配置 {request.IMS_ConfigurationId} 不存在"); |
|||
} |
|||
|
|||
// 检查新名称是否与其他配置冲突
|
|||
var configWithSameName = await _imsConfigurationRepository.GetIMS_ConfigurationByNameAsync(request.Name, cancellationToken); |
|||
if (configWithSameName != null && configWithSameName.Id != request.IMS_ConfigurationId) |
|||
{ |
|||
_logger.LogWarning("IMS配置名称已存在: {Name}", request.Name); |
|||
return OperationResult<UpdateIMS_ConfigurationResponse>.CreateFailure($"IMS配置名称 {request.Name} 已存在"); |
|||
} |
|||
|
|||
// 获取当前用户ID
|
|||
var currentUserId = _currentUserService.GetCurrentUserId(); |
|||
if (string.IsNullOrEmpty(currentUserId)) |
|||
{ |
|||
_logger.LogError("无法获取当前用户ID,用户可能未认证"); |
|||
return OperationResult<UpdateIMS_ConfigurationResponse>.CreateFailure("用户未认证,无法更新IMS配置"); |
|||
} |
|||
|
|||
// 更新IMS配置
|
|||
existingConfig.Update( |
|||
name: request.Name, |
|||
configContent: request.ConfigContent, |
|||
updatedBy: currentUserId, |
|||
description: request.Description, |
|||
isDisabled: request.IsDisabled); |
|||
|
|||
// 保存更改
|
|||
_imsConfigurationRepository.UpdateIMS_Configuration(existingConfig); |
|||
await _unitOfWork.SaveChangesAsync(cancellationToken); |
|||
|
|||
// 构建响应
|
|||
var response = new UpdateIMS_ConfigurationResponse |
|||
{ |
|||
IMS_ConfigurationId = existingConfig.Id, |
|||
Name = existingConfig.Name, |
|||
ConfigContent = existingConfig.ConfigContent, |
|||
Description = existingConfig.Description, |
|||
IsDisabled = existingConfig.IsDisabled, |
|||
UpdatedAt = existingConfig.UpdatedAt |
|||
}; |
|||
|
|||
_logger.LogInformation("IMS配置更新成功,配置ID: {IMS_ConfigurationId}, 配置名称: {Name}", |
|||
existingConfig.Id, existingConfig.Name); |
|||
return OperationResult<UpdateIMS_ConfigurationResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "更新IMS配置时发生错误,配置ID: {IMS_ConfigurationId}", request.IMS_ConfigurationId); |
|||
return OperationResult<UpdateIMS_ConfigurationResponse>.CreateFailure($"更新IMS配置时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
namespace CellularManagement.Application.Features.IMSConfiguration.Commands.UpdateIMS_Configuration; |
|||
|
|||
/// <summary>
|
|||
/// 更新IMS配置响应
|
|||
/// </summary>
|
|||
public class UpdateIMS_ConfigurationResponse |
|||
{ |
|||
/// <summary>
|
|||
/// IMS配置ID
|
|||
/// </summary>
|
|||
public string IMS_ConfigurationId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置内容(JSON格式)
|
|||
/// </summary>
|
|||
public string ConfigContent { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置描述
|
|||
/// </summary>
|
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否禁用
|
|||
/// </summary>
|
|||
public bool IsDisabled { 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.IMSConfiguration.Queries.GetIMS_ConfigurationById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取IMS配置查询
|
|||
/// </summary>
|
|||
public class GetIMS_ConfigurationByIdQuery : IRequest<OperationResult<GetIMS_ConfigurationByIdResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// IMS配置ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string IMS_ConfigurationId { get; set; } = null!; |
|||
} |
@ -0,0 +1,68 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.IMSConfiguration.Queries.GetIMS_ConfigurationById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取IMS配置查询处理器
|
|||
/// </summary>
|
|||
public class GetIMS_ConfigurationByIdQueryHandler : IRequestHandler<GetIMS_ConfigurationByIdQuery, OperationResult<GetIMS_ConfigurationByIdResponse>> |
|||
{ |
|||
private readonly IIMS_ConfigurationRepository _imsConfigurationRepository; |
|||
private readonly ILogger<GetIMS_ConfigurationByIdQueryHandler> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 初始化查询处理器
|
|||
/// </summary>
|
|||
public GetIMS_ConfigurationByIdQueryHandler( |
|||
IIMS_ConfigurationRepository imsConfigurationRepository, |
|||
ILogger<GetIMS_ConfigurationByIdQueryHandler> logger) |
|||
{ |
|||
_imsConfigurationRepository = imsConfigurationRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理根据ID获取IMS配置查询
|
|||
/// </summary>
|
|||
public async Task<OperationResult<GetIMS_ConfigurationByIdResponse>> Handle(GetIMS_ConfigurationByIdQuery request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始获取IMS配置,配置ID: {IMS_ConfigurationId}", request.IMS_ConfigurationId); |
|||
|
|||
// 获取IMS配置
|
|||
var imsConfiguration = await _imsConfigurationRepository.GetIMS_ConfigurationByIdAsync(request.IMS_ConfigurationId, cancellationToken); |
|||
if (imsConfiguration == null) |
|||
{ |
|||
_logger.LogWarning("IMS配置不存在: {IMS_ConfigurationId}", request.IMS_ConfigurationId); |
|||
return OperationResult<GetIMS_ConfigurationByIdResponse>.CreateFailure($"IMS配置 {request.IMS_ConfigurationId} 不存在"); |
|||
} |
|||
|
|||
// 构建响应
|
|||
var response = new GetIMS_ConfigurationByIdResponse |
|||
{ |
|||
IMS_ConfigurationId = imsConfiguration.Id, |
|||
Name = imsConfiguration.Name, |
|||
ConfigContent = imsConfiguration.ConfigContent, |
|||
Description = imsConfiguration.Description, |
|||
IsDisabled = imsConfiguration.IsDisabled, |
|||
CreatedAt = imsConfiguration.CreatedAt, |
|||
UpdatedAt = imsConfiguration.UpdatedAt, |
|||
CreatedBy = imsConfiguration.CreatedBy, |
|||
UpdatedBy = imsConfiguration.UpdatedBy |
|||
}; |
|||
|
|||
_logger.LogInformation("成功获取IMS配置,配置ID: {IMS_ConfigurationId}, 配置名称: {Name}", |
|||
imsConfiguration.Id, imsConfiguration.Name); |
|||
return OperationResult<GetIMS_ConfigurationByIdResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "获取IMS配置时发生错误,配置ID: {IMS_ConfigurationId}", request.IMS_ConfigurationId); |
|||
return OperationResult<GetIMS_ConfigurationByIdResponse>.CreateFailure($"获取IMS配置时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,52 @@ |
|||
namespace CellularManagement.Application.Features.IMSConfiguration.Queries.GetIMS_ConfigurationById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取IMS配置响应
|
|||
/// </summary>
|
|||
public class GetIMS_ConfigurationByIdResponse |
|||
{ |
|||
/// <summary>
|
|||
/// IMS配置ID
|
|||
/// </summary>
|
|||
public string IMS_ConfigurationId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置内容(JSON格式)
|
|||
/// </summary>
|
|||
public string ConfigContent { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置描述
|
|||
/// </summary>
|
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否禁用
|
|||
/// </summary>
|
|||
public bool IsDisabled { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 创建时间
|
|||
/// </summary>
|
|||
public DateTime CreatedAt { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 更新时间
|
|||
/// </summary>
|
|||
public DateTime? UpdatedAt { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 创建者
|
|||
/// </summary>
|
|||
public string CreatedBy { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 更新者
|
|||
/// </summary>
|
|||
public string UpdatedBy { get; set; } = null!; |
|||
} |
@ -0,0 +1,34 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.IMSConfiguration.Queries.GetIMS_Configurations; |
|||
|
|||
/// <summary>
|
|||
/// 获取IMS配置列表查询
|
|||
/// </summary>
|
|||
public class GetIMS_ConfigurationsQuery : IRequest<OperationResult<GetIMS_ConfigurationsResponse>> |
|||
{ |
|||
/// <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? IsDisabled { get; set; } |
|||
} |
@ -0,0 +1,78 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.IMSConfiguration.Queries.GetIMS_Configurations; |
|||
|
|||
/// <summary>
|
|||
/// 获取IMS配置列表查询处理器
|
|||
/// </summary>
|
|||
public class GetIMS_ConfigurationsQueryHandler : IRequestHandler<GetIMS_ConfigurationsQuery, OperationResult<GetIMS_ConfigurationsResponse>> |
|||
{ |
|||
private readonly IIMS_ConfigurationRepository _imsConfigurationRepository; |
|||
private readonly ILogger<GetIMS_ConfigurationsQueryHandler> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 初始化查询处理器
|
|||
/// </summary>
|
|||
public GetIMS_ConfigurationsQueryHandler( |
|||
IIMS_ConfigurationRepository imsConfigurationRepository, |
|||
ILogger<GetIMS_ConfigurationsQueryHandler> logger) |
|||
{ |
|||
_imsConfigurationRepository = imsConfigurationRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理获取IMS配置列表查询
|
|||
/// </summary>
|
|||
public async Task<OperationResult<GetIMS_ConfigurationsResponse>> Handle(GetIMS_ConfigurationsQuery request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始获取IMS配置列表,页码: {PageNumber}, 每页数量: {PageSize}, 搜索关键词: {SearchTerm}", |
|||
request.PageNumber, request.PageSize, request.SearchTerm ?? "无"); |
|||
|
|||
// 获取IMS配置列表
|
|||
var (totalCount, items) = await _imsConfigurationRepository.SearchIMS_ConfigurationsAsync( |
|||
request.SearchTerm, |
|||
request.PageNumber, |
|||
request.PageSize, |
|||
cancellationToken); |
|||
|
|||
// 计算总页数
|
|||
var totalPages = (int)Math.Ceiling((double)totalCount / request.PageSize); |
|||
|
|||
// 构建响应
|
|||
var response = new GetIMS_ConfigurationsResponse |
|||
{ |
|||
TotalCount = totalCount, |
|||
PageNumber = request.PageNumber, |
|||
PageSize = request.PageSize, |
|||
TotalPages = totalPages, |
|||
Items = items.Select(item => new IMS_ConfigurationDto |
|||
{ |
|||
IMS_ConfigurationId = item.Id, |
|||
Name = item.Name, |
|||
ConfigContent = item.ConfigContent, |
|||
Description = item.Description, |
|||
IsDisabled = item.IsDisabled, |
|||
CreatedAt = item.CreatedAt, |
|||
UpdatedAt = item.UpdatedAt, |
|||
CreatedBy = item.CreatedBy, |
|||
UpdatedBy = item.UpdatedBy |
|||
}).ToList() |
|||
}; |
|||
|
|||
_logger.LogInformation("成功获取IMS配置列表,总数量: {TotalCount}, 当前页数量: {ItemCount}", |
|||
totalCount, items.Count); |
|||
return OperationResult<GetIMS_ConfigurationsResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "获取IMS配置列表时发生错误"); |
|||
return OperationResult<GetIMS_ConfigurationsResponse>.CreateFailure($"获取IMS配置列表时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,83 @@ |
|||
namespace CellularManagement.Application.Features.IMSConfiguration.Queries.GetIMS_Configurations; |
|||
|
|||
/// <summary>
|
|||
/// 获取IMS配置列表响应
|
|||
/// </summary>
|
|||
public class GetIMS_ConfigurationsResponse |
|||
{ |
|||
/// <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>
|
|||
/// IMS配置列表
|
|||
/// </summary>
|
|||
public List<IMS_ConfigurationDto> Items { get; set; } = new(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// IMS配置数据传输对象
|
|||
/// </summary>
|
|||
public class IMS_ConfigurationDto |
|||
{ |
|||
/// <summary>
|
|||
/// IMS配置ID
|
|||
/// </summary>
|
|||
public string IMS_ConfigurationId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置内容(JSON格式)
|
|||
/// </summary>
|
|||
public string ConfigContent { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置描述
|
|||
/// </summary>
|
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否禁用
|
|||
/// </summary>
|
|||
public bool IsDisabled { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 创建时间
|
|||
/// </summary>
|
|||
public DateTime CreatedAt { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 更新时间
|
|||
/// </summary>
|
|||
public DateTime ?UpdatedAt { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 创建者
|
|||
/// </summary>
|
|||
public string CreatedBy { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 更新者
|
|||
/// </summary>
|
|||
public string UpdatedBy { get; set; } = null!; |
|||
} |
@ -1,85 +0,0 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using CellularManagement.Domain.Entities.Device; |
|||
using CellularManagement.Domain.Repositories.Device; |
|||
using CellularManagement.Domain.Services; |
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkConfigs.Commands.CreateNetworkConfig; |
|||
|
|||
/// <summary>
|
|||
/// 创建网络配置命令处理器
|
|||
/// </summary>
|
|||
public class CreateNetworkConfigCommandHandler : IRequestHandler<CreateNetworkConfigCommand, OperationResult<CreateNetworkConfigResponse>> |
|||
{ |
|||
private readonly INetworkConfigRepository _networkConfigRepository; |
|||
private readonly ICurrentUserService _currentUserService; |
|||
|
|||
private readonly ILogger<CreateNetworkConfigCommandHandler> _logger; |
|||
|
|||
public CreateNetworkConfigCommandHandler( |
|||
INetworkConfigRepository networkConfigRepository, |
|||
ICurrentUserService currentUserService, |
|||
ILogger<CreateNetworkConfigCommandHandler> logger) |
|||
{ |
|||
_networkConfigRepository = networkConfigRepository; |
|||
_currentUserService = currentUserService; |
|||
_logger = logger; |
|||
} |
|||
|
|||
public async Task<OperationResult<CreateNetworkConfigResponse>> Handle(CreateNetworkConfigCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
_logger.LogInformation("开始创建网络配置,配置名称: {Name}, 配置类型: {ConfigType}", request.Name, request.ConfigType); |
|||
|
|||
try |
|||
{ |
|||
// 检查配置名称是否已存在
|
|||
if (await _networkConfigRepository.NameExistsAsync(request.Name, cancellationToken)) |
|||
{ |
|||
_logger.LogWarning("配置名称已存在: {Name}", request.Name); |
|||
return OperationResult<CreateNetworkConfigResponse>.CreateFailure($"配置名称 '{request.Name}' 已存在"); |
|||
} |
|||
|
|||
// 获取当前用户
|
|||
var currentUser = _currentUserService.GetCurrentUserId(); |
|||
if (string.IsNullOrEmpty(currentUser)) |
|||
{ |
|||
_logger.LogWarning("用户未认证"); |
|||
return OperationResult<CreateNetworkConfigResponse>.CreateFailure("用户未认证"); |
|||
} |
|||
|
|||
// 创建网络配置
|
|||
var networkConfig = NetworkConfig.Create( |
|||
request.ConfigType, |
|||
request.Name, |
|||
request.ConfigContent, |
|||
currentUser, |
|||
request.Plmn, |
|||
request.Description, |
|||
request.IsDisabled); |
|||
|
|||
// 保存到数据库
|
|||
await _networkConfigRepository.AddNetworkConfigAsync(networkConfig, cancellationToken); |
|||
|
|||
var response = new CreateNetworkConfigResponse |
|||
{ |
|||
NetworkConfigId = networkConfig.Id, |
|||
Name = networkConfig.Name, |
|||
ConfigType = (int)networkConfig.ConfigType |
|||
}; |
|||
|
|||
_logger.LogInformation("成功创建网络配置,配置ID: {NetworkConfigId}", response.NetworkConfigId); |
|||
return OperationResult<CreateNetworkConfigResponse>.CreateSuccess("网络配置创建成功", response); |
|||
} |
|||
catch (ArgumentException ex) |
|||
{ |
|||
_logger.LogWarning("创建网络配置参数错误: {Message}", ex.Message); |
|||
return OperationResult<CreateNetworkConfigResponse>.CreateFailure(ex.Message); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "创建网络配置失败: {Message}", ex.Message); |
|||
return OperationResult<CreateNetworkConfigResponse>.CreateFailure($"创建网络配置失败: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -1,22 +0,0 @@ |
|||
namespace CellularManagement.Application.Features.NetworkConfigs.Commands.CreateNetworkConfig; |
|||
|
|||
/// <summary>
|
|||
/// 创建网络配置响应
|
|||
/// </summary>
|
|||
public class CreateNetworkConfigResponse |
|||
{ |
|||
/// <summary>
|
|||
/// 配置ID
|
|||
/// </summary>
|
|||
public string NetworkConfigId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置类型
|
|||
/// </summary>
|
|||
public int ConfigType { get; set; } |
|||
} |
@ -1,17 +0,0 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkConfigs.Commands.DeleteNetworkConfig; |
|||
|
|||
/// <summary>
|
|||
/// 删除网络配置命令
|
|||
/// </summary>
|
|||
public class DeleteNetworkConfigCommand : IRequest<OperationResult<bool>> |
|||
{ |
|||
/// <summary>
|
|||
/// 网络配置ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string NetworkConfigId { get; set; } = null!; |
|||
} |
@ -1,50 +0,0 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using CellularManagement.Domain.Repositories.Device; |
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkConfigs.Commands.DeleteNetworkConfig; |
|||
|
|||
/// <summary>
|
|||
/// 删除网络配置命令处理器
|
|||
/// </summary>
|
|||
public class DeleteNetworkConfigCommandHandler : IRequestHandler<DeleteNetworkConfigCommand, OperationResult<bool>> |
|||
{ |
|||
private readonly INetworkConfigRepository _networkConfigRepository; |
|||
private readonly ILogger<DeleteNetworkConfigCommandHandler> _logger; |
|||
|
|||
public DeleteNetworkConfigCommandHandler( |
|||
INetworkConfigRepository networkConfigRepository, |
|||
ILogger<DeleteNetworkConfigCommandHandler> logger) |
|||
{ |
|||
_networkConfigRepository = networkConfigRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
public async Task<OperationResult<bool>> Handle(DeleteNetworkConfigCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
_logger.LogInformation("开始删除网络配置,配置ID: {NetworkConfigId}", request.NetworkConfigId); |
|||
|
|||
try |
|||
{ |
|||
// 检查配置是否存在
|
|||
var existingConfig = await _networkConfigRepository.GetNetworkConfigByIdAsync(request.NetworkConfigId, cancellationToken); |
|||
if (existingConfig == null) |
|||
{ |
|||
_logger.LogWarning("网络配置不存在,配置ID: {NetworkConfigId}", request.NetworkConfigId); |
|||
return OperationResult<bool>.CreateFailure("网络配置不存在"); |
|||
} |
|||
|
|||
// 删除网络配置
|
|||
await _networkConfigRepository.DeleteNetworkConfigAsync(request.NetworkConfigId, cancellationToken); |
|||
|
|||
_logger.LogInformation("成功删除网络配置,配置ID: {NetworkConfigId}", request.NetworkConfigId); |
|||
return OperationResult<bool>.CreateSuccess("网络配置删除成功", true); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "删除网络配置失败,配置ID: {NetworkConfigId}, 错误: {Message}", request.NetworkConfigId, ex.Message); |
|||
return OperationResult<bool>.CreateFailure($"删除网络配置失败: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -1,91 +0,0 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using CellularManagement.Domain.Entities.Device; |
|||
using CellularManagement.Domain.Repositories.Device; |
|||
using CellularManagement.Domain.Services; |
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkConfigs.Commands.UpdateNetworkConfig; |
|||
|
|||
/// <summary>
|
|||
/// 更新网络配置命令处理器
|
|||
/// </summary>
|
|||
public class UpdateNetworkConfigCommandHandler : IRequestHandler<UpdateNetworkConfigCommand, OperationResult<UpdateNetworkConfigResponse>> |
|||
{ |
|||
private readonly INetworkConfigRepository _networkConfigRepository; |
|||
private readonly ICurrentUserService _currentUserService; |
|||
private readonly ILogger<UpdateNetworkConfigCommandHandler> _logger; |
|||
|
|||
public UpdateNetworkConfigCommandHandler( |
|||
INetworkConfigRepository networkConfigRepository, |
|||
ICurrentUserService currentUserService, |
|||
ILogger<UpdateNetworkConfigCommandHandler> logger) |
|||
{ |
|||
_networkConfigRepository = networkConfigRepository; |
|||
_currentUserService = currentUserService; |
|||
_logger = logger; |
|||
} |
|||
|
|||
public async Task<OperationResult<UpdateNetworkConfigResponse>> Handle(UpdateNetworkConfigCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
_logger.LogInformation("开始更新网络配置,配置ID: {NetworkConfigId}", request.NetworkConfigId); |
|||
|
|||
try |
|||
{ |
|||
// 检查配置是否存在
|
|||
var existingConfig = await _networkConfigRepository.GetNetworkConfigByIdAsync(request.NetworkConfigId, cancellationToken); |
|||
if (existingConfig == null) |
|||
{ |
|||
_logger.LogWarning("网络配置不存在,配置ID: {NetworkConfigId}", request.NetworkConfigId); |
|||
return OperationResult<UpdateNetworkConfigResponse>.CreateFailure("网络配置不存在"); |
|||
} |
|||
|
|||
// 检查配置名称是否已存在(排除当前配置)
|
|||
if (await _networkConfigRepository.NameExistsAsync(request.Name, request.NetworkConfigId, cancellationToken)) |
|||
{ |
|||
_logger.LogWarning("配置名称已存在: {Name}", request.Name); |
|||
return OperationResult<UpdateNetworkConfigResponse>.CreateFailure($"配置名称 '{request.Name}' 已存在"); |
|||
} |
|||
|
|||
// 获取当前用户
|
|||
var currentUser = _currentUserService.GetCurrentUserId(); |
|||
if (string.IsNullOrEmpty(currentUser)) |
|||
{ |
|||
_logger.LogWarning("用户未认证"); |
|||
return OperationResult<UpdateNetworkConfigResponse>.CreateFailure("用户未认证"); |
|||
} |
|||
|
|||
// 更新网络配置
|
|||
existingConfig.Update( |
|||
request.Name, |
|||
request.ConfigContent, |
|||
currentUser, |
|||
request.Plmn, |
|||
request.Description, |
|||
request.IsDisabled); |
|||
|
|||
// 保存到数据库
|
|||
_networkConfigRepository.UpdateNetworkConfig(existingConfig); |
|||
|
|||
var response = new UpdateNetworkConfigResponse |
|||
{ |
|||
NetworkConfigId = existingConfig.Id, |
|||
Name = existingConfig.Name, |
|||
ConfigType = (int)existingConfig.ConfigType |
|||
}; |
|||
|
|||
_logger.LogInformation("成功更新网络配置,配置ID: {NetworkConfigId}", response.NetworkConfigId); |
|||
return OperationResult<UpdateNetworkConfigResponse>.CreateSuccess("网络配置更新成功", response); |
|||
} |
|||
catch (ArgumentException ex) |
|||
{ |
|||
_logger.LogWarning("更新网络配置参数错误: {Message}", ex.Message); |
|||
return OperationResult<UpdateNetworkConfigResponse>.CreateFailure(ex.Message); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "更新网络配置失败: {Message}", ex.Message); |
|||
return OperationResult<UpdateNetworkConfigResponse>.CreateFailure($"更新网络配置失败: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -1,22 +0,0 @@ |
|||
namespace CellularManagement.Application.Features.NetworkConfigs.Commands.UpdateNetworkConfig; |
|||
|
|||
/// <summary>
|
|||
/// 更新网络配置响应
|
|||
/// </summary>
|
|||
public class UpdateNetworkConfigResponse |
|||
{ |
|||
/// <summary>
|
|||
/// 配置ID
|
|||
/// </summary>
|
|||
public string NetworkConfigId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置类型
|
|||
/// </summary>
|
|||
public int ConfigType { get; set; } |
|||
} |
@ -1,17 +0,0 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkConfigs.Queries.GetNetworkConfigById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取网络配置查询
|
|||
/// </summary>
|
|||
public class GetNetworkConfigByIdQuery : IRequest<OperationResult<GetNetworkConfigByIdResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 网络配置ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string NetworkConfigId { get; set; } = null!; |
|||
} |
@ -1,63 +0,0 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using CellularManagement.Domain.Entities.Device; |
|||
using CellularManagement.Domain.Repositories.Device; |
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkConfigs.Queries.GetNetworkConfigById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取网络配置查询处理器
|
|||
/// </summary>
|
|||
public class GetNetworkConfigByIdQueryHandler : IRequestHandler<GetNetworkConfigByIdQuery, OperationResult<GetNetworkConfigByIdResponse>> |
|||
{ |
|||
private readonly INetworkConfigRepository _networkConfigRepository; |
|||
private readonly ILogger<GetNetworkConfigByIdQueryHandler> _logger; |
|||
|
|||
public GetNetworkConfigByIdQueryHandler( |
|||
INetworkConfigRepository networkConfigRepository, |
|||
ILogger<GetNetworkConfigByIdQueryHandler> logger) |
|||
{ |
|||
_networkConfigRepository = networkConfigRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
public async Task<OperationResult<GetNetworkConfigByIdResponse>> Handle(GetNetworkConfigByIdQuery request, CancellationToken cancellationToken) |
|||
{ |
|||
_logger.LogInformation("开始获取网络配置详情,配置ID: {NetworkConfigId}", request.NetworkConfigId); |
|||
|
|||
try |
|||
{ |
|||
var networkConfig = await _networkConfigRepository.GetNetworkConfigByIdAsync(request.NetworkConfigId, cancellationToken); |
|||
|
|||
if (networkConfig == null) |
|||
{ |
|||
_logger.LogWarning("网络配置不存在,配置ID: {NetworkConfigId}", request.NetworkConfigId); |
|||
return OperationResult<GetNetworkConfigByIdResponse>.CreateFailure("网络配置不存在"); |
|||
} |
|||
|
|||
var response = new GetNetworkConfigByIdResponse |
|||
{ |
|||
Id = networkConfig.Id, |
|||
ConfigType = networkConfig.ConfigType, |
|||
Name = networkConfig.Name, |
|||
Plmn = networkConfig.Plmn, |
|||
ConfigContent = networkConfig.ConfigContent, |
|||
Description = networkConfig.Description, |
|||
IsDisabled = networkConfig.IsDisabled, |
|||
CreatedAt = networkConfig.CreatedAt, |
|||
UpdatedAt = networkConfig.UpdatedAt, |
|||
CreatedBy = networkConfig.CreatedBy, |
|||
UpdatedBy = networkConfig.UpdatedBy |
|||
}; |
|||
|
|||
_logger.LogInformation("成功获取网络配置详情,配置ID: {NetworkConfigId}", request.NetworkConfigId); |
|||
return OperationResult<GetNetworkConfigByIdResponse>.CreateSuccess("获取网络配置详情成功", response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "获取网络配置详情失败,配置ID: {NetworkConfigId}, 错误: {Message}", request.NetworkConfigId, ex.Message); |
|||
return OperationResult<GetNetworkConfigByIdResponse>.CreateFailure($"获取网络配置详情失败: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -1,46 +0,0 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using CellularManagement.Domain.Entities.Device; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkConfigs.Queries.GetNetworkConfigs; |
|||
|
|||
/// <summary>
|
|||
/// 获取网络配置列表查询
|
|||
/// </summary>
|
|||
public class GetNetworkConfigsQuery : IRequest<OperationResult<GetNetworkConfigsResponse>> |
|||
{ |
|||
/// <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>
|
|||
public NetworkConfigType? ConfigType { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// PLMN(可选)
|
|||
/// </summary>
|
|||
[MaxLength(10)] |
|||
public string? Plmn { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否只获取启用的配置
|
|||
/// </summary>
|
|||
public bool? OnlyEnabled { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 搜索关键词
|
|||
/// </summary>
|
|||
[MaxLength(100)] |
|||
public string? Keyword { get; set; } |
|||
} |
@ -1,106 +0,0 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using CellularManagement.Domain.Entities.Device; |
|||
using CellularManagement.Domain.Repositories.Device; |
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkConfigs.Queries.GetNetworkConfigs; |
|||
|
|||
/// <summary>
|
|||
/// 获取网络配置列表查询处理器
|
|||
/// </summary>
|
|||
public class GetNetworkConfigsQueryHandler : IRequestHandler<GetNetworkConfigsQuery, OperationResult<GetNetworkConfigsResponse>> |
|||
{ |
|||
private readonly INetworkConfigRepository _networkConfigRepository; |
|||
|
|||
private readonly ILogger<GetNetworkConfigsQueryHandler> _logger; |
|||
|
|||
public GetNetworkConfigsQueryHandler( |
|||
INetworkConfigRepository networkConfigRepository, |
|||
ILogger<GetNetworkConfigsQueryHandler> logger) |
|||
{ |
|||
_networkConfigRepository = networkConfigRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
public async Task<OperationResult<GetNetworkConfigsResponse>> Handle(GetNetworkConfigsQuery request, CancellationToken cancellationToken) |
|||
{ |
|||
_logger.LogInformation("开始获取网络配置列表,页码: {PageNumber}, 每页数量: {PageSize}, 搜索关键词: {Keyword}, 配置类型: {ConfigType}, PLMN: {Plmn}, 是否启用: {OnlyEnabled}", |
|||
request.PageNumber, request.PageSize, request.Keyword, request.ConfigType, request.Plmn, request.OnlyEnabled); |
|||
|
|||
try |
|||
{ |
|||
IList<NetworkConfig> networkConfigs; |
|||
|
|||
// 根据查询条件获取配置
|
|||
if (!string.IsNullOrWhiteSpace(request.Keyword)) |
|||
{ |
|||
// 使用搜索功能
|
|||
networkConfigs = await _networkConfigRepository.SearchNetworkConfigsAsync( |
|||
request.Keyword, request.ConfigType, request.Plmn, cancellationToken); |
|||
} |
|||
else if (request.OnlyEnabled == true) |
|||
{ |
|||
networkConfigs = await _networkConfigRepository.GetEnabledNetworkConfigsAsync(cancellationToken); |
|||
} |
|||
else if (request.ConfigType.HasValue && !string.IsNullOrEmpty(request.Plmn)) |
|||
{ |
|||
networkConfigs = await _networkConfigRepository.GetNetworkConfigsByTypeAndPlmnAsync( |
|||
request.ConfigType.Value, request.Plmn, cancellationToken); |
|||
} |
|||
else if (request.ConfigType.HasValue) |
|||
{ |
|||
networkConfigs = await _networkConfigRepository.GetNetworkConfigsByTypeAsync( |
|||
request.ConfigType.Value, cancellationToken); |
|||
} |
|||
else if (!string.IsNullOrEmpty(request.Plmn)) |
|||
{ |
|||
networkConfigs = await _networkConfigRepository.GetNetworkConfigsByPlmnAsync( |
|||
request.Plmn, cancellationToken); |
|||
} |
|||
else |
|||
{ |
|||
networkConfigs = await _networkConfigRepository.GetAllNetworkConfigsAsync(cancellationToken); |
|||
} |
|||
|
|||
// 转换为DTO
|
|||
var networkConfigDtos = networkConfigs.Select(config => new NetworkConfigDto |
|||
{ |
|||
Id = config.Id, |
|||
ConfigType = config.ConfigType, |
|||
Name = config.Name, |
|||
Plmn = config.Plmn, |
|||
ConfigContent = config.ConfigContent, |
|||
Description = config.Description, |
|||
IsDisabled = config.IsDisabled, |
|||
CreatedAt = config.CreatedAt, |
|||
UpdatedAt = config.UpdatedAt, |
|||
CreatedBy = config.CreatedBy, |
|||
UpdatedBy = config.UpdatedBy |
|||
}).ToList(); |
|||
|
|||
// 计算分页信息
|
|||
var totalCount = networkConfigDtos.Count; |
|||
var totalPages = (int)Math.Ceiling((double)totalCount / request.PageSize); |
|||
var skip = (request.PageNumber - 1) * request.PageSize; |
|||
var pagedConfigs = networkConfigDtos.Skip(skip).Take(request.PageSize).ToList(); |
|||
|
|||
var response = new GetNetworkConfigsResponse |
|||
{ |
|||
NetworkConfigs = pagedConfigs, |
|||
TotalCount = totalCount, |
|||
PageNumber = request.PageNumber, |
|||
PageSize = request.PageSize, |
|||
TotalPages = totalPages |
|||
}; |
|||
|
|||
_logger.LogInformation("成功获取网络配置列表,共 {Count} 条记录", totalCount); |
|||
return OperationResult<GetNetworkConfigsResponse>.CreateSuccess("获取网络配置列表成功", response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "获取网络配置列表失败: {Message}", ex.Message); |
|||
return OperationResult<GetNetworkConfigsResponse>.CreateFailure($"获取网络配置列表失败: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,35 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkStackConfigs.Commands.CreateNetworkStackConfig; |
|||
|
|||
/// <summary>
|
|||
/// 创建网络栈配置命令
|
|||
/// </summary>
|
|||
public class CreateNetworkStackConfigCommand : IRequest<OperationResult<CreateNetworkStackConfigResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 栈ID(主键)
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "栈ID不能为空")] |
|||
[MaxLength(50, ErrorMessage = "栈ID不能超过50个字符")] |
|||
public string StackId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// RAN配置ID(外键,可为空)
|
|||
/// </summary>
|
|||
[MaxLength(50, ErrorMessage = "RAN配置ID不能超过50个字符")] |
|||
public string? RanId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 描述
|
|||
/// </summary>
|
|||
[MaxLength(500, ErrorMessage = "描述不能超过500个字符")] |
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否激活
|
|||
/// </summary>
|
|||
public bool IsActive { get; set; } = true; |
|||
} |
@ -0,0 +1,95 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories.Base; |
|||
using CellularManagement.Domain.Services; |
|||
using CellularManagement.Domain.Entities.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkStackConfigs.Commands.CreateNetworkStackConfig; |
|||
|
|||
/// <summary>
|
|||
/// 创建网络栈配置命令处理器
|
|||
/// </summary>
|
|||
public class CreateNetworkStackConfigCommandHandler : IRequestHandler<CreateNetworkStackConfigCommand, OperationResult<CreateNetworkStackConfigResponse>> |
|||
{ |
|||
private readonly INetworkStackConfigRepository _networkStackConfigRepository; |
|||
private readonly ILogger<CreateNetworkStackConfigCommandHandler> _logger; |
|||
private readonly IUnitOfWork _unitOfWork; |
|||
private readonly ICurrentUserService _currentUserService; |
|||
|
|||
/// <summary>
|
|||
/// 初始化命令处理器
|
|||
/// </summary>
|
|||
public CreateNetworkStackConfigCommandHandler( |
|||
INetworkStackConfigRepository networkStackConfigRepository, |
|||
ILogger<CreateNetworkStackConfigCommandHandler> logger, |
|||
IUnitOfWork unitOfWork, |
|||
ICurrentUserService currentUserService) |
|||
{ |
|||
_networkStackConfigRepository = networkStackConfigRepository; |
|||
_logger = logger; |
|||
_unitOfWork = unitOfWork; |
|||
_currentUserService = currentUserService; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理创建网络栈配置命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<CreateNetworkStackConfigResponse>> Handle(CreateNetworkStackConfigCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始创建网络栈配置,栈ID: {StackId}", request.StackId); |
|||
|
|||
// 检查栈ID是否已存在
|
|||
if (await _networkStackConfigRepository.StackIdExistsAsync(request.StackId, cancellationToken)) |
|||
{ |
|||
_logger.LogWarning("网络栈配置栈ID已存在: {StackId}", request.StackId); |
|||
return OperationResult<CreateNetworkStackConfigResponse>.CreateFailure($"网络栈配置栈ID {request.StackId} 已存在"); |
|||
} |
|||
|
|||
// 获取当前用户ID
|
|||
var currentUserId = _currentUserService.GetCurrentUserId(); |
|||
if (string.IsNullOrEmpty(currentUserId)) |
|||
{ |
|||
_logger.LogError("无法获取当前用户ID,用户可能未认证"); |
|||
return OperationResult<CreateNetworkStackConfigResponse>.CreateFailure("用户未认证,无法创建网络栈配置"); |
|||
} |
|||
|
|||
// 创建网络栈配置实体
|
|||
var networkStackConfig = NetworkStackConfig.Create( |
|||
stackId: request.StackId, |
|||
createdBy: currentUserId, |
|||
ranId: request.RanId, |
|||
description: request.Description, |
|||
isActive: request.IsActive); |
|||
|
|||
// 保存网络栈配置
|
|||
await _networkStackConfigRepository.AddNetworkStackConfigAsync(networkStackConfig, cancellationToken); |
|||
|
|||
// 保存更改到数据库
|
|||
await _unitOfWork.SaveChangesAsync(cancellationToken); |
|||
|
|||
// 构建响应
|
|||
var response = new CreateNetworkStackConfigResponse |
|||
{ |
|||
NetworkStackConfigId = networkStackConfig.Id, |
|||
StackId = networkStackConfig.StackId, |
|||
RanId = networkStackConfig.RanId, |
|||
Description = networkStackConfig.Description, |
|||
IsActive = networkStackConfig.IsActive, |
|||
CreatedAt = networkStackConfig.CreatedAt |
|||
}; |
|||
|
|||
_logger.LogInformation("网络栈配置创建成功,配置ID: {NetworkStackConfigId}, 栈ID: {StackId}", |
|||
networkStackConfig.Id, networkStackConfig.StackId); |
|||
return OperationResult<CreateNetworkStackConfigResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "创建网络栈配置时发生错误,栈ID: {StackId}", request.StackId); |
|||
return OperationResult<CreateNetworkStackConfigResponse>.CreateFailure($"创建网络栈配置时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
namespace CellularManagement.Application.Features.NetworkStackConfigs.Commands.CreateNetworkStackConfig; |
|||
|
|||
/// <summary>
|
|||
/// 创建网络栈配置响应
|
|||
/// </summary>
|
|||
public class CreateNetworkStackConfigResponse |
|||
{ |
|||
/// <summary>
|
|||
/// 网络栈配置ID
|
|||
/// </summary>
|
|||
public string NetworkStackConfigId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 栈ID(主键)
|
|||
/// </summary>
|
|||
public string StackId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// RAN配置ID(外键,可为空)
|
|||
/// </summary>
|
|||
public string? RanId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 描述
|
|||
/// </summary>
|
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否激活
|
|||
/// </summary>
|
|||
public bool IsActive { 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.NetworkStackConfigs.Commands.DeleteNetworkStackConfig; |
|||
|
|||
/// <summary>
|
|||
/// 删除网络栈配置命令
|
|||
/// </summary>
|
|||
public class DeleteNetworkStackConfigCommand : IRequest<OperationResult<bool>> |
|||
{ |
|||
/// <summary>
|
|||
/// 网络栈配置ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string NetworkStackConfigId { get; set; } = null!; |
|||
} |
@ -0,0 +1,64 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories.Base; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkStackConfigs.Commands.DeleteNetworkStackConfig; |
|||
|
|||
/// <summary>
|
|||
/// 删除网络栈配置命令处理器
|
|||
/// </summary>
|
|||
public class DeleteNetworkStackConfigCommandHandler : IRequestHandler<DeleteNetworkStackConfigCommand, OperationResult<bool>> |
|||
{ |
|||
private readonly INetworkStackConfigRepository _networkStackConfigRepository; |
|||
private readonly ILogger<DeleteNetworkStackConfigCommandHandler> _logger; |
|||
private readonly IUnitOfWork _unitOfWork; |
|||
|
|||
/// <summary>
|
|||
/// 初始化命令处理器
|
|||
/// </summary>
|
|||
public DeleteNetworkStackConfigCommandHandler( |
|||
INetworkStackConfigRepository networkStackConfigRepository, |
|||
ILogger<DeleteNetworkStackConfigCommandHandler> logger, |
|||
IUnitOfWork unitOfWork) |
|||
{ |
|||
_networkStackConfigRepository = networkStackConfigRepository; |
|||
_logger = logger; |
|||
_unitOfWork = unitOfWork; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理删除网络栈配置命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<bool>> Handle(DeleteNetworkStackConfigCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始删除网络栈配置,配置ID: {NetworkStackConfigId}", request.NetworkStackConfigId); |
|||
|
|||
// 检查网络栈配置是否存在
|
|||
var existingConfig = await _networkStackConfigRepository.GetNetworkStackConfigByIdAsync(request.NetworkStackConfigId, cancellationToken); |
|||
if (existingConfig == null) |
|||
{ |
|||
_logger.LogWarning("网络栈配置不存在: {NetworkStackConfigId}", request.NetworkStackConfigId); |
|||
return OperationResult<bool>.CreateFailure($"网络栈配置 {request.NetworkStackConfigId} 不存在"); |
|||
} |
|||
|
|||
// 删除网络栈配置
|
|||
await _networkStackConfigRepository.DeleteNetworkStackConfigAsync(request.NetworkStackConfigId, cancellationToken); |
|||
|
|||
// 保存更改到数据库
|
|||
await _unitOfWork.SaveChangesAsync(cancellationToken); |
|||
|
|||
_logger.LogInformation("网络栈配置删除成功,配置ID: {NetworkStackConfigId}, 栈ID: {StackId}", |
|||
request.NetworkStackConfigId, existingConfig.StackId); |
|||
return OperationResult<bool>.CreateSuccess(true); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "删除网络栈配置时发生错误,配置ID: {NetworkStackConfigId}", request.NetworkStackConfigId); |
|||
return OperationResult<bool>.CreateFailure($"删除网络栈配置时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,34 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkStackConfigs.Commands.UpdateNetworkStackConfig; |
|||
|
|||
/// <summary>
|
|||
/// 更新网络栈配置命令
|
|||
/// </summary>
|
|||
public class UpdateNetworkStackConfigCommand : IRequest<OperationResult<UpdateNetworkStackConfigResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 网络栈配置ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string NetworkStackConfigId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// RAN配置ID(外键,可为空)
|
|||
/// </summary>
|
|||
[MaxLength(50, ErrorMessage = "RAN配置ID不能超过50个字符")] |
|||
public string? RanId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 描述
|
|||
/// </summary>
|
|||
[MaxLength(500, ErrorMessage = "描述不能超过500个字符")] |
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否激活
|
|||
/// </summary>
|
|||
public bool IsActive { get; set; } = true; |
|||
} |
@ -0,0 +1,93 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories.Base; |
|||
using CellularManagement.Domain.Services; |
|||
using CellularManagement.Domain.Entities.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkStackConfigs.Commands.UpdateNetworkStackConfig; |
|||
|
|||
/// <summary>
|
|||
/// 更新网络栈配置命令处理器
|
|||
/// </summary>
|
|||
public class UpdateNetworkStackConfigCommandHandler : IRequestHandler<UpdateNetworkStackConfigCommand, OperationResult<UpdateNetworkStackConfigResponse>> |
|||
{ |
|||
private readonly INetworkStackConfigRepository _networkStackConfigRepository; |
|||
private readonly ILogger<UpdateNetworkStackConfigCommandHandler> _logger; |
|||
private readonly IUnitOfWork _unitOfWork; |
|||
private readonly ICurrentUserService _currentUserService; |
|||
|
|||
/// <summary>
|
|||
/// 初始化命令处理器
|
|||
/// </summary>
|
|||
public UpdateNetworkStackConfigCommandHandler( |
|||
INetworkStackConfigRepository networkStackConfigRepository, |
|||
ILogger<UpdateNetworkStackConfigCommandHandler> logger, |
|||
IUnitOfWork unitOfWork, |
|||
ICurrentUserService currentUserService) |
|||
{ |
|||
_networkStackConfigRepository = networkStackConfigRepository; |
|||
_logger = logger; |
|||
_unitOfWork = unitOfWork; |
|||
_currentUserService = currentUserService; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理更新网络栈配置命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<UpdateNetworkStackConfigResponse>> Handle(UpdateNetworkStackConfigCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始更新网络栈配置,配置ID: {NetworkStackConfigId}", request.NetworkStackConfigId); |
|||
|
|||
// 检查网络栈配置是否存在
|
|||
var existingConfig = await _networkStackConfigRepository.GetNetworkStackConfigByIdAsync(request.NetworkStackConfigId, cancellationToken); |
|||
if (existingConfig == null) |
|||
{ |
|||
_logger.LogWarning("网络栈配置不存在: {NetworkStackConfigId}", request.NetworkStackConfigId); |
|||
return OperationResult<UpdateNetworkStackConfigResponse>.CreateFailure($"网络栈配置 {request.NetworkStackConfigId} 不存在"); |
|||
} |
|||
|
|||
// 获取当前用户ID
|
|||
var currentUserId = _currentUserService.GetCurrentUserId(); |
|||
if (string.IsNullOrEmpty(currentUserId)) |
|||
{ |
|||
_logger.LogError("无法获取当前用户ID,用户可能未认证"); |
|||
return OperationResult<UpdateNetworkStackConfigResponse>.CreateFailure("用户未认证,无法更新网络栈配置"); |
|||
} |
|||
|
|||
// 更新网络栈配置
|
|||
existingConfig.Update( |
|||
updatedBy: currentUserId, |
|||
ranId: request.RanId, |
|||
description: request.Description, |
|||
isActive: request.IsActive); |
|||
|
|||
// 保存更改
|
|||
_networkStackConfigRepository.UpdateNetworkStackConfig(existingConfig); |
|||
await _unitOfWork.SaveChangesAsync(cancellationToken); |
|||
|
|||
// 构建响应
|
|||
var response = new UpdateNetworkStackConfigResponse |
|||
{ |
|||
NetworkStackConfigId = existingConfig.Id, |
|||
StackId = existingConfig.StackId, |
|||
RanId = existingConfig.RanId, |
|||
Description = existingConfig.Description, |
|||
IsActive = existingConfig.IsActive, |
|||
UpdatedAt = existingConfig.UpdatedAt |
|||
}; |
|||
|
|||
_logger.LogInformation("网络栈配置更新成功,配置ID: {NetworkStackConfigId}, 栈ID: {StackId}", |
|||
existingConfig.Id, existingConfig.StackId); |
|||
return OperationResult<UpdateNetworkStackConfigResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "更新网络栈配置时发生错误,配置ID: {NetworkStackConfigId}", request.NetworkStackConfigId); |
|||
return OperationResult<UpdateNetworkStackConfigResponse>.CreateFailure($"更新网络栈配置时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
namespace CellularManagement.Application.Features.NetworkStackConfigs.Commands.UpdateNetworkStackConfig; |
|||
|
|||
/// <summary>
|
|||
/// 更新网络栈配置响应
|
|||
/// </summary>
|
|||
public class UpdateNetworkStackConfigResponse |
|||
{ |
|||
/// <summary>
|
|||
/// 网络栈配置ID
|
|||
/// </summary>
|
|||
public string NetworkStackConfigId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 栈ID(主键)
|
|||
/// </summary>
|
|||
public string StackId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// RAN配置ID(外键,可为空)
|
|||
/// </summary>
|
|||
public string? RanId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 描述
|
|||
/// </summary>
|
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否激活
|
|||
/// </summary>
|
|||
public bool IsActive { 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.NetworkStackConfigs.Queries.GetNetworkStackConfigById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取网络栈配置查询
|
|||
/// </summary>
|
|||
public class GetNetworkStackConfigByIdQuery : IRequest<OperationResult<GetNetworkStackConfigByIdResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 网络栈配置ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string NetworkStackConfigId { get; set; } = null!; |
|||
} |
@ -0,0 +1,68 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkStackConfigs.Queries.GetNetworkStackConfigById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取网络栈配置查询处理器
|
|||
/// </summary>
|
|||
public class GetNetworkStackConfigByIdQueryHandler : IRequestHandler<GetNetworkStackConfigByIdQuery, OperationResult<GetNetworkStackConfigByIdResponse>> |
|||
{ |
|||
private readonly INetworkStackConfigRepository _networkStackConfigRepository; |
|||
private readonly ILogger<GetNetworkStackConfigByIdQueryHandler> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 初始化查询处理器
|
|||
/// </summary>
|
|||
public GetNetworkStackConfigByIdQueryHandler( |
|||
INetworkStackConfigRepository networkStackConfigRepository, |
|||
ILogger<GetNetworkStackConfigByIdQueryHandler> logger) |
|||
{ |
|||
_networkStackConfigRepository = networkStackConfigRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理根据ID获取网络栈配置查询
|
|||
/// </summary>
|
|||
public async Task<OperationResult<GetNetworkStackConfigByIdResponse>> Handle(GetNetworkStackConfigByIdQuery request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始获取网络栈配置,配置ID: {NetworkStackConfigId}", request.NetworkStackConfigId); |
|||
|
|||
// 获取网络栈配置
|
|||
var networkStackConfig = await _networkStackConfigRepository.GetNetworkStackConfigByIdAsync(request.NetworkStackConfigId, cancellationToken); |
|||
if (networkStackConfig == null) |
|||
{ |
|||
_logger.LogWarning("网络栈配置不存在: {NetworkStackConfigId}", request.NetworkStackConfigId); |
|||
return OperationResult<GetNetworkStackConfigByIdResponse>.CreateFailure($"网络栈配置 {request.NetworkStackConfigId} 不存在"); |
|||
} |
|||
|
|||
// 构建响应
|
|||
var response = new GetNetworkStackConfigByIdResponse |
|||
{ |
|||
NetworkStackConfigId = networkStackConfig.Id, |
|||
StackId = networkStackConfig.StackId, |
|||
RanId = networkStackConfig.RanId, |
|||
Description = networkStackConfig.Description, |
|||
IsActive = networkStackConfig.IsActive, |
|||
CreatedAt = networkStackConfig.CreatedAt, |
|||
UpdatedAt = networkStackConfig.UpdatedAt, |
|||
CreatedBy = networkStackConfig.CreatedBy, |
|||
UpdatedBy = networkStackConfig.UpdatedBy |
|||
}; |
|||
|
|||
_logger.LogInformation("成功获取网络栈配置,配置ID: {NetworkStackConfigId}, 栈ID: {StackId}", |
|||
networkStackConfig.Id, networkStackConfig.StackId); |
|||
return OperationResult<GetNetworkStackConfigByIdResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "获取网络栈配置时发生错误,配置ID: {NetworkStackConfigId}", request.NetworkStackConfigId); |
|||
return OperationResult<GetNetworkStackConfigByIdResponse>.CreateFailure($"获取网络栈配置时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,52 @@ |
|||
namespace CellularManagement.Application.Features.NetworkStackConfigs.Queries.GetNetworkStackConfigById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取网络栈配置响应
|
|||
/// </summary>
|
|||
public class GetNetworkStackConfigByIdResponse |
|||
{ |
|||
/// <summary>
|
|||
/// 网络栈配置ID
|
|||
/// </summary>
|
|||
public string NetworkStackConfigId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 栈ID(主键)
|
|||
/// </summary>
|
|||
public string StackId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// RAN配置ID(外键,可为空)
|
|||
/// </summary>
|
|||
public string? RanId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 描述
|
|||
/// </summary>
|
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否激活
|
|||
/// </summary>
|
|||
public bool IsActive { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 创建时间
|
|||
/// </summary>
|
|||
public DateTime CreatedAt { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 更新时间
|
|||
/// </summary>
|
|||
public DateTime? UpdatedAt { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 创建者
|
|||
/// </summary>
|
|||
public string CreatedBy { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 更新者
|
|||
/// </summary>
|
|||
public string? UpdatedBy { get; set; } |
|||
} |
@ -0,0 +1,40 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkStackConfigs.Queries.GetNetworkStackConfigs; |
|||
|
|||
/// <summary>
|
|||
/// 获取网络栈配置列表查询
|
|||
/// </summary>
|
|||
public class GetNetworkStackConfigsQuery : IRequest<OperationResult<GetNetworkStackConfigsResponse>> |
|||
{ |
|||
/// <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>
|
|||
/// 搜索关键词(栈ID或描述)
|
|||
/// </summary>
|
|||
[MaxLength(100, ErrorMessage = "搜索关键词不能超过100个字符")] |
|||
public string? SearchTerm { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否激活过滤
|
|||
/// </summary>
|
|||
public bool? IsActive { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// RAN配置ID过滤
|
|||
/// </summary>
|
|||
[MaxLength(50, ErrorMessage = "RAN配置ID不能超过50个字符")] |
|||
public string? RanId { get; set; } |
|||
} |
@ -0,0 +1,96 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkStackConfigs.Queries.GetNetworkStackConfigs; |
|||
|
|||
/// <summary>
|
|||
/// 获取网络栈配置列表查询处理器
|
|||
/// </summary>
|
|||
public class GetNetworkStackConfigsQueryHandler : IRequestHandler<GetNetworkStackConfigsQuery, OperationResult<GetNetworkStackConfigsResponse>> |
|||
{ |
|||
private readonly INetworkStackConfigRepository _networkStackConfigRepository; |
|||
private readonly ILogger<GetNetworkStackConfigsQueryHandler> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 初始化查询处理器
|
|||
/// </summary>
|
|||
public GetNetworkStackConfigsQueryHandler( |
|||
INetworkStackConfigRepository networkStackConfigRepository, |
|||
ILogger<GetNetworkStackConfigsQueryHandler> logger) |
|||
{ |
|||
_networkStackConfigRepository = networkStackConfigRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理获取网络栈配置列表查询
|
|||
/// </summary>
|
|||
public async Task<OperationResult<GetNetworkStackConfigsResponse>> Handle(GetNetworkStackConfigsQuery request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始获取网络栈配置列表,页码: {PageNumber}, 每页大小: {PageSize}", |
|||
request.PageNumber, request.PageSize); |
|||
|
|||
// 搜索网络栈配置
|
|||
var (totalCount, networkStackConfigs) = await _networkStackConfigRepository.SearchNetworkStackConfigsAsync( |
|||
keyword: request.SearchTerm, |
|||
pageNumber: request.PageNumber, |
|||
pageSize: request.PageSize, |
|||
cancellationToken); |
|||
|
|||
// 应用额外的过滤条件
|
|||
if (request.IsActive.HasValue) |
|||
{ |
|||
networkStackConfigs = networkStackConfigs.Where(config => config.IsActive == request.IsActive.Value).ToList(); |
|||
} |
|||
|
|||
if (!string.IsNullOrEmpty(request.RanId)) |
|||
{ |
|||
networkStackConfigs = networkStackConfigs.Where(config => config.RanId == request.RanId).ToList(); |
|||
} |
|||
|
|||
// 计算分页信息
|
|||
var totalPages = (int)Math.Ceiling((double)totalCount / request.PageSize); |
|||
var hasPreviousPage = request.PageNumber > 1; |
|||
var hasNextPage = request.PageNumber < totalPages; |
|||
|
|||
// 构建DTO列表
|
|||
var networkStackConfigDtos = networkStackConfigs.Select(config => new NetworkStackConfigDto |
|||
{ |
|||
NetworkStackConfigId = config.Id, |
|||
StackId = config.StackId, |
|||
RanId = config.RanId, |
|||
Description = config.Description, |
|||
IsActive = config.IsActive, |
|||
CreatedAt = config.CreatedAt, |
|||
UpdatedAt = config.UpdatedAt, |
|||
CreatedBy = config.CreatedBy, |
|||
UpdatedBy = config.UpdatedBy |
|||
}).ToList(); |
|||
|
|||
// 构建响应
|
|||
var response = new GetNetworkStackConfigsResponse |
|||
{ |
|||
NetworkStackConfigs = networkStackConfigDtos, |
|||
TotalCount = totalCount, |
|||
TotalPages = totalPages, |
|||
PageNumber = request.PageNumber, |
|||
PageSize = request.PageSize, |
|||
HasPreviousPage = hasPreviousPage, |
|||
HasNextPage = hasNextPage |
|||
}; |
|||
|
|||
_logger.LogInformation("成功获取网络栈配置列表,总数: {TotalCount}, 当前页: {PageNumber}/{TotalPages}", |
|||
totalCount, request.PageNumber, totalPages); |
|||
return OperationResult<GetNetworkStackConfigsResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "获取网络栈配置列表时发生错误"); |
|||
return OperationResult<GetNetworkStackConfigsResponse>.CreateFailure($"获取网络栈配置列表时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,93 @@ |
|||
namespace CellularManagement.Application.Features.NetworkStackConfigs.Queries.GetNetworkStackConfigs; |
|||
|
|||
/// <summary>
|
|||
/// 获取网络栈配置列表响应
|
|||
/// </summary>
|
|||
public class GetNetworkStackConfigsResponse |
|||
{ |
|||
/// <summary>
|
|||
/// 网络栈配置列表
|
|||
/// </summary>
|
|||
public List<NetworkStackConfigDto> NetworkStackConfigs { get; set; } = new(); |
|||
|
|||
/// <summary>
|
|||
/// 总记录数
|
|||
/// </summary>
|
|||
public int TotalCount { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 总页数
|
|||
/// </summary>
|
|||
public int TotalPages { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 当前页码
|
|||
/// </summary>
|
|||
public int PageNumber { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 每页大小
|
|||
/// </summary>
|
|||
public int PageSize { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否有上一页
|
|||
/// </summary>
|
|||
public bool HasPreviousPage { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否有下一页
|
|||
/// </summary>
|
|||
public bool HasNextPage { get; set; } |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 网络栈配置DTO
|
|||
/// </summary>
|
|||
public class NetworkStackConfigDto |
|||
{ |
|||
/// <summary>
|
|||
/// 网络栈配置ID
|
|||
/// </summary>
|
|||
public string NetworkStackConfigId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 栈ID(主键)
|
|||
/// </summary>
|
|||
public string StackId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// RAN配置ID(外键,可为空)
|
|||
/// </summary>
|
|||
public string? RanId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 描述
|
|||
/// </summary>
|
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否激活
|
|||
/// </summary>
|
|||
public bool IsActive { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 创建时间
|
|||
/// </summary>
|
|||
public DateTime CreatedAt { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 更新时间
|
|||
/// </summary>
|
|||
public DateTime? UpdatedAt { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 创建者
|
|||
/// </summary>
|
|||
public string CreatedBy { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 更新者
|
|||
/// </summary>
|
|||
public string? UpdatedBy { get; set; } |
|||
} |
@ -0,0 +1,35 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.RANConfiguration.Commands.CreateRAN_Configuration; |
|||
|
|||
/// <summary>
|
|||
/// 创建RAN配置命令
|
|||
/// </summary>
|
|||
public class CreateRAN_ConfigurationCommand : IRequest<OperationResult<CreateRAN_ConfigurationResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "配置名称不能为空")] |
|||
[MaxLength(100, ErrorMessage = "配置名称不能超过100个字符")] |
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置内容(JSON格式)
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "配置内容不能为空")] |
|||
public string ConfigContent { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置描述
|
|||
/// </summary>
|
|||
[MaxLength(500, ErrorMessage = "配置描述不能超过500个字符")] |
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否禁用
|
|||
/// </summary>
|
|||
public bool IsDisabled { get; set; } = false; |
|||
} |
@ -0,0 +1,95 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories.Base; |
|||
using CellularManagement.Domain.Services; |
|||
using CellularManagement.Domain.Entities.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.RANConfiguration.Commands.CreateRAN_Configuration; |
|||
|
|||
/// <summary>
|
|||
/// 创建RAN配置命令处理器
|
|||
/// </summary>
|
|||
public class CreateRAN_ConfigurationCommandHandler : IRequestHandler<CreateRAN_ConfigurationCommand, OperationResult<CreateRAN_ConfigurationResponse>> |
|||
{ |
|||
private readonly IRAN_ConfigurationRepository _ranConfigurationRepository; |
|||
private readonly ILogger<CreateRAN_ConfigurationCommandHandler> _logger; |
|||
private readonly IUnitOfWork _unitOfWork; |
|||
private readonly ICurrentUserService _currentUserService; |
|||
|
|||
/// <summary>
|
|||
/// 初始化命令处理器
|
|||
/// </summary>
|
|||
public CreateRAN_ConfigurationCommandHandler( |
|||
IRAN_ConfigurationRepository ranConfigurationRepository, |
|||
ILogger<CreateRAN_ConfigurationCommandHandler> logger, |
|||
IUnitOfWork unitOfWork, |
|||
ICurrentUserService currentUserService) |
|||
{ |
|||
_ranConfigurationRepository = ranConfigurationRepository; |
|||
_logger = logger; |
|||
_unitOfWork = unitOfWork; |
|||
_currentUserService = currentUserService; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理创建RAN配置命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<CreateRAN_ConfigurationResponse>> Handle(CreateRAN_ConfigurationCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始创建RAN配置,配置名称: {Name}", request.Name); |
|||
|
|||
// 检查配置名称是否已存在
|
|||
if (await _ranConfigurationRepository.NameExistsAsync(request.Name, cancellationToken)) |
|||
{ |
|||
_logger.LogWarning("RAN配置名称已存在: {Name}", request.Name); |
|||
return OperationResult<CreateRAN_ConfigurationResponse>.CreateFailure($"RAN配置名称 {request.Name} 已存在"); |
|||
} |
|||
|
|||
// 获取当前用户ID
|
|||
var currentUserId = _currentUserService.GetCurrentUserId(); |
|||
if (string.IsNullOrEmpty(currentUserId)) |
|||
{ |
|||
_logger.LogError("无法获取当前用户ID,用户可能未认证"); |
|||
return OperationResult<CreateRAN_ConfigurationResponse>.CreateFailure("用户未认证,无法创建RAN配置"); |
|||
} |
|||
|
|||
// 创建RAN配置实体
|
|||
var ranConfiguration = RAN_Configuration.Create( |
|||
name: request.Name, |
|||
configContent: request.ConfigContent, |
|||
createdBy: currentUserId, |
|||
description: request.Description, |
|||
isDisabled: request.IsDisabled); |
|||
|
|||
// 保存RAN配置
|
|||
await _ranConfigurationRepository.AddRAN_ConfigurationAsync(ranConfiguration, cancellationToken); |
|||
|
|||
// 保存更改到数据库
|
|||
await _unitOfWork.SaveChangesAsync(cancellationToken); |
|||
|
|||
// 构建响应
|
|||
var response = new CreateRAN_ConfigurationResponse |
|||
{ |
|||
RAN_ConfigurationId = ranConfiguration.Id, |
|||
Name = ranConfiguration.Name, |
|||
ConfigContent = ranConfiguration.ConfigContent, |
|||
Description = ranConfiguration.Description, |
|||
IsDisabled = ranConfiguration.IsDisabled, |
|||
CreatedAt = ranConfiguration.CreatedAt |
|||
}; |
|||
|
|||
_logger.LogInformation("RAN配置创建成功,配置ID: {RAN_ConfigurationId}, 配置名称: {Name}", |
|||
ranConfiguration.Id, ranConfiguration.Name); |
|||
return OperationResult<CreateRAN_ConfigurationResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "创建RAN配置时发生错误,配置名称: {Name}", request.Name); |
|||
return OperationResult<CreateRAN_ConfigurationResponse>.CreateFailure($"创建RAN配置时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
namespace CellularManagement.Application.Features.RANConfiguration.Commands.CreateRAN_Configuration; |
|||
|
|||
/// <summary>
|
|||
/// 创建RAN配置响应
|
|||
/// </summary>
|
|||
public class CreateRAN_ConfigurationResponse |
|||
{ |
|||
/// <summary>
|
|||
/// RAN配置ID
|
|||
/// </summary>
|
|||
public string RAN_ConfigurationId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置内容(JSON格式)
|
|||
/// </summary>
|
|||
public string ConfigContent { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置描述
|
|||
/// </summary>
|
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否禁用
|
|||
/// </summary>
|
|||
public bool IsDisabled { 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.RANConfiguration.Commands.DeleteRAN_Configuration; |
|||
|
|||
/// <summary>
|
|||
/// 删除RAN配置命令
|
|||
/// </summary>
|
|||
public class DeleteRAN_ConfigurationCommand : IRequest<OperationResult<bool>> |
|||
{ |
|||
/// <summary>
|
|||
/// RAN配置ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string RAN_ConfigurationId { get; set; } = null!; |
|||
} |
@ -0,0 +1,63 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories.Base; |
|||
|
|||
namespace CellularManagement.Application.Features.RANConfiguration.Commands.DeleteRAN_Configuration; |
|||
|
|||
/// <summary>
|
|||
/// 删除RAN配置命令处理器
|
|||
/// </summary>
|
|||
public class DeleteRAN_ConfigurationCommandHandler : IRequestHandler<DeleteRAN_ConfigurationCommand, OperationResult<bool>> |
|||
{ |
|||
private readonly IRAN_ConfigurationRepository _ranConfigurationRepository; |
|||
private readonly ILogger<DeleteRAN_ConfigurationCommandHandler> _logger; |
|||
private readonly IUnitOfWork _unitOfWork; |
|||
|
|||
/// <summary>
|
|||
/// 初始化删除RAN配置命令处理器
|
|||
/// </summary>
|
|||
public DeleteRAN_ConfigurationCommandHandler( |
|||
IRAN_ConfigurationRepository ranConfigurationRepository, |
|||
ILogger<DeleteRAN_ConfigurationCommandHandler> logger, |
|||
IUnitOfWork unitOfWork) |
|||
{ |
|||
_ranConfigurationRepository = ranConfigurationRepository; |
|||
_logger = logger; |
|||
_unitOfWork = unitOfWork; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理删除RAN配置命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<bool>> Handle(DeleteRAN_ConfigurationCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始处理删除RAN配置命令,配置ID: {RAN_ConfigurationId}", request.RAN_ConfigurationId); |
|||
|
|||
// 检查RAN配置是否存在
|
|||
var ranConfiguration = await _ranConfigurationRepository.GetRAN_ConfigurationByIdAsync(request.RAN_ConfigurationId, cancellationToken); |
|||
if (ranConfiguration == null) |
|||
{ |
|||
_logger.LogWarning("未找到RAN配置,配置ID: {RAN_ConfigurationId}", request.RAN_ConfigurationId); |
|||
return OperationResult<bool>.CreateFailure($"未找到ID为 {request.RAN_ConfigurationId} 的RAN配置"); |
|||
} |
|||
|
|||
// 删除RAN配置
|
|||
await _ranConfigurationRepository.DeleteRAN_ConfigurationAsync(request.RAN_ConfigurationId, cancellationToken); |
|||
|
|||
// 保存更改到数据库
|
|||
await _unitOfWork.SaveChangesAsync(cancellationToken); |
|||
|
|||
_logger.LogInformation("RAN配置删除成功,配置ID: {RAN_ConfigurationId}", request.RAN_ConfigurationId); |
|||
return OperationResult<bool>.CreateSuccess("RAN配置删除成功", true); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "删除RAN配置时发生错误,配置ID: {RAN_ConfigurationId}", request.RAN_ConfigurationId); |
|||
return OperationResult<bool>.CreateFailure($"删除RAN配置时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -1,44 +1,37 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using CellularManagement.Domain.Entities.Device; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.NetworkConfigs.Commands.UpdateNetworkConfig; |
|||
namespace CellularManagement.Application.Features.RANConfiguration.Commands.UpdateRAN_Configuration; |
|||
|
|||
/// <summary>
|
|||
/// 更新网络配置命令
|
|||
/// 更新RAN配置命令
|
|||
/// </summary>
|
|||
public class UpdateNetworkConfigCommand : IRequest<OperationResult<UpdateNetworkConfigResponse>> |
|||
public class UpdateRAN_ConfigurationCommand : IRequest<OperationResult<UpdateRAN_ConfigurationResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 网络配置ID
|
|||
/// RAN配置ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string NetworkConfigId { get; set; } = null!; |
|||
public string RAN_ConfigurationId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
[Required] |
|||
[MaxLength(100)] |
|||
[Required(ErrorMessage = "配置名称不能为空")] |
|||
[MaxLength(100, ErrorMessage = "配置名称不能超过100个字符")] |
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// PLMN字段(移动国家代码+移动网络代码)
|
|||
/// </summary>
|
|||
[MaxLength(10)] |
|||
public string? Plmn { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 配置内容(JSON格式)
|
|||
/// </summary>
|
|||
[Required] |
|||
[Required(ErrorMessage = "配置内容不能为空")] |
|||
public string ConfigContent { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置说明
|
|||
/// 配置描述
|
|||
/// </summary>
|
|||
[MaxLength(500)] |
|||
[MaxLength(500, ErrorMessage = "配置描述不能超过500个字符")] |
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
@ -0,0 +1,107 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Entities.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories.Base; |
|||
using CellularManagement.Domain.Services; |
|||
|
|||
namespace CellularManagement.Application.Features.RANConfiguration.Commands.UpdateRAN_Configuration; |
|||
|
|||
/// <summary>
|
|||
/// 更新RAN配置命令处理器
|
|||
/// </summary>
|
|||
public class UpdateRAN_ConfigurationCommandHandler : IRequestHandler<UpdateRAN_ConfigurationCommand, OperationResult<UpdateRAN_ConfigurationResponse>> |
|||
{ |
|||
private readonly IRAN_ConfigurationRepository _ranConfigurationRepository; |
|||
private readonly ILogger<UpdateRAN_ConfigurationCommandHandler> _logger; |
|||
private readonly IUnitOfWork _unitOfWork; |
|||
private readonly ICurrentUserService _currentUserService; |
|||
|
|||
/// <summary>
|
|||
/// 初始化命令处理器
|
|||
/// </summary>
|
|||
public UpdateRAN_ConfigurationCommandHandler( |
|||
IRAN_ConfigurationRepository ranConfigurationRepository, |
|||
ILogger<UpdateRAN_ConfigurationCommandHandler> logger, |
|||
IUnitOfWork unitOfWork, |
|||
ICurrentUserService currentUserService) |
|||
{ |
|||
_ranConfigurationRepository = ranConfigurationRepository; |
|||
_logger = logger; |
|||
_unitOfWork = unitOfWork; |
|||
_currentUserService = currentUserService; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理更新RAN配置命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<UpdateRAN_ConfigurationResponse>> Handle(UpdateRAN_ConfigurationCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始更新RAN配置,配置ID: {RAN_ConfigurationId}, 配置名称: {Name}", |
|||
request.RAN_ConfigurationId, request.Name); |
|||
|
|||
// 检查RAN配置是否存在
|
|||
var existingRanConfiguration = await _ranConfigurationRepository.GetRAN_ConfigurationByIdAsync(request.RAN_ConfigurationId, cancellationToken); |
|||
if (existingRanConfiguration == null) |
|||
{ |
|||
_logger.LogWarning("未找到RAN配置,配置ID: {RAN_ConfigurationId}", request.RAN_ConfigurationId); |
|||
return OperationResult<UpdateRAN_ConfigurationResponse>.CreateFailure($"未找到ID为 {request.RAN_ConfigurationId} 的RAN配置"); |
|||
} |
|||
|
|||
// 如果配置名称发生变化,检查新配置名称是否已存在
|
|||
if (existingRanConfiguration.Name != request.Name) |
|||
{ |
|||
if (await _ranConfigurationRepository.NameExistsAsync(request.Name, cancellationToken)) |
|||
{ |
|||
_logger.LogWarning("RAN配置名称已存在: {Name}", request.Name); |
|||
return OperationResult<UpdateRAN_ConfigurationResponse>.CreateFailure($"RAN配置名称 {request.Name} 已存在"); |
|||
} |
|||
} |
|||
|
|||
// 获取当前用户ID
|
|||
var currentUserId = _currentUserService.GetCurrentUserId(); |
|||
if (string.IsNullOrEmpty(currentUserId)) |
|||
{ |
|||
_logger.LogError("无法获取当前用户ID,用户可能未认证"); |
|||
return OperationResult<UpdateRAN_ConfigurationResponse>.CreateFailure("用户未认证,无法更新RAN配置"); |
|||
} |
|||
|
|||
// 更新RAN配置属性
|
|||
existingRanConfiguration.Update( |
|||
name: request.Name, |
|||
configContent: request.ConfigContent, |
|||
updatedBy: currentUserId, |
|||
description: request.Description, |
|||
isDisabled: request.IsDisabled); |
|||
|
|||
_ranConfigurationRepository.UpdateRAN_Configuration(existingRanConfiguration); |
|||
|
|||
// 保存更改到数据库
|
|||
await _unitOfWork.SaveChangesAsync(cancellationToken); |
|||
|
|||
// 构建响应
|
|||
var response = new UpdateRAN_ConfigurationResponse |
|||
{ |
|||
RAN_ConfigurationId = existingRanConfiguration.Id, |
|||
Name = existingRanConfiguration.Name, |
|||
ConfigContent = existingRanConfiguration.ConfigContent, |
|||
Description = existingRanConfiguration.Description, |
|||
IsDisabled = existingRanConfiguration.IsDisabled, |
|||
UpdatedAt = existingRanConfiguration.UpdatedAt |
|||
}; |
|||
|
|||
_logger.LogInformation("RAN配置更新成功,配置ID: {RAN_ConfigurationId}, 配置名称: {Name}", |
|||
existingRanConfiguration.Id, existingRanConfiguration.Name); |
|||
return OperationResult<UpdateRAN_ConfigurationResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "更新RAN配置时发生错误,配置ID: {RAN_ConfigurationId}, 配置名称: {Name}", |
|||
request.RAN_ConfigurationId, request.Name); |
|||
return OperationResult<UpdateRAN_ConfigurationResponse>.CreateFailure($"更新RAN配置时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
namespace CellularManagement.Application.Features.RANConfiguration.Commands.UpdateRAN_Configuration; |
|||
|
|||
/// <summary>
|
|||
/// 更新RAN配置响应
|
|||
/// </summary>
|
|||
public class UpdateRAN_ConfigurationResponse |
|||
{ |
|||
/// <summary>
|
|||
/// RAN配置ID
|
|||
/// </summary>
|
|||
public string RAN_ConfigurationId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置内容(JSON格式)
|
|||
/// </summary>
|
|||
public string ConfigContent { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置描述
|
|||
/// </summary>
|
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否禁用
|
|||
/// </summary>
|
|||
public bool IsDisabled { 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.RANConfiguration.Queries.GetRAN_ConfigurationById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取RAN配置查询
|
|||
/// </summary>
|
|||
public class GetRAN_ConfigurationByIdQuery : IRequest<OperationResult<GetRAN_ConfigurationByIdResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// RAN配置ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string RAN_ConfigurationId { get; set; } = null!; |
|||
} |
@ -0,0 +1,65 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Entities.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace CellularManagement.Application.Features.RANConfiguration.Queries.GetRAN_ConfigurationById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取RAN配置查询处理器
|
|||
/// </summary>
|
|||
public class GetRAN_ConfigurationByIdQueryHandler : IRequestHandler<GetRAN_ConfigurationByIdQuery, OperationResult<GetRAN_ConfigurationByIdResponse>> |
|||
{ |
|||
private readonly IRAN_ConfigurationRepository _ranConfigurationRepository; |
|||
private readonly ILogger<GetRAN_ConfigurationByIdQueryHandler> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 初始化查询处理器
|
|||
/// </summary>
|
|||
public GetRAN_ConfigurationByIdQueryHandler( |
|||
IRAN_ConfigurationRepository ranConfigurationRepository, |
|||
ILogger<GetRAN_ConfigurationByIdQueryHandler> logger) |
|||
{ |
|||
_ranConfigurationRepository = ranConfigurationRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理查询请求
|
|||
/// </summary>
|
|||
public async Task<OperationResult<GetRAN_ConfigurationByIdResponse>> Handle(GetRAN_ConfigurationByIdQuery request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始查询RAN配置,配置ID: {RAN_ConfigurationId}", request.RAN_ConfigurationId); |
|||
|
|||
var ranConfiguration = await _ranConfigurationRepository.GetRAN_ConfigurationByIdAsync(request.RAN_ConfigurationId, cancellationToken); |
|||
|
|||
if (ranConfiguration == null) |
|||
{ |
|||
_logger.LogWarning("未找到RAN配置,配置ID: {RAN_ConfigurationId}", request.RAN_ConfigurationId); |
|||
return OperationResult<GetRAN_ConfigurationByIdResponse>.CreateFailure($"未找到ID为 {request.RAN_ConfigurationId} 的RAN配置"); |
|||
} |
|||
|
|||
var response = new GetRAN_ConfigurationByIdResponse |
|||
{ |
|||
RAN_ConfigurationId = ranConfiguration.Id, |
|||
Name = ranConfiguration.Name, |
|||
ConfigContent = ranConfiguration.ConfigContent, |
|||
Description = ranConfiguration.Description, |
|||
IsDisabled = ranConfiguration.IsDisabled, |
|||
CreatedAt = ranConfiguration.CreatedAt, |
|||
UpdatedAt = ranConfiguration.UpdatedAt |
|||
}; |
|||
|
|||
_logger.LogInformation("成功查询到RAN配置,配置ID: {RAN_ConfigurationId}", request.RAN_ConfigurationId); |
|||
return OperationResult<GetRAN_ConfigurationByIdResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "查询RAN配置时发生错误,配置ID: {RAN_ConfigurationId}", request.RAN_ConfigurationId); |
|||
return OperationResult<GetRAN_ConfigurationByIdResponse>.CreateFailure($"查询RAN配置时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,42 @@ |
|||
namespace CellularManagement.Application.Features.RANConfiguration.Queries.GetRAN_ConfigurationById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取RAN配置响应
|
|||
/// </summary>
|
|||
public class GetRAN_ConfigurationByIdResponse |
|||
{ |
|||
/// <summary>
|
|||
/// RAN配置ID
|
|||
/// </summary>
|
|||
public string RAN_ConfigurationId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
public string Name { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置内容(JSON格式)
|
|||
/// </summary>
|
|||
public string ConfigContent { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置描述
|
|||
/// </summary>
|
|||
public string? Description { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否禁用
|
|||
/// </summary>
|
|||
public bool IsDisabled { 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.RANConfiguration.Queries.GetRAN_Configurations; |
|||
|
|||
/// <summary>
|
|||
/// 获取RAN配置列表查询
|
|||
/// </summary>
|
|||
public class GetRAN_ConfigurationsQuery : IRequest<OperationResult<GetRAN_ConfigurationsResponse>> |
|||
{ |
|||
/// <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? IsDisabled { get; set; } |
|||
} |
@ -0,0 +1,100 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Entities.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using System.Linq; |
|||
using CellularManagement.Application.Features.RANConfiguration.Queries.GetRAN_ConfigurationById; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.RANConfiguration.Queries.GetRAN_Configurations; |
|||
|
|||
/// <summary>
|
|||
/// 获取RAN配置列表查询处理器
|
|||
/// </summary>
|
|||
public class GetRAN_ConfigurationsQueryHandler : IRequestHandler<GetRAN_ConfigurationsQuery, OperationResult<GetRAN_ConfigurationsResponse>> |
|||
{ |
|||
private readonly IRAN_ConfigurationRepository _ranConfigurationRepository; |
|||
private readonly ILogger<GetRAN_ConfigurationsQueryHandler> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 初始化查询处理器
|
|||
/// </summary>
|
|||
public GetRAN_ConfigurationsQueryHandler( |
|||
IRAN_ConfigurationRepository ranConfigurationRepository, |
|||
ILogger<GetRAN_ConfigurationsQueryHandler> logger) |
|||
{ |
|||
_ranConfigurationRepository = ranConfigurationRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理获取RAN配置列表查询
|
|||
/// </summary>
|
|||
public async Task<OperationResult<GetRAN_ConfigurationsResponse>> Handle(GetRAN_ConfigurationsQuery 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<GetRAN_ConfigurationsResponse>.CreateFailure(errorMessages); |
|||
} |
|||
|
|||
_logger.LogInformation("开始获取RAN配置列表,页码: {PageNumber}, 每页数量: {PageSize}, 搜索关键词: {SearchTerm}, 是否禁用: {IsDisabled}", |
|||
request.PageNumber, request.PageSize, request.SearchTerm, request.IsDisabled); |
|||
|
|||
// 获取RAN配置数据
|
|||
var ranConfigurations = await _ranConfigurationRepository.SearchRAN_ConfigurationsAsync( |
|||
request.SearchTerm, |
|||
cancellationToken); |
|||
|
|||
// 如果指定了禁用状态过滤
|
|||
if (request.IsDisabled.HasValue) |
|||
{ |
|||
ranConfigurations = ranConfigurations.Where(rc => rc.IsDisabled == request.IsDisabled.Value).ToList(); |
|||
} |
|||
|
|||
// 计算分页
|
|||
int totalCount = ranConfigurations.Count(); |
|||
var items = ranConfigurations |
|||
.Skip((request.PageNumber - 1) * request.PageSize) |
|||
.Take(request.PageSize) |
|||
.ToList(); |
|||
|
|||
// 构建响应
|
|||
var response = new GetRAN_ConfigurationsResponse |
|||
{ |
|||
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(rc => new GetRAN_ConfigurationByIdResponse |
|||
{ |
|||
RAN_ConfigurationId = rc.Id, |
|||
Name = rc.Name, |
|||
ConfigContent = rc.ConfigContent, |
|||
Description = rc.Description, |
|||
IsDisabled = rc.IsDisabled, |
|||
CreatedAt = rc.CreatedAt, |
|||
UpdatedAt = rc.UpdatedAt |
|||
}).ToList() |
|||
}; |
|||
|
|||
_logger.LogInformation("成功获取RAN配置列表,共 {Count} 条记录", items.Count); |
|||
return OperationResult<GetRAN_ConfigurationsResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "获取RAN配置列表时发生错误"); |
|||
return OperationResult<GetRAN_ConfigurationsResponse>.CreateFailure($"获取RAN配置列表时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,46 @@ |
|||
|
|||
|
|||
using CellularManagement.Application.Features.RANConfiguration.Queries.GetRAN_ConfigurationById; |
|||
|
|||
namespace CellularManagement.Application.Features.RANConfiguration.Queries.GetRAN_Configurations; |
|||
|
|||
/// <summary>
|
|||
/// 获取RAN配置列表响应
|
|||
/// </summary>
|
|||
public class GetRAN_ConfigurationsResponse |
|||
{ |
|||
/// <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>
|
|||
/// RAN配置列表
|
|||
/// </summary>
|
|||
public List<GetRAN_ConfigurationByIdResponse> Items { get; set; } = new(); |
|||
} |
@ -0,0 +1,39 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.StackCoreIMSBindings.Commands.CreateStackCoreIMSBinding; |
|||
|
|||
/// <summary>
|
|||
/// 创建栈与核心网/IMS绑定关系命令
|
|||
/// </summary>
|
|||
public class CreateStackCoreIMSBindingCommand : IRequest<OperationResult<CreateStackCoreIMSBindingResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 栈ID(外键)
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "栈ID不能为空")] |
|||
[MaxLength(50, ErrorMessage = "栈ID不能超过50个字符")] |
|||
public string StackId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 索引(主键的一部分)
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "索引不能为空")] |
|||
[Range(0, int.MaxValue, ErrorMessage = "索引必须大于等于0")] |
|||
public int Index { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 核心网配置ID(外键)
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "核心网配置ID不能为空")] |
|||
[MaxLength(50, ErrorMessage = "核心网配置ID不能超过50个字符")] |
|||
public string CnId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// IMS配置ID(外键)
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "IMS配置ID不能为空")] |
|||
[MaxLength(50, ErrorMessage = "IMS配置ID不能超过50个字符")] |
|||
public string ImsId { get; set; } = null!; |
|||
} |
@ -0,0 +1,95 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories.Base; |
|||
using CellularManagement.Domain.Services; |
|||
using CellularManagement.Domain.Entities.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.StackCoreIMSBindings.Commands.CreateStackCoreIMSBinding; |
|||
|
|||
/// <summary>
|
|||
/// 创建栈与核心网/IMS绑定关系命令处理器
|
|||
/// </summary>
|
|||
public class CreateStackCoreIMSBindingCommandHandler : IRequestHandler<CreateStackCoreIMSBindingCommand, OperationResult<CreateStackCoreIMSBindingResponse>> |
|||
{ |
|||
private readonly IStack_CoreIMS_BindingRepository _stackCoreIMSBindingRepository; |
|||
private readonly ILogger<CreateStackCoreIMSBindingCommandHandler> _logger; |
|||
private readonly IUnitOfWork _unitOfWork; |
|||
private readonly ICurrentUserService _currentUserService; |
|||
|
|||
/// <summary>
|
|||
/// 初始化命令处理器
|
|||
/// </summary>
|
|||
public CreateStackCoreIMSBindingCommandHandler( |
|||
IStack_CoreIMS_BindingRepository stackCoreIMSBindingRepository, |
|||
ILogger<CreateStackCoreIMSBindingCommandHandler> logger, |
|||
IUnitOfWork unitOfWork, |
|||
ICurrentUserService currentUserService) |
|||
{ |
|||
_stackCoreIMSBindingRepository = stackCoreIMSBindingRepository; |
|||
_logger = logger; |
|||
_unitOfWork = unitOfWork; |
|||
_currentUserService = currentUserService; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理创建栈与核心网/IMS绑定关系命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<CreateStackCoreIMSBindingResponse>> Handle(CreateStackCoreIMSBindingCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始创建栈与核心网/IMS绑定关系,栈ID: {StackId}, 索引: {Index}", request.StackId, request.Index); |
|||
|
|||
// 检查绑定关系是否已存在
|
|||
if (await _stackCoreIMSBindingRepository.StackIdAndIndexExistsAsync(request.StackId, request.Index, cancellationToken)) |
|||
{ |
|||
_logger.LogWarning("栈与核心网/IMS绑定关系已存在,栈ID: {StackId}, 索引: {Index}", request.StackId, request.Index); |
|||
return OperationResult<CreateStackCoreIMSBindingResponse>.CreateFailure($"栈与核心网/IMS绑定关系已存在,栈ID: {request.StackId}, 索引: {request.Index}"); |
|||
} |
|||
|
|||
// 获取当前用户ID
|
|||
var currentUserId = _currentUserService.GetCurrentUserId(); |
|||
if (string.IsNullOrEmpty(currentUserId)) |
|||
{ |
|||
_logger.LogError("无法获取当前用户ID,用户可能未认证"); |
|||
return OperationResult<CreateStackCoreIMSBindingResponse>.CreateFailure("用户未认证,无法创建栈与核心网/IMS绑定关系"); |
|||
} |
|||
|
|||
// 创建栈与核心网/IMS绑定关系实体
|
|||
var binding = Stack_CoreIMS_Binding.Create( |
|||
stackId: request.StackId, |
|||
index: request.Index, |
|||
cnId: request.CnId, |
|||
imsId: request.ImsId, |
|||
createdBy: currentUserId); |
|||
|
|||
// 保存绑定关系
|
|||
await _stackCoreIMSBindingRepository.AddBindingAsync(binding, cancellationToken); |
|||
|
|||
// 保存更改到数据库
|
|||
await _unitOfWork.SaveChangesAsync(cancellationToken); |
|||
|
|||
// 构建响应
|
|||
var response = new CreateStackCoreIMSBindingResponse |
|||
{ |
|||
StackCoreIMSBindingId = binding.Id, |
|||
StackId = binding.StackId, |
|||
Index = binding.Index, |
|||
CnId = binding.CnId, |
|||
ImsId = binding.ImsId, |
|||
CreatedAt = binding.CreatedAt |
|||
}; |
|||
|
|||
_logger.LogInformation("栈与核心网/IMS绑定关系创建成功,绑定ID: {BindingId}, 栈ID: {StackId}, 索引: {Index}", |
|||
binding.Id, binding.StackId, binding.Index); |
|||
return OperationResult<CreateStackCoreIMSBindingResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "创建栈与核心网/IMS绑定关系时发生错误,栈ID: {StackId}, 索引: {Index}", request.StackId, request.Index); |
|||
return OperationResult<CreateStackCoreIMSBindingResponse>.CreateFailure($"创建栈与核心网/IMS绑定关系时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
namespace CellularManagement.Application.Features.StackCoreIMSBindings.Commands.CreateStackCoreIMSBinding; |
|||
|
|||
/// <summary>
|
|||
/// 创建栈与核心网/IMS绑定关系响应
|
|||
/// </summary>
|
|||
public class CreateStackCoreIMSBindingResponse |
|||
{ |
|||
/// <summary>
|
|||
/// 绑定关系ID
|
|||
/// </summary>
|
|||
public string StackCoreIMSBindingId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 栈ID(外键)
|
|||
/// </summary>
|
|||
public string StackId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 索引(主键的一部分)
|
|||
/// </summary>
|
|||
public int Index { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 核心网配置ID(外键)
|
|||
/// </summary>
|
|||
public string CnId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// IMS配置ID(外键)
|
|||
/// </summary>
|
|||
public string ImsId { get; set; } = null!; |
|||
|
|||
/// <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.StackCoreIMSBindings.Commands.DeleteStackCoreIMSBinding; |
|||
|
|||
/// <summary>
|
|||
/// 删除栈与核心网/IMS绑定关系命令
|
|||
/// </summary>
|
|||
public class DeleteStackCoreIMSBindingCommand : IRequest<OperationResult<bool>> |
|||
{ |
|||
/// <summary>
|
|||
/// 绑定关系ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string StackCoreIMSBindingId { get; set; } = null!; |
|||
} |
@ -0,0 +1,64 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories.Base; |
|||
|
|||
namespace CellularManagement.Application.Features.StackCoreIMSBindings.Commands.DeleteStackCoreIMSBinding; |
|||
|
|||
/// <summary>
|
|||
/// 删除栈与核心网/IMS绑定关系命令处理器
|
|||
/// </summary>
|
|||
public class DeleteStackCoreIMSBindingCommandHandler : IRequestHandler<DeleteStackCoreIMSBindingCommand, OperationResult<bool>> |
|||
{ |
|||
private readonly IStack_CoreIMS_BindingRepository _stackCoreIMSBindingRepository; |
|||
private readonly ILogger<DeleteStackCoreIMSBindingCommandHandler> _logger; |
|||
private readonly IUnitOfWork _unitOfWork; |
|||
|
|||
/// <summary>
|
|||
/// 初始化命令处理器
|
|||
/// </summary>
|
|||
public DeleteStackCoreIMSBindingCommandHandler( |
|||
IStack_CoreIMS_BindingRepository stackCoreIMSBindingRepository, |
|||
ILogger<DeleteStackCoreIMSBindingCommandHandler> logger, |
|||
IUnitOfWork unitOfWork) |
|||
{ |
|||
_stackCoreIMSBindingRepository = stackCoreIMSBindingRepository; |
|||
_logger = logger; |
|||
_unitOfWork = unitOfWork; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理删除栈与核心网/IMS绑定关系命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<bool>> Handle(DeleteStackCoreIMSBindingCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始删除栈与核心网/IMS绑定关系,绑定ID: {StackCoreIMSBindingId}", request.StackCoreIMSBindingId); |
|||
|
|||
// 检查绑定关系是否存在
|
|||
var existingBinding = await _stackCoreIMSBindingRepository.GetBindingByIdAsync(request.StackCoreIMSBindingId, cancellationToken); |
|||
if (existingBinding == null) |
|||
{ |
|||
_logger.LogWarning("栈与核心网/IMS绑定关系不存在: {StackCoreIMSBindingId}", request.StackCoreIMSBindingId); |
|||
return OperationResult<bool>.CreateFailure($"栈与核心网/IMS绑定关系 {request.StackCoreIMSBindingId} 不存在"); |
|||
} |
|||
|
|||
// 删除绑定关系
|
|||
await _stackCoreIMSBindingRepository.DeleteBindingAsync(request.StackCoreIMSBindingId, cancellationToken); |
|||
|
|||
// 保存更改到数据库
|
|||
await _unitOfWork.SaveChangesAsync(cancellationToken); |
|||
|
|||
_logger.LogInformation("栈与核心网/IMS绑定关系删除成功,绑定ID: {StackCoreIMSBindingId}, 栈ID: {StackId}, 索引: {Index}", |
|||
request.StackCoreIMSBindingId, existingBinding.StackId, existingBinding.Index); |
|||
return OperationResult<bool>.CreateSuccess(true); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "删除栈与核心网/IMS绑定关系时发生错误,绑定ID: {StackCoreIMSBindingId}", request.StackCoreIMSBindingId); |
|||
return OperationResult<bool>.CreateFailure($"删除栈与核心网/IMS绑定关系时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,38 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.StackCoreIMSBindings.Commands.UpdateStackCoreIMSBinding; |
|||
|
|||
/// <summary>
|
|||
/// 更新栈与核心网/IMS绑定关系命令
|
|||
/// </summary>
|
|||
public class UpdateStackCoreIMSBindingCommand : IRequest<OperationResult<UpdateStackCoreIMSBindingResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 绑定关系ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string StackCoreIMSBindingId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 索引(主键的一部分)
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "索引不能为空")] |
|||
[Range(0, int.MaxValue, ErrorMessage = "索引必须大于等于0")] |
|||
public int Index { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 核心网配置ID(外键)
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "核心网配置ID不能为空")] |
|||
[MaxLength(50, ErrorMessage = "核心网配置ID不能超过50个字符")] |
|||
public string CnId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// IMS配置ID(外键)
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "IMS配置ID不能为空")] |
|||
[MaxLength(50, ErrorMessage = "IMS配置ID不能超过50个字符")] |
|||
public string ImsId { get; set; } = null!; |
|||
} |
@ -0,0 +1,103 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
using CellularManagement.Domain.Repositories.Base; |
|||
using CellularManagement.Domain.Services; |
|||
using CellularManagement.Domain.Entities.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.StackCoreIMSBindings.Commands.UpdateStackCoreIMSBinding; |
|||
|
|||
/// <summary>
|
|||
/// 更新栈与核心网/IMS绑定关系命令处理器
|
|||
/// </summary>
|
|||
public class UpdateStackCoreIMSBindingCommandHandler : IRequestHandler<UpdateStackCoreIMSBindingCommand, OperationResult<UpdateStackCoreIMSBindingResponse>> |
|||
{ |
|||
private readonly IStack_CoreIMS_BindingRepository _stackCoreIMSBindingRepository; |
|||
private readonly ILogger<UpdateStackCoreIMSBindingCommandHandler> _logger; |
|||
private readonly IUnitOfWork _unitOfWork; |
|||
private readonly ICurrentUserService _currentUserService; |
|||
|
|||
/// <summary>
|
|||
/// 初始化命令处理器
|
|||
/// </summary>
|
|||
public UpdateStackCoreIMSBindingCommandHandler( |
|||
IStack_CoreIMS_BindingRepository stackCoreIMSBindingRepository, |
|||
ILogger<UpdateStackCoreIMSBindingCommandHandler> logger, |
|||
IUnitOfWork unitOfWork, |
|||
ICurrentUserService currentUserService) |
|||
{ |
|||
_stackCoreIMSBindingRepository = stackCoreIMSBindingRepository; |
|||
_logger = logger; |
|||
_unitOfWork = unitOfWork; |
|||
_currentUserService = currentUserService; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理更新栈与核心网/IMS绑定关系命令
|
|||
/// </summary>
|
|||
public async Task<OperationResult<UpdateStackCoreIMSBindingResponse>> Handle(UpdateStackCoreIMSBindingCommand request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始更新栈与核心网/IMS绑定关系,绑定ID: {StackCoreIMSBindingId}", request.StackCoreIMSBindingId); |
|||
|
|||
// 检查绑定关系是否存在
|
|||
var existingBinding = await _stackCoreIMSBindingRepository.GetBindingByIdAsync(request.StackCoreIMSBindingId, cancellationToken); |
|||
if (existingBinding == null) |
|||
{ |
|||
_logger.LogWarning("栈与核心网/IMS绑定关系不存在: {StackCoreIMSBindingId}", request.StackCoreIMSBindingId); |
|||
return OperationResult<UpdateStackCoreIMSBindingResponse>.CreateFailure($"栈与核心网/IMS绑定关系 {request.StackCoreIMSBindingId} 不存在"); |
|||
} |
|||
|
|||
// 检查新索引是否与其他绑定关系冲突
|
|||
if (request.Index != existingBinding.Index) |
|||
{ |
|||
if (await _stackCoreIMSBindingRepository.StackIdAndIndexExistsAsync(existingBinding.StackId, request.Index, cancellationToken)) |
|||
{ |
|||
_logger.LogWarning("栈与核心网/IMS绑定关系索引已存在,栈ID: {StackId}, 索引: {Index}", existingBinding.StackId, request.Index); |
|||
return OperationResult<UpdateStackCoreIMSBindingResponse>.CreateFailure($"栈与核心网/IMS绑定关系索引已存在,栈ID: {existingBinding.StackId}, 索引: {request.Index}"); |
|||
} |
|||
} |
|||
|
|||
// 获取当前用户ID
|
|||
var currentUserId = _currentUserService.GetCurrentUserId(); |
|||
if (string.IsNullOrEmpty(currentUserId)) |
|||
{ |
|||
_logger.LogError("无法获取当前用户ID,用户可能未认证"); |
|||
return OperationResult<UpdateStackCoreIMSBindingResponse>.CreateFailure("用户未认证,无法更新栈与核心网/IMS绑定关系"); |
|||
} |
|||
|
|||
// 更新绑定关系
|
|||
existingBinding.Update( |
|||
index: request.Index, |
|||
cnId: request.CnId, |
|||
imsId: request.ImsId, |
|||
updatedBy: currentUserId); |
|||
|
|||
// 保存更改
|
|||
_stackCoreIMSBindingRepository.UpdateBinding(existingBinding); |
|||
await _unitOfWork.SaveChangesAsync(cancellationToken); |
|||
|
|||
// 构建响应
|
|||
var response = new UpdateStackCoreIMSBindingResponse |
|||
{ |
|||
StackCoreIMSBindingId = existingBinding.Id, |
|||
StackId = existingBinding.StackId, |
|||
Index = existingBinding.Index, |
|||
CnId = existingBinding.CnId, |
|||
ImsId = existingBinding.ImsId, |
|||
UpdatedAt = existingBinding.UpdatedAt |
|||
}; |
|||
|
|||
_logger.LogInformation("栈与核心网/IMS绑定关系更新成功,绑定ID: {BindingId}, 栈ID: {StackId}, 索引: {Index}", |
|||
existingBinding.Id, existingBinding.StackId, existingBinding.Index); |
|||
return OperationResult<UpdateStackCoreIMSBindingResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "更新栈与核心网/IMS绑定关系时发生错误,绑定ID: {StackCoreIMSBindingId}", request.StackCoreIMSBindingId); |
|||
return OperationResult<UpdateStackCoreIMSBindingResponse>.CreateFailure($"更新栈与核心网/IMS绑定关系时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
namespace CellularManagement.Application.Features.StackCoreIMSBindings.Commands.UpdateStackCoreIMSBinding; |
|||
|
|||
/// <summary>
|
|||
/// 更新栈与核心网/IMS绑定关系响应
|
|||
/// </summary>
|
|||
public class UpdateStackCoreIMSBindingResponse |
|||
{ |
|||
/// <summary>
|
|||
/// 绑定关系ID
|
|||
/// </summary>
|
|||
public string StackCoreIMSBindingId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 栈ID(外键)
|
|||
/// </summary>
|
|||
public string StackId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 索引(主键的一部分)
|
|||
/// </summary>
|
|||
public int Index { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 核心网配置ID(外键)
|
|||
/// </summary>
|
|||
public string CnId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// IMS配置ID(外键)
|
|||
/// </summary>
|
|||
public string ImsId { get; set; } = null!; |
|||
|
|||
/// <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.StackCoreIMSBindings.Queries.GetStackCoreIMSBindingById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取栈与核心网/IMS绑定关系查询
|
|||
/// </summary>
|
|||
public class GetStackCoreIMSBindingByIdQuery : IRequest<OperationResult<GetStackCoreIMSBindingByIdResponse>> |
|||
{ |
|||
/// <summary>
|
|||
/// 绑定关系ID
|
|||
/// </summary>
|
|||
[Required] |
|||
public string StackCoreIMSBindingId { get; set; } = null!; |
|||
} |
@ -0,0 +1,68 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.StackCoreIMSBindings.Queries.GetStackCoreIMSBindingById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取栈与核心网/IMS绑定关系查询处理器
|
|||
/// </summary>
|
|||
public class GetStackCoreIMSBindingByIdQueryHandler : IRequestHandler<GetStackCoreIMSBindingByIdQuery, OperationResult<GetStackCoreIMSBindingByIdResponse>> |
|||
{ |
|||
private readonly IStack_CoreIMS_BindingRepository _stackCoreIMSBindingRepository; |
|||
private readonly ILogger<GetStackCoreIMSBindingByIdQueryHandler> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 初始化查询处理器
|
|||
/// </summary>
|
|||
public GetStackCoreIMSBindingByIdQueryHandler( |
|||
IStack_CoreIMS_BindingRepository stackCoreIMSBindingRepository, |
|||
ILogger<GetStackCoreIMSBindingByIdQueryHandler> logger) |
|||
{ |
|||
_stackCoreIMSBindingRepository = stackCoreIMSBindingRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理根据ID获取栈与核心网/IMS绑定关系查询
|
|||
/// </summary>
|
|||
public async Task<OperationResult<GetStackCoreIMSBindingByIdResponse>> Handle(GetStackCoreIMSBindingByIdQuery request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始获取栈与核心网/IMS绑定关系,绑定ID: {StackCoreIMSBindingId}", request.StackCoreIMSBindingId); |
|||
|
|||
// 获取绑定关系
|
|||
var binding = await _stackCoreIMSBindingRepository.GetBindingByIdAsync(request.StackCoreIMSBindingId, cancellationToken); |
|||
if (binding == null) |
|||
{ |
|||
_logger.LogWarning("栈与核心网/IMS绑定关系不存在: {StackCoreIMSBindingId}", request.StackCoreIMSBindingId); |
|||
return OperationResult<GetStackCoreIMSBindingByIdResponse>.CreateFailure($"栈与核心网/IMS绑定关系 {request.StackCoreIMSBindingId} 不存在"); |
|||
} |
|||
|
|||
// 构建响应
|
|||
var response = new GetStackCoreIMSBindingByIdResponse |
|||
{ |
|||
StackCoreIMSBindingId = binding.Id, |
|||
StackId = binding.StackId, |
|||
Index = binding.Index, |
|||
CnId = binding.CnId, |
|||
ImsId = binding.ImsId, |
|||
CreatedAt = binding.CreatedAt, |
|||
UpdatedAt = binding.UpdatedAt, |
|||
CreatedBy = binding.CreatedBy, |
|||
UpdatedBy = binding.UpdatedBy |
|||
}; |
|||
|
|||
_logger.LogInformation("成功获取栈与核心网/IMS绑定关系,绑定ID: {StackCoreIMSBindingId}, 栈ID: {StackId}, 索引: {Index}", |
|||
binding.Id, binding.StackId, binding.Index); |
|||
return OperationResult<GetStackCoreIMSBindingByIdResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "获取栈与核心网/IMS绑定关系时发生错误,绑定ID: {StackCoreIMSBindingId}", request.StackCoreIMSBindingId); |
|||
return OperationResult<GetStackCoreIMSBindingByIdResponse>.CreateFailure($"获取栈与核心网/IMS绑定关系时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,52 @@ |
|||
namespace CellularManagement.Application.Features.StackCoreIMSBindings.Queries.GetStackCoreIMSBindingById; |
|||
|
|||
/// <summary>
|
|||
/// 根据ID获取栈与核心网/IMS绑定关系响应
|
|||
/// </summary>
|
|||
public class GetStackCoreIMSBindingByIdResponse |
|||
{ |
|||
/// <summary>
|
|||
/// 绑定关系ID
|
|||
/// </summary>
|
|||
public string StackCoreIMSBindingId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 栈ID(外键)
|
|||
/// </summary>
|
|||
public string StackId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 索引(主键的一部分)
|
|||
/// </summary>
|
|||
public int Index { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 核心网配置ID(外键)
|
|||
/// </summary>
|
|||
public string CnId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// IMS配置ID(外键)
|
|||
/// </summary>
|
|||
public string ImsId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 创建时间
|
|||
/// </summary>
|
|||
public DateTime CreatedAt { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 更新时间
|
|||
/// </summary>
|
|||
public DateTime? UpdatedAt { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 创建者
|
|||
/// </summary>
|
|||
public string CreatedBy { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 更新者
|
|||
/// </summary>
|
|||
public string UpdatedBy { get; set; } = null!; |
|||
} |
@ -0,0 +1,41 @@ |
|||
using CellularManagement.Domain.Common; |
|||
using MediatR; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CellularManagement.Application.Features.StackCoreIMSBindings.Queries.GetStackCoreIMSBindings; |
|||
|
|||
/// <summary>
|
|||
/// 获取栈与核心网/IMS绑定关系列表查询
|
|||
/// </summary>
|
|||
public class GetStackCoreIMSBindingsQuery : IRequest<OperationResult<GetStackCoreIMSBindingsResponse>> |
|||
{ |
|||
/// <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>
|
|||
/// 栈ID(可选过滤条件)
|
|||
/// </summary>
|
|||
[MaxLength(50)] |
|||
public string? StackId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 核心网配置ID(可选过滤条件)
|
|||
/// </summary>
|
|||
[MaxLength(50)] |
|||
public string? CnId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// IMS配置ID(可选过滤条件)
|
|||
/// </summary>
|
|||
[MaxLength(50)] |
|||
public string? ImsId { get; set; } |
|||
} |
@ -0,0 +1,80 @@ |
|||
using MediatR; |
|||
using Microsoft.Extensions.Logging; |
|||
using CellularManagement.Domain.Common; |
|||
using CellularManagement.Domain.Repositories.NetworkProfile; |
|||
|
|||
namespace CellularManagement.Application.Features.StackCoreIMSBindings.Queries.GetStackCoreIMSBindings; |
|||
|
|||
/// <summary>
|
|||
/// 获取栈与核心网/IMS绑定关系列表查询处理器
|
|||
/// </summary>
|
|||
public class GetStackCoreIMSBindingsQueryHandler : IRequestHandler<GetStackCoreIMSBindingsQuery, OperationResult<GetStackCoreIMSBindingsResponse>> |
|||
{ |
|||
private readonly IStack_CoreIMS_BindingRepository _stackCoreIMSBindingRepository; |
|||
private readonly ILogger<GetStackCoreIMSBindingsQueryHandler> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 初始化查询处理器
|
|||
/// </summary>
|
|||
public GetStackCoreIMSBindingsQueryHandler( |
|||
IStack_CoreIMS_BindingRepository stackCoreIMSBindingRepository, |
|||
ILogger<GetStackCoreIMSBindingsQueryHandler> logger) |
|||
{ |
|||
_stackCoreIMSBindingRepository = stackCoreIMSBindingRepository; |
|||
_logger = logger; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 处理获取栈与核心网/IMS绑定关系列表查询
|
|||
/// </summary>
|
|||
public async Task<OperationResult<GetStackCoreIMSBindingsResponse>> Handle(GetStackCoreIMSBindingsQuery request, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
_logger.LogInformation("开始获取栈与核心网/IMS绑定关系列表,页码: {PageNumber}, 每页数量: {PageSize}, 栈ID: {StackId}, 核心网配置ID: {CnId}, IMS配置ID: {ImsId}", |
|||
request.PageNumber, request.PageSize, request.StackId ?? "无", request.CnId ?? "无", request.ImsId ?? "无"); |
|||
|
|||
// 获取绑定关系列表
|
|||
var (totalCount, items) = await _stackCoreIMSBindingRepository.SearchBindingsAsync( |
|||
request.StackId, |
|||
request.CnId, |
|||
request.ImsId, |
|||
request.PageNumber, |
|||
request.PageSize, |
|||
cancellationToken); |
|||
|
|||
// 计算总页数
|
|||
var totalPages = (int)Math.Ceiling((double)totalCount / request.PageSize); |
|||
|
|||
// 构建响应
|
|||
var response = new GetStackCoreIMSBindingsResponse |
|||
{ |
|||
TotalCount = totalCount, |
|||
PageNumber = request.PageNumber, |
|||
PageSize = request.PageSize, |
|||
TotalPages = totalPages, |
|||
Items = items.Select(item => new StackCoreIMSBindingDto |
|||
{ |
|||
StackCoreIMSBindingId = item.Id, |
|||
StackId = item.StackId, |
|||
Index = item.Index, |
|||
CnId = item.CnId, |
|||
ImsId = item.ImsId, |
|||
CreatedAt = item.CreatedAt, |
|||
UpdatedAt = item.UpdatedAt, |
|||
CreatedBy = item.CreatedBy, |
|||
UpdatedBy = item.UpdatedBy |
|||
}).ToList() |
|||
}; |
|||
|
|||
_logger.LogInformation("成功获取栈与核心网/IMS绑定关系列表,总数量: {TotalCount}, 当前页数量: {ItemCount}", |
|||
totalCount, items.Count); |
|||
return OperationResult<GetStackCoreIMSBindingsResponse>.CreateSuccess(response); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "获取栈与核心网/IMS绑定关系列表时发生错误"); |
|||
return OperationResult<GetStackCoreIMSBindingsResponse>.CreateFailure($"获取栈与核心网/IMS绑定关系列表时发生错误: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,83 @@ |
|||
namespace CellularManagement.Application.Features.StackCoreIMSBindings.Queries.GetStackCoreIMSBindings; |
|||
|
|||
/// <summary>
|
|||
/// 获取栈与核心网/IMS绑定关系列表响应
|
|||
/// </summary>
|
|||
public class GetStackCoreIMSBindingsResponse |
|||
{ |
|||
/// <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>
|
|||
/// 栈与核心网/IMS绑定关系列表
|
|||
/// </summary>
|
|||
public List<StackCoreIMSBindingDto> Items { get; set; } = new(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 栈与核心网/IMS绑定关系数据传输对象
|
|||
/// </summary>
|
|||
public class StackCoreIMSBindingDto |
|||
{ |
|||
/// <summary>
|
|||
/// 绑定关系ID
|
|||
/// </summary>
|
|||
public string StackCoreIMSBindingId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 栈ID(外键)
|
|||
/// </summary>
|
|||
public string StackId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 索引(主键的一部分)
|
|||
/// </summary>
|
|||
public int Index { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 核心网配置ID(外键)
|
|||
/// </summary>
|
|||
public string CnId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// IMS配置ID(外键)
|
|||
/// </summary>
|
|||
public string ImsId { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 创建时间
|
|||
/// </summary>
|
|||
public DateTime CreatedAt { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 更新时间
|
|||
/// </summary>
|
|||
public DateTime? UpdatedAt { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 创建者
|
|||
/// </summary>
|
|||
public string CreatedBy { get; set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 更新者
|
|||
/// </summary>
|
|||
public string UpdatedBy { get; set; } = null!; |
|||
} |
@ -1,173 +0,0 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using CellularManagement.Domain.Entities.Common; |
|||
|
|||
namespace CellularManagement.Domain.Entities.Device; |
|||
|
|||
/// <summary>
|
|||
/// 网络配置类型枚举
|
|||
/// </summary>
|
|||
public enum NetworkConfigType |
|||
{ |
|||
/// <summary>
|
|||
/// RAN配置
|
|||
/// </summary>
|
|||
RAN = 1, |
|||
|
|||
/// <summary>
|
|||
/// IMS配置
|
|||
/// </summary>
|
|||
IMS = 2, |
|||
|
|||
/// <summary>
|
|||
/// MME配置
|
|||
/// </summary>
|
|||
MME = 3 |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 网络配置实体
|
|||
/// </summary>
|
|||
public class NetworkConfig : AuditableEntity |
|||
{ |
|||
private NetworkConfig() { } |
|||
|
|||
/// <summary>
|
|||
/// 配置类型
|
|||
/// </summary>
|
|||
[Required] |
|||
public NetworkConfigType ConfigType { get; private set; } |
|||
|
|||
/// <summary>
|
|||
/// 配置名称
|
|||
/// </summary>
|
|||
[Required] |
|||
[MaxLength(100)] |
|||
public string Name { get; private set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// PLMN字段(移动国家代码+移动网络代码)
|
|||
/// </summary>
|
|||
[MaxLength(10)] |
|||
public string? Plmn { get; private set; } |
|||
|
|||
/// <summary>
|
|||
/// 配置内容(JSON格式)
|
|||
/// </summary>
|
|||
[Required] |
|||
public string ConfigContent { get; private set; } = null!; |
|||
|
|||
/// <summary>
|
|||
/// 配置说明
|
|||
/// </summary>
|
|||
[MaxLength(500)] |
|||
public string? Description { get; private set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否禁用
|
|||
/// </summary>
|
|||
public bool IsDisabled { get; private set; } = false; |
|||
|
|||
/// <summary>
|
|||
/// 创建网络配置
|
|||
/// </summary>
|
|||
public static NetworkConfig Create( |
|||
NetworkConfigType configType, |
|||
string name, |
|||
string configContent, |
|||
string createdBy, |
|||
string? plmn = null, |
|||
string? description = null, |
|||
bool isDisabled = false) |
|||
{ |
|||
// 验证业务规则
|
|||
ValidateCreateParameters(configType, plmn); |
|||
|
|||
var networkConfig = new NetworkConfig |
|||
{ |
|||
Id = Guid.NewGuid().ToString(), |
|||
ConfigType = configType, |
|||
Name = name, |
|||
Plmn = plmn, |
|||
ConfigContent = configContent, |
|||
Description = description, |
|||
IsDisabled = isDisabled, |
|||
CreatedAt = DateTime.UtcNow, |
|||
UpdatedAt = DateTime.UtcNow, |
|||
CreatedBy = createdBy, |
|||
UpdatedBy = createdBy |
|||
}; |
|||
|
|||
return networkConfig; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 更新网络配置
|
|||
/// </summary>
|
|||
public void Update( |
|||
string name, |
|||
string configContent, |
|||
string updatedBy, |
|||
string? plmn = null, |
|||
string? description = null, |
|||
bool isDisabled = false) |
|||
{ |
|||
// 验证业务规则
|
|||
ValidateUpdateParameters(ConfigType, plmn); |
|||
|
|||
Name = name; |
|||
Plmn = plmn; |
|||
ConfigContent = configContent; |
|||
Description = description; |
|||
IsDisabled = isDisabled; |
|||
UpdatedAt = DateTime.UtcNow; |
|||
UpdatedBy = updatedBy; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 启用配置
|
|||
/// </summary>
|
|||
public void Enable() |
|||
{ |
|||
IsDisabled = false; |
|||
UpdatedAt = DateTime.UtcNow; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 禁用配置
|
|||
/// </summary>
|
|||
public void Disable() |
|||
{ |
|||
IsDisabled = true; |
|||
UpdatedAt = DateTime.UtcNow; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 验证创建参数
|
|||
/// </summary>
|
|||
private static void ValidateCreateParameters(NetworkConfigType configType, string? plmn) |
|||
{ |
|||
// 验证PLMN字段的必填性
|
|||
if (configType == NetworkConfigType.IMS || configType == NetworkConfigType.MME) |
|||
{ |
|||
if (string.IsNullOrWhiteSpace(plmn)) |
|||
{ |
|||
throw new ArgumentException($"PLMN字段对于{configType}类型是必填的"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 验证更新参数
|
|||
/// </summary>
|
|||
private static void ValidateUpdateParameters(NetworkConfigType configType, string? plmn) |
|||
{ |
|||
// 验证PLMN字段的必填性
|
|||
if (configType == NetworkConfigType.IMS || configType == NetworkConfigType.MME) |
|||
{ |
|||
if (string.IsNullOrWhiteSpace(plmn)) |
|||
{ |
|||
throw new ArgumentException($"PLMN字段对于{configType}类型是必填的"); |
|||
} |
|||
} |
|||
} |
|||
} |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue