Browse Source

feat: 协议版本移除IsForceUpdate,设备增加IsRunning状态字段及相关逻辑

feature/x1-owen-debug
root 4 weeks ago
parent
commit
ed08508922
  1. 5
      src/X1.Application/Features/Devices/Commands/CreateDevice/CreateDeviceCommand.cs
  2. 4
      src/X1.Application/Features/Devices/Commands/CreateDevice/CreateDeviceCommandHandler.cs
  3. 5
      src/X1.Application/Features/Devices/Commands/CreateDevice/CreateDeviceResponse.cs
  4. 5
      src/X1.Application/Features/Devices/Commands/UpdateDevice/UpdateDeviceCommand.cs
  5. 4
      src/X1.Application/Features/Devices/Commands/UpdateDevice/UpdateDeviceCommandHandler.cs
  6. 5
      src/X1.Application/Features/Devices/Commands/UpdateDevice/UpdateDeviceResponse.cs
  7. 1
      src/X1.Application/Features/Devices/Queries/GetDeviceById/GetDeviceByIdQueryHandler.cs
  8. 5
      src/X1.Application/Features/Devices/Queries/GetDeviceById/GetDeviceByIdResponse.cs
  9. 1
      src/X1.Application/Features/Devices/Queries/GetDevices/GetDevicesQueryHandler.cs
  10. 5
      src/X1.Application/Features/ProtocolVersions/Commands/CreateProtocolVersion/CreateProtocolVersionCommand.cs
  11. 2
      src/X1.Application/Features/ProtocolVersions/Commands/CreateProtocolVersion/CreateProtocolVersionCommandHandler.cs
  12. 5
      src/X1.Application/Features/ProtocolVersions/Commands/CreateProtocolVersion/CreateProtocolVersionResponse.cs
  13. 5
      src/X1.Application/Features/ProtocolVersions/Commands/UpdateProtocolVersion/UpdateProtocolVersionCommand.cs
  14. 2
      src/X1.Application/Features/ProtocolVersions/Commands/UpdateProtocolVersion/UpdateProtocolVersionCommandHandler.cs
  15. 5
      src/X1.Application/Features/ProtocolVersions/Commands/UpdateProtocolVersion/UpdateProtocolVersionResponse.cs
  16. 1
      src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersionById/GetProtocolVersionByIdQueryHandler.cs
  17. 5
      src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersionById/GetProtocolVersionByIdResponse.cs
  18. 1
      src/X1.Application/Features/ProtocolVersions/Queries/GetProtocolVersions/GetProtocolVersionsQueryHandler.cs
  19. 31
      src/X1.Domain/Entities/Device/CellularDevice.cs
  20. 18
      src/X1.Domain/Entities/Device/ProtocolVersion.cs
  21. 2
      src/X1.Infrastructure/Configurations/Device/CellularDeviceConfiguration.cs
  22. 1
      src/X1.Infrastructure/Configurations/Device/ProtocolVersionConfiguration.cs
  23. 582
      src/X1.Infrastructure/Migrations/20250705173130_InitProtocolVersionAndDevice.Designer.cs
  24. 183
      src/X1.Infrastructure/Migrations/20250705173130_InitProtocolVersionAndDevice.cs
  25. 583
      src/X1.Infrastructure/Migrations/20250705174217_UpdateProtocolVersionAndCellularDevice.Designer.cs
  26. 64
      src/X1.Infrastructure/Migrations/20250705174217_UpdateProtocolVersionAndCellularDevice.cs
  27. 35
      src/X1.Infrastructure/Migrations/AppDbContextModelSnapshot.cs
  28. 73
      src/X1.WebAPI/Devices.http
  29. 3
      src/X1.WebAPI/ProtocolVersions.http

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

@ -51,4 +51,9 @@ public class CreateDeviceCommand : IRequest<OperationResult<CreateDeviceResponse
/// 是否启用 /// 是否启用
/// </summary> /// </summary>
public bool IsEnabled { get; set; } = true; public bool IsEnabled { get; set; } = true;
/// <summary>
/// 设备状态(启动/未启动)
/// </summary>
public bool IsRunning { get; set; } = false;
} }

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

@ -51,7 +51,8 @@ public class CreateDeviceCommandHandler : IRequestHandler<CreateDeviceCommand, O
protocolVersionId: request.ProtocolVersionId, protocolVersionId: request.ProtocolVersionId,
agentPort: request.AgentPort, agentPort: request.AgentPort,
ipAddress:request.IpAddress, ipAddress:request.IpAddress,
isEnabled: request.IsEnabled); isEnabled: request.IsEnabled,
isRunning: request.IsRunning);
// 保存设备 // 保存设备
await _deviceRepository.AddDeviceAsync(device, cancellationToken); await _deviceRepository.AddDeviceAsync(device, cancellationToken);
@ -69,6 +70,7 @@ public class CreateDeviceCommandHandler : IRequestHandler<CreateDeviceCommand, O
ProtocolVersion = device.ProtocolVersion?.Version ?? "未知", ProtocolVersion = device.ProtocolVersion?.Version ?? "未知",
AgentPort = device.AgentPort, AgentPort = device.AgentPort,
IsEnabled = device.IsEnabled, IsEnabled = device.IsEnabled,
IsRunning = device.IsRunning,
CreatedAt = device.CreatedAt CreatedAt = device.CreatedAt
}; };

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

@ -40,6 +40,11 @@ public class CreateDeviceResponse
/// </summary> /// </summary>
public bool IsEnabled { get; set; } public bool IsEnabled { get; set; }
/// <summary>
/// 设备状态(启动/未启动)
/// </summary>
public bool IsRunning { get; set; }
/// <summary> /// <summary>
/// 创建时间 /// 创建时间
/// </summary> /// </summary>

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

@ -57,4 +57,9 @@ public class UpdateDeviceCommand : IRequest<OperationResult<UpdateDeviceResponse
/// 是否启用 /// 是否启用
/// </summary> /// </summary>
public bool IsEnabled { get; set; } = true; public bool IsEnabled { get; set; } = true;
/// <summary>
/// 设备状态(启动/未启动)
/// </summary>
public bool IsRunning { get; set; } = false;
} }

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

@ -64,7 +64,8 @@ public class UpdateDeviceCommandHandler : IRequestHandler<UpdateDeviceCommand, O
protocolVersionId: request.ProtocolVersionId, protocolVersionId: request.ProtocolVersionId,
agentPort: request.AgentPort, agentPort: request.AgentPort,
ipAddress: request.IpAddress, ipAddress: request.IpAddress,
isEnabled: request.IsEnabled); isEnabled: request.IsEnabled,
isRunning: request.IsRunning);
_deviceRepository.Update(existingDevice); _deviceRepository.Update(existingDevice);
// 保存更新 // 保存更新
@ -83,6 +84,7 @@ public class UpdateDeviceCommandHandler : IRequestHandler<UpdateDeviceCommand, O
ProtocolVersion = existingDevice.ProtocolVersion?.Version ?? "未知", ProtocolVersion = existingDevice.ProtocolVersion?.Version ?? "未知",
AgentPort = existingDevice.AgentPort, AgentPort = existingDevice.AgentPort,
IsEnabled = existingDevice.IsEnabled, IsEnabled = existingDevice.IsEnabled,
IsRunning = existingDevice.IsRunning,
UpdatedAt = DateTime.UtcNow UpdatedAt = DateTime.UtcNow
}; };

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

@ -40,6 +40,11 @@ public class UpdateDeviceResponse
/// </summary> /// </summary>
public bool IsEnabled { get; set; } public bool IsEnabled { get; set; }
/// <summary>
/// 设备状态(启动/未启动)
/// </summary>
public bool IsRunning { get; set; }
/// <summary> /// <summary>
/// 更新时间 /// 更新时间
/// </summary> /// </summary>

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

@ -52,6 +52,7 @@ public class GetDeviceByIdQueryHandler : IRequestHandler<GetDeviceByIdQuery, Ope
ProtocolVersion = device.ProtocolVersion?.Version ?? "未知", ProtocolVersion = device.ProtocolVersion?.Version ?? "未知",
AgentPort = device.AgentPort, AgentPort = device.AgentPort,
IsEnabled = device.IsEnabled, IsEnabled = device.IsEnabled,
IsRunning = device.IsRunning,
CreatedAt = device.CreatedAt CreatedAt = device.CreatedAt
}; };

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

@ -40,6 +40,11 @@ public class GetDeviceByIdResponse
/// </summary> /// </summary>
public bool IsEnabled { get; set; } public bool IsEnabled { get; set; }
/// <summary>
/// 设备状态(启动/未启动)
/// </summary>
public bool IsRunning { get; set; }
/// <summary> /// <summary>
/// 创建时间 /// 创建时间
/// </summary> /// </summary>

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

@ -79,6 +79,7 @@ public class GetDevicesQueryHandler : IRequestHandler<GetDevicesQuery, Operation
ProtocolVersion = d.ProtocolVersion?.Version ?? "未知", ProtocolVersion = d.ProtocolVersion?.Version ?? "未知",
AgentPort = d.AgentPort, AgentPort = d.AgentPort,
IsEnabled = d.IsEnabled, IsEnabled = d.IsEnabled,
IsRunning = d.IsRunning,
CreatedAt = d.CreatedAt CreatedAt = d.CreatedAt
}).ToList() }).ToList()
}; };

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

@ -39,10 +39,7 @@ public class CreateProtocolVersionCommand : IRequest<OperationResult<CreateProto
/// </summary> /// </summary>
public DateTime? ReleaseDate { get; set; } public DateTime? ReleaseDate { get; set; }
/// <summary>
/// 是否强制更新
/// </summary>
public bool IsForceUpdate { get; set; } = false;
/// <summary> /// <summary>
/// 最低支持版本 /// 最低支持版本

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

@ -49,7 +49,6 @@ public class CreateProtocolVersionCommandHandler : IRequestHandler<CreateProtoco
description: request.Description, description: request.Description,
isEnabled: request.IsEnabled, isEnabled: request.IsEnabled,
releaseDate: request.ReleaseDate, releaseDate: request.ReleaseDate,
isForceUpdate: request.IsForceUpdate,
minimumSupportedVersion: request.MinimumSupportedVersion); minimumSupportedVersion: request.MinimumSupportedVersion);
// 保存协议版本 // 保存协议版本
@ -64,7 +63,6 @@ public class CreateProtocolVersionCommandHandler : IRequestHandler<CreateProtoco
Description = protocolVersion.Description, Description = protocolVersion.Description,
IsEnabled = protocolVersion.IsEnabled, IsEnabled = protocolVersion.IsEnabled,
ReleaseDate = protocolVersion.ReleaseDate, ReleaseDate = protocolVersion.ReleaseDate,
IsForceUpdate = protocolVersion.IsForceUpdate,
MinimumSupportedVersion = protocolVersion.MinimumSupportedVersion, MinimumSupportedVersion = protocolVersion.MinimumSupportedVersion,
CreatedAt = protocolVersion.CreatedAt CreatedAt = protocolVersion.CreatedAt
}; };

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

@ -35,10 +35,7 @@ public class CreateProtocolVersionResponse
/// </summary> /// </summary>
public DateTime? ReleaseDate { get; set; } public DateTime? ReleaseDate { get; set; }
/// <summary>
/// 是否强制更新
/// </summary>
public bool IsForceUpdate { get; set; }
/// <summary> /// <summary>
/// 最低支持版本 /// 最低支持版本

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

@ -45,10 +45,7 @@ public class UpdateProtocolVersionCommand : IRequest<OperationResult<UpdateProto
/// </summary> /// </summary>
public DateTime? ReleaseDate { get; set; } public DateTime? ReleaseDate { get; set; }
/// <summary>
/// 是否强制更新
/// </summary>
public bool IsForceUpdate { get; set; } = false;
/// <summary> /// <summary>
/// 最低支持版本 /// 最低支持版本

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

@ -60,7 +60,6 @@ public class UpdateProtocolVersionCommandHandler : IRequestHandler<UpdateProtoco
description: request.Description, description: request.Description,
isEnabled: request.IsEnabled, isEnabled: request.IsEnabled,
releaseDate: request.ReleaseDate, releaseDate: request.ReleaseDate,
isForceUpdate: request.IsForceUpdate,
minimumSupportedVersion: request.MinimumSupportedVersion); minimumSupportedVersion: request.MinimumSupportedVersion);
_protocolVersionRepository.UpdateProtocolVersion(existingProtocolVersion); _protocolVersionRepository.UpdateProtocolVersion(existingProtocolVersion);
@ -74,7 +73,6 @@ public class UpdateProtocolVersionCommandHandler : IRequestHandler<UpdateProtoco
Description = existingProtocolVersion.Description, Description = existingProtocolVersion.Description,
IsEnabled = existingProtocolVersion.IsEnabled, IsEnabled = existingProtocolVersion.IsEnabled,
ReleaseDate = existingProtocolVersion.ReleaseDate, ReleaseDate = existingProtocolVersion.ReleaseDate,
IsForceUpdate = existingProtocolVersion.IsForceUpdate,
MinimumSupportedVersion = existingProtocolVersion.MinimumSupportedVersion, MinimumSupportedVersion = existingProtocolVersion.MinimumSupportedVersion,
UpdatedAt = DateTime.UtcNow UpdatedAt = DateTime.UtcNow
}; };

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

@ -35,10 +35,7 @@ public class UpdateProtocolVersionResponse
/// </summary> /// </summary>
public DateTime? ReleaseDate { get; set; } public DateTime? ReleaseDate { get; set; }
/// <summary>
/// 是否强制更新
/// </summary>
public bool IsForceUpdate { get; set; }
/// <summary> /// <summary>
/// 最低支持版本 /// 最低支持版本

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

@ -50,7 +50,6 @@ public class GetProtocolVersionByIdQueryHandler : IRequestHandler<GetProtocolVer
Description = protocolVersion.Description, Description = protocolVersion.Description,
IsEnabled = protocolVersion.IsEnabled, IsEnabled = protocolVersion.IsEnabled,
ReleaseDate = protocolVersion.ReleaseDate, ReleaseDate = protocolVersion.ReleaseDate,
IsForceUpdate = protocolVersion.IsForceUpdate,
MinimumSupportedVersion = protocolVersion.MinimumSupportedVersion, MinimumSupportedVersion = protocolVersion.MinimumSupportedVersion,
CreatedAt = protocolVersion.CreatedAt, CreatedAt = protocolVersion.CreatedAt,
UpdatedAt = protocolVersion.UpdatedAt UpdatedAt = protocolVersion.UpdatedAt

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

@ -35,10 +35,7 @@ public class GetProtocolVersionByIdResponse
/// </summary> /// </summary>
public DateTime? ReleaseDate { get; set; } public DateTime? ReleaseDate { get; set; }
/// <summary>
/// 是否强制更新
/// </summary>
public bool IsForceUpdate { get; set; }
/// <summary> /// <summary>
/// 最低支持版本 /// 最低支持版本

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

@ -84,7 +84,6 @@ public class GetProtocolVersionsQueryHandler : IRequestHandler<GetProtocolVersio
Description = pv.Description, Description = pv.Description,
IsEnabled = pv.IsEnabled, IsEnabled = pv.IsEnabled,
ReleaseDate = pv.ReleaseDate, ReleaseDate = pv.ReleaseDate,
IsForceUpdate = pv.IsForceUpdate,
MinimumSupportedVersion = pv.MinimumSupportedVersion, MinimumSupportedVersion = pv.MinimumSupportedVersion,
CreatedAt = pv.CreatedAt, CreatedAt = pv.CreatedAt,
UpdatedAt = pv.UpdatedAt UpdatedAt = pv.UpdatedAt

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

@ -61,6 +61,11 @@ public class CellularDevice : AuditableEntity
/// </summary> /// </summary>
public bool IsEnabled { get; private set; } = true; public bool IsEnabled { get; private set; } = true;
/// <summary>
/// 设备状态(启动/未启动)
/// </summary>
public bool IsRunning { get; private set; } = false;
/// <summary> /// <summary>
/// 创建设备 /// 创建设备
/// </summary> /// </summary>
@ -71,7 +76,8 @@ public class CellularDevice : AuditableEntity
string protocolVersionId, string protocolVersionId,
int agentPort, int agentPort,
string ipAddress, string ipAddress,
bool isEnabled = true) bool isEnabled = true,
bool isRunning = false)
{ {
var device = new CellularDevice var device = new CellularDevice
{ {
@ -83,6 +89,7 @@ public class CellularDevice : AuditableEntity
AgentPort = agentPort, AgentPort = agentPort,
IpAddress = ipAddress, IpAddress = ipAddress,
IsEnabled = isEnabled, IsEnabled = isEnabled,
IsRunning = isRunning,
CreatedAt = DateTime.UtcNow, CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow UpdatedAt = DateTime.UtcNow
}; };
@ -100,7 +107,8 @@ public class CellularDevice : AuditableEntity
string protocolVersionId, string protocolVersionId,
int agentPort, int agentPort,
string ipAddress, string ipAddress,
bool isEnabled = true) bool isEnabled = true,
bool isRunning = false)
{ {
Name = name; Name = name;
SerialNumber = serialNumber; SerialNumber = serialNumber;
@ -109,6 +117,7 @@ public class CellularDevice : AuditableEntity
AgentPort = agentPort; AgentPort = agentPort;
IpAddress = ipAddress; IpAddress = ipAddress;
IsEnabled = isEnabled; IsEnabled = isEnabled;
IsRunning = isRunning;
UpdatedAt = DateTime.UtcNow; UpdatedAt = DateTime.UtcNow;
} }
@ -129,4 +138,22 @@ public class CellularDevice : AuditableEntity
IsEnabled = false; IsEnabled = false;
UpdatedAt = DateTime.UtcNow; UpdatedAt = DateTime.UtcNow;
} }
/// <summary>
/// 启动设备
/// </summary>
public void Start()
{
IsRunning = true;
UpdatedAt = DateTime.UtcNow;
}
/// <summary>
/// 停止设备
/// </summary>
public void Stop()
{
IsRunning = false;
UpdatedAt = DateTime.UtcNow;
}
} }

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

@ -40,10 +40,7 @@ public class ProtocolVersion : AuditableEntity
/// </summary> /// </summary>
public DateTime? ReleaseDate { get; private set; } public DateTime? ReleaseDate { get; private set; }
/// <summary>
/// 是否强制更新
/// </summary>
public bool IsForceUpdate { get; private set; }
/// <summary> /// <summary>
/// 最低支持版本 /// 最低支持版本
@ -60,7 +57,6 @@ public class ProtocolVersion : AuditableEntity
string? description = null, string? description = null,
bool isEnabled = true, bool isEnabled = true,
DateTime? releaseDate = null, DateTime? releaseDate = null,
bool isForceUpdate = false,
string? minimumSupportedVersion = null) string? minimumSupportedVersion = null)
{ {
var protocolVersion = new ProtocolVersion var protocolVersion = new ProtocolVersion
@ -71,7 +67,6 @@ public class ProtocolVersion : AuditableEntity
Description = description, Description = description,
IsEnabled = isEnabled, IsEnabled = isEnabled,
ReleaseDate = releaseDate, ReleaseDate = releaseDate,
IsForceUpdate = isForceUpdate,
MinimumSupportedVersion = minimumSupportedVersion, MinimumSupportedVersion = minimumSupportedVersion,
CreatedAt = DateTime.UtcNow, CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow UpdatedAt = DateTime.UtcNow
@ -89,7 +84,6 @@ public class ProtocolVersion : AuditableEntity
string? description = null, string? description = null,
bool isEnabled = true, bool isEnabled = true,
DateTime? releaseDate = null, DateTime? releaseDate = null,
bool isForceUpdate = false,
string? minimumSupportedVersion = null) string? minimumSupportedVersion = null)
{ {
Name = name; Name = name;
@ -97,7 +91,6 @@ public class ProtocolVersion : AuditableEntity
Description = description; Description = description;
IsEnabled = isEnabled; IsEnabled = isEnabled;
ReleaseDate = releaseDate; ReleaseDate = releaseDate;
IsForceUpdate = isForceUpdate;
MinimumSupportedVersion = minimumSupportedVersion; MinimumSupportedVersion = minimumSupportedVersion;
UpdatedAt = DateTime.UtcNow; UpdatedAt = DateTime.UtcNow;
} }
@ -120,12 +113,5 @@ public class ProtocolVersion : AuditableEntity
UpdatedAt = DateTime.UtcNow; UpdatedAt = DateTime.UtcNow;
} }
/// <summary>
/// 设置强制更新
/// </summary>
public void SetForceUpdate(bool isForceUpdate)
{
IsForceUpdate = isForceUpdate;
UpdatedAt = DateTime.UtcNow;
}
} }

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

@ -22,7 +22,9 @@ public class CellularDeviceConfiguration : IEntityTypeConfiguration<CellularDevi
builder.Property(d => d.Description).HasMaxLength(500).HasComment("设备描述"); builder.Property(d => d.Description).HasMaxLength(500).HasComment("设备描述");
builder.Property(d => d.ProtocolVersionId).IsRequired().HasMaxLength(50).HasComment("协议版本ID"); builder.Property(d => d.ProtocolVersionId).IsRequired().HasMaxLength(50).HasComment("协议版本ID");
builder.Property(d => d.AgentPort).IsRequired().HasComment("Agent端口"); builder.Property(d => d.AgentPort).IsRequired().HasComment("Agent端口");
builder.Property(d => d.IpAddress).IsRequired().HasMaxLength(45).HasComment("IP地址");
builder.Property(d => d.IsEnabled).IsRequired().HasComment("是否启用"); builder.Property(d => d.IsEnabled).IsRequired().HasComment("是否启用");
builder.Property(d => d.IsRunning).IsRequired().HasComment("设备状态(启动/未启动)");
builder.Property(d => d.CreatedAt).IsRequired().HasComment("创建时间"); builder.Property(d => d.CreatedAt).IsRequired().HasComment("创建时间");
builder.Property(d => d.UpdatedAt).IsRequired().HasComment("更新时间"); builder.Property(d => d.UpdatedAt).IsRequired().HasComment("更新时间");

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

@ -21,7 +21,6 @@ public class ProtocolVersionConfiguration : IEntityTypeConfiguration<ProtocolVer
builder.Property(v => v.Description).HasMaxLength(500).HasComment("版本描述"); builder.Property(v => v.Description).HasMaxLength(500).HasComment("版本描述");
builder.Property(v => v.IsEnabled).IsRequired().HasComment("是否启用"); builder.Property(v => v.IsEnabled).IsRequired().HasComment("是否启用");
builder.Property(v => v.ReleaseDate).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.MinimumSupportedVersion).HasMaxLength(20).HasComment("最低支持版本");
builder.Property(v => v.CreatedAt).IsRequired().HasComment("创建时间"); builder.Property(v => v.CreatedAt).IsRequired().HasComment("创建时间");
builder.Property(v => v.UpdatedAt).IsRequired().HasComment("更新时间"); builder.Property(v => v.UpdatedAt).IsRequired().HasComment("更新时间");

582
src/X1.Infrastructure/Migrations/20250705173130_InitProtocolVersionAndDevice.Designer.cs

@ -0,0 +1,582 @@
// <auto-generated />
using System;
using CellularManagement.Infrastructure.Context;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace X1.Infrastructure.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250705173130_InitProtocolVersionAndDevice")]
partial class InitProtocolVersionAndDevice
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("CellularManagement.Domain.Entities.AppRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text")
.HasComment("角色ID,主键");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text")
.HasComment("并发控制戳");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间");
b.Property<string>("Description")
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasComment("角色描述");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasComment("角色名称");
b.Property<string>("NormalizedName")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasComment("标准化角色名称(大写)");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("更新时间");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique()
.HasDatabaseName("IX_Roles_Name");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("Roles", null, t =>
{
t.HasComment("角色表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.AppUser", b =>
{
b.Property<string>("Id")
.HasColumnType("text")
.HasComment("用户ID,主键");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer")
.HasComment("登录失败次数");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text")
.HasComment("并发控制戳");
b.Property<DateTime>("CreatedTime")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间");
b.Property<string>("Email")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasComment("电子邮箱");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean")
.HasComment("邮箱是否已验证");
b.Property<bool>("IsActive")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(true)
.HasComment("用户状态(true: 启用, false: 禁用)");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false)
.HasComment("是否已删除");
b.Property<DateTime?>("LastLoginTime")
.HasColumnType("timestamp with time zone")
.HasComment("最后登录时间");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean")
.HasComment("是否启用账户锁定");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone")
.HasComment("账户锁定结束时间");
b.Property<DateTime?>("ModifiedTime")
.HasColumnType("timestamp with time zone")
.HasComment("修改时间");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasComment("标准化电子邮箱(大写)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasComment("标准化账号(大写)");
b.Property<string>("PasswordHash")
.HasColumnType("text")
.HasComment("密码哈希值");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("text")
.HasComment("电话号码");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean")
.HasComment("电话号码是否已验证");
b.Property<string>("RealName")
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("用户名");
b.Property<string>("SecurityStamp")
.HasColumnType("text")
.HasComment("安全戳,用于并发控制");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean")
.HasComment("是否启用双因素认证");
b.Property<string>("UserName")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasComment("账号");
b.HasKey("Id");
b.HasIndex("Email")
.IsUnique()
.HasDatabaseName("IX_Users_Email");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.HasIndex("PhoneNumber")
.IsUnique()
.HasDatabaseName("IX_Users_PhoneNumber");
b.HasIndex("UserName")
.IsUnique()
.HasDatabaseName("IX_Users_UserName");
b.ToTable("Users", null, t =>
{
t.HasComment("用户表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Device.CellularDevice", b =>
{
b.Property<string>("Id")
.HasColumnType("text")
.HasComment("设备ID");
b.Property<int>("AgentPort")
.HasColumnType("integer")
.HasComment("Agent端口");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasComment("设备描述");
b.Property<string>("IpAddress")
.IsRequired()
.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)
.HasColumnType("character varying(100)")
.HasComment("设备名称");
b.Property<string>("ProtocolVersionId")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("协议版本ID");
b.Property<string>("SerialNumber")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("序列号");
b.Property<DateTime?>("UpdatedAt")
.IsRequired()
.HasColumnType("timestamp with time zone")
.HasComment("更新时间");
b.Property<string>("UpdatedBy")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ProtocolVersionId")
.HasDatabaseName("IX_CellularDevices_ProtocolVersionId");
b.HasIndex("SerialNumber")
.IsUnique()
.HasDatabaseName("IX_CellularDevices_SerialNumber");
b.ToTable("CellularDevices", null, t =>
{
t.HasComment("蜂窝设备表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Device.ProtocolVersion", b =>
{
b.Property<string>("Id")
.HasColumnType("text")
.HasComment("版本ID");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasComment("版本描述");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean")
.HasComment("是否启用");
b.Property<bool>("IsForceUpdate")
.HasColumnType("boolean")
.HasComment("是否强制更新");
b.Property<string>("MinimumSupportedVersion")
.HasMaxLength(20)
.HasColumnType("character varying(20)")
.HasComment("最低支持版本");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("版本名称");
b.Property<DateTime?>("ReleaseDate")
.HasColumnType("timestamp with time zone")
.HasComment("发布日期");
b.Property<DateTime?>("UpdatedAt")
.IsRequired()
.HasColumnType("timestamp with time zone")
.HasComment("更新时间");
b.Property<string>("UpdatedBy")
.HasColumnType("text");
b.Property<string>("Version")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("character varying(20)")
.HasComment("版本号");
b.HasKey("Id");
b.HasIndex("Version")
.IsUnique()
.HasDatabaseName("IX_ProtocolVersions_Version");
b.ToTable("ProtocolVersions", null, t =>
{
t.HasComment("协议版本表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Logging.LoginLog", b =>
{
b.Property<string>("Id")
.HasColumnType("text")
.HasComment("日志ID");
b.Property<string>("Browser")
.HasMaxLength(100)
.HasColumnType("character varying(100)")
.HasComment("浏览器信息");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("FailureReason")
.HasMaxLength(200)
.HasColumnType("character varying(200)")
.HasComment("失败原因");
b.Property<string>("IpAddress")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("登录IP");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<bool>("IsSuccess")
.HasColumnType("boolean")
.HasComment("登录状态(成功/失败)");
b.Property<string>("Location")
.HasMaxLength(200)
.HasColumnType("character varying(200)")
.HasComment("登录位置");
b.Property<string>("LoginSource")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<DateTime>("LoginTime")
.HasColumnType("timestamp with time zone")
.HasComment("登录时间");
b.Property<string>("LoginType")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<string>("OperatingSystem")
.HasMaxLength(100)
.HasColumnType("character varying(100)")
.HasComment("操作系统信息");
b.Property<string>("SessionId")
.HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("UserAgent")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasComment("设备信息");
b.Property<string>("UserId")
.IsRequired()
.HasMaxLength(450)
.HasColumnType("character varying(450)")
.HasComment("用户ID");
b.HasKey("Id");
b.HasIndex("IpAddress")
.HasDatabaseName("IX_LoginLogs_IpAddress");
b.HasIndex("LoginTime")
.HasDatabaseName("IX_LoginLogs_LoginTime");
b.HasIndex("UserId")
.HasDatabaseName("IX_LoginLogs_UserId");
b.HasIndex("UserId", "LoginTime")
.HasDatabaseName("IX_LoginLogs_UserId_LoginTime");
b.ToTable("LoginLogs", null, t =>
{
t.HasComment("用户登录日志表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Permission", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Code")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.HasMaxLength(200)
.HasColumnType("character varying(200)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<string>("Type")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.HasKey("Id");
b.ToTable("Permissions", (string)null);
});
modelBuilder.Entity("CellularManagement.Domain.Entities.RolePermission", b =>
{
b.Property<string>("RoleId")
.HasColumnType("text");
b.Property<string>("PermissionId")
.HasColumnType("text");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.HasKey("RoleId", "PermissionId");
b.HasIndex("PermissionId");
b.ToTable("RolePermissions", (string)null);
});
modelBuilder.Entity("CellularManagement.Domain.Entities.UserRole", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("UserRoles", null, t =>
{
t.HasComment("用户角色关系表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Device.CellularDevice", b =>
{
b.HasOne("CellularManagement.Domain.Entities.Device.ProtocolVersion", "ProtocolVersion")
.WithMany()
.HasForeignKey("ProtocolVersionId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("ProtocolVersion");
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Logging.LoginLog", b =>
{
b.HasOne("CellularManagement.Domain.Entities.AppUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
});
modelBuilder.Entity("CellularManagement.Domain.Entities.RolePermission", b =>
{
b.HasOne("CellularManagement.Domain.Entities.Permission", "Permission")
.WithMany("RolePermissions")
.HasForeignKey("PermissionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("CellularManagement.Domain.Entities.AppRole", "Role")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Permission");
b.Navigation("Role");
});
modelBuilder.Entity("CellularManagement.Domain.Entities.UserRole", b =>
{
b.HasOne("CellularManagement.Domain.Entities.AppRole", "Role")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("CellularManagement.Domain.Entities.AppUser", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Role");
b.Navigation("User");
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Permission", b =>
{
b.Navigation("RolePermissions");
});
#pragma warning restore 612, 618
}
}
}

183
src/X1.Infrastructure/Migrations/20250705173130_InitProtocolVersionAndDevice.cs

@ -0,0 +1,183 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace X1.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class InitProtocolVersionAndDevice : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ProtocolType",
table: "ProtocolVersions");
migrationBuilder.AlterColumn<string>(
name: "Version",
table: "ProtocolVersions",
type: "character varying(20)",
maxLength: 20,
nullable: false,
comment: "版本号",
oldClrType: typeof(string),
oldType: "character varying(50)",
oldMaxLength: 50,
oldComment: "版本号");
migrationBuilder.AlterColumn<DateTime>(
name: "ReleaseDate",
table: "ProtocolVersions",
type: "timestamp with time zone",
nullable: true,
comment: "发布日期",
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "ProtocolVersions",
type: "character varying(50)",
maxLength: 50,
nullable: false,
comment: "版本名称",
oldClrType: typeof(string),
oldType: "character varying(50)",
oldMaxLength: 50);
migrationBuilder.AlterColumn<string>(
name: "MinimumSupportedVersion",
table: "ProtocolVersions",
type: "character varying(20)",
maxLength: 20,
nullable: true,
comment: "最低支持版本",
oldClrType: typeof(string),
oldType: "character varying(20)",
oldMaxLength: 20,
oldNullable: true);
migrationBuilder.AlterColumn<bool>(
name: "IsForceUpdate",
table: "ProtocolVersions",
type: "boolean",
nullable: false,
comment: "是否强制更新",
oldClrType: typeof(bool),
oldType: "boolean");
migrationBuilder.AlterColumn<bool>(
name: "IsEnabled",
table: "ProtocolVersions",
type: "boolean",
nullable: false,
comment: "是否启用",
oldClrType: typeof(bool),
oldType: "boolean");
migrationBuilder.AlterColumn<string>(
name: "Description",
table: "ProtocolVersions",
type: "character varying(500)",
maxLength: 500,
nullable: true,
comment: "版本描述",
oldClrType: typeof(string),
oldType: "character varying(200)",
oldMaxLength: 200,
oldNullable: true,
oldComment: "版本描述");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Version",
table: "ProtocolVersions",
type: "character varying(50)",
maxLength: 50,
nullable: false,
comment: "版本号",
oldClrType: typeof(string),
oldType: "character varying(20)",
oldMaxLength: 20,
oldComment: "版本号");
migrationBuilder.AlterColumn<DateTime>(
name: "ReleaseDate",
table: "ProtocolVersions",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldNullable: true,
oldComment: "发布日期");
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "ProtocolVersions",
type: "character varying(50)",
maxLength: 50,
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(50)",
oldMaxLength: 50,
oldComment: "版本名称");
migrationBuilder.AlterColumn<string>(
name: "MinimumSupportedVersion",
table: "ProtocolVersions",
type: "character varying(20)",
maxLength: 20,
nullable: true,
oldClrType: typeof(string),
oldType: "character varying(20)",
oldMaxLength: 20,
oldNullable: true,
oldComment: "最低支持版本");
migrationBuilder.AlterColumn<bool>(
name: "IsForceUpdate",
table: "ProtocolVersions",
type: "boolean",
nullable: false,
oldClrType: typeof(bool),
oldType: "boolean",
oldComment: "是否强制更新");
migrationBuilder.AlterColumn<bool>(
name: "IsEnabled",
table: "ProtocolVersions",
type: "boolean",
nullable: false,
oldClrType: typeof(bool),
oldType: "boolean",
oldComment: "是否启用");
migrationBuilder.AlterColumn<string>(
name: "Description",
table: "ProtocolVersions",
type: "character varying(200)",
maxLength: 200,
nullable: true,
comment: "版本描述",
oldClrType: typeof(string),
oldType: "character varying(500)",
oldMaxLength: 500,
oldNullable: true,
oldComment: "版本描述");
migrationBuilder.AddColumn<string>(
name: "ProtocolType",
table: "ProtocolVersions",
type: "character varying(50)",
maxLength: 50,
nullable: false,
defaultValue: "");
}
}
}

583
src/X1.Infrastructure/Migrations/20250705174217_UpdateProtocolVersionAndCellularDevice.Designer.cs

@ -0,0 +1,583 @@
// <auto-generated />
using System;
using CellularManagement.Infrastructure.Context;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace X1.Infrastructure.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250705174217_UpdateProtocolVersionAndCellularDevice")]
partial class UpdateProtocolVersionAndCellularDevice
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("CellularManagement.Domain.Entities.AppRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text")
.HasComment("角色ID,主键");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text")
.HasComment("并发控制戳");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间");
b.Property<string>("Description")
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasComment("角色描述");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasComment("角色名称");
b.Property<string>("NormalizedName")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasComment("标准化角色名称(大写)");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("更新时间");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique()
.HasDatabaseName("IX_Roles_Name");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("Roles", null, t =>
{
t.HasComment("角色表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.AppUser", b =>
{
b.Property<string>("Id")
.HasColumnType("text")
.HasComment("用户ID,主键");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer")
.HasComment("登录失败次数");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text")
.HasComment("并发控制戳");
b.Property<DateTime>("CreatedTime")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间");
b.Property<string>("Email")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasComment("电子邮箱");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean")
.HasComment("邮箱是否已验证");
b.Property<bool>("IsActive")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(true)
.HasComment("用户状态(true: 启用, false: 禁用)");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false)
.HasComment("是否已删除");
b.Property<DateTime?>("LastLoginTime")
.HasColumnType("timestamp with time zone")
.HasComment("最后登录时间");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean")
.HasComment("是否启用账户锁定");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone")
.HasComment("账户锁定结束时间");
b.Property<DateTime?>("ModifiedTime")
.HasColumnType("timestamp with time zone")
.HasComment("修改时间");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasComment("标准化电子邮箱(大写)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasComment("标准化账号(大写)");
b.Property<string>("PasswordHash")
.HasColumnType("text")
.HasComment("密码哈希值");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("text")
.HasComment("电话号码");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean")
.HasComment("电话号码是否已验证");
b.Property<string>("RealName")
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("用户名");
b.Property<string>("SecurityStamp")
.HasColumnType("text")
.HasComment("安全戳,用于并发控制");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean")
.HasComment("是否启用双因素认证");
b.Property<string>("UserName")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasComment("账号");
b.HasKey("Id");
b.HasIndex("Email")
.IsUnique()
.HasDatabaseName("IX_Users_Email");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.HasIndex("PhoneNumber")
.IsUnique()
.HasDatabaseName("IX_Users_PhoneNumber");
b.HasIndex("UserName")
.IsUnique()
.HasDatabaseName("IX_Users_UserName");
b.ToTable("Users", null, t =>
{
t.HasComment("用户表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Device.CellularDevice", b =>
{
b.Property<string>("Id")
.HasColumnType("text")
.HasComment("设备ID");
b.Property<int>("AgentPort")
.HasColumnType("integer")
.HasComment("Agent端口");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasComment("设备描述");
b.Property<string>("IpAddress")
.IsRequired()
.HasMaxLength(45)
.HasColumnType("character varying(45)")
.HasComment("IP地址");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean")
.HasComment("是否启用");
b.Property<bool>("IsRunning")
.HasColumnType("boolean")
.HasComment("设备状态(启动/未启动)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)")
.HasComment("设备名称");
b.Property<string>("ProtocolVersionId")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("协议版本ID");
b.Property<string>("SerialNumber")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("序列号");
b.Property<DateTime?>("UpdatedAt")
.IsRequired()
.HasColumnType("timestamp with time zone")
.HasComment("更新时间");
b.Property<string>("UpdatedBy")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ProtocolVersionId")
.HasDatabaseName("IX_CellularDevices_ProtocolVersionId");
b.HasIndex("SerialNumber")
.IsUnique()
.HasDatabaseName("IX_CellularDevices_SerialNumber");
b.ToTable("CellularDevices", null, t =>
{
t.HasComment("蜂窝设备表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Device.ProtocolVersion", b =>
{
b.Property<string>("Id")
.HasColumnType("text")
.HasComment("版本ID");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasComment("版本描述");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean")
.HasComment("是否启用");
b.Property<string>("MinimumSupportedVersion")
.HasMaxLength(20)
.HasColumnType("character varying(20)")
.HasComment("最低支持版本");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("版本名称");
b.Property<DateTime?>("ReleaseDate")
.HasColumnType("timestamp with time zone")
.HasComment("发布日期");
b.Property<DateTime?>("UpdatedAt")
.IsRequired()
.HasColumnType("timestamp with time zone")
.HasComment("更新时间");
b.Property<string>("UpdatedBy")
.HasColumnType("text");
b.Property<string>("Version")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("character varying(20)")
.HasComment("版本号");
b.HasKey("Id");
b.HasIndex("Version")
.IsUnique()
.HasDatabaseName("IX_ProtocolVersions_Version");
b.ToTable("ProtocolVersions", null, t =>
{
t.HasComment("协议版本表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Logging.LoginLog", b =>
{
b.Property<string>("Id")
.HasColumnType("text")
.HasComment("日志ID");
b.Property<string>("Browser")
.HasMaxLength(100)
.HasColumnType("character varying(100)")
.HasComment("浏览器信息");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("FailureReason")
.HasMaxLength(200)
.HasColumnType("character varying(200)")
.HasComment("失败原因");
b.Property<string>("IpAddress")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasComment("登录IP");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<bool>("IsSuccess")
.HasColumnType("boolean")
.HasComment("登录状态(成功/失败)");
b.Property<string>("Location")
.HasMaxLength(200)
.HasColumnType("character varying(200)")
.HasComment("登录位置");
b.Property<string>("LoginSource")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<DateTime>("LoginTime")
.HasColumnType("timestamp with time zone")
.HasComment("登录时间");
b.Property<string>("LoginType")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<string>("OperatingSystem")
.HasMaxLength(100)
.HasColumnType("character varying(100)")
.HasComment("操作系统信息");
b.Property<string>("SessionId")
.HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("UserAgent")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasComment("设备信息");
b.Property<string>("UserId")
.IsRequired()
.HasMaxLength(450)
.HasColumnType("character varying(450)")
.HasComment("用户ID");
b.HasKey("Id");
b.HasIndex("IpAddress")
.HasDatabaseName("IX_LoginLogs_IpAddress");
b.HasIndex("LoginTime")
.HasDatabaseName("IX_LoginLogs_LoginTime");
b.HasIndex("UserId")
.HasDatabaseName("IX_LoginLogs_UserId");
b.HasIndex("UserId", "LoginTime")
.HasDatabaseName("IX_LoginLogs_UserId_LoginTime");
b.ToTable("LoginLogs", null, t =>
{
t.HasComment("用户登录日志表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Permission", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Code")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.HasMaxLength(200)
.HasColumnType("character varying(200)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<string>("Type")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.HasKey("Id");
b.ToTable("Permissions", (string)null);
});
modelBuilder.Entity("CellularManagement.Domain.Entities.RolePermission", b =>
{
b.Property<string>("RoleId")
.HasColumnType("text");
b.Property<string>("PermissionId")
.HasColumnType("text");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.HasKey("RoleId", "PermissionId");
b.HasIndex("PermissionId");
b.ToTable("RolePermissions", (string)null);
});
modelBuilder.Entity("CellularManagement.Domain.Entities.UserRole", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("UserRoles", null, t =>
{
t.HasComment("用户角色关系表");
});
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Device.CellularDevice", b =>
{
b.HasOne("CellularManagement.Domain.Entities.Device.ProtocolVersion", "ProtocolVersion")
.WithMany()
.HasForeignKey("ProtocolVersionId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("ProtocolVersion");
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Logging.LoginLog", b =>
{
b.HasOne("CellularManagement.Domain.Entities.AppUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
});
modelBuilder.Entity("CellularManagement.Domain.Entities.RolePermission", b =>
{
b.HasOne("CellularManagement.Domain.Entities.Permission", "Permission")
.WithMany("RolePermissions")
.HasForeignKey("PermissionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("CellularManagement.Domain.Entities.AppRole", "Role")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Permission");
b.Navigation("Role");
});
modelBuilder.Entity("CellularManagement.Domain.Entities.UserRole", b =>
{
b.HasOne("CellularManagement.Domain.Entities.AppRole", "Role")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("CellularManagement.Domain.Entities.AppUser", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Role");
b.Navigation("User");
});
modelBuilder.Entity("CellularManagement.Domain.Entities.Permission", b =>
{
b.Navigation("RolePermissions");
});
#pragma warning restore 612, 618
}
}
}

64
src/X1.Infrastructure/Migrations/20250705174217_UpdateProtocolVersionAndCellularDevice.cs

@ -0,0 +1,64 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace X1.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class UpdateProtocolVersionAndCellularDevice : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsForceUpdate",
table: "ProtocolVersions");
migrationBuilder.AlterColumn<string>(
name: "IpAddress",
table: "CellularDevices",
type: "character varying(45)",
maxLength: 45,
nullable: false,
comment: "IP地址",
oldClrType: typeof(string),
oldType: "character varying(45)",
oldMaxLength: 45);
migrationBuilder.AddColumn<bool>(
name: "IsRunning",
table: "CellularDevices",
type: "boolean",
nullable: false,
defaultValue: false,
comment: "设备状态(启动/未启动)");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsRunning",
table: "CellularDevices");
migrationBuilder.AddColumn<bool>(
name: "IsForceUpdate",
table: "ProtocolVersions",
type: "boolean",
nullable: false,
defaultValue: false,
comment: "是否强制更新");
migrationBuilder.AlterColumn<string>(
name: "IpAddress",
table: "CellularDevices",
type: "character varying(45)",
maxLength: 45,
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(45)",
oldMaxLength: 45,
oldComment: "IP地址");
}
}
}

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

@ -227,7 +227,8 @@ namespace X1.Infrastructure.Migrations
b.Property<string>("IpAddress") b.Property<string>("IpAddress")
.IsRequired() .IsRequired()
.HasMaxLength(45) .HasMaxLength(45)
.HasColumnType("character varying(45)"); .HasColumnType("character varying(45)")
.HasComment("IP地址");
b.Property<bool>("IsDeleted") b.Property<bool>("IsDeleted")
.HasColumnType("boolean"); .HasColumnType("boolean");
@ -236,6 +237,10 @@ namespace X1.Infrastructure.Migrations
.HasColumnType("boolean") .HasColumnType("boolean")
.HasComment("是否启用"); .HasComment("是否启用");
b.Property<bool>("IsRunning")
.HasColumnType("boolean")
.HasComment("设备状态(启动/未启动)");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasMaxLength(100) .HasMaxLength(100)
@ -292,35 +297,31 @@ namespace X1.Infrastructure.Migrations
.HasColumnType("text"); .HasColumnType("text");
b.Property<string>("Description") b.Property<string>("Description")
.HasMaxLength(200) .HasMaxLength(500)
.HasColumnType("character varying(200)") .HasColumnType("character varying(500)")
.HasComment("版本描述"); .HasComment("版本描述");
b.Property<bool>("IsDeleted") b.Property<bool>("IsDeleted")
.HasColumnType("boolean"); .HasColumnType("boolean");
b.Property<bool>("IsEnabled") b.Property<bool>("IsEnabled")
.HasColumnType("boolean"); .HasColumnType("boolean")
.HasComment("是否启用");
b.Property<bool>("IsForceUpdate")
.HasColumnType("boolean");
b.Property<string>("MinimumSupportedVersion") b.Property<string>("MinimumSupportedVersion")
.HasMaxLength(20) .HasMaxLength(20)
.HasColumnType("character varying(20)"); .HasColumnType("character varying(20)")
.HasComment("最低支持版本");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasMaxLength(50) .HasMaxLength(50)
.HasColumnType("character varying(50)"); .HasColumnType("character varying(50)")
.HasComment("版本名称");
b.Property<string>("ProtocolType")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<DateTime?>("ReleaseDate") b.Property<DateTime?>("ReleaseDate")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp with time zone")
.HasComment("发布日期");
b.Property<DateTime?>("UpdatedAt") b.Property<DateTime?>("UpdatedAt")
.IsRequired() .IsRequired()
@ -332,8 +333,8 @@ namespace X1.Infrastructure.Migrations
b.Property<string>("Version") b.Property<string>("Version")
.IsRequired() .IsRequired()
.HasMaxLength(50) .HasMaxLength(20)
.HasColumnType("character varying(50)") .HasColumnType("character varying(20)")
.HasComment("版本号"); .HasComment("版本号");
b.HasKey("Id"); b.HasKey("Id");

73
src/X1.WebAPI/Devices.http

@ -0,0 +1,73 @@
### 设备 CRUD API 测试
### 1. 创建设备
POST {{baseUrl}}/api/devices
Content-Type: application/json
Authorization: Bearer {{token}}
{
"deviceName": "测试设备1",
"serialNumber": "SN001",
"description": "这是一个测试设备",
"protocolVersionId": "{{protocolVersionId}}",
"agentPort": 8080,
"ipAddress": "192.168.1.100",
"isEnabled": true,
"isRunning": false
}
### 2. 创建另一个设备
POST {{baseUrl}}/api/devices
Content-Type: application/json
Authorization: Bearer {{token}}
{
"deviceName": "测试设备2",
"serialNumber": "SN002",
"description": "这是另一个测试设备",
"protocolVersionId": "{{protocolVersionId}}",
"agentPort": 8081,
"ipAddress": "192.168.1.101",
"isEnabled": true,
"isRunning": true
}
### 3. 获取设备列表
GET {{baseUrl}}/api/devices?pageNumber=1&pageSize=10
Authorization: Bearer {{token}}
### 4. 搜索设备
GET {{baseUrl}}/api/devices?searchTerm=测试&pageNumber=1&pageSize=10
Authorization: Bearer {{token}}
### 5. 根据ID获取设备
GET {{baseUrl}}/api/devices/{{deviceId}}
Authorization: Bearer {{token}}
### 6. 更新设备
PUT {{baseUrl}}/api/devices/{{deviceId}}
Content-Type: application/json
Authorization: Bearer {{token}}
{
"deviceId": "{{deviceId}}",
"deviceName": "测试设备1(已更新)",
"serialNumber": "SN001-UPDATED",
"description": "这是一个已更新的测试设备",
"protocolVersionId": "{{protocolVersionId}}",
"agentPort": 8082,
"ipAddress": "192.168.1.102",
"isEnabled": true,
"isRunning": true
}
### 7. 删除设备
DELETE {{baseUrl}}/api/devices/{{deviceId}}
Authorization: Bearer {{token}}
### 环境变量设置
# 在 VS Code 的 REST Client 扩展中设置以下变量:
# baseUrl: http://localhost:5000
# token: 你的JWT令牌
# protocolVersionId: 从协议版本创建响应中获取的协议版本ID
# deviceId: 从设备创建响应中获取的设备ID

3
src/X1.WebAPI/ProtocolVersions.http

@ -11,7 +11,6 @@ Authorization: Bearer {{token}}
"description": "HTTP协议1.1版本", "description": "HTTP协议1.1版本",
"isEnabled": true, "isEnabled": true,
"releaseDate": "1997-01-01T00:00:00Z", "releaseDate": "1997-01-01T00:00:00Z",
"isForceUpdate": false,
"minimumSupportedVersion": "1.0.0" "minimumSupportedVersion": "1.0.0"
} }
@ -26,7 +25,6 @@ Authorization: Bearer {{token}}
"description": "HTTP协议2.0版本", "description": "HTTP协议2.0版本",
"isEnabled": true, "isEnabled": true,
"releaseDate": "2015-05-14T00:00:00Z", "releaseDate": "2015-05-14T00:00:00Z",
"isForceUpdate": true,
"minimumSupportedVersion": "1.1.0" "minimumSupportedVersion": "1.1.0"
} }
@ -58,7 +56,6 @@ Authorization: Bearer {{token}}
"description": "HTTP协议1.1版本(已更新)", "description": "HTTP协议1.1版本(已更新)",
"isEnabled": true, "isEnabled": true,
"releaseDate": "1997-01-01T00:00:00Z", "releaseDate": "1997-01-01T00:00:00Z",
"isForceUpdate": true,
"minimumSupportedVersion": "1.0.0" "minimumSupportedVersion": "1.0.0"
} }

Loading…
Cancel
Save