|
|
|
@@ -57,8 +57,9 @@ 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, Integer> childCounts = childCounts(source.records());
|
|
|
|
|
List<UnifiedOrderResponse.Row> rows = source.records().stream()
|
|
|
|
|
.map(order -> row(order, inboundByOrder.get(order.getId()), latestNotes.get(order.getId()))).toList();
|
|
|
|
|
.map(order -> row(order, inboundByOrder.get(order.getId()), latestNotes.get(order.getId()), childCounts)).toList();
|
|
|
|
|
return new PageResult<>(rows, source.page(), source.size(), source.total(), source.pages());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -71,7 +72,8 @@ public class UnifiedOrderQueryService {
|
|
|
|
|
FirstlegUnifiedOrderClient.Detail inbound = order.getStatus() == OrderStatus.SUBMITTED
|
|
|
|
|
? 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);
|
|
|
|
|
UnifiedOrderResponse.Row summary = row(order, inbound == null ? null : inbound.summary(), latestNote,
|
|
|
|
|
childCounts(List.of(order)));
|
|
|
|
|
List<UnifiedOrderResponse.TimelineEvent> timeline = new ArrayList<>();
|
|
|
|
|
orderDetail.statusHistory().forEach(item -> timeline.add(new UnifiedOrderResponse.TimelineEvent(
|
|
|
|
|
"ORDER", "STATUS", orderMainStatus(item.getToStatus()), item.getAction(), item.getReason(),
|
|
|
|
@@ -105,8 +107,10 @@ 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, 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())))
|
|
|
|
|
.map(summary -> row(summary, orderById.get(summary.inbound().orderId()),
|
|
|
|
|
latestNotes.get(summary.inbound().orderId()), childCounts))
|
|
|
|
|
.toList();
|
|
|
|
|
return new PageResult<>(records, source.page(), source.size(), source.total(), source.pages());
|
|
|
|
|
}
|
|
|
|
@@ -131,11 +135,33 @@ public class UnifiedOrderQueryService {
|
|
|
|
|
OrderInternalNoteEntity::getOrderId, OrderInternalNoteEntity::getContent, (latest, ignored) -> latest));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UnifiedOrderResponse.Row row(OrderEntity order, FirstlegUnifiedOrderClient.Summary summary, String latestInternalNote) {
|
|
|
|
|
private Map<Long, Integer> childCounts(List<OrderEntity> pageOrders) {
|
|
|
|
|
if (pageOrders.isEmpty()) return Map.of();
|
|
|
|
|
return orders.findChildrenByParentOrders(pageOrders).stream()
|
|
|
|
|
.filter(child -> child.getParentOrderId() != null)
|
|
|
|
|
.collect(Collectors.toMap(OrderEntity::getParentOrderId, ignored -> 1, Integer::sum));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UnifiedOrderResponse.OrderRelationSummary relation(OrderEntity order,
|
|
|
|
|
Map<Long, Integer> childCounts) {
|
|
|
|
|
if (order == null) return null;
|
|
|
|
|
if (order.getParentOrderId() != null) {
|
|
|
|
|
Long rootOrderId = order.getRootOrderId() == null ? order.getParentOrderId() : order.getRootOrderId();
|
|
|
|
|
return new UnifiedOrderResponse.OrderRelationSummary(
|
|
|
|
|
"CHILD", rootOrderId, order.getParentOrderId(), order.getSplitSequence(), 0);
|
|
|
|
|
}
|
|
|
|
|
int childCount = childCounts.getOrDefault(order.getId(), 0);
|
|
|
|
|
return childCount == 0 ? null : new UnifiedOrderResponse.OrderRelationSummary(
|
|
|
|
|
"PARENT", order.getId(), null, null, childCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UnifiedOrderResponse.Row row(OrderEntity order, FirstlegUnifiedOrderClient.Summary summary,
|
|
|
|
|
String latestInternalNote, Map<Long, Integer> childCounts) {
|
|
|
|
|
if (summary == null) {
|
|
|
|
|
String mainStatus = orderMainStatus(order.getStatus());
|
|
|
|
|
return new UnifiedOrderResponse.Row(order.getId(), order.getTenantId(), order.getOrderNo(), mainStatus,
|
|
|
|
|
order.getStatus() == OrderStatus.SUBMITTED ? "APPROVE_ORDER" : null,
|
|
|
|
|
relation(order, childCounts),
|
|
|
|
|
order.getStatus(), order.getCustomerId(), order.getCustomerName(),
|
|
|
|
|
order.getChannelName(), order.getReceivingWarehouseId(), order.getReceivingWarehouseName(),
|
|
|
|
|
order.getDestinationWarehouseId(), order.getDestinationWarehouseName(), null, null,
|
|
|
|
@@ -146,7 +172,8 @@ public class UnifiedOrderQueryService {
|
|
|
|
|
}
|
|
|
|
|
FirstlegUnifiedOrderClient.Inbound inbound = summary.inbound();
|
|
|
|
|
return new UnifiedOrderResponse.Row(order.getId(), order.getTenantId(), order.getOrderNo(),
|
|
|
|
|
summary.mainStatus(), summary.nextAction(), order.getStatus(), order.getCustomerId(), order.getCustomerName(),
|
|
|
|
|
summary.mainStatus(), summary.nextAction(), relation(order, childCounts), order.getStatus(),
|
|
|
|
|
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(),
|
|
|
|
@@ -157,10 +184,11 @@ public class UnifiedOrderQueryService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UnifiedOrderResponse.Row row(FirstlegUnifiedOrderClient.Summary summary, OrderEntity order,
|
|
|
|
|
String latestInternalNote) {
|
|
|
|
|
String latestInternalNote, Map<Long, Integer> childCounts) {
|
|
|
|
|
var inbound = summary.inbound();
|
|
|
|
|
return new UnifiedOrderResponse.Row(inbound.orderId(), inbound.tenantId(), inbound.orderNo(),
|
|
|
|
|
summary.mainStatus(), summary.nextAction(), parseOrderStatus(inbound.orderStatusSnapshot()),
|
|
|
|
|
summary.mainStatus(), summary.nextAction(), relation(order, childCounts),
|
|
|
|
|
parseOrderStatus(inbound.orderStatusSnapshot()),
|
|
|
|
|
inbound.customerId(), inbound.customerName(), inbound.channelName(), inbound.warehouseId(),
|
|
|
|
|
inbound.warehouseName(), inbound.deliveryWarehouseId(), inbound.deliveryWarehouseName(),
|
|
|
|
|
inbound.id(), inbound.version(), inbound.inboundCode(), null, inbound.totalPackageCount(),
|
|
|
|
|