fix(firstleg): normalize split carton label pools

This commit is contained in:
2026-08-24 14:20:59 +08:00
parent 8e61cfd202
commit e781cbe9cb
3 changed files with 19 additions and 3 deletions
@@ -151,7 +151,10 @@ public interface InboundSplitSettlementMapper {
@Update("""
UPDATE fl_inbound_carton_label
SET inbound_id=#{childInboundId}, order_id=#{childOrderId}, inbound_code=#{childInboundCode}
SET inbound_id=#{childInboundId}, order_id=#{childOrderId}, inbound_code=#{childInboundCode},
carton_index=carton_index-#{loadedPackageCount},
total_carton_count=#{remainingPackageCount},
detail_package_count=LEAST(detail_package_count,#{remainingPackageCount})
WHERE tenant_id=#{accountId} AND inbound_id=#{sourceInboundId} AND batch_status='ACTIVE'
ORDER BY carton_index DESC
LIMIT #{remainingPackageCount}
@@ -161,8 +164,19 @@ public interface InboundSplitSettlementMapper {
@Param("childInboundId") long childInboundId,
@Param("childOrderId") long childOrderId,
@Param("childInboundCode") String childInboundCode,
@Param("loadedPackageCount") int loadedPackageCount,
@Param("remainingPackageCount") int remainingPackageCount);
@Update("""
UPDATE fl_inbound_carton_label
SET total_carton_count=#{loadedPackageCount},
detail_package_count=LEAST(detail_package_count,#{loadedPackageCount})
WHERE tenant_id=#{accountId} AND inbound_id=#{sourceInboundId} AND batch_status='ACTIVE'
""")
int normalizeLoadedCartonLabels(@Param("accountId") long accountId,
@Param("sourceInboundId") long sourceInboundId,
@Param("loadedPackageCount") int loadedPackageCount);
@Update("""
UPDATE fl_inbound_order
SET package_count = GREATEST(COALESCE(package_count, total_package_count) - #{packageCount}, 0),
@@ -186,7 +186,8 @@ public class PdaPickSettlementService {
orderSplit.remainderChild().orderId(), orderSplit.remainderChild().orderNo(),
remainderChildCode, childPackageCount, sequence, "REMAINDER", operatorId, operatorName), "余量子入库单");
splits.transferRemainingCartonLabels(parent.tenantId(), parentInboundId, remainderChildId,
orderSplit.remainderChild().orderId(), remainderChildCode, childPackageCount);
orderSplit.remainderChild().orderId(), remainderChildCode, pickedPackageCount, childPackageCount);
splits.normalizeLoadedCartonLabels(parent.tenantId(), parentInboundId, pickedPackageCount);
}
requireAffected(splits.insertBatchWithChildren(batchId, parent.tenantId(), rootInboundId, operationId, parentInboundId,
idempotencyKey, rootVersion, parentAvailable, null, remainderChildId == 0L ? null : remainderChildId,
@@ -67,7 +67,8 @@ class PdaPickSettlementServiceTest {
eq(1002L), eq("ORDER-REMAINDER"), eq("IN-001-1"), eq(12),
eq(1), eq("REMAINDER"), eq(9L), eq("operator"));
verify(splits).transferRemainingCartonLabels(eq(10001L), eq(31L), anyLong(),
eq(1002L), eq("IN-001-1"), eq(12));
eq(1002L), eq("IN-001-1"), eq(8), eq(12));
verify(splits).normalizeLoadedCartonLabels(10001L, 31L, 8);
verify(splits).markSourceLoaded(10001L, 31L, 8, 9L, 3);
verify(allocations).consume(10001L, 31L, 1L, 8);
verify(warehouse).settle(eq("internal-token"), org.mockito.ArgumentMatchers.argThat(request ->