完善 WMS 搬运任务与库位状态相关接口。

补齐运输规划与任务服务在状态/优先级字段上的读写与调度衔接。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zhaowei.huang
2026-07-26 11:32:29 +08:00
co-authored by Cursor
parent 95c1a74122
commit ef63dda228
3 changed files with 70 additions and 7 deletions
+22 -1
View File
@@ -499,7 +499,14 @@ public sealed class WmsService
});
await AddContainerMoveEventAsync(req.ContainerId, fromStorageId, toStorageId, actor, req.Reason.TrimOr(""), now);
await _db.SaveChangesAsync();
try
{
await _db.SaveChangesAsync();
}
catch (DbUpdateException ex) when (IsUniqueConstraintViolation(ex))
{
throw new InvalidOperationException("目标库位已被其他容器占用,库位与容器为 1 对 1");
}
await SyncOccupancyStatus(containerId: req.ContainerId, storageId: fromStorageId);
await SyncOccupancyStatus(storageId: toStorageId);
return current;
@@ -857,6 +864,20 @@ public sealed class WmsService
throw new InvalidOperationException("数据已被其他用户修改,请刷新后重试");
}
private static bool IsUniqueConstraintViolation(DbUpdateException ex)
{
for (Exception? e = ex; e != null; e = e.InnerException)
{
var msg = e.Message;
if (msg.Contains("UNIQUE constraint failed", StringComparison.OrdinalIgnoreCase)
|| msg.Contains("unique index", StringComparison.OrdinalIgnoreCase)
|| msg.Contains("duplicate key", StringComparison.OrdinalIgnoreCase))
return true;
}
return false;
}
private static void EnsureUnlocked(EntityBase entity)
{
if (entity.IsLock) throw new InvalidOperationException("数据已锁定,不能修改");