|
|
|
@@ -9,6 +9,7 @@ import com.baiyue.order.dto.OrderDetailResponse;
|
|
|
|
|
import com.baiyue.order.dto.UnifiedOrderQuery;
|
|
|
|
|
import com.baiyue.order.dto.UnifiedOrderResponse;
|
|
|
|
|
import com.baiyue.order.entity.OrderEntity;
|
|
|
|
|
import com.baiyue.order.entity.OrderCargoEntity;
|
|
|
|
|
import com.baiyue.order.entity.OrderInternalNoteEntity;
|
|
|
|
|
import com.baiyue.order.entity.OrderStatus;
|
|
|
|
|
import com.baiyue.order.repository.OrderRepository;
|
|
|
|
@@ -23,6 +24,7 @@ import java.util.Comparator;
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
@@ -56,9 +58,12 @@ public class UnifiedOrderQueryService {
|
|
|
|
|
? Map.of()
|
|
|
|
|
: summaries(tenantId, source.records().stream().map(OrderEntity::getId).toList());
|
|
|
|
|
Map<Long, String> latestNotes = latestNotes(tenantId, source.records().stream().map(OrderEntity::getId).toList());
|
|
|
|
|
Map<Long, CargoSummary> cargoSummaries = cargoSummaries(tenantId,
|
|
|
|
|
source.records().stream().map(OrderEntity::getId).toList());
|
|
|
|
|
Map<Long, Integer> childCounts = childCounts(source.records());
|
|
|
|
|
List<UnifiedOrderResponse.Row> rows = source.records().stream()
|
|
|
|
|
.map(order -> row(order, inboundByOrder.get(order.getId()), latestNotes.get(order.getId()), childCounts)).toList();
|
|
|
|
|
.map(order -> row(order, inboundByOrder.get(order.getId()), latestNotes.get(order.getId()),
|
|
|
|
|
childCounts, cargoSummaries.get(order.getId()))).toList();
|
|
|
|
|
return new PageResult<>(rows, source.page(), source.size(), source.total(), source.pages());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -72,7 +77,7 @@ public class UnifiedOrderQueryService {
|
|
|
|
|
? null : firstlegDetail(tenantId, orderId);
|
|
|
|
|
String latestNote = orderDetail.internalNotes().isEmpty() ? null : orderDetail.internalNotes().get(0).getContent();
|
|
|
|
|
UnifiedOrderResponse.Row summary = row(order, inbound == null ? null : inbound.summary(), latestNote,
|
|
|
|
|
childCounts(List.of(order)));
|
|
|
|
|
childCounts(List.of(order)), CargoSummary.from(orderDetail.cargoes()));
|
|
|
|
|
List<UnifiedOrderResponse.TimelineEvent> timeline = new ArrayList<>();
|
|
|
|
|
orderDetail.statusHistory().forEach(item -> timeline.add(new UnifiedOrderResponse.TimelineEvent(
|
|
|
|
|
"ORDER", "STATUS", orderMainStatus(item.getToStatus()), item.getAction(), item.getReason(),
|
|
|
|
@@ -106,10 +111,12 @@ public class UnifiedOrderQueryService {
|
|
|
|
|
Map<Long, OrderEntity> orderById = orders.findByIds(tenantId, orderIds).stream()
|
|
|
|
|
.collect(Collectors.toMap(OrderEntity::getId, Function.identity(), (left, right) -> left));
|
|
|
|
|
Map<Long, String> latestNotes = latestNotes(tenantId, orderIds);
|
|
|
|
|
Map<Long, CargoSummary> cargoSummaries = cargoSummaries(tenantId, orderIds);
|
|
|
|
|
Map<Long, Integer> childCounts = childCounts(List.copyOf(orderById.values()));
|
|
|
|
|
List<UnifiedOrderResponse.Row> records = source.records().stream()
|
|
|
|
|
.map(summary -> row(summary, orderById.get(summary.inbound().orderId()),
|
|
|
|
|
latestNotes.get(summary.inbound().orderId()), childCounts))
|
|
|
|
|
latestNotes.get(summary.inbound().orderId()), childCounts,
|
|
|
|
|
cargoSummaries.get(summary.inbound().orderId())))
|
|
|
|
|
.toList();
|
|
|
|
|
return new PageResult<>(records, source.page(), source.size(), source.total(), source.pages());
|
|
|
|
|
}
|
|
|
|
@@ -134,6 +141,13 @@ public class UnifiedOrderQueryService {
|
|
|
|
|
OrderInternalNoteEntity::getOrderId, OrderInternalNoteEntity::getContent, (latest, ignored) -> latest));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<Long, CargoSummary> cargoSummaries(Long tenantId, List<Long> orderIds) {
|
|
|
|
|
if (orderIds.isEmpty()) return Map.of();
|
|
|
|
|
return orders.findCargoByOrderIds(tenantId, orderIds).stream()
|
|
|
|
|
.collect(Collectors.groupingBy(OrderCargoEntity::getOrderId,
|
|
|
|
|
Collectors.collectingAndThen(Collectors.toList(), CargoSummary::from)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<Long, Integer> childCounts(List<OrderEntity> pageOrders) {
|
|
|
|
|
if (pageOrders.isEmpty()) return Map.of();
|
|
|
|
|
return orders.findChildrenByParentOrders(pageOrders).stream()
|
|
|
|
@@ -155,7 +169,8 @@ public class UnifiedOrderQueryService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UnifiedOrderResponse.Row row(OrderEntity order, FirstlegUnifiedOrderClient.Summary summary,
|
|
|
|
|
String latestInternalNote, Map<Long, Integer> childCounts) {
|
|
|
|
|
String latestInternalNote, Map<Long, Integer> childCounts,
|
|
|
|
|
CargoSummary cargo) {
|
|
|
|
|
if (summary == null) {
|
|
|
|
|
String mainStatus = orderMainStatus(order.getStatus());
|
|
|
|
|
return new UnifiedOrderResponse.Row(order.getId(), order.getTenantId(), order.getOrderNo(), mainStatus,
|
|
|
|
@@ -165,7 +180,12 @@ public class UnifiedOrderQueryService {
|
|
|
|
|
order.getChannelName(), order.getReceivingWarehouseId(), order.getReceivingWarehouseName(),
|
|
|
|
|
order.getDestinationWarehouseId(), order.getDestinationWarehouseName(), null, null,
|
|
|
|
|
order.getInboundCode(),
|
|
|
|
|
order.getExpectedShipDate(), null, null, null, null, null, null, null, null, null, null,
|
|
|
|
|
order.getExpectedShipDate(), null, null, null, null,
|
|
|
|
|
null, null, null, null, null, order.getPickupMethod(), order.getTaxMode(), order.getContainerMode(),
|
|
|
|
|
order.getCustomsInspection(), order.getDestinationType(), order.getAmazonWarehouseCode(),
|
|
|
|
|
null, null, null, null, null, null, order.getExpressCompany(), order.getExpressTrackingNo(),
|
|
|
|
|
string(order.getCreatedBy()), skuNos(cargo), totalQuantity(cargo), order.getShipmentId(), order.getReferenceId(),
|
|
|
|
|
null, null, null, null, null,
|
|
|
|
|
order.getCustomerRemark(), latestInternalNote,
|
|
|
|
|
order.getCreatedAt(), order.getUpdatedAt());
|
|
|
|
|
}
|
|
|
|
@@ -175,15 +195,21 @@ public class UnifiedOrderQueryService {
|
|
|
|
|
order.getCustomerId(), order.getCustomerName(),
|
|
|
|
|
order.getChannelName(), order.getReceivingWarehouseId(), order.getReceivingWarehouseName(),
|
|
|
|
|
order.getDestinationWarehouseId(), order.getDestinationWarehouseName(), inbound.id(), inbound.version(), inbound.inboundCode(),
|
|
|
|
|
order.getExpectedShipDate(), inbound.totalPackageCount(), "STANDARD", inbound.locationCodes(),
|
|
|
|
|
inbound.actualGrossWeightKg(), inbound.actualVolumeCbm(), measurement(inbound),
|
|
|
|
|
order.getExpectedShipDate(), inbound.totalPackageCount(), null, inbound.locationCodes(),
|
|
|
|
|
inbound.actualGrossWeightKg(), inbound.actualVolumeCbm(), inbound.expectedArrivalAt(), inbound.feeReviewStatus(),
|
|
|
|
|
inbound.companyName(), inbound.businessType(), order.getPickupMethod(), inbound.taxMode(), inbound.containerMode(),
|
|
|
|
|
inbound.customsInspection(), inbound.destinationType(), inbound.destinationCode(), inbound.palletCount(),
|
|
|
|
|
inbound.chargeableVolumeCbm(), inbound.volumeWeightKg(), inbound.actualNetWeightKg(),
|
|
|
|
|
inbound.measureCompletedAt(), inbound.inboundedAt(), inbound.expressCompanyName(), inbound.expressTrackingNo(),
|
|
|
|
|
inbound.createdByName(), skuNos(cargo), totalQuantity(cargo), order.getShipmentId(), order.getReferenceId(), measurement(inbound),
|
|
|
|
|
preload(summary.preload()), loading(summary.loading()),
|
|
|
|
|
delivery(summary.delivery()), transport(inbound), order.getCustomerRemark(), latestInternalNote,
|
|
|
|
|
order.getCreatedAt(), order.getUpdatedAt());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UnifiedOrderResponse.Row row(FirstlegUnifiedOrderClient.Summary summary, OrderEntity order,
|
|
|
|
|
String latestInternalNote, Map<Long, Integer> childCounts) {
|
|
|
|
|
String latestInternalNote, Map<Long, Integer> childCounts,
|
|
|
|
|
CargoSummary cargo) {
|
|
|
|
|
var inbound = summary.inbound();
|
|
|
|
|
return new UnifiedOrderResponse.Row(inbound.orderId(), inbound.tenantId(), inbound.orderNo(),
|
|
|
|
|
summary.mainStatus(), summary.nextAction(), relation(order, childCounts),
|
|
|
|
@@ -191,8 +217,14 @@ public class UnifiedOrderQueryService {
|
|
|
|
|
inbound.customerId(), inbound.customerName(), inbound.channelName(), inbound.warehouseId(),
|
|
|
|
|
inbound.warehouseName(), inbound.deliveryWarehouseId(), inbound.deliveryWarehouseName(),
|
|
|
|
|
inbound.id(), inbound.version(), inbound.inboundCode(), null, inbound.totalPackageCount(),
|
|
|
|
|
"STANDARD", inbound.locationCodes(), inbound.actualGrossWeightKg(),
|
|
|
|
|
inbound.actualVolumeCbm(), measurement(inbound), preload(summary.preload()), loading(summary.loading()),
|
|
|
|
|
null, inbound.locationCodes(), inbound.actualGrossWeightKg(),
|
|
|
|
|
inbound.actualVolumeCbm(), inbound.expectedArrivalAt(), inbound.feeReviewStatus(), inbound.companyName(),
|
|
|
|
|
inbound.businessType(), order == null ? null : order.getPickupMethod(), inbound.taxMode(), inbound.containerMode(),
|
|
|
|
|
inbound.customsInspection(), inbound.destinationType(), inbound.destinationCode(), inbound.palletCount(),
|
|
|
|
|
inbound.chargeableVolumeCbm(), inbound.volumeWeightKg(), inbound.actualNetWeightKg(),
|
|
|
|
|
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()),
|
|
|
|
|
delivery(summary.delivery()), transport(inbound), order == null ? null : order.getCustomerRemark(), latestInternalNote,
|
|
|
|
|
inbound.createdAt(), inbound.updatedAt());
|
|
|
|
|
}
|
|
|
|
@@ -225,6 +257,28 @@ public class UnifiedOrderQueryService {
|
|
|
|
|
return status == OrderStatus.SUBMITTED ? "PENDING_REVIEW"
|
|
|
|
|
: ACTIVE_ORDER_STATUSES.contains(status) ? "WAIT_MEASURE" : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String string(Long value) {
|
|
|
|
|
return value == null ? null : value.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<String> skuNos(CargoSummary cargo) {
|
|
|
|
|
return cargo == null || cargo.skuNos().isEmpty() ? null : cargo.skuNos();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Integer totalQuantity(CargoSummary cargo) {
|
|
|
|
|
return cargo == null ? null : cargo.totalQuantity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private record CargoSummary(List<String> skuNos, Integer totalQuantity) {
|
|
|
|
|
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();
|
|
|
|
|
int totalQuantity = cargoes.stream().map(OrderCargoEntity::getTotalQuantity)
|
|
|
|
|
.filter(Objects::nonNull).mapToInt(Integer::intValue).sum();
|
|
|
|
|
return new CargoSummary(skuNos, totalQuantity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private String inboundMainStatus(String status) {
|
|
|
|
|
if (status == null) return null;
|
|
|
|
|
return switch (status) {
|
|
|
|
|