- 新增 MiGu.DB 项目,迁移所有领域实体与枚举,统一模型约定 - 实现 Entity/Repository/UoW/Provider/Exception 等接口与实现 - 支持数据修补机制,完善 Sqlite 初始迁移与数据库管理 - Server 侧移除 EF Core 相关,依赖 MiGu.DB,PlatformPersistence 适配 - 业务服务注入 UoW/Repository,状态字段统一用 enum 及辅助类 - 统一异常处理,Controller 映射 HTTP 状态码 - 配置项与文档补充数据库启动、SchemaMode、迁移说明 - 新增 GlobalUsings.Db.cs、WmsStatusAliases.cs 简化类型引用 - 新增 HttpActorContextMiddleware 支持操作者上下文一致性 - 新增 MiGuDbContextModelSnapshot 追踪数据库结构 - 优化代码结构,解耦领域与持久层,提升扩展性与安全性
70 lines
2.4 KiB
C#
70 lines
2.4 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 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);
|
|
}
|
|
}
|