优化
This commit is contained in:
@@ -30,9 +30,25 @@ function validPdf(response) {
|
||||
|
||||
async function reusablePallets(context, warehouseId) {
|
||||
const cacheKey = asId(warehouseId)
|
||||
if (reusablePalletsByWarehouse.has(cacheKey)) return reusablePalletsByWarehouse.get(cacheKey)
|
||||
const allowAnyExistingPallet = context.context?.allowAnyExistingPallet === true
|
||||
const scopedCacheKey = `${cacheKey}:${allowAnyExistingPallet ? 'any' : 'fixed'}`
|
||||
if (reusablePalletsByWarehouse.has(scopedCacheKey)) return reusablePalletsByWarehouse.get(scopedCacheKey)
|
||||
|
||||
const pallets = []
|
||||
if (allowAnyExistingPallet) {
|
||||
const response = await context.request('GET',
|
||||
`/api/platform/v1/pallets?page=1&size=100&tenantId=0&warehouseId=${encodeURIComponent(warehouseId)}`)
|
||||
const page = context.apiSuccess(MODULE, '查询当前仓库已有可复用托盘', response,
|
||||
`warehouseId=${warehouseId}`, OPTIONS)
|
||||
const candidates = (page?.records || []).filter((item) => asId(item?.warehouseId) === cacheKey
|
||||
&& asId(item?.id) && String(item?.palletCode || '').trim())
|
||||
context.assert(MODULE, '当前仓库至少存在一个可复用托盘', response, candidates.length > 0,
|
||||
`warehouseId=${warehouseId}, matched=${candidates.map((item) => item.palletCode).join('|') || 'missing'}`, OPTIONS)
|
||||
if (candidates.length === 0) return null
|
||||
const selected = candidates.slice(0, 2).map((item) => ({ id: asId(item.id), code: String(item.palletCode) }))
|
||||
reusablePalletsByWarehouse.set(scopedCacheKey, selected)
|
||||
return selected
|
||||
}
|
||||
for (const palletCode of REUSABLE_PALLET_CODES) {
|
||||
const response = await context.request('GET',
|
||||
`/api/platform/v1/pallets?page=1&size=20&tenantId=0&warehouseId=${encodeURIComponent(warehouseId)}&palletCode=${encodeURIComponent(palletCode)}`)
|
||||
@@ -45,7 +61,7 @@ async function reusablePallets(context, warehouseId) {
|
||||
if (!exact) return null
|
||||
pallets.push({ id: asId(exact.id), code: palletCode })
|
||||
}
|
||||
reusablePalletsByWarehouse.set(cacheKey, pallets)
|
||||
reusablePalletsByWarehouse.set(scopedCacheKey, pallets)
|
||||
return pallets
|
||||
}
|
||||
|
||||
@@ -79,7 +95,7 @@ async function provisionWarehouseResources(context, { inboundId, warehouseId, pa
|
||||
for (let index = 1; index <= palletCount; index += 1) {
|
||||
const palletId = palletIds[index - 1]
|
||||
context.assert(MODULE, `随机复用原有称重托盘 ${index}/${palletCount}`, null,
|
||||
REUSABLE_PALLET_CODES.includes(candidates.find((item) => item.id === palletId)?.code),
|
||||
Boolean(candidates.find((item) => item.id === palletId)?.code),
|
||||
`warehouseId=${warehouseId}, palletId=${palletId}`, OPTIONS)
|
||||
// 库位由 Warehouse 在测量审核时按正式规则分配;普通位不足会复用唯一的 A0 共享溢出位。
|
||||
// 验收脚本不得为了制造容量而新增普通库位。
|
||||
|
||||
Reference in New Issue
Block a user