This commit is contained in:
2026-09-14 18:34:37 +08:00
parent d9a4384585
commit d53de922db
8 changed files with 525 additions and 11 deletions
@@ -88,7 +88,8 @@ async function waitForCompletedMeasurement(context, measurementPath, expectedSta
return { response, measurement, attempts }
}
export async function completeDropshipPalletization(context, { inboundId, inboundCode, warehouseId, measurement }) {
export async function completeDropshipPalletization(context, { inboundId, inboundCode, warehouseId, measurement,
targetPalletNo = null, deferSeal = false, mergeToFirstPallet = false }) {
const pendingResponse = await context.request('GET',
`/api/platform/v1/first-leg/pda-dropship/tasks/pending?warehouseId=${warehouseId}&keyword=${encodeURIComponent(inboundCode)}`)
const pending = context.apiSuccess(MODULE, '查询一件代发待合托任务', pendingResponse,
@@ -154,7 +155,7 @@ export async function completeDropshipPalletization(context, { inboundId, inboun
discrepancyAction: 'MATCH',
discrepancyRemark: null,
})),
palletNo: index === 0 ? null : generatedPallets[Math.min(index, generatedPallets.length - 1)].palletNo,
palletNo: index === 0 ? null : (targetPalletNo || generatedPallets[Math.min(index, generatedPallets.length - 1)].palletNo),
operationId: `${context.marker}-dropship-count-${index + 1}`.slice(0, 128),
}
const countResponse = await context.request('POST',
@@ -186,16 +187,19 @@ export async function completeDropshipPalletization(context, { inboundId, inboun
&& Number(replayed?.unboundCartons) === Number(counted?.unboundCartons),
`counted=${replayed?.countedCartons ?? 'missing'}, unbound=${replayed?.unboundCartons ?? 'missing'}`, OPTIONS)
const firstPallet = generatedPallets[0]
const firstPallet = targetPalletNo ? { palletNo: targetPalletNo } : generatedPallets[0]
const bindPayload = { warehouseId, palletNo: firstPallet.palletNo,
operationId: `${context.marker}-dropship-bind-first`.slice(0, 128) }
const bindResponse = await context.request('POST',
`/api/platform/v1/first-leg/pda-dropship/tasks/${taskId}/pallets/bind-pending`, bindPayload)
const bound = context.apiSuccess(MODULE, '后扫预生成托盘码并绑定全部待组托箱', bindResponse,
`taskId=${taskId}`, OPTIONS)
const pallet = bound?.pallets?.find((item) => asId(item.palletId) === asId(firstPallet.palletId)) || null
const pallet = bound?.pallets?.find((item) => item.palletNo === firstPallet.palletNo) || null
context.assert(MODULE, '待组托箱绑定到OPEN托盘且不再游离', bindResponse,
Number(bound?.unboundCartons) === 0 && Number(pallet?.cartonCount) === 1
Number(bound?.unboundCartons) === 0
&& (targetPalletNo
? pallet?.cartons?.filter((item) => asId(item.inboundId) === inboundId).length === 1
: Number(pallet?.cartonCount) === 1)
&& pallet?.status === 'OPEN' && pallet?.palletNo === firstPallet.palletNo
&& bound?.pallets?.length === 1,
`unbound=${bound?.unboundCartons ?? 'missing'}, palletStatus=${pallet?.status ?? 'missing'}`, OPTIONS)
@@ -207,7 +211,8 @@ export async function completeDropshipPalletization(context, { inboundId, inboun
&& Number(replayBind?.boundCartons) === Number(bound?.boundCartons)
&& Number(replayBind?.unboundCartons) === 0, '', OPTIONS)
} else {
const expectedPallet = generatedPallets[Math.min(index, generatedPallets.length - 1)]
const expectedPallet = targetPalletNo ? { palletNo: targetPalletNo }
: generatedPallets[Math.min(index, generatedPallets.length - 1)]
context.assert(MODULE, `第${index + 1}箱直接进入当前OPEN托盘`, countResponse,
counted?.pallet?.palletNo === expectedPallet.palletNo && counted?.pallet?.status === 'OPEN',
`palletNo=${counted?.pallet?.palletNo ?? 'missing'}, status=${counted?.pallet?.status ?? 'missing'}`, OPTIONS)
@@ -218,10 +223,40 @@ export async function completeDropshipPalletization(context, { inboundId, inboun
context.assert(MODULE, '预生成托盘覆盖测量冻结的全部箱数', countedTaskResponse,
totalCartons > 0 && countedCartons === totalCartons
&& Number(sealed?.boundCartons) === totalCartons
&& sealed?.pallets?.length === expectedPalletCount
&& sealed?.pallets?.length === (targetPalletNo ? 1 : expectedPalletCount)
&& sealed?.pallets?.every((item) => Number(item?.cartonCount) > 0),
`counted=${countedCartons}, bound=${sealed?.boundCartons ?? 'missing'}, expected=${totalCartons || 'missing'}`, OPTIONS)
if (mergeToFirstPallet) {
const target = sealed?.pallets?.[0]
const sources = (sealed?.pallets || []).slice(1)
context.assert(MODULE, '单票合托前确有多个实物托盘', countedTaskResponse,
Boolean(target) && sources.length > 0, '', OPTIONS)
if (!target || sources.length === 0) return null
for (const source of sources) {
for (const carton of source.cartons || []) {
const payload = { warehouseId, targetPalletNo: target.palletNo,
operationId: `${context.marker}-merge-${carton.cartonId}`.slice(0, 128) }
const path = `/api/platform/v1/first-leg/pda-dropship/tasks/${taskId}/cartons/${carton.cartonId}/move`
const movedResponse = await context.request('POST', path, payload)
sealed = context.apiSuccess(MODULE, '通过正式移箱接口合并单票托盘', movedResponse, '', OPTIONS)
const replayResponse = await context.request('POST', path, payload)
const replay = context.apiSuccess(MODULE, '单票合托移箱同键重放', replayResponse, '', OPTIONS)
context.assert(MODULE, '移箱重放保持总箱数守恒', replayResponse,
Number(replay?.boundCartons) === totalCartons && Number(replay?.unboundCartons) === 0, '', OPTIONS)
}
}
context.assert(MODULE, '单票合托后仅一个实物托盘且箱唛不丢失', null,
sealed?.pallets?.length === 1 && sealed.pallets[0].palletNo === target.palletNo
&& sealed.pallets[0].cartons?.length === totalCartons
&& new Set(sealed.pallets[0].cartons.map((item) => item.boxCode)).size === totalCartons,
'', OPTIONS)
}
if (deferSeal) {
context.assert(MODULE, '多票合托首票归托后保持开放等待下一票', null,
sealed?.taskStatus !== 'COMPLETED' && sealed?.pallets?.every((item) => item.status === 'OPEN'), '', OPTIONS)
return { ...sealed, sealedCartonMarks, sealedSourcePalletNos: [] }
}
let lastSealResponse = countedTaskResponse
for (let index = 0; index < (sealed?.pallets || []).length; index += 1) {
const pallet = sealed.pallets.find((item) => item.status === 'OPEN')