RobotCacheLocationConfiguration.cs 3.16 KB
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Rcs.Domain.Entities;

namespace Rcs.Infrastructure.DB.Configuration.Domain
{
    /// <summary>
    /// RobotCacheLocation实体的EF Core配置
    /// </summary>
    public class RobotCacheLocationConfiguration : IEntityTypeConfiguration<RobotCacheLocation>
    {
        public void Configure(EntityTypeBuilder<RobotCacheLocation> builder)
        {
            // 配置表名
            builder.ToTable("robot_cache_locations");

            // 配置主键
            builder.HasKey(e => e.CacheLocationId);

            // 配置属性
            builder.Property(e => e.CacheLocationId)
                .HasColumnName("id")
                .ValueGeneratedNever();

            builder.Property(e => e.RobotId)
                .HasColumnName("robot_id")
                .IsRequired();

            builder.Property(e => e.LocationCode)
                .HasColumnName("location_code")
                .HasMaxLength(100)
                .IsRequired();

            builder.Property(e => e.Row)
                .HasColumnName("row")
                .IsRequired();

            builder.Property(e => e.Column)
                .HasColumnName("column")
                .IsRequired();

            builder.Property(e => e.Level)
                .HasColumnName("level")
                .IsRequired();

            builder.Property(e => e.ContainerId)
                .HasColumnName("container_id")
                .HasMaxLength(100);

            builder.Property(e => e.MaterialCode)
                .HasColumnName("material_code")
                .HasMaxLength(100);

            builder.Property(e => e.MaterialName)
                .HasColumnName("material_name")
                .HasMaxLength(200);

            builder.Property(e => e.Quantity)
                .HasColumnName("quantity");

            builder.Property(e => e.Weight)
                .HasColumnName("weight");

            builder.Property(e => e.Remark)
                .HasColumnName("remark")
                .HasMaxLength(500);

            builder.Property(e => e.CreatedAt)
                .HasColumnName("created_at")
                .HasColumnType("timestamp without time zone");

            builder.Property(e => e.UpdatedAt)
                .HasColumnName("updated_at")
                .HasColumnType("timestamp without time zone");

            // 配置索引
            builder.HasIndex(e => e.RobotId)
                .HasDatabaseName("idx_robot_cache_location_robot_id");

            builder.HasIndex(e => e.LocationCode)
                .HasDatabaseName("idx_robot_cache_location_code");

            builder.HasIndex(e => e.Row)
                .HasDatabaseName("idx_robot_cache_location_row");

            builder.HasIndex(e => e.Column)
                .HasDatabaseName("idx_robot_cache_location_column");

            builder.HasIndex(e => e.Level)
                .HasDatabaseName("idx_robot_cache_location_level");

            // 配置复合索引(排-列-层)用于快速查询
            builder.HasIndex(e => new { e.Row, e.Column, e.Level })
                .HasDatabaseName("idx_robot_cache_location_position");
        }
    }
}