fix(inventory): enforce warehouse transfer reservation ownership

This commit is contained in:
2026-10-05 07:24:53 +08:00
parent 548a133de6
commit 5b4d9624a9
14 changed files with 293 additions and 62 deletions
@@ -6,6 +6,8 @@ import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
@Mapper public interface WarehouseTransferOrderMapper extends BaseMapper<WarehouseTransferOrder> {
@Select("SELECT * FROM ll_warehouse_transfer_order WHERE customer_id=#{customerId} AND lastleg_order_id=#{tailOrderId} LIMIT 1 FOR UPDATE")
WarehouseTransferOrder lockTailOrder(@Param("customerId") String customerId, @Param("tailOrderId") Long tailOrderId);
@Select("SELECT * FROM ll_warehouse_transfer_order WHERE customer_id=#{customerId} AND idempotency_key=#{key} LIMIT 1")
WarehouseTransferOrder findKey(@Param("customerId") String customerId, @Param("key") String key);
@Select("SELECT * FROM ll_warehouse_transfer_order WHERE customer_id=#{customerId} AND transfer_no=#{transferNo} LIMIT 1")
@@ -71,7 +71,7 @@ public class WarehouseTransferRelabelCompletionService {
if (allocations.countActiveDispatchLock(customer, current.getPalletId()) > 0)
throw conflict("本票换标托盘已被排车占用");
String key = "WAREHOUSE_TRANSFER:" + transfer.getTransferNo() + ":RELABEL:" + item.getId();
inventory.releaseTransferRelabel(customer, operator, new InventoryCommandRequests.Move(current.getId(), count,
inventory.releaseTransferRelabel(customer, operator, transfer.getId(), new InventoryCommandRequests.Move(current.getId(), count,
transfer.getTransferNo(), null, key, key + ":RELEASE", "本票换标客户确认"), item.getSkuCode());
String outputSku = source.getNewSku() == null ? item.getSkuCode() : source.getNewSku();
if (!outputSku.equals(item.getSkuCode())) {
@@ -103,7 +103,7 @@ public class WarehouseTransferRelabelCompletionService {
if (current == null || balance == null || current.getHoldPackages() == null || current.getHoldPackages() < count)
throw conflict("未换标的转运余量不可用");
String key = "WAREHOUSE_TRANSFER:" + transfer.getTransferNo() + ":UNLABELLED:" + row.getId();
inventory.releaseTransferRelabel(customer, operator, new InventoryCommandRequests.Move(current.getId(), count,
inventory.releaseTransferRelabel(customer, operator, transfer.getId(), new InventoryCommandRequests.Move(current.getId(), count,
transfer.getTransferNo(), null, key, key + ":RELEASE", "本票未换标余量确认"), row.getSkuCode());
addTarget(targets, balance, current, count, row.getSkuCode());
}
@@ -1122,7 +1122,7 @@ public class WarehouseTransferService {
for (ConfirmedStockSource source : entry.getValue()) {
if (source.remainingPackages <= 0) continue;
String holdKey = "WAREHOUSE_TRANSFER:" + transferNo + ":UNLABELLED:" + source.allocationId;
inventory.hold(customerId, operatorId, new InventoryCommandRequests.Move(source.positionId,
inventory.holdWarehouseTransfer(customerId, operatorId, transfer.getId(), new InventoryCommandRequests.Move(source.positionId,
source.remainingPackages, transferNo, null, holdKey, holdKey + ":HOLD", "本票转运未换标余量预留"));
}
}
@@ -1181,21 +1181,18 @@ public class WarehouseTransferService {
InventoryCommandRequests.Move move = new InventoryCommandRequests.Move(
allocation.getInventoryPositionId(), allocation.getPackageCount(), transferNo, transferNo,
"WAREHOUSE_TRANSFER_OUTBOUND:" + transferNo, keyBase + ":ALLOCATE", trim(request.remark()));
if (Boolean.TRUE.equals(transfer.getNeedRelabel()))
inventory.allocateTransferSnapshot(customerId, operatorId, move, allocation.getSkuCode());
else inventory.allocate(customerId, operatorId, move);
inventory.allocateWarehouseTransfer(customerId, operatorId, transfer.getId(), move,
Boolean.TRUE.equals(transfer.getNeedRelabel()) ? allocation.getSkuCode() : null);
var pick = new InventoryCommandRequests.Move(
allocation.getInventoryPositionId(), allocation.getPackageCount(), transferNo, transferNo,
"WAREHOUSE_TRANSFER_OUTBOUND:" + transferNo, keyBase + ":PICK", trim(request.remark()));
if (Boolean.TRUE.equals(transfer.getNeedRelabel()))
inventory.pickTransferSnapshot(customerId, operatorId, pick, allocation.getSkuCode());
else inventory.pick(customerId, operatorId, pick);
inventory.pickWarehouseTransfer(customerId, operatorId, transfer.getId(), pick,
Boolean.TRUE.equals(transfer.getNeedRelabel()) ? allocation.getSkuCode() : null);
var ship = new InventoryCommandRequests.Move(
allocation.getInventoryPositionId(), allocation.getPackageCount(), transferNo, transferNo,
"WAREHOUSE_TRANSFER_OUTBOUND:" + transferNo, keyBase + ":SHIP", trim(request.remark()));
if (Boolean.TRUE.equals(transfer.getNeedRelabel()))
inventory.shipTransferSnapshot(customerId, operatorId, ship, allocation.getSkuCode());
else inventory.ship(customerId, operatorId, ship);
inventory.shipWarehouseTransfer(customerId, operatorId, transfer.getId(), ship,
Boolean.TRUE.equals(transfer.getNeedRelabel()) ? allocation.getSkuCode() : null);
allocation.setStatus("SHIPPED"); allocation.setActivePositionKey(null);
allocation.setShippedAt(now); allocation.setUpdatedAt(now); inventoryAllocations.updateById(allocation);
}