This commit is contained in:
2026-09-30 17:13:11 +08:00
parent babc7de4b6
commit 32fb9ec7b3
26 changed files with 1484 additions and 70 deletions
@@ -57,6 +57,25 @@ function deliveryNumbers(data) {
return transferDeliveries(data).map((value) => id(value.deliveryNo)).sort()
}
export function dispatchDestinationConservation(detail, fixture, deliveries = null) {
const codes = values => values.map(value => id(value).trim().toUpperCase())
const sameSet = (left,right) => left.length > 0 && right.length > 0 && left.every(nonBlank)
&& right.every(nonBlank) && JSON.stringify([...new Set(left)].sort()) === JSON.stringify([...new Set(right)].sort())
const items = detail?.items
if (!Array.isArray(items) || !items.length || !Array.isArray(fixture?.planPalletIds)
|| !Array.isArray(fixture?.destinationWarehouseCodes) || !nonBlank(detail?.route)) return false
const actualIds = items.map(row => id(row.planPalletId)), expectedIds=fixture.planPalletIds.map(id)
if (!actualIds.every(nonBlank) || actualIds.length !== expectedIds.length
|| new Set(actualIds).size !== actualIds.length || !sameSet(actualIds,expectedIds)) return false
const actual = codes(items.map(row => row.fbaWarehouseCode || row.destinationWarehouseCode))
const frozen = codes(fixture.destinationWarehouseCodes), route = codes(detail.route.split(','))
if (!sameSet(actual,frozen) || !sameSet(route,actual) || route.length !== new Set(route).size) return false
if (deliveries == null) return true
if (!Array.isArray(deliveries) || !deliveries.length) return false
const delivered=codes(deliveries.map(row => row.destinationWarehouseCode))
return delivered.length === new Set(delivered).size && sameSet(delivered,actual)
}
async function poll(action, predicate, attempts = 45, intervalMs = 1_000) {
let result = null
for (let attempt = 1; attempt <= attempts; attempt += 1) {
@@ -873,6 +892,14 @@ export async function run(context) {
const beforeEdit = await platform(context, 'GET', '编辑车辆前读取服务端目的仓线路', `${DISPATCH_BASE}/${encodeURIComponent(dispatchNo)}`)
if (!success(beforeEdit.response) || beforeEdit.data?.dispatchNo !== dispatchNo) return
const routeProof = context.createdResources.phase5OverseasFulfillment.routeProof = {
frozenPlanPalletIds:source.dispatch.planPalletIds,
frozenDestinationWarehouseCodes:source.dispatch.destinationWarehouseCodes,
beforeEdit:beforeEdit.data,
}
context.assert(MODULE,'排车线路目的地集合与实际托盘及本轮冻结候选完全一致',beforeEdit.response,
dispatchDestinationConservation(beforeEdit.data,source.dispatch),trace(beforeEdit.response),OPTIONS)
if (!dispatchDestinationConservation(beforeEdit.data,source.dispatch)) return
const updateBody = {
vehiclePlate: `DEV-${context.marker.slice(-8)}`.slice(0, 64),
driverName: `五期验收司机-${context.marker.slice(-6)}`,
@@ -909,6 +936,10 @@ export async function run(context) {
const deliveries = transferDeliveries(transferred.data)
const deliveryNos = deliveryNumbers(transferred.data)
const destinationKeys = deliveries.map((value) => id(value.destinationWarehouseCode || value.destinationWarehouseId))
routeProof.deliveries = deliveries
context.assert(MODULE,'转派送目的地集合与实际排车线路及本轮冻结候选守恒',transferred.response,
dispatchDestinationConservation(beforeEdit.data,source.dispatch,deliveries),trace(transferred.response),OPTIONS)
if (!dispatchDestinationConservation(beforeEdit.data,source.dispatch,deliveries)) return
const deliveryNo = deliveryNos[0] || ''
context.assert(MODULE, '转派送按目的FBA仓生成WAIT_DELIVERY单据数组', transferred.response,
nonBlank(outboundNo) && deliveries.length > 0 && new Set(deliveryNos).size === deliveries.length