fix(warehouse-overseas): enforce pallet location invariant

This commit is contained in:
2026-09-08 14:47:35 +08:00
parent 07688005a1
commit a0ad3382af
9 changed files with 276 additions and 25 deletions
@@ -188,19 +188,14 @@ public class WarehouseResourceService {
WarehousePalletEntity pallet = matches.get(0);
if (pallet.getLocationId() == null) throw new BizException(ResultCode.CONFLICT, "托盘未绑定库位");
if ("SCRAPPED".equals(pallet.getStatus())) throw new BizException(ResultCode.CONFLICT, "托盘已报废");
return new WarehousePalletResolveResponse(pallet.getId(), pallet.getPalletCode(), pallet.getWarehouseId(),
pallet.getLocationId(), pallet.getStatus(), pallet.getFbaWarehouseCode(),
pallet.getUnitPrice(),
pallet.getVersion() == null ? 0 : pallet.getVersion());
return palletReference(pallet);
}
public WarehousePalletResolveResponse resolvePublicPallet(long palletId) {
WarehousePalletEntity pallet = repository.findPublicPallet(palletId);
if (pallet == null) throw new BizException(ResultCode.NOT_FOUND, "托盘不存在");
if (pallet.getLocationId() == null) throw new BizException(ResultCode.CONFLICT, "托盘未绑定库位");
return new WarehousePalletResolveResponse(pallet.getId(), pallet.getPalletCode(), pallet.getWarehouseId(),
pallet.getLocationId(), pallet.getStatus(), pallet.getFbaWarehouseCode(), pallet.getUnitPrice(),
pallet.getVersion() == null ? 0 : pallet.getVersion());
return palletReference(pallet);
}
public WarehouseLocationResolveResponse resolvePublicLocation(long warehouseId, String locationCode) {
@@ -222,6 +217,26 @@ public class WarehouseResourceService {
location.getLocationType(), location.getMaxLoadKg(), location.getStatus());
}
private WarehousePalletResolveResponse palletReference(WarehousePalletEntity pallet) {
WarehouseLocationEntity location = repository.findLocation(PUBLIC_RESOURCE_SCOPE,
pallet.getWarehouseId(), pallet.getLocationId());
String blockReason = reservationBlockReason(pallet, location);
return new WarehousePalletResolveResponse(pallet.getId(), pallet.getPalletCode(), pallet.getWarehouseId(),
pallet.getLocationId(), pallet.getStatus(), pallet.getFbaWarehouseCode(), pallet.getUnitPrice(),
pallet.getVersion() == null ? 0 : pallet.getVersion(),
location == null ? null : location.getLocationType(),
location == null ? null : location.getStatus(), blockReason == null, blockReason);
}
private static String reservationBlockReason(WarehousePalletEntity pallet, WarehouseLocationEntity location) {
if (!"IDLE".equals(pallet.getStatus())) return "PALLET_NOT_IDLE";
if (location == null) return "LOCATION_NOT_FOUND";
if ("VIRTUAL".equals(location.getLocationType())) {
return "ACTIVE".equals(location.getStatus()) ? null : "VIRTUAL_LOCATION_NOT_ACTIVE";
}
return "IDLE".equals(location.getStatus()) ? null : "LOCATION_NOT_IDLE";
}
public PageResult<WarehousePalletEntity> pallets(long customerId, long warehouseId,
PalletRequests.QueryRequest query) {
requireWarehouse(customerId, warehouseId);