fix(firstleg): derive remainder pallet labels from frozen allocation facts

This commit is contained in:
2026-09-30 15:28:50 +08:00
parent 71202bce70
commit 1a7e4800f5
2 changed files with 155 additions and 0 deletions
@@ -11,12 +11,24 @@ import java.util.List;
@Mapper
public interface LoadingPalletLabelMapper {
// Remainder slices inherit bound slots, not new weight records. Their slot/weight
// identity survives release or transfer; preserved empty slots are not pallets.
@Select("""
SELECT p.id AS plan_id,p.plan_no,p.plan_status,b.container_no,b.cabinet_no,b.warehouse_id,
i.id AS item_id,i.account_id,i.inbound_id,i.inbound_code,i.destination_warehouse_id,
i.destination_warehouse_code,i.destination_warehouse_name,
COALESCE(NULLIF(i.pallet_count,0),
CEIL(COALESCE(NULLIF(o.pallet_count,0),
NULLIF((SELECT COUNT(DISTINCT weight.id)
FROM fl_inbound_pallet_allocation allocation
JOIN fl_inbound_weight_result weight
ON weight.id=allocation.weight_result_id AND weight.tenant_id=allocation.tenant_id
AND weight.deleted=0 AND weight.recognition_status='CONFIRMED'
AND (weight.inbound_id=o.id OR weight.inbound_id=o.root_inbound_id)
WHERE allocation.tenant_id=i.account_id AND allocation.inbound_id=i.inbound_id
AND allocation.block_id>0 AND allocation.slot_no>0 AND allocation.reservation_id>0
AND allocation.allocated_package_count>0
AND allocation.allocation_status IN ('CONFIRMED','TRANSFERRED','RELEASED')),0),
(SELECT COUNT(*) FROM fl_inbound_weight_result weight
WHERE weight.tenant_id=i.account_id AND weight.inbound_id=i.inbound_id
AND weight.deleted=0 AND weight.recognition_status='CONFIRMED'),0)