fix: prepare mixed-SKU dropship acceptance data

This commit is contained in:
2026-09-11 16:21:14 +08:00
parent 51ce609ab1
commit 010475a4c3
4 changed files with 38 additions and 4 deletions
@@ -358,8 +358,18 @@ public class InboundCartonLabelService implements CartonLabelBindingResolver {
Map<Long, List<InboundCartonLabelSkuMapper.SkuRow>> skuRowsByLabel) {
List<InboundCartonLabelSkuMapper.SkuRow> lines = skuRowsByLabel.get(label.getId());
if (lines == null || lines.isEmpty()) return label.getSkuCode();
return lines.stream().map(InboundCartonLabelSkuMapper.SkuRow::getSkuCode)
.filter(StringUtils::hasText).distinct().collect(java.util.stream.Collectors.joining(" / "));
List<String> skuCodes = lines.stream().map(InboundCartonLabelSkuMapper.SkuRow::getSkuCode)
.filter(StringUtils::hasText).map(String::trim).distinct().toList();
if (skuCodes.isEmpty()) return label.getSkuCode();
String joined = String.join(" / ", skuCodes);
if (joined.codePointCount(0, joined.length()) <= 64) return joined;
String suffix = " / +" + Math.max(0, skuCodes.size() - 1) + " SKU";
int firstLimit = 64 - suffix.codePointCount(0, suffix.length());
String first = skuCodes.get(0);
if (first.codePointCount(0, first.length()) > firstLimit) {
first = first.substring(0, first.offsetByCodePoints(0, firstLimit));
}
return first + suffix;
}
private void requireIds(long tenantId, long inboundId) {
@@ -19,6 +19,7 @@ import org.springframework.test.util.ReflectionTestUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -98,6 +99,23 @@ class InboundCartonLabelServiceTest {
any(Long.class), any(String.class), any(), any(Integer.class), any(Integer.class));
}
@Test
void mixedCartonSkuSummaryStaysWithinPrintContractLimit() {
InboundCartonLabelEntity label = new InboundCartonLabelEntity();
label.setId(90001L);
List<InboundCartonLabelSkuMapper.SkuRow> rows = List.of(
skuRow(90001L, "SKU-SMALL-ADMIN-API-20260911081504632"),
skuRow(90001L, "SKU-MEDIUM-ADMIN-API-20260911081504632"),
skuRow(90001L, "SKU-LARGE-ADMIN-API-20260911081504632"),
skuRow(90001L, "SKU-EXTRA-LARGE-ADMIN-API-20260911081504632"));
String summary = ReflectionTestUtils.invokeMethod(service, "displaySkuCodes", label,
Map.of(90001L, rows));
assertThat(summary.codePointCount(0, summary.length())).isLessThanOrEqualTo(64);
assertThat(summary).startsWith("SKU-SMALL-").endsWith(" / +3 SKU");
}
@Test
void repeatedAndPartialPrintsReadFrozenMappingWithoutReallocation() {
InboundOrderEntity inbound = inbound();
@@ -312,6 +330,13 @@ class InboundCartonLabelServiceTest {
units, new BigDecimal("60"), new BigDecimal("40"), new BigDecimal("30"), null, group);
}
private InboundCartonLabelSkuMapper.SkuRow skuRow(long labelId, String skuCode) {
InboundCartonLabelSkuMapper.SkuRow row = new InboundCartonLabelSkuMapper.SkuRow();
row.setCartonLabelId(labelId);
row.setSkuCode(skuCode);
return row;
}
private List<InboundCartonLabelEntity> labels(InboundOrderEntity inbound, int total) {
List<InboundCartonLabelEntity> values = new ArrayList<>();
for (int index = 1; index <= total; index++) {