- 新增 MiGu.DB 项目,迁移所有领域实体与枚举,统一模型约定 - 实现 Entity/Repository/UoW/Provider/Exception 等接口与实现 - 支持数据修补机制,完善 Sqlite 初始迁移与数据库管理 - Server 侧移除 EF Core 相关,依赖 MiGu.DB,PlatformPersistence 适配 - 业务服务注入 UoW/Repository,状态字段统一用 enum 及辅助类 - 统一异常处理,Controller 映射 HTTP 状态码 - 配置项与文档补充数据库启动、SchemaMode、迁移说明 - 新增 GlobalUsings.Db.cs、WmsStatusAliases.cs 简化类型引用 - 新增 HttpActorContextMiddleware 支持操作者上下文一致性 - 新增 MiGuDbContextModelSnapshot 追踪数据库结构 - 优化代码结构,解耦领域与持久层,提升扩展性与安全性
113 lines
5.0 KiB
C#
113 lines
5.0 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
using MiGu.DB.Domains.Dashboard;
|
|
using MiGu.DB.Domains.SimpleFields;
|
|
using MiGu.DB.Domains.Transport;
|
|
|
|
namespace MiGu.DB.Domains.Transport
|
|
{
|
|
public sealed class WmsTransportRuleConfiguration : IEntityTypeConfiguration<WmsTransportRule>
|
|
{
|
|
public void Configure(EntityTypeBuilder<WmsTransportRule> b)
|
|
{
|
|
b.ToTable("wms_transport_rules");
|
|
b.HasKey(x => x.Id);
|
|
b.HasIndex(x => x.Code).IsUnique();
|
|
b.HasIndex(x => new { x.TriggerType, x.Enabled, x.Priority });
|
|
b.Property(x => x.SourceSelectorJson).HasColumnType("text");
|
|
b.Property(x => x.TargetSelectorJson).HasColumnType("text");
|
|
b.Property(x => x.TaskOptionsJson).HasColumnType("text");
|
|
}
|
|
}
|
|
|
|
public sealed class WmsTransportTaskConfiguration : IEntityTypeConfiguration<WmsTransportTask>
|
|
{
|
|
public void Configure(EntityTypeBuilder<WmsTransportTask> b)
|
|
{
|
|
b.ToTable("wms_transport_tasks");
|
|
b.HasKey(x => x.Id);
|
|
b.HasIndex(x => x.Status);
|
|
b.HasIndex(x => x.ContainerId);
|
|
b.HasIndex(x => x.TargetStorageId);
|
|
b.Property(x => x.Quantity).HasPrecision(18, 4);
|
|
b.Property(x => x.SnapshotJson).HasColumnType("text");
|
|
}
|
|
}
|
|
|
|
public sealed class WmsTransportReservationConfiguration : IEntityTypeConfiguration<WmsTransportReservation>
|
|
{
|
|
public void Configure(EntityTypeBuilder<WmsTransportReservation> b)
|
|
{
|
|
b.ToTable("wms_transport_reservations");
|
|
b.HasKey(x => x.Id);
|
|
b.HasIndex(x => new { x.ContainerId, x.Status });
|
|
b.HasIndex(x => new { x.TargetStorageId, x.Status });
|
|
}
|
|
}
|
|
|
|
public sealed class WmsTransportTaskHistoryConfiguration : IEntityTypeConfiguration<WmsTransportTaskHistory>
|
|
{
|
|
public void Configure(EntityTypeBuilder<WmsTransportTaskHistory> b)
|
|
{
|
|
b.ToTable("wms_transport_task_history");
|
|
b.HasKey(x => x.Id);
|
|
b.Property(x => x.FromStatus).HasMaxLength(32);
|
|
b.Property(x => x.ToStatus).HasMaxLength(32);
|
|
b.Property(x => x.Operator).HasMaxLength(128);
|
|
b.Property(x => x.Reason).HasMaxLength(500);
|
|
b.Property(x => x.ErrorMessage).HasMaxLength(1000);
|
|
b.Property(x => x.SnapshotJson).HasColumnType("text");
|
|
b.HasIndex(x => x.TaskId);
|
|
b.HasIndex(x => x.OperatedAt);
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace MiGu.DB.Domains.SimpleFields
|
|
{
|
|
public sealed class SimpleFieldConfiguration : IEntityTypeConfiguration<SimpleField>
|
|
{
|
|
public void Configure(EntityTypeBuilder<SimpleField> b)
|
|
{
|
|
b.ToTable("simple_fields");
|
|
b.HasKey(x => x.Id);
|
|
b.Property(x => x.Id).HasColumnName("id");
|
|
b.Property(x => x.CarType).HasColumnName("car_type").HasMaxLength(64);
|
|
b.Property(x => x.FieldType).HasColumnName("field_type").HasMaxLength(64);
|
|
b.Property(x => x.Key).HasColumnName("key").HasMaxLength(128);
|
|
b.Property(x => x.Value).HasColumnName("value");
|
|
b.Property(x => x.DataType).HasColumnName("data_type").HasMaxLength(128);
|
|
b.Property(x => x.Chinese).HasColumnName("chinese").HasMaxLength(256).IsRequired(false);
|
|
b.Property(x => x.English).HasColumnName("english").HasMaxLength(256).IsRequired(false);
|
|
b.Property(x => x.Other).HasColumnName("other").HasMaxLength(512);
|
|
b.Property(x => x.IsDefault).HasColumnName("is_default");
|
|
var dateTime = new ValueConverter<DateTimeOffset, string>(
|
|
v => SimpleFieldDateTime.ToStorage(v),
|
|
v => SimpleFieldDateTime.FromStorage(v));
|
|
b.Property(x => x.CreateTime).HasColumnName("create_time").HasConversion(dateTime).HasMaxLength(19);
|
|
b.Property(x => x.UpdateTime).HasColumnName("update_time").HasConversion(dateTime).HasMaxLength(19);
|
|
b.HasIndex(x => new { x.CarType, x.FieldType, x.Key }).IsUnique();
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace MiGu.DB.Domains.Dashboard
|
|
{
|
|
public sealed class UserDashboardShortcutConfiguration : IEntityTypeConfiguration<UserDashboardShortcut>
|
|
{
|
|
public void Configure(EntityTypeBuilder<UserDashboardShortcut> b)
|
|
{
|
|
b.ToTable("user_dashboard_shortcuts");
|
|
b.HasKey(x => new { x.UserId, x.Scope });
|
|
b.Property(x => x.UserId).HasColumnName("user_id").HasMaxLength(64);
|
|
b.Property(x => x.Scope).HasColumnName("scope").HasMaxLength(32);
|
|
b.Property(x => x.KeysJson).HasColumnName("keys_json").HasColumnType("text");
|
|
var dateTime = new ValueConverter<DateTimeOffset, string>(
|
|
v => v.UtcDateTime.ToString("O"),
|
|
v => DateTimeOffset.Parse(v));
|
|
b.Property(x => x.UpdatedAt).HasColumnName("updated_at").HasConversion(dateTime).HasMaxLength(40);
|
|
}
|
|
}
|
|
}
|