1
This commit is contained in:
@@ -24,6 +24,7 @@ import java.util.ArrayList;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -186,7 +187,7 @@ public class UnifiedOrderQueryService {
|
||||
null, null, null, null, order.getPickupMethod(), order.getTaxMode(), order.getContainerMode(),
|
||||
order.getCustomsInspection(), order.getDestinationType(), order.getAmazonWarehouseCode(),
|
||||
null, null, null, null, netWeightKg(cargo), null, null, order.getExpressCompany(), order.getExpressTrackingNo(),
|
||||
string(order.getCreatedBy()), skuNos(cargo), totalQuantity(cargo), order.getShipmentId(), order.getReferenceId(),
|
||||
string(order.getCreatedBy()), skuNos(cargo), totalQuantity(cargo), shipmentId(order, cargo), referenceId(order, cargo),
|
||||
null, null, null, null, null,
|
||||
order.getCustomerRemark(), latestInternalNote,
|
||||
order.getCreatedAt(), order.getUpdatedAt(), order.getRequestedPickupAt());
|
||||
@@ -205,7 +206,7 @@ public class UnifiedOrderQueryService {
|
||||
inbound.chargeableWeightKg(), inbound.chargeableVolumeCbm(), inbound.volumeWeightKg(),
|
||||
inbound.actualNetWeightKg() != null ? inbound.actualNetWeightKg() : netWeightKg(cargo),
|
||||
inbound.measureCompletedAt(), inbound.inboundedAt(), inbound.expressCompanyName(), inbound.expressTrackingNo(),
|
||||
inbound.createdByName(), skuNos(cargo), totalQuantity(cargo), order.getShipmentId(), order.getReferenceId(), measurement(inbound),
|
||||
inbound.createdByName(), skuNos(cargo), totalQuantity(cargo), shipmentId(order, cargo), referenceId(order, cargo), measurement(inbound),
|
||||
preload(summary.preload()), loading(summary.loading()),
|
||||
delivery(summary.delivery()), transport(inbound), order.getCustomerRemark(), latestInternalNote,
|
||||
order.getCreatedAt(), order.getUpdatedAt(), inbound.requestedPickupAt());
|
||||
@@ -231,8 +232,8 @@ public class UnifiedOrderQueryService {
|
||||
inbound.chargeableWeightKg(), inbound.chargeableVolumeCbm(), inbound.volumeWeightKg(),
|
||||
inbound.actualNetWeightKg() != null ? inbound.actualNetWeightKg() : netWeightKg(cargo),
|
||||
inbound.measureCompletedAt(), inbound.inboundedAt(), inbound.expressCompanyName(), inbound.expressTrackingNo(),
|
||||
inbound.createdByName(), skuNos(cargo), totalQuantity(cargo), order == null ? null : order.getShipmentId(),
|
||||
order == null ? null : order.getReferenceId(), measurement(inbound), preload(summary.preload()), loading(summary.loading()),
|
||||
inbound.createdByName(), skuNos(cargo), totalQuantity(cargo), shipmentId(order, cargo), referenceId(order, cargo),
|
||||
measurement(inbound), preload(summary.preload()), loading(summary.loading()),
|
||||
delivery(summary.delivery()), transport(inbound), order == null ? null : order.getCustomerRemark(), latestInternalNote,
|
||||
inbound.createdAt(), inbound.updatedAt(), inbound.requestedPickupAt());
|
||||
}
|
||||
@@ -281,6 +282,21 @@ public class UnifiedOrderQueryService {
|
||||
return cargo == null || cargo.skuNos().isEmpty() ? null : cargo.skuNos();
|
||||
}
|
||||
|
||||
private String shipmentId(OrderEntity order, CargoSummary cargo) {
|
||||
return joinIdentifiers(order == null ? null : order.getShipmentId(), cargo == null ? List.of() : cargo.shipmentIds());
|
||||
}
|
||||
|
||||
private String referenceId(OrderEntity order, CargoSummary cargo) {
|
||||
return joinIdentifiers(order == null ? null : order.getReferenceId(), cargo == null ? List.of() : cargo.referenceIds());
|
||||
}
|
||||
|
||||
private String joinIdentifiers(String orderValue, List<String> cargoValues) {
|
||||
LinkedHashSet<String> values = new LinkedHashSet<>();
|
||||
if (StringUtils.hasText(orderValue)) values.add(orderValue.trim());
|
||||
cargoValues.stream().filter(StringUtils::hasText).map(String::trim).forEach(values::add);
|
||||
return values.isEmpty() ? null : String.join(", ", values);
|
||||
}
|
||||
|
||||
private Integer totalQuantity(CargoSummary cargo) {
|
||||
return cargo == null ? null : cargo.totalQuantity();
|
||||
}
|
||||
@@ -301,11 +317,16 @@ public class UnifiedOrderQueryService {
|
||||
return cargo == null ? null : cargo.volumeCbm();
|
||||
}
|
||||
|
||||
private record CargoSummary(List<String> skuNos, Integer totalQuantity, Integer totalPackageCount,
|
||||
BigDecimal grossWeightKg, BigDecimal netWeightKg, BigDecimal volumeCbm) {
|
||||
private record CargoSummary(List<String> skuNos, List<String> shipmentIds, List<String> referenceIds,
|
||||
Integer totalQuantity, Integer totalPackageCount, BigDecimal grossWeightKg,
|
||||
BigDecimal netWeightKg, BigDecimal volumeCbm) {
|
||||
private static CargoSummary from(List<OrderCargoEntity> cargoes) {
|
||||
List<String> skuNos = cargoes.stream().map(OrderCargoEntity::getSkuNo)
|
||||
.filter(Objects::nonNull).map(String::trim).filter(value -> !value.isEmpty()).distinct().toList();
|
||||
List<String> shipmentIds = cargoes.stream().map(OrderCargoEntity::getShipmentId)
|
||||
.filter(StringUtils::hasText).map(String::trim).distinct().toList();
|
||||
List<String> referenceIds = cargoes.stream().map(OrderCargoEntity::getReferenceId)
|
||||
.filter(StringUtils::hasText).map(String::trim).distinct().toList();
|
||||
int totalQuantity = cargoes.stream().map(OrderCargoEntity::getTotalQuantity)
|
||||
.filter(Objects::nonNull).mapToInt(Integer::intValue).sum();
|
||||
List<Integer> packageCounts = cargoes.stream().map(OrderCargoEntity::getPackageCount)
|
||||
@@ -315,7 +336,8 @@ public class UnifiedOrderQueryService {
|
||||
BigDecimal grossWeightKg = sum(cargoes, OrderCargoEntity::getGrossWeightKg);
|
||||
BigDecimal netWeightKg = sum(cargoes, OrderCargoEntity::getNetWeightKg);
|
||||
BigDecimal volumeCbm = sum(cargoes, OrderCargoEntity::getVolumeCbm);
|
||||
return new CargoSummary(skuNos, totalQuantity, totalPackageCount, grossWeightKg, netWeightKg, volumeCbm);
|
||||
return new CargoSummary(skuNos, shipmentIds, referenceIds, totalQuantity, totalPackageCount,
|
||||
grossWeightKg, netWeightKg, volumeCbm);
|
||||
}
|
||||
|
||||
private static BigDecimal sum(List<OrderCargoEntity> cargoes,
|
||||
|
||||
@@ -101,6 +101,27 @@ class UnifiedOrderQueryServiceTest {
|
||||
verify(orders).findCargoByOrderIds(10001L, List.of(77L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listAggregatesShipmentAndReferenceIdsFromAllCargoLines() {
|
||||
UnifiedOrderQuery query = query(null);
|
||||
OrderEntity order = order(OrderStatus.APPROVED);
|
||||
order.setShipmentId("SHIP-1");
|
||||
order.setReferenceId("REF-1");
|
||||
OrderCargoEntity first = new OrderCargoEntity();
|
||||
first.setOrderId(77L); first.setShipmentId("SHIP-1"); first.setReferenceId("REF-1");
|
||||
OrderCargoEntity second = new OrderCargoEntity();
|
||||
second.setOrderId(77L); second.setShipmentId("SHIP-2"); second.setReferenceId("REF-2");
|
||||
when(orders.unifiedPage(eq(10001L), eq(query), any()))
|
||||
.thenReturn(new PageResult<>(List.of(order), 1, 20, 1, 1));
|
||||
when(firstleg.summaries(eq("internal-token"), any())).thenReturn(ApiResponse.success(List.of()));
|
||||
when(orders.findCargoByOrderIds(10001L, List.of(77L))).thenReturn(List.of(first, second));
|
||||
|
||||
assertThat(service.page(10001L, query).records()).singleElement().satisfies(row -> {
|
||||
assertThat(row.shipmentId()).isEqualTo("SHIP-1, SHIP-2");
|
||||
assertThat(row.referenceId()).isEqualTo("REF-1, REF-2");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void inboundPackageCountRemainsTheFulfillmentFactAfterSplit() {
|
||||
UnifiedOrderQuery query = query(null);
|
||||
|
||||
Reference in New Issue
Block a user