Files
Migu2.0/MiGu.Server/Wms/WmsReferenceValidator.cs
T
wei.wu 125372b157 移除历史状态归一化及相关遗留逻辑
- 移除 LegacyStatusNormalizationMigrator,仅保留 AreaLayoutModeDefaultMigrator
- 删除 WmsDispatchStatus 枚举、常量和全局 using
- 统一所有 DbContext 注入为 MiGuDbContext,移除 PlatformDbContext
- 服务实体操作统一用 IEditableRepository<T>,移除本地实现
- 移除 WmsService 的 MigrateLegacyAsync 方法
- 精简接口模型,移除部分字段和请求体
- 前端保存容器时 status 字段取自已有数据,移除写死默认值
- 更新文档,去除旧说明,统一数据库初始化流程
2026-08-03 09:41:03 +08:00

70 lines
2.4 KiB
C#

using Microsoft.EntityFrameworkCore;
using MiGu.Server.Persistence;
namespace MiGu.Server.Wms;
public sealed class WmsReferenceValidator
{
private readonly MiGuDbContext _db;
public WmsReferenceValidator(MiGuDbContext db)
{
_db = db;
}
public async Task EnsureWarehouseAsync(Guid id)
{
if (!await _db.Warehouses.AnyAsync(x => x.Id == id))
throw new InvalidOperationException("仓库不存在");
}
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 EnsureMaterialTypeCodeAsync(string typeCode)
{
if (!await _db.MaterialTypes.AnyAsync(x => x.Code == typeCode))
throw new InvalidOperationException("物料类型不存在");
}
public async Task<(string Code, string Name)> ResolveLocationSnapshotAsync(string locationType, string locationId)
{
if (!ContainerLocationTypes.IsDefined(locationType))
throw new InvalidOperationException("位置类型无效");
if (string.IsNullOrWhiteSpace(locationId))
throw new InvalidOperationException("位置 ID 不能为空");
if (ContainerLocationTypes.EqualsString(ContainerLocationTypes.Storage, locationType))
{
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);
}
}