2026-08-27 17:16:33 +08:00
|
|
|
export const CONTAINER_SUMMARY_ENDPOINT = '/api/platform/v1/last-leg/orders/container-summaries'
|
|
|
|
|
export const CONTAINER_CONVERT_ENDPOINT = '/api/platform/v1/last-leg/inbound-plans/convert-container'
|
2026-08-27 16:34:30 +08:00
|
|
|
export const CONTAINER_CONVERT_EXPECTED_ORDERS = 15
|
|
|
|
|
|
|
|
|
|
export function groupOrdersByCustomer(orders) {
|
|
|
|
|
if (!Array.isArray(orders)) return new Map()
|
|
|
|
|
const result = new Map()
|
|
|
|
|
for (const order of orders) {
|
|
|
|
|
const customerId = String(order?.customerId ?? '').trim()
|
|
|
|
|
if (!customerId) return new Map()
|
|
|
|
|
result.set(customerId, [...(result.get(customerId) || []), order])
|
|
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function validContainerBatchResult(result, sourceOrders) {
|
2026-08-27 17:16:33 +08:00
|
|
|
const plans = Array.isArray(result) ? result : []
|
2026-08-27 16:34:30 +08:00
|
|
|
if (!Array.isArray(sourceOrders) || !sourceOrders.length || plans.length !== sourceOrders.length) return false
|
|
|
|
|
const sourceIds = new Set(sourceOrders.map((order) => String(order.orderId)))
|
|
|
|
|
const resultIds = plans.flatMap((plan) => Array.isArray(plan?.lines) ? plan.lines : [])
|
|
|
|
|
.map((line) => String(line?.orderId))
|
|
|
|
|
return resultIds.length === sourceIds.size
|
|
|
|
|
&& new Set(resultIds).size === sourceIds.size
|
|
|
|
|
&& resultIds.every((orderId) => sourceIds.has(orderId))
|
|
|
|
|
&& plans.every((plan) => {
|
|
|
|
|
const lines = Array.isArray(plan?.lines) ? plan.lines : []
|
|
|
|
|
const expected = sourceOrders.find((order) => String(order.orderId) === String(lines[0]?.orderId))
|
|
|
|
|
return plan?.status === 'PENDING_ASSIGNMENT'
|
|
|
|
|
&& lines.length === 1 && expected != null
|
|
|
|
|
&& String(plan?.customerId ?? '') === String(expected.customerId)
|
|
|
|
|
&& String(plan?.planNo ?? '').length > 0
|
|
|
|
|
&& Array.isArray(plan?.pallets) && Array.isArray(plan?.allocations)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-27 17:16:33 +08:00
|
|
|
export function validContainerSummaryPage(data, expected) {
|
|
|
|
|
if (!Array.isArray(data?.records)) return false
|
|
|
|
|
const row = data.records.find((item) => String(item?.sourceContainerBookingId ?? '')
|
|
|
|
|
=== String(expected?.sourceContainerBookingId ?? ''))
|
|
|
|
|
return Number(data.page) >= 1 && Number(data.size) >= 1 && Number(data.total) >= 1
|
|
|
|
|
&& Number(data.pages) >= 1 && String(row?.containerNo ?? '') === String(expected?.containerNo ?? '')
|
2026-08-28 13:58:49 +08:00
|
|
|
&& Number(row?.totalOrderCount) === Number(expected?.totalOrderCount)
|
2026-08-27 17:16:33 +08:00
|
|
|
&& Number(row?.inboundCodeCount) === Number(expected?.inboundCodeCount)
|
2026-08-28 13:58:49 +08:00
|
|
|
&& Number(row?.missingInboundCodeCount) === Number(expected?.missingInboundCodeCount)
|
|
|
|
|
&& Number(row?.planCount) === Number(expected?.planCount)
|
|
|
|
|
&& Number(row?.plannedInboundCodeCount) === Number(expected?.plannedInboundCodeCount)
|
|
|
|
|
&& Number(row?.pendingPlanCount) === Number(expected?.pendingPlanCount)
|
|
|
|
|
&& Boolean(row?.allPlansReady) === Boolean(expected?.allPlansReady)
|
2026-08-27 16:34:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function zeroDrift(before, after) {
|
|
|
|
|
return JSON.stringify(before) === JSON.stringify(after)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function stableReplay(first, replay) {
|
|
|
|
|
return zeroDrift(first, replay)
|
|
|
|
|
}
|