Files
WMSlite/WmsLite.Api/Dtos/Inventory/InventoryMutationRequestBase.cs
T
2026-05-31 01:03:55 +08:00

97 lines
3.8 KiB
C#

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using WmsLite.Api.Dtos.Common;
using WmsLite.Api.Enums;
namespace WmsLite.Api.Dtos.Inventory;
public abstract class InventoryMutationRequestBase : IValidatableObject
{
[Required(ErrorMessage = "BizType is required.")]
[StringLength(64)]
public string BizType { get; set; } = string.Empty;
[Required(ErrorMessage = "InventoryKind is required.")]
[EnumDataType(typeof(InventoryKind), ErrorMessage = "InventoryKind is invalid.")]
public InventoryKind InventoryKind { get; set; } = InventoryKind.Material;
[Required]
[EnumDataType(typeof(InventoryStatus), ErrorMessage = "InventoryStatus is invalid.")]
public InventoryStatus InventoryStatus { get; set; } = InventoryStatus.Available;
[StringLength(64)]
public string? MaterialCode { get; set; }
[StringLength(64)]
public string? ContainerCode { get; set; }
[Required(ErrorMessage = "WarehouseCode is required.")]
[StringLength(64)]
public string WarehouseCode { get; set; } = string.Empty;
[Required(ErrorMessage = "AreaCode is required.")]
[StringLength(64)]
public string AreaCode { get; set; } = string.Empty;
[Required(ErrorMessage = "分区编码不能为空。")]
[StringLength(64)]
public string ZoneCode { get; set; } = string.Empty;
[Required(ErrorMessage = "LocationCode is required.")]
[StringLength(64)]
public string LocationCode { get; set; } = string.Empty;
[Range(typeof(decimal), "0", "9999999999999999", ErrorMessage = "Qty must be greater than or equal to 0.")]
public decimal Qty { get; set; }
[Range(typeof(decimal), "0", "9999999999999999", ErrorMessage = "PendingInboundQty must be greater than or equal to 0.")]
public decimal PendingInboundQty { get; set; }
[Range(typeof(decimal), "0", "9999999999999999", ErrorMessage = "PendingOutboundQty must be greater than or equal to 0.")]
public decimal PendingOutboundQty { get; set; }
[Range(typeof(decimal), "0", "9999999999999999", ErrorMessage = "FrozenQty must be greater than or equal to 0.")]
public decimal FrozenQty { get; set; }
[Required(ErrorMessage = "Unit is required.")]
[StringLength(32)]
public string Unit { get; set; } = string.Empty;
public Dictionary<string, object>? Attrs { get; set; }
public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (!Enum.IsDefined(typeof(InventoryKind), InventoryKind)
|| (InventoryKind != InventoryKind.Material && InventoryKind != InventoryKind.EmptyContainer))
{
yield return new ValidationResult("InventoryKind is invalid.", new[] { nameof(InventoryKind) });
yield break;
}
if (InventoryKind == InventoryKind.Material)
{
if (string.IsNullOrWhiteSpace(MaterialCode))
{
yield return new ValidationResult("MaterialCode is required for material inventory.", new[] { nameof(MaterialCode) });
}
if (!string.IsNullOrWhiteSpace(ContainerCode))
{
yield return new ValidationResult("ContainerCode must be empty for material inventory.", new[] { nameof(ContainerCode) });
}
}
else if (InventoryKind == InventoryKind.EmptyContainer)
{
if (string.IsNullOrWhiteSpace(ContainerCode))
{
yield return new ValidationResult("ContainerCode is required for empty container inventory.", new[] { nameof(ContainerCode) });
}
if (!string.IsNullOrWhiteSpace(MaterialCode))
{
yield return new ValidationResult("MaterialCode must be empty for empty container inventory.", new[] { nameof(MaterialCode) });
}
}
}
}