Files
Migu2.0/MiGu.Server/Wms/WmsReferenceValidator.cs
T
ArtoriasWu f2ef32a22b 引入WMS仓储主数据与关系管理全流程能力
后端实现基于EF Core的库区/库位/容器/物料/关系/历史等模型、服务与RESTful接口,支持多数据库Provider。前端新增类型、API与聚合页面,支持主数据及容器位置/物料关系的增删改查、绑定/解绑、装料/卸料、历史追溯。完善权限、菜单与文档,平台具备完整WMS能力。
2026-06-22 09:15:42 +08:00

58 lines
2.0 KiB
C#

using Microsoft.EntityFrameworkCore;
using MiGu.Server.Persistence;
namespace MiGu.Server.Wms;
public sealed class WmsReferenceValidator
{
private readonly PlatformDbContext _db;
public WmsReferenceValidator(PlatformDbContext db)
{
_db = db;
}
public async Task EnsureAreaAsync(Guid id)
{
if (!await _db.WarehouseAreas.AnyAsync(x => x.Id == id))
throw new InvalidOperationException("库区不存在");
}
public async Task EnsureStorageAsync(Guid id)
{
if (!await _db.Storages.AnyAsync(x => x.Id == id))
throw new InvalidOperationException("库位不存在");
}
public async Task EnsureContainerAsync(Guid id)
{
if (!await _db.Containers.AnyAsync(x => x.Id == id))
throw new InvalidOperationException("容器不存在");
}
public async Task EnsureMaterialAsync(Guid id)
{
if (!await _db.Materials.AnyAsync(x => x.Id == id))
throw new InvalidOperationException("物料不存在");
}
public async Task<(string Code, string Name)> ResolveLocationSnapshotAsync(string locationType, string locationId)
{
if (!ContainerLocationTypes.All.Contains(locationType))
throw new InvalidOperationException("位置类型无效");
if (string.IsNullOrWhiteSpace(locationId))
throw new InvalidOperationException("位置 ID 不能为空");
if (string.Equals(locationType, ContainerLocationTypes.Storage, StringComparison.OrdinalIgnoreCase))
{
if (!Guid.TryParse(locationId, out var id)) throw new InvalidOperationException("库位 ID 格式无效");
var s = await _db.Storages.FirstOrDefaultAsync(x => x.Id == id);
if (s == null) throw new InvalidOperationException("库位不存在");
return (s.Code, s.Name);
}
// 车辆来自现有调度/投影系统,首期不建库内外键,保留原始 ID 并作为快照展示。
return (locationId, locationId);
}
}