StorageLocation.cs 2.85 KB
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Rcs.Domain.Attributes;

namespace Rcs.Domain.Entities;

/// <summary>
/// 库位实体
/// @author zzy
/// </summary>
[Table("storage_locations")]
public class StorageLocation : Entity
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    [Column("location_id")]
    public Guid LocationId { get; set; }

    /// <summary>
    /// 所属库区ID(外键)
    /// </summary>
    [Column("area_id")]
    public Guid AreaId { get; set; }

    /// <summary>
    /// 储位类型ID(外键)
    /// @author zzy
    /// </summary>
    [Column("location_type_id")]
    public Guid? LocationTypeId { get; set; }

    /// <summary>
    /// 关联的地图节点ID(外键,可为空)
    /// @author zzy
    /// </summary>
    [Column("map_node_id")]
    public Guid? MapNodeId { get; set; }


    /// <summary>
    /// 库位编码
    /// </summary>
    [Required]
    [Column("location_code")]
    [MaxLength(50)]
    public string LocationCode { get; set; }

    /// <summary>
    /// 库位名称
    /// </summary>
    [Column("location_name")]
    [MaxLength(100)]
    public string? LocationName { get; set; }

    /// <summary>
    /// 层数(用于多层货架)
    /// </summary>
    [Column("layer_number")]
    public int? LayerNumber { get; set; }

    /// <summary>
    /// 库位状态
    /// </summary>
    [Column("status")]
    public StorageLocationStatus Status { get; set; } = StorageLocationStatus.Empty;

    /// <summary>
    /// 是否启用
    /// </summary>
    [Column("is_active")]
    public bool IsActive { get; set; } = true;

    /// <summary>
    /// 创建时间
    /// </summary>
    [Column("created_at", TypeName = "timestamp")]
    public DateTime CreatedAt { get; set; }

    /// <summary>
    /// 更新时间
    /// </summary>
    [Column("updated_at", TypeName = "timestamp")]
    public DateTime? UpdatedAt { get; set; }


    #region 导航属性

    /// <summary>
    /// 所属库区
    /// </summary>
    [ForeignKey(nameof(AreaId))]
    public virtual StorageArea StorageArea { get; set; }

    /// <summary>
    /// 关联的地图节点
    /// @author zzy
    /// </summary>
    [ForeignKey(nameof(MapNodeId))]
    public virtual MapNode? MapNode { get; set; }

    /// <summary>
    /// 储位类型
    /// @author zzy
    /// </summary>
    [ForeignKey(nameof(LocationTypeId))]
    public virtual StorageLocationType? LocationType { get; set; }

    #endregion
}

/// <summary>
/// 库位状态枚举
/// @author zzy
/// </summary>
public enum StorageLocationStatus
{
    [EnumDescription("空闲", "Empty")]
    Empty = 0,

    [EnumDescription("占用", "Occupied")]
    Occupied = 1,

    [EnumDescription("预占用", "Reserved")]
    Reserved = 2,

    [EnumDescription("禁用", "Disabled")]
    Disabled = 3
}