Browse Source

feat: 实现ProtocolVersion完整CRUD功能

- 优化CellularDevice仓储接口,移除未使用的方法
- 为ProtocolVersion实体添加工厂方法和更新方法
- 创建ProtocolVersion仓储接口和实现类
- 实现ProtocolVersion完整的CQRS命令和查询
- 创建ProtocolVersionsController,统一使用OperationResult返回
- 更新数据库配置和依赖注入
- 添加HTTP测试文件
feature/x1-owen-debug
root 4 weeks ago
parent
commit
98503a1048
  1. 30
      src/X1.Application/Features/Devices/Commands/CreateDevice/CreateDeviceCommand.cs
  2. 14
      src/X1.Application/Features/Devices/Commands/CreateDevice/CreateDeviceCommandHandler.cs
  3. 16
      src/X1.Application/Features/Devices/Commands/CreateDevice/CreateDeviceResponse.cs
  4. 25
      src/X1.Application/Features/Devices/Commands/UpdateDevice/UpdateDeviceCommand.cs
  5. 20
      src/X1.Application/Features/Devices/Commands/UpdateDevice/UpdateDeviceCommandHandler.cs
  6. 16
      src/X1.Application/Features/Devices/Commands/UpdateDevice/UpdateDeviceResponse.cs
  7. 6
      src/X1.Application/Features/Devices/Queries/GetDeviceById/GetDeviceByIdQueryHandler.cs
  8. 16
      src/X1.Application/Features/Devices/Queries/GetDeviceById/GetDeviceByIdResponse.cs
  9. 8
      src/X1.Application/Features/Devices/Queries/GetDevices/GetDevicesQueryHandler.cs
  10. 52
      src/X1.Application/Features/ProtocolVersions/Commands/CreateProtocolVersion/CreateProtocolVersionCommand.cs
  11. 83
      src/X1.Application/Features/ProtocolVersions/Commands/CreateProtocolVersion/CreateProtocolVersionCommandHandler.cs
  12. 52
      src/X1.Application/Features/ProtocolVersions/Commands/CreateProtocolVersion/CreateProtocolVersionResponse.cs
  13. 17
      src/X1.Application/Features/ProtocolVersions/Commands/DeleteProtocolVersion/DeleteProtocolVersionCommand.cs
  14. 56
      src/X1.Application/Features/ProtocolVersions/Commands/DeleteProtocolVersion/DeleteProtocolVersionCommandHandler.cs
  15. 58
      src/X1.Application/Features/ProtocolVersions/Commands/UpdateProtocolVersion/UpdateProtocolVersionCommand.cs
  16. 93
      src/X1.Application/Features/ProtocolVersions/Commands/UpdateProtocolVersion/UpdateProtocolVersionCommandHandler.cs
  17. 52
      src/X1.Application/Features/ProtocolVersions/Commands/UpdateProtocolVersion/UpdateProtocolVersionResponse.cs
  18. 17
      src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersionById/GetProtocolVersionByIdQuery.cs
  19. 68
      src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersionById/GetProtocolVersionByIdQueryHandler.cs
  20. 57
      src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersionById/GetProtocolVersionByIdResponse.cs
  21. 34
      src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersions/GetProtocolVersionsQuery.cs
  22. 103
      src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersions/GetProtocolVersionsQueryHandler.cs
  23. 44
      src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersions/GetProtocolVersionsResponse.cs
  24. 87
      src/X1.Domain/Entities/Device/CellularDevice.cs
  25. 46
      src/X1.Domain/Entities/Device/DeviceStatus.cs
  26. 40
      src/X1.Domain/Entities/Device/DeviceType.cs
  27. 101
      src/X1.Domain/Entities/Device/ProtocolVersion.cs
  28. 30
      src/X1.Domain/Repositories/Device/ICellularDeviceRepository.cs
  29. 63
      src/X1.Domain/Repositories/Device/IProtocolVersionRepository.cs
  30. 19
      src/X1.Infrastructure/Configurations/Device/CellularDeviceConfiguration.cs
  31. 21
      src/X1.Infrastructure/Configurations/Device/DeviceStatusConfiguration.cs
  32. 21
      src/X1.Infrastructure/Configurations/Device/DeviceTypeConfiguration.cs
  33. 9
      src/X1.Infrastructure/Configurations/Device/ProtocolVersionConfiguration.cs
  34. 10
      src/X1.Infrastructure/Context/AppDbContext.cs
  35. 6
      src/X1.Infrastructure/DependencyInjection.cs
  36. 168
      src/X1.Infrastructure/Migrations/20250705165102_InitialCreate.Designer.cs
  37. 81
      src/X1.Infrastructure/Migrations/20250705165102_InitialCreate.cs
  38. 166
      src/X1.Infrastructure/Migrations/AppDbContextModelSnapshot.cs
  39. 72
      src/X1.Infrastructure/Repositories/Device/CellularDeviceRepository.cs
  40. 129
      src/X1.Infrastructure/Repositories/Device/ProtocolVersionRepository.cs
  41. 135
      src/X1.Presentation/Controllers/ProtocolVersionsController.cs
  42. 73
      src/X1.WebAPI/ProtocolVersions.http

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

@ -25,32 +25,30 @@ public class CreateDeviceCommand : IRequest<OperationResult<CreateDeviceResponse
public string SerialNumber { get; set; }
/// <summary>
/// 备注
/// 设备描述
/// </summary>
[MaxLength(500, ErrorMessage = "备注不能超过500个字符")]
public string Comment { get; set; }
[MaxLength(500, ErrorMessage = "设备描述不能超过500个字符")]
public string Description { get; set; }
/// <summary>
/// 设备类型ID
/// 协议版本ID
/// </summary>
[Required(ErrorMessage = "设备类型不能为空")]
public string DeviceTypeId { get; set; }
[Required(ErrorMessage = "协议版本不能为空")]
public string ProtocolVersionId { get; set; }
/// <summary>
/// 状态ID
/// IP地址
/// </summary>
[Required(ErrorMessage = "设备状态不能为空")]
public string StatusId { get; set; }
[MaxLength(45, ErrorMessage = "Agent端口不能为空")]
public string IpAddress { get; private set; } = null!;
/// <summary>
/// 协议版本ID
/// Agent端口
/// </summary>
[Required(ErrorMessage = "协议版本不能为空")]
public string ProtocolVersionId { get; set; }
[Required(ErrorMessage = "Agent端口不能为空")]
public int AgentPort { get; set; }
/// <summary>
/// 硬件版本
/// 是否启用
/// </summary>
[MaxLength(50, ErrorMessage = "硬件版本不能超过50个字符")]
public string HardwareVersion { get; set; }
public bool IsEnabled { get; set; } = true;
}

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

@ -47,11 +47,11 @@ public class CreateDeviceCommandHandler : IRequestHandler<CreateDeviceCommand, O
var device = CellularDevice.Create(
name: request.DeviceName,
serialNumber: request.SerialNumber,
description: request.Comment,
deviceTypeId: request.DeviceTypeId,
statusId: request.StatusId,
description: request.Description,
protocolVersionId: request.ProtocolVersionId,
firmwareVersion: request.HardwareVersion);
agentPort: request.AgentPort,
ipAddress:request.IpAddress,
isEnabled: request.IsEnabled);
// 保存设备
await _deviceRepository.AddDeviceAsync(device, cancellationToken);
@ -65,10 +65,10 @@ public class CreateDeviceCommandHandler : IRequestHandler<CreateDeviceCommand, O
DeviceId = device.Id,
DeviceName = device.Name,
SerialNumber = device.SerialNumber,
DeviceType = device.DeviceType?.Name ?? "未知",
Status = device.Status?.Name ?? "未知",
Description = device.Description,
ProtocolVersion = device.ProtocolVersion?.Version ?? "未知",
FirmwareVersion = device.FirmwareVersion,
AgentPort = device.AgentPort,
IsEnabled = device.IsEnabled,
CreatedAt = device.CreatedAt
};

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

@ -21,24 +21,24 @@ public class CreateDeviceResponse
public string SerialNumber { get; set; }
/// <summary>
/// 设备类型
/// 设备描述
/// </summary>
public string DeviceType { get; set; }
public string Description { get; set; }
/// <summary>
/// 设备状态
/// 协议版本
/// </summary>
public string Status { get; set; }
public string ProtocolVersion { get; set; }
/// <summary>
/// 协议版本
/// Agent端口
/// </summary>
public string ProtocolVersion { get; set; }
public int AgentPort { get; set; }
/// <summary>
/// 固件版本
/// 是否启用
/// </summary>
public string FirmwareVersion { get; set; }
public bool IsEnabled { get; set; }
/// <summary>
/// 创建时间

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

@ -31,33 +31,30 @@ public class UpdateDeviceCommand : IRequest<OperationResult<UpdateDeviceResponse
public string SerialNumber { get; set; }
/// <summary>
/// 备注
/// 设备描述
/// </summary>
[MaxLength(500)]
public string Comment { get; set; }
public string Description { get; set; }
/// <summary>
/// 设备类型ID
/// 协议版本ID
/// </summary>
[Required]
public string DeviceTypeId { get; set; }
public string ProtocolVersionId { get; set; }
/// <summary>
/// 设备状态ID
/// IP地址
/// </summary>
[Required]
public string StatusId { get; set; }
[MaxLength(45)]
public string IpAddress { get; private set; } = null!;
/// <summary>
/// 协议版本ID
/// Agent端口
/// </summary>
[Required]
public string ProtocolVersionId { get; set; }
public int AgentPort { get; set; }
/// <summary>
/// 硬件版本
/// 是否启用
/// </summary>
[Required]
[MaxLength(50)]
public string HardwareVersion { get; set; }
public bool IsEnabled { get; set; } = true;
}

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

@ -5,6 +5,7 @@ using CellularManagement.Domain.Entities.Device;
using CellularManagement.Domain.Repositories;
using CellularManagement.Application.Features.Devices.Commands.UpdateDevice;
using CellularManagement.Domain.Repositories.Device;
using System.Net;
namespace CellularManagement.Application.Features.Devices.Commands.UpdateDevice;
@ -59,14 +60,15 @@ public class UpdateDeviceCommandHandler : IRequestHandler<UpdateDeviceCommand, O
existingDevice.Update(
name: request.DeviceName,
serialNumber: request.SerialNumber,
description: request.Comment,
deviceTypeId: request.DeviceTypeId,
statusId: request.StatusId,
description: request.Description,
protocolVersionId: request.ProtocolVersionId,
firmwareVersion: request.HardwareVersion);
agentPort: request.AgentPort,
ipAddress: request.IpAddress,
isEnabled: request.IsEnabled);
_deviceRepository.Update(existingDevice);
// 保存更新
await _deviceRepository.UpdateDeviceAsync(existingDevice, cancellationToken);
//await _deviceRepository.UpdateDeviceAsync(existingDevice, cancellationToken);
// 加载导航属性
//await _deviceRepository.LoadNavigationPropertiesAsync(existingDevice, cancellationToken);
@ -77,11 +79,11 @@ public class UpdateDeviceCommandHandler : IRequestHandler<UpdateDeviceCommand, O
DeviceId = existingDevice.Id,
DeviceName = existingDevice.Name,
SerialNumber = existingDevice.SerialNumber,
DeviceType = existingDevice.DeviceType?.Name ?? "未知",
Status = existingDevice.Status?.Name ?? "未知",
Description = existingDevice.Description,
ProtocolVersion = existingDevice.ProtocolVersion?.Version ?? "未知",
FirmwareVersion = existingDevice.FirmwareVersion,
UpdatedAt = existingDevice.UpdatedAt
AgentPort = existingDevice.AgentPort,
IsEnabled = existingDevice.IsEnabled,
UpdatedAt = DateTime.UtcNow
};
_logger.LogInformation("设备更新成功,设备ID: {DeviceId}, 设备名称: {DeviceName}",

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

@ -21,24 +21,24 @@ public class UpdateDeviceResponse
public string SerialNumber { get; set; }
/// <summary>
/// 设备类型
/// 设备描述
/// </summary>
public string DeviceType { get; set; }
public string Description { get; set; }
/// <summary>
/// 设备状态
/// 协议版本
/// </summary>
public string Status { get; set; }
public string ProtocolVersion { get; set; }
/// <summary>
/// 协议版本
/// Agent端口
/// </summary>
public string ProtocolVersion { get; set; }
public int AgentPort { get; set; }
/// <summary>
/// 固件版本
/// 是否启用
/// </summary>
public string FirmwareVersion { get; set; }
public bool IsEnabled { get; set; }
/// <summary>
/// 更新时间

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

@ -48,10 +48,10 @@ public class GetDeviceByIdQueryHandler : IRequestHandler<GetDeviceByIdQuery, Ope
DeviceId = device.Id,
DeviceName = device.Name,
SerialNumber = device.SerialNumber,
DeviceType = device.DeviceType?.Name ?? "未知",
Status = device.Status?.Name ?? "未知",
Description = device.Description,
ProtocolVersion = device.ProtocolVersion?.Version ?? "未知",
FirmwareVersion = device.FirmwareVersion,
AgentPort = device.AgentPort,
IsEnabled = device.IsEnabled,
CreatedAt = device.CreatedAt
};

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

@ -21,24 +21,24 @@ public class GetDeviceByIdResponse
public string SerialNumber { get; set; }
/// <summary>
/// 设备类型
/// 设备描述
/// </summary>
public string DeviceType { get; set; }
public string Description { get; set; }
/// <summary>
/// 设备状态
/// 协议版本
/// </summary>
public string Status { get; set; }
public string ProtocolVersion { get; set; }
/// <summary>
/// 协议版本
/// Agent端口
/// </summary>
public string ProtocolVersion { get; set; }
public int AgentPort { get; set; }
/// <summary>
/// 固件版本
/// 是否启用
/// </summary>
public string FirmwareVersion { get; set; }
public bool IsEnabled { get; set; }
/// <summary>
/// 创建时间

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

@ -52,8 +52,6 @@ public class GetDevicesQueryHandler : IRequestHandler<GetDevicesQuery, Operation
// 获取分页数据
var devices = await _deviceRepository.SearchDevicesAsync(
request.SearchTerm,
null, // deviceTypeId
null, // statusId
cancellationToken);
// 计算分页
@ -77,10 +75,10 @@ public class GetDevicesQueryHandler : IRequestHandler<GetDevicesQuery, Operation
DeviceId = d.Id,
DeviceName = d.Name,
SerialNumber = d.SerialNumber,
DeviceType = d.DeviceType?.Name ?? "未知",
Status = d.Status?.Name ?? "未知",
Description = d.Description,
ProtocolVersion = d.ProtocolVersion?.Version ?? "未知",
FirmwareVersion = d.FirmwareVersion,
AgentPort = d.AgentPort,
IsEnabled = d.IsEnabled,
CreatedAt = d.CreatedAt
}).ToList()
};

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

@ -0,0 +1,52 @@
using CellularManagement.Domain.Common;
using MediatR;
using System.ComponentModel.DataAnnotations;
namespace CellularManagement.Application.Features.ProtocolVersions.Commands.CreateProtocolVersion;
/// <summary>
/// 创建协议版本命令
/// </summary>
public class CreateProtocolVersionCommand : IRequest<OperationResult<CreateProtocolVersionResponse>>
{
/// <summary>
/// 版本名称
/// </summary>
[Required]
[MaxLength(50)]
public string Name { get; set; } = null!;
/// <summary>
/// 版本号
/// </summary>
[Required]
[MaxLength(20)]
public string Version { get; set; } = null!;
/// <summary>
/// 版本描述
/// </summary>
[MaxLength(500)]
public string? Description { get; set; }
/// <summary>
/// 是否启用
/// </summary>
public bool IsEnabled { get; set; } = true;
/// <summary>
/// 发布日期
/// </summary>
public DateTime? ReleaseDate { get; set; }
/// <summary>
/// 是否强制更新
/// </summary>
public bool IsForceUpdate { get; set; } = false;
/// <summary>
/// 最低支持版本
/// </summary>
[MaxLength(20)]
public string? MinimumSupportedVersion { get; set; }
}

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

@ -0,0 +1,83 @@
using MediatR;
using Microsoft.Extensions.Logging;
using CellularManagement.Domain.Common;
using CellularManagement.Domain.Entities.Device;
using CellularManagement.Domain.Repositories.Device;
namespace CellularManagement.Application.Features.ProtocolVersions.Commands.CreateProtocolVersion;
/// <summary>
/// 创建协议版本命令处理器
/// </summary>
public class CreateProtocolVersionCommandHandler : IRequestHandler<CreateProtocolVersionCommand, OperationResult<CreateProtocolVersionResponse>>
{
private readonly IProtocolVersionRepository _protocolVersionRepository;
private readonly ILogger<CreateProtocolVersionCommandHandler> _logger;
/// <summary>
/// 初始化命令处理器
/// </summary>
public CreateProtocolVersionCommandHandler(
IProtocolVersionRepository protocolVersionRepository,
ILogger<CreateProtocolVersionCommandHandler> logger)
{
_protocolVersionRepository = protocolVersionRepository;
_logger = logger;
}
/// <summary>
/// 处理创建协议版本命令
/// </summary>
public async Task<OperationResult<CreateProtocolVersionResponse>> Handle(CreateProtocolVersionCommand request, CancellationToken cancellationToken)
{
try
{
_logger.LogInformation("开始创建协议版本,版本名称: {Name}, 版本号: {Version}",
request.Name, request.Version);
// 检查版本号是否已存在
if (await _protocolVersionRepository.VersionExistsAsync(request.Version, cancellationToken))
{
_logger.LogWarning("协议版本号已存在: {Version}", request.Version);
return OperationResult<CreateProtocolVersionResponse>.CreateFailure($"协议版本号 {request.Version} 已存在");
}
// 创建协议版本实体
var protocolVersion = ProtocolVersion.Create(
name: request.Name,
version: request.Version,
description: request.Description,
isEnabled: request.IsEnabled,
releaseDate: request.ReleaseDate,
isForceUpdate: request.IsForceUpdate,
minimumSupportedVersion: request.MinimumSupportedVersion);
// 保存协议版本
await _protocolVersionRepository.AddProtocolVersionAsync(protocolVersion, cancellationToken);
// 构建响应
var response = new CreateProtocolVersionResponse
{
ProtocolVersionId = protocolVersion.Id,
Name = protocolVersion.Name,
Version = protocolVersion.Version,
Description = protocolVersion.Description,
IsEnabled = protocolVersion.IsEnabled,
ReleaseDate = protocolVersion.ReleaseDate,
IsForceUpdate = protocolVersion.IsForceUpdate,
MinimumSupportedVersion = protocolVersion.MinimumSupportedVersion,
CreatedAt = protocolVersion.CreatedAt
};
_logger.LogInformation("协议版本创建成功,版本ID: {ProtocolVersionId}, 版本名称: {Name}, 版本号: {Version}",
protocolVersion.Id, protocolVersion.Name, protocolVersion.Version);
return OperationResult<CreateProtocolVersionResponse>.CreateSuccess(response);
}
catch (Exception ex)
{
_logger.LogError(ex, "创建协议版本时发生错误,版本名称: {Name}, 版本号: {Version}",
request.Name, request.Version);
return OperationResult<CreateProtocolVersionResponse>.CreateFailure($"创建协议版本时发生错误: {ex.Message}");
}
}
}

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

@ -0,0 +1,52 @@
namespace CellularManagement.Application.Features.ProtocolVersions.Commands.CreateProtocolVersion;
/// <summary>
/// 创建协议版本响应
/// </summary>
public class CreateProtocolVersionResponse
{
/// <summary>
/// 协议版本ID
/// </summary>
public string ProtocolVersionId { get; set; } = null!;
/// <summary>
/// 版本名称
/// </summary>
public string Name { get; set; } = null!;
/// <summary>
/// 版本号
/// </summary>
public string Version { get; set; } = null!;
/// <summary>
/// 版本描述
/// </summary>
public string? Description { get; set; }
/// <summary>
/// 是否启用
/// </summary>
public bool IsEnabled { get; set; }
/// <summary>
/// 发布日期
/// </summary>
public DateTime? ReleaseDate { get; set; }
/// <summary>
/// 是否强制更新
/// </summary>
public bool IsForceUpdate { get; set; }
/// <summary>
/// 最低支持版本
/// </summary>
public string? MinimumSupportedVersion { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreatedAt { get; set; }
}

17
src/X1.Application/Features/ProtocolVersions/Commands/DeleteProtocolVersion/DeleteProtocolVersionCommand.cs

@ -0,0 +1,17 @@
using CellularManagement.Domain.Common;
using MediatR;
using System.ComponentModel.DataAnnotations;
namespace CellularManagement.Application.Features.ProtocolVersions.Commands.DeleteProtocolVersion;
/// <summary>
/// 删除协议版本命令
/// </summary>
public class DeleteProtocolVersionCommand : IRequest<OperationResult<bool>>
{
/// <summary>
/// 协议版本ID
/// </summary>
[Required]
public string ProtocolVersionId { get; set; } = null!;
}

56
src/X1.Application/Features/ProtocolVersions/Commands/DeleteProtocolVersion/DeleteProtocolVersionCommandHandler.cs

@ -0,0 +1,56 @@
using MediatR;
using Microsoft.Extensions.Logging;
using CellularManagement.Domain.Common;
using CellularManagement.Domain.Repositories.Device;
namespace CellularManagement.Application.Features.ProtocolVersions.Commands.DeleteProtocolVersion;
/// <summary>
/// 删除协议版本命令处理器
/// </summary>
public class DeleteProtocolVersionCommandHandler : IRequestHandler<DeleteProtocolVersionCommand, OperationResult<bool>>
{
private readonly IProtocolVersionRepository _protocolVersionRepository;
private readonly ILogger<DeleteProtocolVersionCommandHandler> _logger;
/// <summary>
/// 初始化删除协议版本命令处理器
/// </summary>
public DeleteProtocolVersionCommandHandler(
IProtocolVersionRepository protocolVersionRepository,
ILogger<DeleteProtocolVersionCommandHandler> logger)
{
_protocolVersionRepository = protocolVersionRepository;
_logger = logger;
}
/// <summary>
/// 处理删除协议版本命令
/// </summary>
public async Task<OperationResult<bool>> Handle(DeleteProtocolVersionCommand request, CancellationToken cancellationToken)
{
try
{
_logger.LogInformation("开始处理删除协议版本命令,版本ID: {ProtocolVersionId}", request.ProtocolVersionId);
// 检查协议版本是否存在
var protocolVersion = await _protocolVersionRepository.GetProtocolVersionByIdAsync(request.ProtocolVersionId, cancellationToken);
if (protocolVersion == null)
{
_logger.LogWarning("未找到协议版本,版本ID: {ProtocolVersionId}", request.ProtocolVersionId);
return OperationResult<bool>.CreateFailure($"未找到ID为 {request.ProtocolVersionId} 的协议版本");
}
// 删除协议版本
await _protocolVersionRepository.DeleteProtocolVersionAsync(request.ProtocolVersionId, cancellationToken);
_logger.LogInformation("协议版本删除成功,版本ID: {ProtocolVersionId}", request.ProtocolVersionId);
return OperationResult<bool>.CreateSuccess("协议版本删除成功", true);
}
catch (Exception ex)
{
_logger.LogError(ex, "删除协议版本时发生错误,版本ID: {ProtocolVersionId}", request.ProtocolVersionId);
return OperationResult<bool>.CreateFailure($"删除协议版本时发生错误: {ex.Message}");
}
}
}

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

@ -0,0 +1,58 @@
using CellularManagement.Domain.Common;
using MediatR;
using System.ComponentModel.DataAnnotations;
namespace CellularManagement.Application.Features.ProtocolVersions.Commands.UpdateProtocolVersion;
/// <summary>
/// 更新协议版本命令
/// </summary>
public class UpdateProtocolVersionCommand : IRequest<OperationResult<UpdateProtocolVersionResponse>>
{
/// <summary>
/// 协议版本ID
/// </summary>
[Required]
public string ProtocolVersionId { get; set; } = null!;
/// <summary>
/// 版本名称
/// </summary>
[Required]
[MaxLength(50)]
public string Name { get; set; } = null!;
/// <summary>
/// 版本号
/// </summary>
[Required]
[MaxLength(20)]
public string Version { get; set; } = null!;
/// <summary>
/// 版本描述
/// </summary>
[MaxLength(500)]
public string? Description { get; set; }
/// <summary>
/// 是否启用
/// </summary>
public bool IsEnabled { get; set; } = true;
/// <summary>
/// 发布日期
/// </summary>
public DateTime? ReleaseDate { get; set; }
/// <summary>
/// 是否强制更新
/// </summary>
public bool IsForceUpdate { get; set; } = false;
/// <summary>
/// 最低支持版本
/// </summary>
[MaxLength(20)]
public string? MinimumSupportedVersion { get; set; }
}

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

@ -0,0 +1,93 @@
using MediatR;
using Microsoft.Extensions.Logging;
using CellularManagement.Domain.Common;
using CellularManagement.Domain.Entities.Device;
using CellularManagement.Domain.Repositories.Device;
namespace CellularManagement.Application.Features.ProtocolVersions.Commands.UpdateProtocolVersion;
/// <summary>
/// 更新协议版本命令处理器
/// </summary>
public class UpdateProtocolVersionCommandHandler : IRequestHandler<UpdateProtocolVersionCommand, OperationResult<UpdateProtocolVersionResponse>>
{
private readonly IProtocolVersionRepository _protocolVersionRepository;
private readonly ILogger<UpdateProtocolVersionCommandHandler> _logger;
/// <summary>
/// 初始化命令处理器
/// </summary>
public UpdateProtocolVersionCommandHandler(
IProtocolVersionRepository protocolVersionRepository,
ILogger<UpdateProtocolVersionCommandHandler> logger)
{
_protocolVersionRepository = protocolVersionRepository;
_logger = logger;
}
/// <summary>
/// 处理更新协议版本命令
/// </summary>
public async Task<OperationResult<UpdateProtocolVersionResponse>> Handle(UpdateProtocolVersionCommand request, CancellationToken cancellationToken)
{
try
{
_logger.LogInformation("开始更新协议版本,版本ID: {ProtocolVersionId}, 版本名称: {Name}",
request.ProtocolVersionId, request.Name);
// 检查协议版本是否存在
var existingProtocolVersion = await _protocolVersionRepository.GetProtocolVersionByIdAsync(request.ProtocolVersionId, cancellationToken);
if (existingProtocolVersion == null)
{
_logger.LogWarning("未找到协议版本,版本ID: {ProtocolVersionId}", request.ProtocolVersionId);
return OperationResult<UpdateProtocolVersionResponse>.CreateFailure($"未找到ID为 {request.ProtocolVersionId} 的协议版本");
}
// 如果版本号发生变化,检查新版本号是否已存在
if (existingProtocolVersion.Version != request.Version)
{
if (await _protocolVersionRepository.VersionExistsAsync(request.Version, cancellationToken))
{
_logger.LogWarning("协议版本号已存在: {Version}", request.Version);
return OperationResult<UpdateProtocolVersionResponse>.CreateFailure($"协议版本号 {request.Version} 已存在");
}
}
// 更新协议版本属性
existingProtocolVersion.Update(
name: request.Name,
version: request.Version,
description: request.Description,
isEnabled: request.IsEnabled,
releaseDate: request.ReleaseDate,
isForceUpdate: request.IsForceUpdate,
minimumSupportedVersion: request.MinimumSupportedVersion);
_protocolVersionRepository.UpdateProtocolVersion(existingProtocolVersion);
// 构建响应
var response = new UpdateProtocolVersionResponse
{
ProtocolVersionId = existingProtocolVersion.Id,
Name = existingProtocolVersion.Name,
Version = existingProtocolVersion.Version,
Description = existingProtocolVersion.Description,
IsEnabled = existingProtocolVersion.IsEnabled,
ReleaseDate = existingProtocolVersion.ReleaseDate,
IsForceUpdate = existingProtocolVersion.IsForceUpdate,
MinimumSupportedVersion = existingProtocolVersion.MinimumSupportedVersion,
UpdatedAt = DateTime.UtcNow
};
_logger.LogInformation("协议版本更新成功,版本ID: {ProtocolVersionId}, 版本名称: {Name}",
existingProtocolVersion.Id, existingProtocolVersion.Name);
return OperationResult<UpdateProtocolVersionResponse>.CreateSuccess(response);
}
catch (Exception ex)
{
_logger.LogError(ex, "更新协议版本时发生错误,版本ID: {ProtocolVersionId}, 版本名称: {Name}",
request.ProtocolVersionId, request.Name);
return OperationResult<UpdateProtocolVersionResponse>.CreateFailure($"更新协议版本时发生错误: {ex.Message}");
}
}
}

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

@ -0,0 +1,52 @@
namespace CellularManagement.Application.Features.ProtocolVersions.Commands.UpdateProtocolVersion;
/// <summary>
/// 更新协议版本响应
/// </summary>
public class UpdateProtocolVersionResponse
{
/// <summary>
/// 协议版本ID
/// </summary>
public string ProtocolVersionId { get; set; } = null!;
/// <summary>
/// 版本名称
/// </summary>
public string Name { get; set; } = null!;
/// <summary>
/// 版本号
/// </summary>
public string Version { get; set; } = null!;
/// <summary>
/// 版本描述
/// </summary>
public string? Description { get; set; }
/// <summary>
/// 是否启用
/// </summary>
public bool IsEnabled { get; set; }
/// <summary>
/// 发布日期
/// </summary>
public DateTime? ReleaseDate { get; set; }
/// <summary>
/// 是否强制更新
/// </summary>
public bool IsForceUpdate { get; set; }
/// <summary>
/// 最低支持版本
/// </summary>
public string? MinimumSupportedVersion { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime UpdatedAt { get; set; }
}

17
src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersionById/GetProtocolVersionByIdQuery.cs

@ -0,0 +1,17 @@
using CellularManagement.Domain.Common;
using MediatR;
using System.ComponentModel.DataAnnotations;
namespace CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersionById;
/// <summary>
/// 根据ID获取协议版本查询
/// </summary>
public class GetProtocolVersionByIdQuery : IRequest<OperationResult<GetProtocolVersionByIdResponse>>
{
/// <summary>
/// 协议版本ID
/// </summary>
[Required]
public string ProtocolVersionId { get; set; } = null!;
}

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

@ -0,0 +1,68 @@
using CellularManagement.Domain.Common;
using CellularManagement.Domain.Entities.Device;
using CellularManagement.Domain.Repositories.Device;
using MediatR;
using Microsoft.Extensions.Logging;
namespace CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersionById;
/// <summary>
/// 根据ID获取协议版本查询处理器
/// </summary>
public class GetProtocolVersionByIdQueryHandler : IRequestHandler<GetProtocolVersionByIdQuery, OperationResult<GetProtocolVersionByIdResponse>>
{
private readonly IProtocolVersionRepository _protocolVersionRepository;
private readonly ILogger<GetProtocolVersionByIdQueryHandler> _logger;
/// <summary>
/// 初始化查询处理器
/// </summary>
public GetProtocolVersionByIdQueryHandler(
IProtocolVersionRepository protocolVersionRepository,
ILogger<GetProtocolVersionByIdQueryHandler> logger)
{
_protocolVersionRepository = protocolVersionRepository;
_logger = logger;
}
/// <summary>
/// 处理查询请求
/// </summary>
public async Task<OperationResult<GetProtocolVersionByIdResponse>> Handle(GetProtocolVersionByIdQuery request, CancellationToken cancellationToken)
{
try
{
_logger.LogInformation("开始查询协议版本,版本ID: {ProtocolVersionId}", request.ProtocolVersionId);
var protocolVersion = await _protocolVersionRepository.GetProtocolVersionByIdAsync(request.ProtocolVersionId, cancellationToken);
if (protocolVersion == null)
{
_logger.LogWarning("未找到协议版本,版本ID: {ProtocolVersionId}", request.ProtocolVersionId);
return OperationResult<GetProtocolVersionByIdResponse>.CreateFailure($"未找到ID为 {request.ProtocolVersionId} 的协议版本");
}
var response = new GetProtocolVersionByIdResponse
{
ProtocolVersionId = protocolVersion.Id,
Name = protocolVersion.Name,
Version = protocolVersion.Version,
Description = protocolVersion.Description,
IsEnabled = protocolVersion.IsEnabled,
ReleaseDate = protocolVersion.ReleaseDate,
IsForceUpdate = protocolVersion.IsForceUpdate,
MinimumSupportedVersion = protocolVersion.MinimumSupportedVersion,
CreatedAt = protocolVersion.CreatedAt,
UpdatedAt = protocolVersion.UpdatedAt
};
_logger.LogInformation("成功查询到协议版本,版本ID: {ProtocolVersionId}", request.ProtocolVersionId);
return OperationResult<GetProtocolVersionByIdResponse>.CreateSuccess(response);
}
catch (Exception ex)
{
_logger.LogError(ex, "查询协议版本时发生错误,版本ID: {ProtocolVersionId}", request.ProtocolVersionId);
return OperationResult<GetProtocolVersionByIdResponse>.CreateFailure($"查询协议版本时发生错误: {ex.Message}");
}
}
}

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

@ -0,0 +1,57 @@
namespace CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersionById;
/// <summary>
/// 根据ID获取协议版本响应
/// </summary>
public class GetProtocolVersionByIdResponse
{
/// <summary>
/// 协议版本ID
/// </summary>
public string ProtocolVersionId { get; set; } = null!;
/// <summary>
/// 版本名称
/// </summary>
public string Name { get; set; } = null!;
/// <summary>
/// 版本号
/// </summary>
public string Version { get; set; } = null!;
/// <summary>
/// 版本描述
/// </summary>
public string? Description { get; set; }
/// <summary>
/// 是否启用
/// </summary>
public bool IsEnabled { get; set; }
/// <summary>
/// 发布日期
/// </summary>
public DateTime? ReleaseDate { get; set; }
/// <summary>
/// 是否强制更新
/// </summary>
public bool IsForceUpdate { get; set; }
/// <summary>
/// 最低支持版本
/// </summary>
public string? MinimumSupportedVersion { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreatedAt { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime? UpdatedAt { get; set; }
}

34
src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersions/GetProtocolVersionsQuery.cs

@ -0,0 +1,34 @@
using CellularManagement.Domain.Common;
using MediatR;
using System.ComponentModel.DataAnnotations;
namespace CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersions;
/// <summary>
/// 获取协议版本列表查询
/// </summary>
public class GetProtocolVersionsQuery : IRequest<OperationResult<GetProtocolVersionsResponse>>
{
/// <summary>
/// 页码
/// </summary>
[Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")]
public int PageNumber { get; set; } = 1;
/// <summary>
/// 每页数量
/// </summary>
[Range(1, 100, ErrorMessage = "每页数量必须在1-100之间")]
public int PageSize { get; set; } = 10;
/// <summary>
/// 搜索关键词
/// </summary>
[MaxLength(100)]
public string? SearchTerm { get; set; }
/// <summary>
/// 是否只获取启用的版本
/// </summary>
public bool? IsEnabled { get; set; }
}

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

@ -0,0 +1,103 @@
using MediatR;
using Microsoft.Extensions.Logging;
using CellularManagement.Domain.Common;
using CellularManagement.Domain.Entities.Device;
using CellularManagement.Domain.Repositories;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersionById;
using CellularManagement.Domain.Repositories.Device;
namespace CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersions;
/// <summary>
/// 获取协议版本列表查询处理器
/// </summary>
public class GetProtocolVersionsQueryHandler : IRequestHandler<GetProtocolVersionsQuery, OperationResult<GetProtocolVersionsResponse>>
{
private readonly IProtocolVersionRepository _protocolVersionRepository;
private readonly ILogger<GetProtocolVersionsQueryHandler> _logger;
/// <summary>
/// 初始化查询处理器
/// </summary>
public GetProtocolVersionsQueryHandler(
IProtocolVersionRepository protocolVersionRepository,
ILogger<GetProtocolVersionsQueryHandler> logger)
{
_protocolVersionRepository = protocolVersionRepository;
_logger = logger;
}
/// <summary>
/// 处理获取协议版本列表查询
/// </summary>
public async Task<OperationResult<GetProtocolVersionsResponse>> Handle(GetProtocolVersionsQuery request, CancellationToken cancellationToken)
{
try
{
// 验证请求参数
var validationContext = new ValidationContext(request);
var validationResults = new List<ValidationResult>();
if (!Validator.TryValidateObject(request, validationContext, validationResults, true))
{
var errorMessages = validationResults.Select(r => r.ErrorMessage).ToList();
_logger.LogWarning("请求参数无效: {Errors}", string.Join(", ", errorMessages));
return OperationResult<GetProtocolVersionsResponse>.CreateFailure(errorMessages);
}
_logger.LogInformation("开始获取协议版本列表,页码: {PageNumber}, 每页数量: {PageSize}, 搜索关键词: {SearchTerm}, 是否启用: {IsEnabled}",
request.PageNumber, request.PageSize, request.SearchTerm, request.IsEnabled);
// 获取协议版本数据
var protocolVersions = await _protocolVersionRepository.SearchProtocolVersionsAsync(
request.SearchTerm,
cancellationToken);
// 如果指定了启用状态过滤
if (request.IsEnabled.HasValue)
{
protocolVersions = protocolVersions.Where(pv => pv.IsEnabled == request.IsEnabled.Value).ToList();
}
// 计算分页
int totalCount = protocolVersions.Count();
var items = protocolVersions
.Skip((request.PageNumber - 1) * request.PageSize)
.Take(request.PageSize)
.ToList();
// 构建响应
var response = new GetProtocolVersionsResponse
{
TotalCount = totalCount,
PageNumber = request.PageNumber,
PageSize = request.PageSize,
TotalPages = (int)Math.Ceiling(totalCount / (double)request.PageSize),
HasPreviousPage = request.PageNumber > 1,
HasNextPage = request.PageNumber < (int)Math.Ceiling(totalCount / (double)request.PageSize),
Items = items.Select(pv => new GetProtocolVersionByIdResponse
{
ProtocolVersionId = pv.Id,
Name = pv.Name,
Version = pv.Version,
Description = pv.Description,
IsEnabled = pv.IsEnabled,
ReleaseDate = pv.ReleaseDate,
IsForceUpdate = pv.IsForceUpdate,
MinimumSupportedVersion = pv.MinimumSupportedVersion,
CreatedAt = pv.CreatedAt,
UpdatedAt = pv.UpdatedAt
}).ToList()
};
_logger.LogInformation("成功获取协议版本列表,共 {Count} 条记录", items.Count);
return OperationResult<GetProtocolVersionsResponse>.CreateSuccess(response);
}
catch (Exception ex)
{
_logger.LogError(ex, "获取协议版本列表时发生错误");
return OperationResult<GetProtocolVersionsResponse>.CreateFailure($"获取协议版本列表时发生错误: {ex.Message}");
}
}
}

44
src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersions/GetProtocolVersionsResponse.cs

@ -0,0 +1,44 @@
using CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersionById;
namespace CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersions;
/// <summary>
/// 获取协议版本列表响应
/// </summary>
public class GetProtocolVersionsResponse
{
/// <summary>
/// 总数量
/// </summary>
public int TotalCount { get; set; }
/// <summary>
/// 当前页码
/// </summary>
public int PageNumber { get; set; }
/// <summary>
/// 每页数量
/// </summary>
public int PageSize { get; set; }
/// <summary>
/// 总页数
/// </summary>
public int TotalPages { get; set; }
/// <summary>
/// 是否有上一页
/// </summary>
public bool HasPreviousPage { get; set; }
/// <summary>
/// 是否有下一页
/// </summary>
public bool HasNextPage { get; set; }
/// <summary>
/// 协议版本列表
/// </summary>
public List<GetProtocolVersionByIdResponse> Items { get; set; } = new();
}

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

@ -11,12 +11,6 @@ public class CellularDevice : AuditableEntity
{
private CellularDevice() { }
/// <summary>
/// 设备ID
/// </summary>
[Key]
public string Id { get; private set; }
/// <summary>
/// 设备名称
/// </summary>
@ -37,30 +31,6 @@ public class CellularDevice : AuditableEntity
[MaxLength(500)]
public string Description { get; private set; }
/// <summary>
/// 设备类型ID
/// </summary>
[Required]
public string DeviceTypeId { get; private set; }
/// <summary>
/// 设备类型
/// </summary>
[ForeignKey(nameof(DeviceTypeId))]
public virtual DeviceType DeviceType { get; private set; } = null!;
/// <summary>
/// 设备状态ID
/// </summary>
[Required]
public string StatusId { get; private set; }
/// <summary>
/// 设备状态
/// </summary>
[ForeignKey(nameof(StatusId))]
public virtual DeviceStatus Status { get; private set; } = null!;
/// <summary>
/// 协议版本ID
/// </summary>
@ -74,21 +44,22 @@ public class CellularDevice : AuditableEntity
public virtual ProtocolVersion ProtocolVersion { get; private set; } = null!;
/// <summary>
/// 当前固件版本
/// Agent端口
/// </summary>
[Required]
[MaxLength(50)]
public string FirmwareVersion { get; private set; } = null!;
public int AgentPort { get; private set; }
/// <summary>
/// 创建时间
/// IP地址
/// </summary>
public DateTime CreatedAt { get; private set; }
[Required]
[MaxLength(45)]
public string IpAddress { get; private set; } = null!;
/// <summary>
/// 更新时间
/// 是否启用
/// </summary>
public DateTime UpdatedAt { get; private set; }
public bool IsEnabled { get; private set; } = true;
/// <summary>
/// 创建设备
@ -97,10 +68,10 @@ public class CellularDevice : AuditableEntity
string name,
string serialNumber,
string description,
string deviceTypeId,
string statusId,
string protocolVersionId,
string firmwareVersion)
int agentPort,
string ipAddress,
bool isEnabled = true)
{
var device = new CellularDevice
{
@ -108,10 +79,10 @@ public class CellularDevice : AuditableEntity
Name = name,
SerialNumber = serialNumber,
Description = description,
DeviceTypeId = deviceTypeId,
StatusId = statusId,
ProtocolVersionId = protocolVersionId,
FirmwareVersion = firmwareVersion,
AgentPort = agentPort,
IpAddress = ipAddress,
IsEnabled = isEnabled,
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow
};
@ -126,18 +97,36 @@ public class CellularDevice : AuditableEntity
string name,
string serialNumber,
string description,
string deviceTypeId,
string statusId,
string protocolVersionId,
string firmwareVersion)
int agentPort,
string ipAddress,
bool isEnabled = true)
{
Name = name;
SerialNumber = serialNumber;
Description = description;
DeviceTypeId = deviceTypeId;
StatusId = statusId;
ProtocolVersionId = protocolVersionId;
FirmwareVersion = firmwareVersion;
AgentPort = agentPort;
IpAddress = ipAddress;
IsEnabled = isEnabled;
UpdatedAt = DateTime.UtcNow;
}
/// <summary>
/// 启用设备
/// </summary>
public void Enable()
{
IsEnabled = true;
UpdatedAt = DateTime.UtcNow;
}
/// <summary>
/// 禁用设备
/// </summary>
public void Disable()
{
IsEnabled = false;
UpdatedAt = DateTime.UtcNow;
}
}

46
src/X1.Domain/Entities/Device/DeviceStatus.cs

@ -1,46 +0,0 @@
using System.ComponentModel.DataAnnotations;
using CellularManagement.Domain.Entities.Common;
namespace CellularManagement.Domain.Entities.Device;
/// <summary>
/// 设备状态实体
/// </summary>
public class DeviceStatus : AuditableEntity
{
/// <summary>
/// 状态名称
/// </summary>
[Required]
[MaxLength(50)]
public string Name { get; set; } = null!;
/// <summary>
/// 状态代码
/// </summary>
[Required]
[MaxLength(20)]
public string Code { get; set; } = null!;
/// <summary>
/// 状态描述
/// </summary>
[MaxLength(200)]
public string? Description { get; set; }
/// <summary>
/// 状态颜色
/// </summary>
[MaxLength(20)]
public string? Color { get; set; }
/// <summary>
/// 是否启用
/// </summary>
public bool IsEnabled { get; set; } = true;
/// <summary>
/// 排序号
/// </summary>
public int SortOrder { get; set; }
}

40
src/X1.Domain/Entities/Device/DeviceType.cs

@ -1,40 +0,0 @@
using System.ComponentModel.DataAnnotations;
using CellularManagement.Domain.Entities.Common;
namespace CellularManagement.Domain.Entities.Device;
/// <summary>
/// 设备类型实体
/// </summary>
public class DeviceType : AuditableEntity
{
/// <summary>
/// 类型名称
/// </summary>
[Required]
[MaxLength(50)]
public string Name { get; set; } = null!;
/// <summary>
/// 类型代码
/// </summary>
[Required]
[MaxLength(20)]
public string Code { get; set; } = null!;
/// <summary>
/// 类型描述
/// </summary>
[MaxLength(200)]
public string? Description { get; set; }
/// <summary>
/// 是否启用
/// </summary>
public bool IsEnabled { get; set; } = true;
/// <summary>
/// 排序号
/// </summary>
public int SortOrder { get; set; }
}

101
src/X1.Domain/Entities/Device/ProtocolVersion.cs

@ -8,51 +8,124 @@ namespace CellularManagement.Domain.Entities.Device;
/// </summary>
public class ProtocolVersion : AuditableEntity
{
private ProtocolVersion() { }
/// <summary>
/// 版本名称
/// </summary>
[Required]
[MaxLength(50)]
public string Name { get; set; } = null!;
public string Name { get; private set; } = null!;
/// <summary>
/// 版本号
/// </summary>
[Required]
[MaxLength(20)]
public string Version { get; set; } = null!;
/// <summary>
/// 协议类型
/// </summary>
[Required]
[MaxLength(50)]
public string ProtocolType { get; set; } = null!;
public string Version { get; private set; } = null!;
/// <summary>
/// 版本描述
/// </summary>
[MaxLength(500)]
public string? Description { get; set; }
public string? Description { get; private set; }
/// <summary>
/// 是否启用
/// </summary>
public bool IsEnabled { get; set; } = true;
public bool IsEnabled { get; private set; } = true;
/// <summary>
/// 发布日期
/// </summary>
public DateTime? ReleaseDate { get; set; }
public DateTime? ReleaseDate { get; private set; }
/// <summary>
/// 是否强制更新
/// </summary>
public bool IsForceUpdate { get; set; }
public bool IsForceUpdate { get; private set; }
/// <summary>
/// 最低支持版本
/// </summary>
[MaxLength(20)]
public string? MinimumSupportedVersion { get; set; }
public string? MinimumSupportedVersion { get; private set; }
/// <summary>
/// 创建协议版本
/// </summary>
public static ProtocolVersion Create(
string name,
string version,
string? description = null,
bool isEnabled = true,
DateTime? releaseDate = null,
bool isForceUpdate = false,
string? minimumSupportedVersion = null)
{
var protocolVersion = new ProtocolVersion
{
Id = Guid.NewGuid().ToString(),
Name = name,
Version = version,
Description = description,
IsEnabled = isEnabled,
ReleaseDate = releaseDate,
IsForceUpdate = isForceUpdate,
MinimumSupportedVersion = minimumSupportedVersion,
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow
};
return protocolVersion;
}
/// <summary>
/// 更新协议版本
/// </summary>
public void Update(
string name,
string version,
string? description = null,
bool isEnabled = true,
DateTime? releaseDate = null,
bool isForceUpdate = false,
string? minimumSupportedVersion = null)
{
Name = name;
Version = version;
Description = description;
IsEnabled = isEnabled;
ReleaseDate = releaseDate;
IsForceUpdate = isForceUpdate;
MinimumSupportedVersion = minimumSupportedVersion;
UpdatedAt = DateTime.UtcNow;
}
/// <summary>
/// 启用协议版本
/// </summary>
public void Enable()
{
IsEnabled = true;
UpdatedAt = DateTime.UtcNow;
}
/// <summary>
/// 禁用协议版本
/// </summary>
public void Disable()
{
IsEnabled = false;
UpdatedAt = DateTime.UtcNow;
}
/// <summary>
/// 设置强制更新
/// </summary>
public void SetForceUpdate(bool isForceUpdate)
{
IsForceUpdate = isForceUpdate;
UpdatedAt = DateTime.UtcNow;
}
}

30
src/X1.Domain/Repositories/Device/ICellularDeviceRepository.cs

@ -10,7 +10,6 @@ namespace CellularManagement.Domain.Repositories.Device;
/// </summary>
public interface ICellularDeviceRepository : IBaseRepository<CellularDevice>
{
/// <summary>
/// 添加蜂窝设备
/// </summary>
@ -19,28 +18,13 @@ public interface ICellularDeviceRepository : IBaseRepository<CellularDevice>
/// <summary>
/// 更新蜂窝设备
/// </summary>
Task UpdateDeviceAsync(CellularDevice device, CancellationToken cancellationToken = default);
void UpdateDevice(CellularDevice device);
/// <summary>
/// 删除蜂窝设备
/// </summary>
Task DeleteDeviceAsync(string id, CancellationToken cancellationToken = default);
/// <summary>
/// 批量添加蜂窝设备
/// </summary>
Task AddDevicesAsync(IEnumerable<CellularDevice> devices, CancellationToken cancellationToken = default);
/// <summary>
/// 批量更新蜂窝设备
/// </summary>
Task UpdateDevicesAsync(IEnumerable<CellularDevice> devices, CancellationToken cancellationToken = default);
/// <summary>
/// 批量删除蜂窝设备
/// </summary>
Task DeleteDevicesAsync(IEnumerable<string> ids, CancellationToken cancellationToken = default);
/// <summary>
/// 获取所有蜂窝设备
/// </summary>
@ -56,23 +40,11 @@ public interface ICellularDeviceRepository : IBaseRepository<CellularDevice>
/// </summary>
Task<CellularDevice?> GetDeviceBySerialNumberAsync(string serialNumber, CancellationToken cancellationToken = default);
/// <summary>
/// 获取指定类型的蜂窝设备
/// </summary>
Task<IList<CellularDevice>> GetDevicesByTypeAsync(string deviceTypeId, CancellationToken cancellationToken = default);
/// <summary>
/// 获取指定状态的蜂窝设备
/// </summary>
Task<IList<CellularDevice>> GetDevicesByStatusAsync(string statusId, CancellationToken cancellationToken = default);
/// <summary>
/// 搜索蜂窝设备
/// </summary>
Task<IList<CellularDevice>> SearchDevicesAsync(
string? keyword,
string? deviceTypeId,
string? statusId,
CancellationToken cancellationToken = default);
/// <summary>

63
src/X1.Domain/Repositories/Device/IProtocolVersionRepository.cs

@ -0,0 +1,63 @@
using CellularManagement.Domain.Entities;
using CellularManagement.Domain.Entities.Device;
using CellularManagement.Domain.Repositories.Base;
namespace CellularManagement.Domain.Repositories.Device;
/// <summary>
/// 协议版本仓储接口
/// </summary>
public interface IProtocolVersionRepository : IBaseRepository<ProtocolVersion>
{
/// <summary>
/// 添加协议版本
/// </summary>
Task<ProtocolVersion> AddProtocolVersionAsync(ProtocolVersion protocolVersion, CancellationToken cancellationToken = default);
/// <summary>
/// 更新协议版本
/// </summary>
void UpdateProtocolVersion(ProtocolVersion protocolVersion);
/// <summary>
/// 删除协议版本
/// </summary>
Task DeleteProtocolVersionAsync(string id, CancellationToken cancellationToken = default);
/// <summary>
/// 获取所有协议版本
/// </summary>
Task<IList<ProtocolVersion>> GetAllProtocolVersionsAsync(CancellationToken cancellationToken = default);
/// <summary>
/// 根据ID获取协议版本
/// </summary>
Task<ProtocolVersion?> GetProtocolVersionByIdAsync(string id, CancellationToken cancellationToken = default);
/// <summary>
/// 根据版本号获取协议版本
/// </summary>
Task<ProtocolVersion?> GetProtocolVersionByVersionAsync(string version, CancellationToken cancellationToken = default);
/// <summary>
/// 搜索协议版本
/// </summary>
Task<IList<ProtocolVersion>> SearchProtocolVersionsAsync(
string? keyword,
CancellationToken cancellationToken = default);
/// <summary>
/// 检查协议版本是否存在
/// </summary>
Task<bool> ExistsAsync(string id, CancellationToken cancellationToken = default);
/// <summary>
/// 检查版本号是否存在
/// </summary>
Task<bool> VersionExistsAsync(string version, CancellationToken cancellationToken = default);
/// <summary>
/// 获取启用的协议版本
/// </summary>
Task<IList<ProtocolVersion>> GetEnabledProtocolVersionsAsync(CancellationToken cancellationToken = default);
}

19
src/X1.Infrastructure/Configurations/Device/CellularDeviceConfiguration.cs

@ -13,8 +13,6 @@ public class CellularDeviceConfiguration : IEntityTypeConfiguration<CellularDevi
// 配置索引
builder.HasIndex(d => d.SerialNumber).IsUnique().HasDatabaseName("IX_CellularDevices_SerialNumber");
builder.HasIndex(d => d.DeviceTypeId).HasDatabaseName("IX_CellularDevices_DeviceTypeId");
builder.HasIndex(d => d.StatusId).HasDatabaseName("IX_CellularDevices_StatusId");
builder.HasIndex(d => d.ProtocolVersionId).HasDatabaseName("IX_CellularDevices_ProtocolVersionId");
// 配置属性
@ -22,24 +20,13 @@ public class CellularDeviceConfiguration : IEntityTypeConfiguration<CellularDevi
builder.Property(d => d.Name).IsRequired().HasMaxLength(100).HasComment("设备名称");
builder.Property(d => d.SerialNumber).IsRequired().HasMaxLength(50).HasComment("序列号");
builder.Property(d => d.Description).HasMaxLength(500).HasComment("设备描述");
builder.Property(d => d.DeviceTypeId).IsRequired().HasMaxLength(50).HasComment("设备类型ID");
builder.Property(d => d.StatusId).IsRequired().HasMaxLength(50).HasComment("设备状态ID");
builder.Property(d => d.ProtocolVersionId).IsRequired().HasMaxLength(50).HasComment("协议版本ID");
builder.Property(d => d.FirmwareVersion).HasMaxLength(50).HasComment("固件版本");
builder.Property(d => d.AgentPort).IsRequired().HasComment("Agent端口");
builder.Property(d => d.IsEnabled).IsRequired().HasComment("是否启用");
builder.Property(d => d.CreatedAt).IsRequired().HasComment("创建时间");
builder.Property(d => d.UpdatedAt).IsRequired().HasComment("更新时间");
// 配置外键关系
builder.HasOne(d => d.DeviceType)
.WithMany()
.HasForeignKey(d => d.DeviceTypeId)
.OnDelete(DeleteBehavior.Restrict);
builder.HasOne(d => d.Status)
.WithMany()
.HasForeignKey(d => d.StatusId)
.OnDelete(DeleteBehavior.Restrict);
// 配置关系
builder.HasOne(d => d.ProtocolVersion)
.WithMany()
.HasForeignKey(d => d.ProtocolVersionId)

21
src/X1.Infrastructure/Configurations/Device/DeviceStatusConfiguration.cs

@ -1,21 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using CellularManagement.Domain.Entities.Device;
namespace CellularManagement.Infrastructure.Configurations.Device;
public class DeviceStatusConfiguration : IEntityTypeConfiguration<DeviceStatus>
{
public void Configure(EntityTypeBuilder<DeviceStatus> builder)
{
builder.ToTable("DeviceStatuses", t => t.HasComment("设备状态表"));
builder.HasKey(s => s.Id);
// 配置属性
builder.Property(s => s.Id).HasComment("状态ID");
builder.Property(s => s.Name).IsRequired().HasMaxLength(50).HasComment("状态名称");
builder.Property(s => s.Description).HasMaxLength(200).HasComment("状态描述");
builder.Property(s => s.CreatedAt).IsRequired().HasComment("创建时间");
builder.Property(s => s.UpdatedAt).IsRequired().HasComment("更新时间");
}
}

21
src/X1.Infrastructure/Configurations/Device/DeviceTypeConfiguration.cs

@ -1,21 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using CellularManagement.Domain.Entities.Device;
namespace CellularManagement.Infrastructure.Configurations.Device;
public class DeviceTypeConfiguration : IEntityTypeConfiguration<DeviceType>
{
public void Configure(EntityTypeBuilder<DeviceType> builder)
{
builder.ToTable("DeviceTypes", t => t.HasComment("设备类型表"));
builder.HasKey(t => t.Id);
// 配置属性
builder.Property(t => t.Id).HasComment("类型ID");
builder.Property(t => t.Name).IsRequired().HasMaxLength(50).HasComment("类型名称");
builder.Property(t => t.Description).HasMaxLength(200).HasComment("类型描述");
builder.Property(t => t.CreatedAt).IsRequired().HasComment("创建时间");
builder.Property(t => t.UpdatedAt).IsRequired().HasComment("更新时间");
}
}

9
src/X1.Infrastructure/Configurations/Device/ProtocolVersionConfiguration.cs

@ -16,8 +16,13 @@ public class ProtocolVersionConfiguration : IEntityTypeConfiguration<ProtocolVer
// 配置属性
builder.Property(v => v.Id).HasComment("版本ID");
builder.Property(v => v.Version).IsRequired().HasMaxLength(50).HasComment("版本号");
builder.Property(v => v.Description).HasMaxLength(200).HasComment("版本描述");
builder.Property(v => v.Name).IsRequired().HasMaxLength(50).HasComment("版本名称");
builder.Property(v => v.Version).IsRequired().HasMaxLength(20).HasComment("版本号");
builder.Property(v => v.Description).HasMaxLength(500).HasComment("版本描述");
builder.Property(v => v.IsEnabled).IsRequired().HasComment("是否启用");
builder.Property(v => v.ReleaseDate).HasComment("发布日期");
builder.Property(v => v.IsForceUpdate).IsRequired().HasComment("是否强制更新");
builder.Property(v => v.MinimumSupportedVersion).HasMaxLength(20).HasComment("最低支持版本");
builder.Property(v => v.CreatedAt).IsRequired().HasComment("创建时间");
builder.Property(v => v.UpdatedAt).IsRequired().HasComment("更新时间");
}

10
src/X1.Infrastructure/Context/AppDbContext.cs

@ -41,16 +41,6 @@ public class AppDbContext : IdentityDbContext<AppUser, AppRole, string>
/// </summary>
public DbSet<CellularDevice> CellularDevices { get; set; } = null!;
/// <summary>
/// 设备类型集合
/// </summary>
public DbSet<DeviceType> DeviceTypes { get; set; } = null!;
/// <summary>
/// 设备状态集合
/// </summary>
public DbSet<DeviceStatus> DeviceStatuses { get; set; } = null!;
/// <summary>
/// 协议版本集合
/// </summary>

6
src/X1.Infrastructure/DependencyInjection.cs

@ -23,6 +23,8 @@ using CellularManagement.Infrastructure.Services.Authentication;
using CellularManagement.Infrastructure.Services.Infrastructure;
using CellularManagement.Infrastructure.Services.Security;
using CellularManagement.Infrastructure.Services.UserManagement;
using CellularManagement.Domain.Repositories.Device;
using CellularManagement.Infrastructure.Repositories.Device;
namespace CellularManagement.Infrastructure;
@ -170,6 +172,10 @@ public static class DependencyInjection
services.AddScoped<IUserRoleRepository, UserRoleRepository>();
services.AddScoped<IUserRoleServiceRepository, UserRoleServiceRepository>();
// 注册设备相关仓储
services.AddScoped<ICellularDeviceRepository, CellularDeviceRepository>();
services.AddScoped<IProtocolVersionRepository, ProtocolVersionRepository>();
return services;
}

168
src/X1.Infrastructure/Migrations/20250606094331_InitialCreate.Designer.cs → src/X1.Infrastructure/Migrations/20250705165102_InitialCreate.Designer.cs

@ -9,10 +9,10 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace CellularManagement.Infrastructure.Migrations
namespace X1.Infrastructure.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250606094331_InitialCreate")]
[Migration("20250705165102_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
@ -209,6 +209,10 @@ namespace CellularManagement.Infrastructure.Migrations
.HasColumnType("text")
.HasComment("设备ID");
b.Property<int>("AgentPort")
.HasColumnType("integer")
.HasComment("Agent端口");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间");
@ -223,21 +227,18 @@ namespace CellularManagement.Infrastructure.Migrations
.HasColumnType("character varying(500)")
.HasComment("设备描述");
b.Property<string>("DeviceTypeId")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("设备类型ID");
b.Property<string>("FirmwareVersion")
b.Property<string>("IpAddress")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("固件版本");
.HasMaxLength(45)
.HasColumnType("character varying(45)");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean")
.HasComment("是否启用");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
@ -256,13 +257,8 @@ namespace CellularManagement.Infrastructure.Migrations
.HasColumnType("character varying(50)")
.HasComment("序列号");
b.Property<string>("StatusId")
b.Property<DateTime?>("UpdatedAt")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("设备状态ID");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("更新时间");
@ -271,9 +267,6 @@ namespace CellularManagement.Infrastructure.Migrations
b.HasKey("Id");
b.HasIndex("DeviceTypeId")
.HasDatabaseName("IX_CellularDevices_DeviceTypeId");
b.HasIndex("ProtocolVersionId")
.HasDatabaseName("IX_CellularDevices_ProtocolVersionId");
@ -281,129 +274,12 @@ namespace CellularManagement.Infrastructure.Migrations
.IsUnique()
.HasDatabaseName("IX_CellularDevices_SerialNumber");
b.HasIndex("StatusId")
.HasDatabaseName("IX_CellularDevices_StatusId");
b.ToTable("CellularDevices", null, t =>
{
t.HasComment("蜂窝设备表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Device.DeviceStatus", b =>
{
b.Property<string>("Id")
.HasColumnType("text")
.HasComment("状态ID");
b.Property<string>("Code")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<string>("Color")
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.HasMaxLength(200)
.HasColumnType("character varying(200)")
.HasComment("状态描述");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("状态名称");
b.Property<int>("SortOrder")
.HasColumnType("integer");
b.Property<DateTime?>("UpdatedAt")
.IsRequired()
.HasColumnType("timestamp with time zone")
.HasComment("更新时间");
b.Property<string>("UpdatedBy")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("DeviceStatuses", null, t =>
{
t.HasComment("设备状态表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Device.DeviceType", b =>
{
b.Property<string>("Id")
.HasColumnType("text")
.HasComment("类型ID");
b.Property<string>("Code")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.HasMaxLength(200)
.HasColumnType("character varying(200)")
.HasComment("类型描述");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("类型名称");
b.Property<int>("SortOrder")
.HasColumnType("integer");
b.Property<DateTime?>("UpdatedAt")
.IsRequired()
.HasColumnType("timestamp with time zone")
.HasComment("更新时间");
b.Property<string>("UpdatedBy")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("DeviceTypes", null, t =>
{
t.HasComment("设备类型表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Device.ProtocolVersion", b =>
{
b.Property<string>("Id")
@ -640,29 +516,13 @@ namespace CellularManagement.Infrastructure.Migrations
modelBuilder.Entity("CellularManagement.Domain.Entities.Device.CellularDevice", b =>
{
b.HasOne("CellularManagement.Domain.Entities.Device.DeviceType", "DeviceType")
.WithMany()
.HasForeignKey("DeviceTypeId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("CellularManagement.Domain.Entities.Device.ProtocolVersion", "ProtocolVersion")
.WithMany()
.HasForeignKey("ProtocolVersionId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("CellularManagement.Domain.Entities.Device.DeviceStatus", "Status")
.WithMany()
.HasForeignKey("StatusId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("DeviceType");
b.Navigation("ProtocolVersion");
b.Navigation("Status");
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Logging.LoginLog", b =>

81
src/X1.Infrastructure/Migrations/20250606094331_InitialCreate.cs → src/X1.Infrastructure/Migrations/20250705165102_InitialCreate.cs

@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace CellularManagement.Infrastructure.Migrations
namespace X1.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
@ -11,51 +11,6 @@ namespace CellularManagement.Infrastructure.Migrations
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "DeviceStatuses",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false, comment: "状态ID"),
Name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, comment: "状态名称"),
Code = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
Description = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true, comment: "状态描述"),
Color = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true),
IsEnabled = table.Column<bool>(type: "boolean", nullable: false),
SortOrder = table.Column<int>(type: "integer", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "创建时间"),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "更新时间"),
IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
CreatedBy = table.Column<string>(type: "text", nullable: false),
UpdatedBy = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DeviceStatuses", x => x.Id);
},
comment: "设备状态表");
migrationBuilder.CreateTable(
name: "DeviceTypes",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false, comment: "类型ID"),
Name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, comment: "类型名称"),
Code = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
Description = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true, comment: "类型描述"),
IsEnabled = table.Column<bool>(type: "boolean", nullable: false),
SortOrder = table.Column<int>(type: "integer", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "创建时间"),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "更新时间"),
IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
CreatedBy = table.Column<string>(type: "text", nullable: false),
UpdatedBy = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DeviceTypes", x => x.Id);
},
comment: "设备类型表");
migrationBuilder.CreateTable(
name: "Permissions",
columns: table => new
@ -155,10 +110,10 @@ namespace CellularManagement.Infrastructure.Migrations
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false, comment: "设备名称"),
SerialNumber = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, comment: "序列号"),
Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false, comment: "设备描述"),
DeviceTypeId = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, comment: "设备类型ID"),
StatusId = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, comment: "设备状态ID"),
ProtocolVersionId = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, comment: "协议版本ID"),
FirmwareVersion = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, comment: "固件版本"),
AgentPort = table.Column<int>(type: "integer", nullable: false, comment: "Agent端口"),
IpAddress = table.Column<string>(type: "character varying(45)", maxLength: 45, nullable: false),
IsEnabled = table.Column<bool>(type: "boolean", nullable: false, comment: "是否启用"),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "创建时间"),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "更新时间"),
IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
@ -168,18 +123,6 @@ namespace CellularManagement.Infrastructure.Migrations
constraints: table =>
{
table.PrimaryKey("PK_CellularDevices", x => x.Id);
table.ForeignKey(
name: "FK_CellularDevices_DeviceStatuses_StatusId",
column: x => x.StatusId,
principalTable: "DeviceStatuses",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_CellularDevices_DeviceTypes_DeviceTypeId",
column: x => x.DeviceTypeId,
principalTable: "DeviceTypes",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_CellularDevices_ProtocolVersions_ProtocolVersionId",
column: x => x.ProtocolVersionId,
@ -272,11 +215,6 @@ namespace CellularManagement.Infrastructure.Migrations
},
comment: "用户角色关系表");
migrationBuilder.CreateIndex(
name: "IX_CellularDevices_DeviceTypeId",
table: "CellularDevices",
column: "DeviceTypeId");
migrationBuilder.CreateIndex(
name: "IX_CellularDevices_ProtocolVersionId",
table: "CellularDevices",
@ -288,11 +226,6 @@ namespace CellularManagement.Infrastructure.Migrations
column: "SerialNumber",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_CellularDevices_StatusId",
table: "CellularDevices",
column: "StatusId");
migrationBuilder.CreateIndex(
name: "IX_LoginLogs_IpAddress",
table: "LoginLogs",
@ -386,12 +319,6 @@ namespace CellularManagement.Infrastructure.Migrations
migrationBuilder.DropTable(
name: "UserRoles");
migrationBuilder.DropTable(
name: "DeviceStatuses");
migrationBuilder.DropTable(
name: "DeviceTypes");
migrationBuilder.DropTable(
name: "ProtocolVersions");

166
src/X1.Infrastructure/Migrations/AppDbContextModelSnapshot.cs

@ -8,7 +8,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace CellularManagement.Infrastructure.Migrations
namespace X1.Infrastructure.Migrations
{
[DbContext(typeof(AppDbContext))]
partial class AppDbContextModelSnapshot : ModelSnapshot
@ -206,6 +206,10 @@ namespace CellularManagement.Infrastructure.Migrations
.HasColumnType("text")
.HasComment("设备ID");
b.Property<int>("AgentPort")
.HasColumnType("integer")
.HasComment("Agent端口");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间");
@ -220,21 +224,18 @@ namespace CellularManagement.Infrastructure.Migrations
.HasColumnType("character varying(500)")
.HasComment("设备描述");
b.Property<string>("DeviceTypeId")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("设备类型ID");
b.Property<string>("FirmwareVersion")
b.Property<string>("IpAddress")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("固件版本");
.HasMaxLength(45)
.HasColumnType("character varying(45)");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean")
.HasComment("是否启用");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
@ -253,13 +254,8 @@ namespace CellularManagement.Infrastructure.Migrations
.HasColumnType("character varying(50)")
.HasComment("序列号");
b.Property<string>("StatusId")
b.Property<DateTime?>("UpdatedAt")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("设备状态ID");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("更新时间");
@ -268,9 +264,6 @@ namespace CellularManagement.Infrastructure.Migrations
b.HasKey("Id");
b.HasIndex("DeviceTypeId")
.HasDatabaseName("IX_CellularDevices_DeviceTypeId");
b.HasIndex("ProtocolVersionId")
.HasDatabaseName("IX_CellularDevices_ProtocolVersionId");
@ -278,129 +271,12 @@ namespace CellularManagement.Infrastructure.Migrations
.IsUnique()
.HasDatabaseName("IX_CellularDevices_SerialNumber");
b.HasIndex("StatusId")
.HasDatabaseName("IX_CellularDevices_StatusId");
b.ToTable("CellularDevices", null, t =>
{
t.HasComment("蜂窝设备表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Device.DeviceStatus", b =>
{
b.Property<string>("Id")
.HasColumnType("text")
.HasComment("状态ID");
b.Property<string>("Code")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<string>("Color")
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.HasMaxLength(200)
.HasColumnType("character varying(200)")
.HasComment("状态描述");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("状态名称");
b.Property<int>("SortOrder")
.HasColumnType("integer");
b.Property<DateTime?>("UpdatedAt")
.IsRequired()
.HasColumnType("timestamp with time zone")
.HasComment("更新时间");
b.Property<string>("UpdatedBy")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("DeviceStatuses", null, t =>
{
t.HasComment("设备状态表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Device.DeviceType", b =>
{
b.Property<string>("Id")
.HasColumnType("text")
.HasComment("类型ID");
b.Property<string>("Code")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.HasMaxLength(200)
.HasColumnType("character varying(200)")
.HasComment("类型描述");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("类型名称");
b.Property<int>("SortOrder")
.HasColumnType("integer");
b.Property<DateTime?>("UpdatedAt")
.IsRequired()
.HasColumnType("timestamp with time zone")
.HasComment("更新时间");
b.Property<string>("UpdatedBy")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("DeviceTypes", null, t =>
{
t.HasComment("设备类型表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Device.ProtocolVersion", b =>
{
b.Property<string>("Id")
@ -637,29 +513,13 @@ namespace CellularManagement.Infrastructure.Migrations
modelBuilder.Entity("CellularManagement.Domain.Entities.Device.CellularDevice", b =>
{
b.HasOne("CellularManagement.Domain.Entities.Device.DeviceType", "DeviceType")
.WithMany()
.HasForeignKey("DeviceTypeId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("CellularManagement.Domain.Entities.Device.ProtocolVersion", "ProtocolVersion")
.WithMany()
.HasForeignKey("ProtocolVersionId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("CellularManagement.Domain.Entities.Device.DeviceStatus", "Status")
.WithMany()
.HasForeignKey("StatusId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("DeviceType");
b.Navigation("ProtocolVersion");
b.Navigation("Status");
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Logging.LoginLog", b =>

72
src/X1.Infrastructure/Repositories/Device/CellularDeviceRepository.cs

@ -19,8 +19,6 @@ namespace CellularManagement.Infrastructure.Repositories.Device;
public class CellularDeviceRepository : BaseRepository<CellularDevice>, ICellularDeviceRepository
{
private readonly ILogger<CellularDeviceRepository> _logger;
private readonly IQueryRepository<DeviceType> _deviceTypeQueryRepository;
private readonly IQueryRepository<DeviceStatus> _deviceStatusQueryRepository;
private readonly IQueryRepository<ProtocolVersion> _protocolVersionQueryRepository;
/// <summary>
@ -29,20 +27,14 @@ public class CellularDeviceRepository : BaseRepository<CellularDevice>, ICellula
public CellularDeviceRepository(
ICommandRepository<CellularDevice> commandRepository,
IQueryRepository<CellularDevice> queryRepository,
IQueryRepository<DeviceType> deviceTypeQueryRepository,
IQueryRepository<DeviceStatus> deviceStatusQueryRepository,
IQueryRepository<ProtocolVersion> protocolVersionQueryRepository,
ILogger<CellularDeviceRepository> logger)
: base(commandRepository, queryRepository, logger)
{
_logger = logger;
_deviceTypeQueryRepository = deviceTypeQueryRepository;
_deviceStatusQueryRepository = deviceStatusQueryRepository;
_protocolVersionQueryRepository = protocolVersionQueryRepository;
}
#region ICellularDeviceCommandRepository 实现
/// <summary>
/// 添加蜂窝设备
/// </summary>
@ -54,7 +46,7 @@ public class CellularDeviceRepository : BaseRepository<CellularDevice>, ICellula
/// <summary>
/// 更新蜂窝设备
/// </summary>
public async Task UpdateDeviceAsync(CellularDevice device, CancellationToken cancellationToken = default)
public void UpdateDevice(CellularDevice device)
{
CommandRepository.Update(device);
}
@ -67,34 +59,6 @@ public class CellularDeviceRepository : BaseRepository<CellularDevice>, ICellula
await CommandRepository.DeleteByIdAsync(id, cancellationToken);
}
/// <summary>
/// 批量添加蜂窝设备
/// </summary>
public async Task AddDevicesAsync(IEnumerable<CellularDevice> devices, CancellationToken cancellationToken = default)
{
await CommandRepository.AddRangeAsync(devices, cancellationToken);
}
/// <summary>
/// 批量更新蜂窝设备
/// </summary>
public async Task UpdateDevicesAsync(IEnumerable<CellularDevice> devices, CancellationToken cancellationToken = default)
{
CommandRepository.UpdateRange(devices);
}
/// <summary>
/// 批量删除蜂窝设备
/// </summary>
public async Task DeleteDevicesAsync(IEnumerable<string> ids, CancellationToken cancellationToken = default)
{
await CommandRepository.DeleteWhereAsync(d => ids.Contains(d.Id), cancellationToken);
}
#endregion
#region ICellularDeviceQueryRepository 实现
/// <summary>
/// 获取所有蜂窝设备
/// </summary>
@ -120,34 +84,14 @@ public class CellularDeviceRepository : BaseRepository<CellularDevice>, ICellula
return await QueryRepository.FirstOrDefaultAsync(d => d.SerialNumber == serialNumber, cancellationToken);
}
/// <summary>
/// 获取指定类型的蜂窝设备
/// </summary>
public async Task<IList<CellularDevice>> GetDevicesByTypeAsync(string deviceTypeId, CancellationToken cancellationToken = default)
{
var devices = await QueryRepository.FindAsync(d => d.DeviceTypeId == deviceTypeId, cancellationToken);
return devices.ToList();
}
/// <summary>
/// 获取指定状态的蜂窝设备
/// </summary>
public async Task<IList<CellularDevice>> GetDevicesByStatusAsync(string statusId, CancellationToken cancellationToken = default)
{
var devices = await QueryRepository.FindAsync(d => d.StatusId == statusId, cancellationToken);
return devices.ToList();
}
/// <summary>
/// 搜索蜂窝设备
/// </summary>
public async Task<IList<CellularDevice>> SearchDevicesAsync(
string? keyword,
string? deviceTypeId,
string? statusId,
CancellationToken cancellationToken = default)
{
var query =await QueryRepository.FindAsync(d => true, cancellationToken);
var query = await QueryRepository.FindAsync(d => true, cancellationToken);
if (!string.IsNullOrWhiteSpace(keyword))
{
@ -157,16 +101,6 @@ public class CellularDeviceRepository : BaseRepository<CellularDevice>, ICellula
d.Description.Contains(keyword));
}
if (!string.IsNullOrWhiteSpace(deviceTypeId))
{
query = query.Where(d => d.DeviceTypeId == deviceTypeId);
}
if (!string.IsNullOrWhiteSpace(statusId))
{
query = query.Where(d => d.StatusId == statusId);
}
var devices = query;
return devices.ToList();
}
@ -186,6 +120,4 @@ public class CellularDeviceRepository : BaseRepository<CellularDevice>, ICellula
{
return await QueryRepository.AnyAsync(d => d.SerialNumber == serialNumber, cancellationToken);
}
#endregion
}

129
src/X1.Infrastructure/Repositories/Device/ProtocolVersionRepository.cs

@ -0,0 +1,129 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using System.Linq;
using Microsoft.Extensions.Logging;
using CellularManagement.Domain.Entities;
using CellularManagement.Domain.Repositories;
using CellularManagement.Infrastructure.Repositories.Base;
using CellularManagement.Domain.Entities.Device;
using CellularManagement.Domain.Repositories.Base;
using CellularManagement.Domain.Repositories.Device;
namespace CellularManagement.Infrastructure.Repositories.Device;
/// <summary>
/// 协议版本仓储实现类
/// </summary>
public class ProtocolVersionRepository : BaseRepository<ProtocolVersion>, IProtocolVersionRepository
{
private readonly ILogger<ProtocolVersionRepository> _logger;
/// <summary>
/// 初始化仓储
/// </summary>
public ProtocolVersionRepository(
ICommandRepository<ProtocolVersion> commandRepository,
IQueryRepository<ProtocolVersion> queryRepository,
ILogger<ProtocolVersionRepository> logger)
: base(commandRepository, queryRepository, logger)
{
_logger = logger;
}
/// <summary>
/// 添加协议版本
/// </summary>
public async Task<ProtocolVersion> AddProtocolVersionAsync(ProtocolVersion protocolVersion, CancellationToken cancellationToken = default)
{
return await CommandRepository.AddAsync(protocolVersion, cancellationToken);
}
/// <summary>
/// 更新协议版本
/// </summary>
public void UpdateProtocolVersion(ProtocolVersion protocolVersion)
{
CommandRepository.Update(protocolVersion);
}
/// <summary>
/// 删除协议版本
/// </summary>
public async Task DeleteProtocolVersionAsync(string id, CancellationToken cancellationToken = default)
{
await CommandRepository.DeleteByIdAsync(id, cancellationToken);
}
/// <summary>
/// 获取所有协议版本
/// </summary>
public async Task<IList<ProtocolVersion>> GetAllProtocolVersionsAsync(CancellationToken cancellationToken = default)
{
var protocolVersions = await QueryRepository.GetAllAsync(cancellationToken);
return protocolVersions.ToList();
}
/// <summary>
/// 根据ID获取协议版本
/// </summary>
public async Task<ProtocolVersion?> GetProtocolVersionByIdAsync(string id, CancellationToken cancellationToken = default)
{
return await QueryRepository.GetByIdAsync(id, cancellationToken);
}
/// <summary>
/// 根据版本号获取协议版本
/// </summary>
public async Task<ProtocolVersion?> GetProtocolVersionByVersionAsync(string version, CancellationToken cancellationToken = default)
{
return await QueryRepository.FirstOrDefaultAsync(pv => pv.Version == version, cancellationToken);
}
/// <summary>
/// 搜索协议版本
/// </summary>
public async Task<IList<ProtocolVersion>> SearchProtocolVersionsAsync(
string? keyword,
CancellationToken cancellationToken = default)
{
var query = await QueryRepository.FindAsync(pv => true, cancellationToken);
if (!string.IsNullOrWhiteSpace(keyword))
{
query = query.Where(pv =>
pv.Name.Contains(keyword) ||
pv.Version.Contains(keyword) ||
pv.Description.Contains(keyword));
}
var protocolVersions = query;
return protocolVersions.ToList();
}
/// <summary>
/// 检查协议版本是否存在
/// </summary>
public async Task<bool> ExistsAsync(string id, CancellationToken cancellationToken = default)
{
return await QueryRepository.AnyAsync(pv => pv.Id == id, cancellationToken);
}
/// <summary>
/// 检查版本号是否存在
/// </summary>
public async Task<bool> VersionExistsAsync(string version, CancellationToken cancellationToken = default)
{
return await QueryRepository.AnyAsync(pv => pv.Version == version, cancellationToken);
}
/// <summary>
/// 获取启用的协议版本
/// </summary>
public async Task<IList<ProtocolVersion>> GetEnabledProtocolVersionsAsync(CancellationToken cancellationToken = default)
{
var protocolVersions = await QueryRepository.FindAsync(pv => pv.IsEnabled, cancellationToken);
return protocolVersions.ToList();
}
}

135
src/X1.Presentation/Controllers/ProtocolVersionsController.cs

@ -0,0 +1,135 @@
using CellularManagement.Application.Features.ProtocolVersions.Commands.CreateProtocolVersion;
using CellularManagement.Application.Features.ProtocolVersions.Commands.DeleteProtocolVersion;
using CellularManagement.Application.Features.ProtocolVersions.Commands.UpdateProtocolVersion;
using CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersionById;
using CellularManagement.Application.Features.ProtocolVersions.Queries.GetProtocolVersions;
using CellularManagement.Domain.Common;
using CellularManagement.Presentation.Abstractions;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace CellularManagement.Presentation.Controllers;
/// <summary>
/// 协议版本管理控制器
/// </summary>
[Route("api/protocolversions")]
[ApiController]
[Authorize]
public class ProtocolVersionsController : ApiController
{
private readonly ILogger<ProtocolVersionsController> _logger;
/// <summary>
/// 初始化协议版本控制器
/// </summary>
public ProtocolVersionsController(IMediator mediator, ILogger<ProtocolVersionsController> logger)
: base(mediator)
{
_logger = logger;
}
/// <summary>
/// 获取协议版本列表
/// </summary>
[HttpGet]
public async Task<OperationResult<GetProtocolVersionsResponse>> GetAll([FromQuery] GetProtocolVersionsQuery query)
{
_logger.LogInformation("开始获取协议版本列表,页码: {PageNumber}, 每页数量: {PageSize}, 搜索关键词: {SearchTerm}, 是否启用: {IsEnabled}",
query.PageNumber, query.PageSize, query.SearchTerm, query.IsEnabled);
var result = await mediator.Send(query);
if (!result.IsSuccess)
{
_logger.LogWarning("获取协议版本列表失败: {Message}", result.ErrorMessages);
return result;
}
_logger.LogInformation("成功获取协议版本列表,共 {Count} 条记录", result.Data?.TotalCount ?? 0);
return result;
}
/// <summary>
/// 获取协议版本详情
/// </summary>
[HttpGet("{id}")]
public async Task<OperationResult<GetProtocolVersionByIdResponse>> GetById(string id)
{
_logger.LogInformation("开始获取协议版本详情,版本ID: {ProtocolVersionId}", id);
var result = await mediator.Send(new GetProtocolVersionByIdQuery { ProtocolVersionId = id });
if (!result.IsSuccess)
{
_logger.LogWarning("获取协议版本详情失败: {Message}", result.ErrorMessages);
return result;
}
_logger.LogInformation("成功获取协议版本详情,版本ID: {ProtocolVersionId}", id);
return result;
}
/// <summary>
/// 创建协议版本
/// </summary>
[HttpPost]
public async Task<OperationResult<CreateProtocolVersionResponse>> Create([FromBody] CreateProtocolVersionCommand command)
{
_logger.LogInformation("开始创建协议版本,版本名称: {Name}, 版本号: {Version}", command.Name, command.Version);
var result = await mediator.Send(command);
if (!result.IsSuccess)
{
_logger.LogWarning("创建协议版本失败: {Message}", result.ErrorMessages);
return result;
}
_logger.LogInformation("成功创建协议版本,版本ID: {ProtocolVersionId}", result.Data.ProtocolVersionId);
return result;
}
/// <summary>
/// 更新协议版本
/// </summary>
[HttpPut("{id}")]
public async Task<OperationResult<UpdateProtocolVersionResponse>> Update(string id, [FromBody] UpdateProtocolVersionCommand command)
{
_logger.LogInformation("开始更新协议版本,版本ID: {ProtocolVersionId}", id);
if (id != command.ProtocolVersionId)
{
_logger.LogWarning("协议版本ID不匹配,路径ID: {PathId}, 命令ID: {CommandId}", id, command.ProtocolVersionId);
return OperationResult<UpdateProtocolVersionResponse>.CreateFailure("协议版本ID不匹配");
}
var result = await mediator.Send(command);
if (!result.IsSuccess)
{
_logger.LogWarning("更新协议版本失败: {Message}", result.ErrorMessages);
return result;
}
_logger.LogInformation("成功更新协议版本,版本ID: {ProtocolVersionId}", id);
return result;
}
/// <summary>
/// 删除协议版本
/// </summary>
[HttpDelete("{id}")]
public async Task<OperationResult<bool>> Delete(string id)
{
_logger.LogInformation("开始删除协议版本,版本ID: {ProtocolVersionId}", id);
var result = await mediator.Send(new DeleteProtocolVersionCommand { ProtocolVersionId = id });
if (!result.IsSuccess)
{
_logger.LogWarning("删除协议版本失败: {Message}", result.ErrorMessages);
return result;
}
_logger.LogInformation("成功删除协议版本,版本ID: {ProtocolVersionId}", id);
return result;
}
}

73
src/X1.WebAPI/ProtocolVersions.http

@ -0,0 +1,73 @@
### 协议版本 CRUD API 测试
### 1. 创建协议版本
POST {{baseUrl}}/api/protocolversions
Content-Type: application/json
Authorization: Bearer {{token}}
{
"name": "HTTP/1.1",
"version": "1.1.0",
"description": "HTTP协议1.1版本",
"isEnabled": true,
"releaseDate": "1997-01-01T00:00:00Z",
"isForceUpdate": false,
"minimumSupportedVersion": "1.0.0"
}
### 2. 创建另一个协议版本
POST {{baseUrl}}/api/protocolversions
Content-Type: application/json
Authorization: Bearer {{token}}
{
"name": "HTTP/2.0",
"version": "2.0.0",
"description": "HTTP协议2.0版本",
"isEnabled": true,
"releaseDate": "2015-05-14T00:00:00Z",
"isForceUpdate": true,
"minimumSupportedVersion": "1.1.0"
}
### 3. 获取协议版本列表
GET {{baseUrl}}/api/protocolversions?pageNumber=1&pageSize=10
Authorization: Bearer {{token}}
### 4. 搜索协议版本
GET {{baseUrl}}/api/protocolversions?searchTerm=HTTP&pageNumber=1&pageSize=10
Authorization: Bearer {{token}}
### 5. 获取启用的协议版本
GET {{baseUrl}}/api/protocolversions?isEnabled=true&pageNumber=1&pageSize=10
Authorization: Bearer {{token}}
### 6. 根据ID获取协议版本
GET {{baseUrl}}/api/protocolversions/{{protocolVersionId}}
Authorization: Bearer {{token}}
### 7. 更新协议版本
PUT {{baseUrl}}/api/protocolversions/{{protocolVersionId}}
Content-Type: application/json
Authorization: Bearer {{token}}
{
"protocolVersionId": "{{protocolVersionId}}",
"name": "HTTP/1.1 Updated",
"version": "1.1.1",
"description": "HTTP协议1.1版本(已更新)",
"isEnabled": true,
"releaseDate": "1997-01-01T00:00:00Z",
"isForceUpdate": true,
"minimumSupportedVersion": "1.0.0"
}
### 8. 删除协议版本
DELETE {{baseUrl}}/api/protocolversions/{{protocolVersionId}}
Authorization: Bearer {{token}}
### 环境变量设置
# 在 VS Code 的 REST Client 扩展中设置以下变量:
# baseUrl: http://localhost:5000
# token: 你的JWT令牌
# protocolVersionId: 从创建响应中获取的协议版本ID
Loading…
Cancel
Save