Browse Source

feat: 实现完整的网络配置管理功能

- 重构 NetworkConfigs 为 CoreNetworkConfigs,避免命名冲突
- 新增 IMSConfiguration Features 实现
- 新增 NetworkStackConfigs Features 实现
- 新增 StackCoreIMSBindings Features 实现
- 新增 RANConfiguration Features 实现
- 创建对应的控制器:CoreNetworkConfigsController, IMSConfigurationController, NetworkStackConfigsController, StackCoreIMSBindingsController, RANConfigurationController
- 更新数据库上下文和依赖注入配置
- 添加完整的仓储接口和实现
- 添加 EF Core 配置类
- 修复 Devices Features 中的命名问题
feature/x1-web-request
root 7 days ago
parent
commit
6f493e78eb
  1. 35
      src/X1.Application/Features/CoreNetworkConfigs/Commands/CreateCoreNetworkConfig/CreateCoreNetworkConfigCommand.cs
  2. 95
      src/X1.Application/Features/CoreNetworkConfigs/Commands/CreateCoreNetworkConfig/CreateCoreNetworkConfigCommandHandler.cs
  3. 37
      src/X1.Application/Features/CoreNetworkConfigs/Commands/CreateCoreNetworkConfig/CreateCoreNetworkConfigResponse.cs
  4. 17
      src/X1.Application/Features/CoreNetworkConfigs/Commands/DeleteCoreNetworkConfig/DeleteCoreNetworkConfigCommand.cs
  5. 64
      src/X1.Application/Features/CoreNetworkConfigs/Commands/DeleteCoreNetworkConfig/DeleteCoreNetworkConfigCommandHandler.cs
  6. 41
      src/X1.Application/Features/CoreNetworkConfigs/Commands/UpdateCoreNetworkConfig/UpdateCoreNetworkConfigCommand.cs
  7. 102
      src/X1.Application/Features/CoreNetworkConfigs/Commands/UpdateCoreNetworkConfig/UpdateCoreNetworkConfigCommandHandler.cs
  8. 37
      src/X1.Application/Features/CoreNetworkConfigs/Commands/UpdateCoreNetworkConfig/UpdateCoreNetworkConfigResponse.cs
  9. 17
      src/X1.Application/Features/CoreNetworkConfigs/Queries/GetCoreNetworkConfigById/GetCoreNetworkConfigByIdQuery.cs
  10. 68
      src/X1.Application/Features/CoreNetworkConfigs/Queries/GetCoreNetworkConfigById/GetCoreNetworkConfigByIdQueryHandler.cs
  11. 28
      src/X1.Application/Features/CoreNetworkConfigs/Queries/GetCoreNetworkConfigById/GetCoreNetworkConfigByIdResponse.cs
  12. 34
      src/X1.Application/Features/CoreNetworkConfigs/Queries/GetCoreNetworkConfigs/GetCoreNetworkConfigsQuery.cs
  13. 78
      src/X1.Application/Features/CoreNetworkConfigs/Queries/GetCoreNetworkConfigs/GetCoreNetworkConfigsQueryHandler.cs
  14. 80
      src/X1.Application/Features/CoreNetworkConfigs/Queries/GetCoreNetworkConfigs/GetCoreNetworkConfigsResponse.cs
  15. 6
      src/X1.Application/Features/Devices/Commands/CreateDevice/CreateDeviceCommand.cs
  16. 10
      src/X1.Application/Features/Devices/Commands/CreateDevice/CreateDeviceCommandHandler.cs
  17. 5
      src/X1.Application/Features/Devices/Commands/CreateDevice/CreateDeviceResponse.cs
  18. 6
      src/X1.Application/Features/Devices/Commands/UpdateDevice/UpdateDeviceCommand.cs
  19. 10
      src/X1.Application/Features/Devices/Commands/UpdateDevice/UpdateDeviceCommandHandler.cs
  20. 5
      src/X1.Application/Features/Devices/Commands/UpdateDevice/UpdateDeviceResponse.cs
  21. 9
      src/X1.Application/Features/Devices/Queries/GetDeviceById/GetDeviceByIdQueryHandler.cs
  22. 5
      src/X1.Application/Features/Devices/Queries/GetDeviceById/GetDeviceByIdResponse.cs
  23. 7
      src/X1.Application/Features/Devices/Queries/GetDevices/GetDevicesQueryHandler.cs
  24. 35
      src/X1.Application/Features/IMSConfiguration/Commands/CreateIMS_Configuration/CreateIMS_ConfigurationCommand.cs
  25. 95
      src/X1.Application/Features/IMSConfiguration/Commands/CreateIMS_Configuration/CreateIMS_ConfigurationCommandHandler.cs
  26. 37
      src/X1.Application/Features/IMSConfiguration/Commands/CreateIMS_Configuration/CreateIMS_ConfigurationResponse.cs
  27. 17
      src/X1.Application/Features/IMSConfiguration/Commands/DeleteIMS_Configuration/DeleteIMS_ConfigurationCommand.cs
  28. 64
      src/X1.Application/Features/IMSConfiguration/Commands/DeleteIMS_Configuration/DeleteIMS_ConfigurationCommandHandler.cs
  29. 28
      src/X1.Application/Features/IMSConfiguration/Commands/UpdateIMS_Configuration/UpdateIMS_ConfigurationCommand.cs
  30. 102
      src/X1.Application/Features/IMSConfiguration/Commands/UpdateIMS_Configuration/UpdateIMS_ConfigurationCommandHandler.cs
  31. 37
      src/X1.Application/Features/IMSConfiguration/Commands/UpdateIMS_Configuration/UpdateIMS_ConfigurationResponse.cs
  32. 17
      src/X1.Application/Features/IMSConfiguration/Queries/GetIMS_ConfigurationById/GetIMS_ConfigurationByIdQuery.cs
  33. 68
      src/X1.Application/Features/IMSConfiguration/Queries/GetIMS_ConfigurationById/GetIMS_ConfigurationByIdQueryHandler.cs
  34. 52
      src/X1.Application/Features/IMSConfiguration/Queries/GetIMS_ConfigurationById/GetIMS_ConfigurationByIdResponse.cs
  35. 34
      src/X1.Application/Features/IMSConfiguration/Queries/GetIMS_Configurations/GetIMS_ConfigurationsQuery.cs
  36. 78
      src/X1.Application/Features/IMSConfiguration/Queries/GetIMS_Configurations/GetIMS_ConfigurationsQueryHandler.cs
  37. 83
      src/X1.Application/Features/IMSConfiguration/Queries/GetIMS_Configurations/GetIMS_ConfigurationsResponse.cs
  38. 85
      src/X1.Application/Features/NetworkConfigs/Commands/CreateNetworkConfig/CreateNetworkConfigCommandHandler.cs
  39. 22
      src/X1.Application/Features/NetworkConfigs/Commands/CreateNetworkConfig/CreateNetworkConfigResponse.cs
  40. 17
      src/X1.Application/Features/NetworkConfigs/Commands/DeleteNetworkConfig/DeleteNetworkConfigCommand.cs
  41. 50
      src/X1.Application/Features/NetworkConfigs/Commands/DeleteNetworkConfig/DeleteNetworkConfigCommandHandler.cs
  42. 91
      src/X1.Application/Features/NetworkConfigs/Commands/UpdateNetworkConfig/UpdateNetworkConfigCommandHandler.cs
  43. 22
      src/X1.Application/Features/NetworkConfigs/Commands/UpdateNetworkConfig/UpdateNetworkConfigResponse.cs
  44. 17
      src/X1.Application/Features/NetworkConfigs/Queries/GetNetworkConfigById/GetNetworkConfigByIdQuery.cs
  45. 63
      src/X1.Application/Features/NetworkConfigs/Queries/GetNetworkConfigById/GetNetworkConfigByIdQueryHandler.cs
  46. 46
      src/X1.Application/Features/NetworkConfigs/Queries/GetNetworkConfigs/GetNetworkConfigsQuery.cs
  47. 106
      src/X1.Application/Features/NetworkConfigs/Queries/GetNetworkConfigs/GetNetworkConfigsQueryHandler.cs
  48. 35
      src/X1.Application/Features/NetworkStackConfigs/Commands/CreateNetworkStackConfig/CreateNetworkStackConfigCommand.cs
  49. 95
      src/X1.Application/Features/NetworkStackConfigs/Commands/CreateNetworkStackConfig/CreateNetworkStackConfigCommandHandler.cs
  50. 37
      src/X1.Application/Features/NetworkStackConfigs/Commands/CreateNetworkStackConfig/CreateNetworkStackConfigResponse.cs
  51. 17
      src/X1.Application/Features/NetworkStackConfigs/Commands/DeleteNetworkStackConfig/DeleteNetworkStackConfigCommand.cs
  52. 64
      src/X1.Application/Features/NetworkStackConfigs/Commands/DeleteNetworkStackConfig/DeleteNetworkStackConfigCommandHandler.cs
  53. 34
      src/X1.Application/Features/NetworkStackConfigs/Commands/UpdateNetworkStackConfig/UpdateNetworkStackConfigCommand.cs
  54. 93
      src/X1.Application/Features/NetworkStackConfigs/Commands/UpdateNetworkStackConfig/UpdateNetworkStackConfigCommandHandler.cs
  55. 37
      src/X1.Application/Features/NetworkStackConfigs/Commands/UpdateNetworkStackConfig/UpdateNetworkStackConfigResponse.cs
  56. 17
      src/X1.Application/Features/NetworkStackConfigs/Queries/GetNetworkStackConfigById/GetNetworkStackConfigByIdQuery.cs
  57. 68
      src/X1.Application/Features/NetworkStackConfigs/Queries/GetNetworkStackConfigById/GetNetworkStackConfigByIdQueryHandler.cs
  58. 52
      src/X1.Application/Features/NetworkStackConfigs/Queries/GetNetworkStackConfigById/GetNetworkStackConfigByIdResponse.cs
  59. 40
      src/X1.Application/Features/NetworkStackConfigs/Queries/GetNetworkStackConfigs/GetNetworkStackConfigsQuery.cs
  60. 96
      src/X1.Application/Features/NetworkStackConfigs/Queries/GetNetworkStackConfigs/GetNetworkStackConfigsQueryHandler.cs
  61. 93
      src/X1.Application/Features/NetworkStackConfigs/Queries/GetNetworkStackConfigs/GetNetworkStackConfigsResponse.cs
  62. 7
      src/X1.Application/Features/ProtocolVersions/Commands/CreateProtocolVersion/CreateProtocolVersionCommand.cs
  63. 2
      src/X1.Application/Features/ProtocolVersions/Commands/CreateProtocolVersion/CreateProtocolVersionCommandHandler.cs
  64. 5
      src/X1.Application/Features/ProtocolVersions/Commands/CreateProtocolVersion/CreateProtocolVersionResponse.cs
  65. 7
      src/X1.Application/Features/ProtocolVersions/Commands/UpdateProtocolVersion/UpdateProtocolVersionCommand.cs
  66. 2
      src/X1.Application/Features/ProtocolVersions/Commands/UpdateProtocolVersion/UpdateProtocolVersionCommandHandler.cs
  67. 5
      src/X1.Application/Features/ProtocolVersions/Commands/UpdateProtocolVersion/UpdateProtocolVersionResponse.cs
  68. 1
      src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersionById/GetProtocolVersionByIdQueryHandler.cs
  69. 5
      src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersionById/GetProtocolVersionByIdResponse.cs
  70. 1
      src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersions/GetProtocolVersionsQueryHandler.cs
  71. 35
      src/X1.Application/Features/RANConfiguration/Commands/CreateRAN_Configuration/CreateRAN_ConfigurationCommand.cs
  72. 95
      src/X1.Application/Features/RANConfiguration/Commands/CreateRAN_Configuration/CreateRAN_ConfigurationCommandHandler.cs
  73. 37
      src/X1.Application/Features/RANConfiguration/Commands/CreateRAN_Configuration/CreateRAN_ConfigurationResponse.cs
  74. 17
      src/X1.Application/Features/RANConfiguration/Commands/DeleteRAN_Configuration/DeleteRAN_ConfigurationCommand.cs
  75. 63
      src/X1.Application/Features/RANConfiguration/Commands/DeleteRAN_Configuration/DeleteRAN_ConfigurationCommandHandler.cs
  76. 27
      src/X1.Application/Features/RANConfiguration/Commands/UpdateRAN_Configuration/UpdateRAN_ConfigurationCommand.cs
  77. 107
      src/X1.Application/Features/RANConfiguration/Commands/UpdateRAN_Configuration/UpdateRAN_ConfigurationCommandHandler.cs
  78. 37
      src/X1.Application/Features/RANConfiguration/Commands/UpdateRAN_Configuration/UpdateRAN_ConfigurationResponse.cs
  79. 17
      src/X1.Application/Features/RANConfiguration/Queries/GetRAN_ConfigurationById/GetRAN_ConfigurationByIdQuery.cs
  80. 65
      src/X1.Application/Features/RANConfiguration/Queries/GetRAN_ConfigurationById/GetRAN_ConfigurationByIdQueryHandler.cs
  81. 42
      src/X1.Application/Features/RANConfiguration/Queries/GetRAN_ConfigurationById/GetRAN_ConfigurationByIdResponse.cs
  82. 34
      src/X1.Application/Features/RANConfiguration/Queries/GetRAN_Configurations/GetRAN_ConfigurationsQuery.cs
  83. 100
      src/X1.Application/Features/RANConfiguration/Queries/GetRAN_Configurations/GetRAN_ConfigurationsQueryHandler.cs
  84. 46
      src/X1.Application/Features/RANConfiguration/Queries/GetRAN_Configurations/GetRAN_ConfigurationsResponse.cs
  85. 39
      src/X1.Application/Features/StackCoreIMSBindings/Commands/CreateStackCoreIMSBinding/CreateStackCoreIMSBindingCommand.cs
  86. 95
      src/X1.Application/Features/StackCoreIMSBindings/Commands/CreateStackCoreIMSBinding/CreateStackCoreIMSBindingCommandHandler.cs
  87. 37
      src/X1.Application/Features/StackCoreIMSBindings/Commands/CreateStackCoreIMSBinding/CreateStackCoreIMSBindingResponse.cs
  88. 17
      src/X1.Application/Features/StackCoreIMSBindings/Commands/DeleteStackCoreIMSBinding/DeleteStackCoreIMSBindingCommand.cs
  89. 64
      src/X1.Application/Features/StackCoreIMSBindings/Commands/DeleteStackCoreIMSBinding/DeleteStackCoreIMSBindingCommandHandler.cs
  90. 38
      src/X1.Application/Features/StackCoreIMSBindings/Commands/UpdateStackCoreIMSBinding/UpdateStackCoreIMSBindingCommand.cs
  91. 103
      src/X1.Application/Features/StackCoreIMSBindings/Commands/UpdateStackCoreIMSBinding/UpdateStackCoreIMSBindingCommandHandler.cs
  92. 37
      src/X1.Application/Features/StackCoreIMSBindings/Commands/UpdateStackCoreIMSBinding/UpdateStackCoreIMSBindingResponse.cs
  93. 17
      src/X1.Application/Features/StackCoreIMSBindings/Queries/GetStackCoreIMSBindingById/GetStackCoreIMSBindingByIdQuery.cs
  94. 68
      src/X1.Application/Features/StackCoreIMSBindings/Queries/GetStackCoreIMSBindingById/GetStackCoreIMSBindingByIdQueryHandler.cs
  95. 52
      src/X1.Application/Features/StackCoreIMSBindings/Queries/GetStackCoreIMSBindingById/GetStackCoreIMSBindingByIdResponse.cs
  96. 41
      src/X1.Application/Features/StackCoreIMSBindings/Queries/GetStackCoreIMSBindings/GetStackCoreIMSBindingsQuery.cs
  97. 80
      src/X1.Application/Features/StackCoreIMSBindings/Queries/GetStackCoreIMSBindings/GetStackCoreIMSBindingsQueryHandler.cs
  98. 83
      src/X1.Application/Features/StackCoreIMSBindings/Queries/GetStackCoreIMSBindings/GetStackCoreIMSBindingsResponse.cs
  99. 15
      src/X1.Domain/Entities/Device/CellularDevice.cs
  100. 173
      src/X1.Domain/Entities/Device/NetworkConfig.cs

35
src/X1.Application/Features/CoreNetworkConfigs/Commands/CreateCoreNetworkConfig/CreateCoreNetworkConfigCommand.cs

@ -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;
}

95
src/X1.Application/Features/CoreNetworkConfigs/Commands/CreateCoreNetworkConfig/CreateCoreNetworkConfigCommandHandler.cs

@ -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}");
}
}
}

37
src/X1.Application/Features/CoreNetworkConfigs/Commands/CreateCoreNetworkConfig/CreateCoreNetworkConfigResponse.cs

@ -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; }
}

17
src/X1.Application/Features/CoreNetworkConfigs/Commands/DeleteCoreNetworkConfig/DeleteCoreNetworkConfigCommand.cs

@ -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!;
}

64
src/X1.Application/Features/CoreNetworkConfigs/Commands/DeleteCoreNetworkConfig/DeleteCoreNetworkConfigCommandHandler.cs

@ -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}");
}
}
}

41
src/X1.Application/Features/CoreNetworkConfigs/Commands/UpdateCoreNetworkConfig/UpdateCoreNetworkConfigCommand.cs

@ -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;
}

102
src/X1.Application/Features/CoreNetworkConfigs/Commands/UpdateCoreNetworkConfig/UpdateCoreNetworkConfigCommandHandler.cs

@ -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}");
}
}
}

37
src/X1.Application/Features/CoreNetworkConfigs/Commands/UpdateCoreNetworkConfig/UpdateCoreNetworkConfigResponse.cs

@ -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; }
}

17
src/X1.Application/Features/CoreNetworkConfigs/Queries/GetCoreNetworkConfigById/GetCoreNetworkConfigByIdQuery.cs

@ -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!;
}

68
src/X1.Application/Features/CoreNetworkConfigs/Queries/GetCoreNetworkConfigById/GetCoreNetworkConfigByIdQueryHandler.cs

@ -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}");
}
}
}

28
src/X1.Application/Features/NetworkConfigs/Queries/GetNetworkConfigById/GetNetworkConfigByIdResponse.cs → src/X1.Application/Features/CoreNetworkConfigs/Queries/GetCoreNetworkConfigById/GetCoreNetworkConfigByIdResponse.cs

@ -1,21 +1,14 @@
using CellularManagement.Domain.Entities.Device;
namespace CellularManagement.Application.Features.NetworkConfigs.Queries.GetNetworkConfigById;
namespace CellularManagement.Application.Features.CoreNetworkConfigs.Queries.GetCoreNetworkConfigById;
/// <summary>
/// 根据ID获取网配置响应
/// 根据ID获取核心网配置响应
/// </summary>
public class GetNetworkConfigByIdResponse
public class GetCoreNetworkConfigByIdResponse
{
/// <summary>
/// 配置ID
/// </summary>
public string Id { get; set; } = null!;
/// <summary>
/// 配置类型
/// 核心网配置ID
/// </summary>
public NetworkConfigType ConfigType { get; set; }
public string CoreNetworkConfigId { get; set; } = null!;
/// <summary>
/// 配置名称
@ -23,17 +16,12 @@ public class GetNetworkConfigByIdResponse
public string Name { get; set; } = null!;
/// <summary>
/// PLMN字段
/// </summary>
public string? Plmn { get; set; }
/// <summary>
/// 配置内容
/// 配置内容(JSON格式)
/// </summary>
public string ConfigContent { get; set; } = null!;
/// <summary>
/// 配置说明
/// 配置描述
/// </summary>
public string? Description { get; set; }
@ -60,5 +48,5 @@ public class GetNetworkConfigByIdResponse
/// <summary>
/// 更新者
/// </summary>
public string? UpdatedBy { get; set; } = null!;
public string UpdatedBy { get; set; } = null!;
}

34
src/X1.Application/Features/CoreNetworkConfigs/Queries/GetCoreNetworkConfigs/GetCoreNetworkConfigsQuery.cs

@ -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; }
}

78
src/X1.Application/Features/CoreNetworkConfigs/Queries/GetCoreNetworkConfigs/GetCoreNetworkConfigsQueryHandler.cs

@ -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}");
}
}
}

80
src/X1.Application/Features/NetworkConfigs/Queries/GetNetworkConfigs/GetNetworkConfigsResponse.cs → src/X1.Application/Features/CoreNetworkConfigs/Queries/GetCoreNetworkConfigs/GetCoreNetworkConfigsResponse.cs

@ -1,39 +1,58 @@
using CellularManagement.Domain.Entities.Device;
namespace CellularManagement.Application.Features.NetworkConfigs.Queries.GetNetworkConfigs;
namespace CellularManagement.Application.Features.CoreNetworkConfigs.Queries.GetCoreNetworkConfigs;
/// <summary>
/// 网络配置信息
/// 获取核心网配置列表响应
/// </summary>
public class NetworkConfigDto
public class GetCoreNetworkConfigsResponse
{
/// <summary>
/// 配置ID
/// 总数量
/// </summary>
public string Id { get; set; } = null!;
public int TotalCount { get; set; }
/// <summary>
/// 配置类型
/// 当前页码
/// </summary>
public NetworkConfigType ConfigType { get; set; }
public int PageNumber { get; set; }
/// <summary>
/// 配置名称
/// 每页数量
/// </summary>
public string Name { get; set; } = null!;
public int PageSize { get; set; }
/// <summary>
/// 总页数
/// </summary>
public int TotalPages { get; set; }
/// <summary>
/// PLMN字段
/// 核心网配置列表
/// </summary>
public string? Plmn { get; set; }
public List<CoreNetworkConfigDto> Items { get; set; } = new();
}
/// <summary>
/// 核心网配置数据传输对象
/// </summary>
public class CoreNetworkConfigDto
{
/// <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; }
@ -61,35 +80,4 @@ public class NetworkConfigDto
/// 更新者
/// </summary>
public string UpdatedBy { get; set; } = null!;
}
/// <summary>
/// 获取网络配置列表响应
/// </summary>
public class GetNetworkConfigsResponse
{
/// <summary>
/// 网络配置列表
/// </summary>
public List<NetworkConfigDto> NetworkConfigs { get; set; } = new();
/// <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; }
}

6
src/X1.Application/Features/Devices/Commands/CreateDevice/CreateDeviceCommand.cs

@ -30,11 +30,7 @@ public class CreateDeviceCommand : IRequest<OperationResult<CreateDeviceResponse
[MaxLength(500, ErrorMessage = "设备描述不能超过500个字符")]
public string Description { get; set; }
/// <summary>
/// 协议版本ID
/// </summary>
[Required(ErrorMessage = "协议版本不能为空")]
public string ProtocolVersionId { get; set; }
/// <summary>
/// IP地址
/// </summary>

10
src/X1.Application/Features/Devices/Commands/CreateDevice/CreateDeviceCommandHandler.cs

@ -15,7 +15,6 @@ namespace CellularManagement.Application.Features.Devices.Commands.CreateDevice;
public class CreateDeviceCommandHandler : IRequestHandler<CreateDeviceCommand, OperationResult<CreateDeviceResponse>>
{
private readonly ICellularDeviceRepository _deviceRepository;
private readonly IProtocolVersionRepository _protocolVersionRepository;
private readonly ILogger<CreateDeviceCommandHandler> _logger;
private readonly IUnitOfWork _unitOfWork;
private readonly ICurrentUserService _currentUserService;
@ -25,13 +24,11 @@ public class CreateDeviceCommandHandler : IRequestHandler<CreateDeviceCommand, O
/// </summary>
public CreateDeviceCommandHandler(
ICellularDeviceRepository deviceRepository,
IProtocolVersionRepository protocolVersionRepository,
ILogger<CreateDeviceCommandHandler> logger,
IUnitOfWork unitOfWork,
ICurrentUserService currentUserService)
{
_deviceRepository = deviceRepository;
_protocolVersionRepository = protocolVersionRepository;
_logger = logger;
_unitOfWork = unitOfWork;
_currentUserService = currentUserService;
@ -67,7 +64,6 @@ public class CreateDeviceCommandHandler : IRequestHandler<CreateDeviceCommand, O
name: request.DeviceName,
serialNumber: request.SerialNumber,
description: request.Description,
protocolVersionId: request.ProtocolVersionId,
agentPort: request.AgentPort,
ipAddress: request.IpAddress,
createdBy: currentUserId,
@ -80,9 +76,6 @@ public class CreateDeviceCommandHandler : IRequestHandler<CreateDeviceCommand, O
// 保存更改到数据库
await _unitOfWork.SaveChangesAsync(cancellationToken);
// 获取协议版本信息
var protocolVersion = await _protocolVersionRepository.GetProtocolVersionByIdAsync(device.ProtocolVersionId, cancellationToken);
// 构建响应
var response = new CreateDeviceResponse
{
@ -90,7 +83,6 @@ public class CreateDeviceCommandHandler : IRequestHandler<CreateDeviceCommand, O
DeviceName = device.Name,
SerialNumber = device.SerialNumber,
Description = device.Description,
ProtocolVersion = protocolVersion?.Version ?? "未知",
AgentPort = device.AgentPort,
IsEnabled = device.IsEnabled,
IsRunning = device.IsRunning,
@ -108,4 +100,6 @@ public class CreateDeviceCommandHandler : IRequestHandler<CreateDeviceCommand, O
return OperationResult<CreateDeviceResponse>.CreateFailure($"创建设备时发生错误: {ex.Message}");
}
}
}

5
src/X1.Application/Features/Devices/Commands/CreateDevice/CreateDeviceResponse.cs

@ -25,10 +25,7 @@ public class CreateDeviceResponse
/// </summary>
public string Description { get; set; }
/// <summary>
/// 协议版本
/// </summary>
public string ProtocolVersion { get; set; }
/// <summary>
/// Agent端口

6
src/X1.Application/Features/Devices/Commands/UpdateDevice/UpdateDeviceCommand.cs

@ -36,11 +36,7 @@ public class UpdateDeviceCommand : IRequest<OperationResult<UpdateDeviceResponse
[MaxLength(500)]
public string Description { get; set; }
/// <summary>
/// 协议版本ID
/// </summary>
[Required]
public string ProtocolVersionId { get; set; }
/// <summary>
/// IP地址
/// </summary>

10
src/X1.Application/Features/Devices/Commands/UpdateDevice/UpdateDeviceCommandHandler.cs

@ -17,7 +17,6 @@ namespace CellularManagement.Application.Features.Devices.Commands.UpdateDevice;
public class UpdateDeviceCommandHandler : IRequestHandler<UpdateDeviceCommand, OperationResult<UpdateDeviceResponse>>
{
private readonly ICellularDeviceRepository _deviceRepository;
private readonly IProtocolVersionRepository _protocolVersionRepository;
private readonly ILogger<UpdateDeviceCommandHandler> _logger;
private readonly IUnitOfWork _unitOfWork;
private readonly ICurrentUserService _currentUserService;
@ -27,13 +26,11 @@ public class UpdateDeviceCommandHandler : IRequestHandler<UpdateDeviceCommand, O
/// </summary>
public UpdateDeviceCommandHandler(
ICellularDeviceRepository deviceRepository,
IProtocolVersionRepository protocolVersionRepository,
ILogger<UpdateDeviceCommandHandler> logger,
IUnitOfWork unitOfWork,
ICurrentUserService currentUserService)
{
_deviceRepository = deviceRepository;
_protocolVersionRepository = protocolVersionRepository;
_logger = logger;
_unitOfWork = unitOfWork;
_currentUserService = currentUserService;
@ -80,7 +77,6 @@ public class UpdateDeviceCommandHandler : IRequestHandler<UpdateDeviceCommand, O
name: request.DeviceName,
serialNumber: request.SerialNumber,
description: request.Description,
protocolVersionId: request.ProtocolVersionId,
agentPort: request.AgentPort,
ipAddress: request.IpAddress,
updatedBy: currentUserId,
@ -92,9 +88,6 @@ public class UpdateDeviceCommandHandler : IRequestHandler<UpdateDeviceCommand, O
// 保存更改到数据库
await _unitOfWork.SaveChangesAsync(cancellationToken);
// 获取协议版本信息
var protocolVersion = await _protocolVersionRepository.GetProtocolVersionByIdAsync(existingDevice.ProtocolVersionId, cancellationToken);
// 构建响应
var response = new UpdateDeviceResponse
{
@ -102,7 +95,6 @@ public class UpdateDeviceCommandHandler : IRequestHandler<UpdateDeviceCommand, O
DeviceName = existingDevice.Name,
SerialNumber = existingDevice.SerialNumber,
Description = existingDevice.Description,
ProtocolVersion = protocolVersion?.Version ?? "未知",
AgentPort = existingDevice.AgentPort,
IsEnabled = existingDevice.IsEnabled,
IsRunning = existingDevice.IsRunning,
@ -120,4 +112,6 @@ public class UpdateDeviceCommandHandler : IRequestHandler<UpdateDeviceCommand, O
return OperationResult<UpdateDeviceResponse>.CreateFailure($"更新设备时发生错误: {ex.Message}");
}
}
}

5
src/X1.Application/Features/Devices/Commands/UpdateDevice/UpdateDeviceResponse.cs

@ -25,10 +25,7 @@ public class UpdateDeviceResponse
/// </summary>
public string Description { get; set; }
/// <summary>
/// 协议版本
/// </summary>
public string ProtocolVersion { get; set; }
/// <summary>
/// Agent端口

9
src/X1.Application/Features/Devices/Queries/GetDeviceById/GetDeviceByIdQueryHandler.cs

@ -13,7 +13,6 @@ namespace CellularManagement.Application.Features.Devices.Queries.GetDeviceById;
public class GetDeviceByIdQueryHandler : IRequestHandler<GetDeviceByIdQuery, OperationResult<GetDeviceByIdResponse>>
{
private readonly ICellularDeviceRepository _deviceRepository;
private readonly IProtocolVersionRepository _protocolVersionRepository;
private readonly ILogger<GetDeviceByIdQueryHandler> _logger;
/// <summary>
@ -21,11 +20,9 @@ public class GetDeviceByIdQueryHandler : IRequestHandler<GetDeviceByIdQuery, Ope
/// </summary>
public GetDeviceByIdQueryHandler(
ICellularDeviceRepository deviceRepository,
IProtocolVersionRepository protocolVersionRepository,
ILogger<GetDeviceByIdQueryHandler> logger)
{
_deviceRepository = deviceRepository;
_protocolVersionRepository = protocolVersionRepository;
_logger = logger;
}
@ -46,16 +43,12 @@ public class GetDeviceByIdQueryHandler : IRequestHandler<GetDeviceByIdQuery, Ope
return OperationResult<GetDeviceByIdResponse>.CreateFailure($"未找到ID为 {request.DeviceId} 的设备");
}
// 获取协议版本信息
var protocolVersion = await _protocolVersionRepository.GetProtocolVersionByIdAsync(device.ProtocolVersionId, cancellationToken);
var response = new GetDeviceByIdResponse
{
DeviceId = device.Id,
DeviceName = device.Name,
SerialNumber = device.SerialNumber,
Description = device.Description,
ProtocolVersion = protocolVersion?.Version ?? "未知",
AgentPort = device.AgentPort,
IsEnabled = device.IsEnabled,
IsRunning = device.IsRunning,
@ -71,4 +64,6 @@ public class GetDeviceByIdQueryHandler : IRequestHandler<GetDeviceByIdQuery, Ope
return OperationResult<GetDeviceByIdResponse>.CreateFailure($"查询设备时发生错误: {ex.Message}");
}
}
}

5
src/X1.Application/Features/Devices/Queries/GetDeviceById/GetDeviceByIdResponse.cs

@ -25,10 +25,7 @@ public class GetDeviceByIdResponse
/// </summary>
public string Description { get; set; }
/// <summary>
/// 协议版本
/// </summary>
public string ProtocolVersion { get; set; }
/// <summary>
/// Agent端口

7
src/X1.Application/Features/Devices/Queries/GetDevices/GetDevicesQueryHandler.cs

@ -49,8 +49,8 @@ public class GetDevicesQueryHandler : IRequestHandler<GetDevicesQuery, Operation
_logger.LogInformation("开始获取设备列表,页码: {PageNumber}, 每页数量: {PageSize}, 搜索关键词: {SearchTerm}",
request.PageNumber, request.PageSize, request.SearchTerm);
// 获取分页数据,使用导航属性包含ProtocolVersion
var devices = await _deviceRepository.SearchDevicesWithProtocolVersionAsync(
// 获取分页数据
var devices = await _deviceRepository.SearchDevicesAsync(
request.SearchTerm,
request.PageNumber,
request.PageSize,
@ -71,7 +71,6 @@ public class GetDevicesQueryHandler : IRequestHandler<GetDevicesQuery, Operation
DeviceName = device.Name,
SerialNumber = device.SerialNumber,
Description = device.Description,
ProtocolVersion = device.ProtocolVersion?.Version ?? "未知",
AgentPort = device.AgentPort,
IsEnabled = device.IsEnabled,
IsRunning = device.IsRunning,
@ -88,4 +87,6 @@ public class GetDevicesQueryHandler : IRequestHandler<GetDevicesQuery, Operation
return OperationResult<GetDevicesResponse>.CreateFailure($"获取设备列表时发生错误: {ex.Message}");
}
}
}

35
src/X1.Application/Features/IMSConfiguration/Commands/CreateIMS_Configuration/CreateIMS_ConfigurationCommand.cs

@ -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;
}

95
src/X1.Application/Features/IMSConfiguration/Commands/CreateIMS_Configuration/CreateIMS_ConfigurationCommandHandler.cs

@ -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}");
}
}
}

37
src/X1.Application/Features/IMSConfiguration/Commands/CreateIMS_Configuration/CreateIMS_ConfigurationResponse.cs

@ -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; }
}

17
src/X1.Application/Features/IMSConfiguration/Commands/DeleteIMS_Configuration/DeleteIMS_ConfigurationCommand.cs

@ -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!;
}

64
src/X1.Application/Features/IMSConfiguration/Commands/DeleteIMS_Configuration/DeleteIMS_ConfigurationCommandHandler.cs

@ -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}");
}
}
}

28
src/X1.Application/Features/NetworkConfigs/Commands/CreateNetworkConfig/CreateNetworkConfigCommand.cs → src/X1.Application/Features/IMSConfiguration/Commands/UpdateIMS_Configuration/UpdateIMS_ConfigurationCommand.cs

@ -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>

102
src/X1.Application/Features/IMSConfiguration/Commands/UpdateIMS_Configuration/UpdateIMS_ConfigurationCommandHandler.cs

@ -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}");
}
}
}

37
src/X1.Application/Features/IMSConfiguration/Commands/UpdateIMS_Configuration/UpdateIMS_ConfigurationResponse.cs

@ -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; }
}

17
src/X1.Application/Features/IMSConfiguration/Queries/GetIMS_ConfigurationById/GetIMS_ConfigurationByIdQuery.cs

@ -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!;
}

68
src/X1.Application/Features/IMSConfiguration/Queries/GetIMS_ConfigurationById/GetIMS_ConfigurationByIdQueryHandler.cs

@ -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}");
}
}
}

52
src/X1.Application/Features/IMSConfiguration/Queries/GetIMS_ConfigurationById/GetIMS_ConfigurationByIdResponse.cs

@ -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!;
}

34
src/X1.Application/Features/IMSConfiguration/Queries/GetIMS_Configurations/GetIMS_ConfigurationsQuery.cs

@ -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; }
}

78
src/X1.Application/Features/IMSConfiguration/Queries/GetIMS_Configurations/GetIMS_ConfigurationsQueryHandler.cs

@ -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}");
}
}
}

83
src/X1.Application/Features/IMSConfiguration/Queries/GetIMS_Configurations/GetIMS_ConfigurationsResponse.cs

@ -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!;
}

85
src/X1.Application/Features/NetworkConfigs/Commands/CreateNetworkConfig/CreateNetworkConfigCommandHandler.cs

@ -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}");
}
}
}

22
src/X1.Application/Features/NetworkConfigs/Commands/CreateNetworkConfig/CreateNetworkConfigResponse.cs

@ -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; }
}

17
src/X1.Application/Features/NetworkConfigs/Commands/DeleteNetworkConfig/DeleteNetworkConfigCommand.cs

@ -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!;
}

50
src/X1.Application/Features/NetworkConfigs/Commands/DeleteNetworkConfig/DeleteNetworkConfigCommandHandler.cs

@ -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}");
}
}
}

91
src/X1.Application/Features/NetworkConfigs/Commands/UpdateNetworkConfig/UpdateNetworkConfigCommandHandler.cs

@ -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}");
}
}
}

22
src/X1.Application/Features/NetworkConfigs/Commands/UpdateNetworkConfig/UpdateNetworkConfigResponse.cs

@ -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; }
}

17
src/X1.Application/Features/NetworkConfigs/Queries/GetNetworkConfigById/GetNetworkConfigByIdQuery.cs

@ -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!;
}

63
src/X1.Application/Features/NetworkConfigs/Queries/GetNetworkConfigById/GetNetworkConfigByIdQueryHandler.cs

@ -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}");
}
}
}

46
src/X1.Application/Features/NetworkConfigs/Queries/GetNetworkConfigs/GetNetworkConfigsQuery.cs

@ -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; }
}

106
src/X1.Application/Features/NetworkConfigs/Queries/GetNetworkConfigs/GetNetworkConfigsQueryHandler.cs

@ -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}");
}
}
}

35
src/X1.Application/Features/NetworkStackConfigs/Commands/CreateNetworkStackConfig/CreateNetworkStackConfigCommand.cs

@ -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;
}

95
src/X1.Application/Features/NetworkStackConfigs/Commands/CreateNetworkStackConfig/CreateNetworkStackConfigCommandHandler.cs

@ -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}");
}
}
}

37
src/X1.Application/Features/NetworkStackConfigs/Commands/CreateNetworkStackConfig/CreateNetworkStackConfigResponse.cs

@ -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; }
}

17
src/X1.Application/Features/NetworkStackConfigs/Commands/DeleteNetworkStackConfig/DeleteNetworkStackConfigCommand.cs

@ -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!;
}

64
src/X1.Application/Features/NetworkStackConfigs/Commands/DeleteNetworkStackConfig/DeleteNetworkStackConfigCommandHandler.cs

@ -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}");
}
}
}

34
src/X1.Application/Features/NetworkStackConfigs/Commands/UpdateNetworkStackConfig/UpdateNetworkStackConfigCommand.cs

@ -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;
}

93
src/X1.Application/Features/NetworkStackConfigs/Commands/UpdateNetworkStackConfig/UpdateNetworkStackConfigCommandHandler.cs

@ -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}");
}
}
}

37
src/X1.Application/Features/NetworkStackConfigs/Commands/UpdateNetworkStackConfig/UpdateNetworkStackConfigResponse.cs

@ -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; }
}

17
src/X1.Application/Features/NetworkStackConfigs/Queries/GetNetworkStackConfigById/GetNetworkStackConfigByIdQuery.cs

@ -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!;
}

68
src/X1.Application/Features/NetworkStackConfigs/Queries/GetNetworkStackConfigById/GetNetworkStackConfigByIdQueryHandler.cs

@ -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}");
}
}
}

52
src/X1.Application/Features/NetworkStackConfigs/Queries/GetNetworkStackConfigById/GetNetworkStackConfigByIdResponse.cs

@ -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; }
}

40
src/X1.Application/Features/NetworkStackConfigs/Queries/GetNetworkStackConfigs/GetNetworkStackConfigsQuery.cs

@ -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; }
}

96
src/X1.Application/Features/NetworkStackConfigs/Queries/GetNetworkStackConfigs/GetNetworkStackConfigsQueryHandler.cs

@ -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}");
}
}
}

93
src/X1.Application/Features/NetworkStackConfigs/Queries/GetNetworkStackConfigs/GetNetworkStackConfigsResponse.cs

@ -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; }
}

7
src/X1.Application/Features/ProtocolVersions/Commands/CreateProtocolVersion/CreateProtocolVersionCommand.cs

@ -46,4 +46,11 @@ public class CreateProtocolVersionCommand : IRequest<OperationResult<CreateProto
/// </summary>
[MaxLength(20)]
public string? MinimumSupportedVersion { get; set; }
/// <summary>
/// 设备序列号
/// </summary>
[Required(ErrorMessage = "设备序列号不能为空")]
[MaxLength(50, ErrorMessage = "设备序列号不能超过50个字符")]
public string SerialNumber { get; set; } = null!;
}

2
src/X1.Application/Features/ProtocolVersions/Commands/CreateProtocolVersion/CreateProtocolVersionCommandHandler.cs

@ -62,6 +62,7 @@ public class CreateProtocolVersionCommandHandler : IRequestHandler<CreateProtoco
var protocolVersion = ProtocolVersion.Create(
name: request.Name,
version: request.Version,
serialNumber: request.SerialNumber,
createdBy: currentUserId,
description: request.Description,
isEnabled: request.IsEnabled,
@ -84,6 +85,7 @@ public class CreateProtocolVersionCommandHandler : IRequestHandler<CreateProtoco
IsEnabled = protocolVersion.IsEnabled,
ReleaseDate = protocolVersion.ReleaseDate,
MinimumSupportedVersion = protocolVersion.MinimumSupportedVersion,
SerialNumber = protocolVersion.SerialNumber,
CreatedAt = protocolVersion.CreatedAt
};

5
src/X1.Application/Features/ProtocolVersions/Commands/CreateProtocolVersion/CreateProtocolVersionResponse.cs

@ -42,6 +42,11 @@ public class CreateProtocolVersionResponse
/// </summary>
public string? MinimumSupportedVersion { get; set; }
/// <summary>
/// 设备序列号
/// </summary>
public string SerialNumber { get; set; } = null!;
/// <summary>
/// 创建时间
/// </summary>

7
src/X1.Application/Features/ProtocolVersions/Commands/UpdateProtocolVersion/UpdateProtocolVersionCommand.cs

@ -52,4 +52,11 @@ public class UpdateProtocolVersionCommand : IRequest<OperationResult<UpdateProto
/// </summary>
[MaxLength(20)]
public string? MinimumSupportedVersion { get; set; }
/// <summary>
/// 设备序列号
/// </summary>
[Required(ErrorMessage = "设备序列号不能为空")]
[MaxLength(50, ErrorMessage = "设备序列号不能超过50个字符")]
public string SerialNumber { get; set; } = null!;
}

2
src/X1.Application/Features/ProtocolVersions/Commands/UpdateProtocolVersion/UpdateProtocolVersionCommandHandler.cs

@ -73,6 +73,7 @@ public class UpdateProtocolVersionCommandHandler : IRequestHandler<UpdateProtoco
existingProtocolVersion.Update(
name: request.Name,
version: request.Version,
serialNumber: request.SerialNumber,
updatedBy: currentUserId,
description: request.Description,
isEnabled: request.IsEnabled,
@ -94,6 +95,7 @@ public class UpdateProtocolVersionCommandHandler : IRequestHandler<UpdateProtoco
IsEnabled = existingProtocolVersion.IsEnabled,
ReleaseDate = existingProtocolVersion.ReleaseDate,
MinimumSupportedVersion = existingProtocolVersion.MinimumSupportedVersion,
SerialNumber = existingProtocolVersion.SerialNumber,
UpdatedAt = existingProtocolVersion.UpdatedAt
};

5
src/X1.Application/Features/ProtocolVersions/Commands/UpdateProtocolVersion/UpdateProtocolVersionResponse.cs

@ -42,6 +42,11 @@ public class UpdateProtocolVersionResponse
/// </summary>
public string? MinimumSupportedVersion { get; set; }
/// <summary>
/// 设备序列号
/// </summary>
public string SerialNumber { get; set; } = null!;
/// <summary>
/// 更新时间
/// </summary>

1
src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersionById/GetProtocolVersionByIdQueryHandler.cs

@ -51,6 +51,7 @@ public class GetProtocolVersionByIdQueryHandler : IRequestHandler<GetProtocolVer
IsEnabled = protocolVersion.IsEnabled,
ReleaseDate = protocolVersion.ReleaseDate,
MinimumSupportedVersion = protocolVersion.MinimumSupportedVersion,
SerialNumber = protocolVersion.SerialNumber,
CreatedAt = protocolVersion.CreatedAt,
UpdatedAt = protocolVersion.UpdatedAt
};

5
src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersionById/GetProtocolVersionByIdResponse.cs

@ -42,6 +42,11 @@ public class GetProtocolVersionByIdResponse
/// </summary>
public string? MinimumSupportedVersion { get; set; }
/// <summary>
/// 设备序列号
/// </summary>
public string SerialNumber { get; set; } = null!;
/// <summary>
/// 创建时间
/// </summary>

1
src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersions/GetProtocolVersionsQueryHandler.cs

@ -85,6 +85,7 @@ public class GetProtocolVersionsQueryHandler : IRequestHandler<GetProtocolVersio
IsEnabled = pv.IsEnabled,
ReleaseDate = pv.ReleaseDate,
MinimumSupportedVersion = pv.MinimumSupportedVersion,
SerialNumber = pv.SerialNumber,
CreatedAt = pv.CreatedAt,
UpdatedAt = pv.UpdatedAt
}).ToList()

35
src/X1.Application/Features/RANConfiguration/Commands/CreateRAN_Configuration/CreateRAN_ConfigurationCommand.cs

@ -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;
}

95
src/X1.Application/Features/RANConfiguration/Commands/CreateRAN_Configuration/CreateRAN_ConfigurationCommandHandler.cs

@ -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}");
}
}
}

37
src/X1.Application/Features/RANConfiguration/Commands/CreateRAN_Configuration/CreateRAN_ConfigurationResponse.cs

@ -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; }
}

17
src/X1.Application/Features/RANConfiguration/Commands/DeleteRAN_Configuration/DeleteRAN_ConfigurationCommand.cs

@ -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!;
}

63
src/X1.Application/Features/RANConfiguration/Commands/DeleteRAN_Configuration/DeleteRAN_ConfigurationCommandHandler.cs

@ -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}");
}
}
}

27
src/X1.Application/Features/NetworkConfigs/Commands/UpdateNetworkConfig/UpdateNetworkConfigCommand.cs → src/X1.Application/Features/RANConfiguration/Commands/UpdateRAN_Configuration/UpdateRAN_ConfigurationCommand.cs

@ -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>

107
src/X1.Application/Features/RANConfiguration/Commands/UpdateRAN_Configuration/UpdateRAN_ConfigurationCommandHandler.cs

@ -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}");
}
}
}

37
src/X1.Application/Features/RANConfiguration/Commands/UpdateRAN_Configuration/UpdateRAN_ConfigurationResponse.cs

@ -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; }
}

17
src/X1.Application/Features/RANConfiguration/Queries/GetRAN_ConfigurationById/GetRAN_ConfigurationByIdQuery.cs

@ -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!;
}

65
src/X1.Application/Features/RANConfiguration/Queries/GetRAN_ConfigurationById/GetRAN_ConfigurationByIdQueryHandler.cs

@ -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}");
}
}
}

42
src/X1.Application/Features/RANConfiguration/Queries/GetRAN_ConfigurationById/GetRAN_ConfigurationByIdResponse.cs

@ -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; }
}

34
src/X1.Application/Features/RANConfiguration/Queries/GetRAN_Configurations/GetRAN_ConfigurationsQuery.cs

@ -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; }
}

100
src/X1.Application/Features/RANConfiguration/Queries/GetRAN_Configurations/GetRAN_ConfigurationsQueryHandler.cs

@ -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}");
}
}
}

46
src/X1.Application/Features/RANConfiguration/Queries/GetRAN_Configurations/GetRAN_ConfigurationsResponse.cs

@ -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();
}

39
src/X1.Application/Features/StackCoreIMSBindings/Commands/CreateStackCoreIMSBinding/CreateStackCoreIMSBindingCommand.cs

@ -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!;
}

95
src/X1.Application/Features/StackCoreIMSBindings/Commands/CreateStackCoreIMSBinding/CreateStackCoreIMSBindingCommandHandler.cs

@ -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}");
}
}
}

37
src/X1.Application/Features/StackCoreIMSBindings/Commands/CreateStackCoreIMSBinding/CreateStackCoreIMSBindingResponse.cs

@ -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; }
}

17
src/X1.Application/Features/StackCoreIMSBindings/Commands/DeleteStackCoreIMSBinding/DeleteStackCoreIMSBindingCommand.cs

@ -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!;
}

64
src/X1.Application/Features/StackCoreIMSBindings/Commands/DeleteStackCoreIMSBinding/DeleteStackCoreIMSBindingCommandHandler.cs

@ -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}");
}
}
}

38
src/X1.Application/Features/StackCoreIMSBindings/Commands/UpdateStackCoreIMSBinding/UpdateStackCoreIMSBindingCommand.cs

@ -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!;
}

103
src/X1.Application/Features/StackCoreIMSBindings/Commands/UpdateStackCoreIMSBinding/UpdateStackCoreIMSBindingCommandHandler.cs

@ -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}");
}
}
}

37
src/X1.Application/Features/StackCoreIMSBindings/Commands/UpdateStackCoreIMSBinding/UpdateStackCoreIMSBindingResponse.cs

@ -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; }
}

17
src/X1.Application/Features/StackCoreIMSBindings/Queries/GetStackCoreIMSBindingById/GetStackCoreIMSBindingByIdQuery.cs

@ -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!;
}

68
src/X1.Application/Features/StackCoreIMSBindings/Queries/GetStackCoreIMSBindingById/GetStackCoreIMSBindingByIdQueryHandler.cs

@ -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}");
}
}
}

52
src/X1.Application/Features/StackCoreIMSBindings/Queries/GetStackCoreIMSBindingById/GetStackCoreIMSBindingByIdResponse.cs

@ -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!;
}

41
src/X1.Application/Features/StackCoreIMSBindings/Queries/GetStackCoreIMSBindings/GetStackCoreIMSBindingsQuery.cs

@ -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; }
}

80
src/X1.Application/Features/StackCoreIMSBindings/Queries/GetStackCoreIMSBindings/GetStackCoreIMSBindingsQueryHandler.cs

@ -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}");
}
}
}

83
src/X1.Application/Features/StackCoreIMSBindings/Queries/GetStackCoreIMSBindings/GetStackCoreIMSBindingsResponse.cs

@ -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!;
}

15
src/X1.Domain/Entities/Device/CellularDevice.cs

@ -32,16 +32,11 @@ public class CellularDevice : AuditableEntity
public string Description { get; private set; }
/// <summary>
/// 协议版本ID
/// 协议版本集合
/// </summary>
[Required]
public string ProtocolVersionId { get; private set; }
public virtual ICollection<ProtocolVersion> ProtocolVersions { get; private set; } = new List<ProtocolVersion>();
/// <summary>
/// 协议版本
/// </summary>
[ForeignKey(nameof(ProtocolVersionId))]
public virtual ProtocolVersion ProtocolVersion { get; private set; } = null!;
/// <summary>
/// Agent端口
@ -73,7 +68,6 @@ public class CellularDevice : AuditableEntity
string name,
string serialNumber,
string description,
string protocolVersionId,
int agentPort,
string ipAddress,
string createdBy,
@ -86,7 +80,6 @@ public class CellularDevice : AuditableEntity
Name = name,
SerialNumber = serialNumber,
Description = description,
ProtocolVersionId = protocolVersionId,
AgentPort = agentPort,
IpAddress = ipAddress,
IsEnabled = isEnabled,
@ -107,7 +100,6 @@ public class CellularDevice : AuditableEntity
string name,
string serialNumber,
string description,
string protocolVersionId,
int agentPort,
string ipAddress,
string updatedBy,
@ -117,7 +109,6 @@ public class CellularDevice : AuditableEntity
Name = name;
SerialNumber = serialNumber;
Description = description;
ProtocolVersionId = protocolVersionId;
AgentPort = agentPort;
IpAddress = ipAddress;
IsEnabled = isEnabled;

173
src/X1.Domain/Entities/Device/NetworkConfig.cs

@ -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…
Cancel
Save