fix(wave): 波次快递号分配后台任务等待分配真正完成并显式传仓库ID

This commit is contained in:
liufumingren 2026-10-07 23:26:02 +08:00
parent 7ba10a1e4a
commit 49fb70fcbf

View File

@ -10259,7 +10259,8 @@ class WaveService extends OrderBaseService {
/**
* 执行批次分配快递号后台任务。
*
* 任务仅负责提交分配请求到快递分配流水线,实际分配过程由快递服务异步处理。
* 任务会等待快递分配流水线中所有批次真正完成分配(awaitTasks=true)后
* 才写入 success 状态,避免进度接口在分配尚未完成时提前返回完成。
*
* @param {Object} params 任务参数。
* @param {string} params.taskId 任务ID。
@ -10494,7 +10495,13 @@ class WaveService extends OrderBaseService {
totalOrderCount: normalizedOrders.length,
sampleOrderIds: normalizedOrders.slice(0, 20).map(item => Number(item && item.order_id || 0)).filter(Boolean),
});
const pipelineResult = await this.service.systems.express.createWaybillCodePipeline(normalizedOrders);
// awaitTasks=true:等待所有批次真正分配完成后再返回,避免任务被提前标记 success。
// warehouseId 显式传入:后台任务运行在 setImmediate 异步上下文中,ctx.user 可能已失效,
// 防止 getCurrentWarehouseId() 返回 0 导致跨仓/无效仓查询。
const pipelineResult = await this.service.systems.express.createWaybillCodePipeline(normalizedOrders, {
awaitTasks: true,
warehouseId,
});
const durationMs = Date.now() - startTime;
this.ctx.logger.info('[wave.batchAllocateExpress] 快递号分配流水线执行完成', {