fix(inventory): normalize FBA return SKU and match durable shipment command identity

This commit is contained in:
2026-09-30 12:32:59 +08:00
parent 2f0b202590
commit 5cb2a5145f
4 changed files with 96 additions and 4 deletions
@@ -56,10 +56,12 @@ public interface InventoryCommandMapper {
"AND l.outbound_order_no=o.dispatch_no AND EXISTS (" +
"SELECT 1 FROM ll_dispatch_pda_task t JOIN ll_dispatch_pda_pick p " +
"ON p.customer_id=t.customer_id AND p.task_id=t.id " +
"JOIN ll_inventory_operation op ON op.customer_id=p.customer_id " +
"AND op.operation_type='SHIP' AND op.status='COMPLETED' " +
"AND op.idempotency_key=CONCAT('DISPATCH:',o.dispatch_no,':',p.dispatch_item_id,':',p.idempotency_key,':SHIP') " +
"WHERE t.customer_id=o.customer_id AND t.dispatch_order_id=o.dispatch_order_id " +
"AND t.warehouse_id=o.overseas_warehouse_id AND p.inventory_position_id=l.position_id " +
"AND p.packages=-l.delta_packages AND l.idempotency_key=CONCAT('DISPATCH:',o.dispatch_no,':'," +
"p.dispatch_item_id,':',p.idempotency_key,':SHIP'))) " +
"AND p.packages=-l.delta_packages AND l.idempotency_key=CONCAT(op.idempotency_key,':',op.id))) " +
"OR (o.outbound_type<>'DISPATCH_DELIVERY' AND l.outbound_order_no=o.outbound_no))")
long shippedPackages(@Param("customerId") String customerId, @Param("positionId") Long positionId,
@Param("outboundNo") String outboundNo, @Param("skuCode") String skuCode);
@@ -294,7 +294,7 @@ public class InventoryCommandService {
|| source.maxReturnPackages() <= 0) {
throw badRequest("A valid returned inventory source is required");
}
String sourceSku = required(source.skuCode(), "Returned inventory source SKU is required");
String sourceSku = sku(source.skuCode());
ReturnedInventoryRestoreRequest.SourceItem normalized = new ReturnedInventoryRestoreRequest.SourceItem(
source.outboundPalletItemId(), source.inventoryPositionId(), sourceSku, source.maxReturnPackages());
if (sources.putIfAbsent(source.outboundPalletItemId(), normalized) != null) {