'use strict'; /** * 拣货完成补偿定时任务。 * 每 1 分钟在单 worker 中扫描一次:当 wms_picking 中存在 status='pending' 的遗漏记录, * 且对应订单已迁移到配送 dispatch 表且 pick_status='fin' 时,补扣库存并写入出库流水。 * * 补偿判断条件: * 1. wms_picking.status = 'pending' 且 warehouse_id > 0 * 2. 对应订单在 order_delivery_dispatch 表中 pick_status = 'fin' * 3. 对应订单不在 order_delivery 主表中(已迁移) */ module.exports = { schedule: { interval: '1m', type: 'worker', immediate: true, disable: false, }, /** * 执行拣货完成补偿任务。 * * @param {Object} ctx Egg 上下文。 * @return {Promise} 无返回值。 */ async task(ctx) { if (ctx.app._pickCompensationRunning) { return; } ctx.app._pickCompensationRunning = true; try { const result = await ctx.service.systems.pickCompensation.executeCompensation(); ctx.logger.info( `[pick-compensation] 本轮补偿完成,共处理 ${result && result.totalCompensated || 0} 条拣货记录` ); } catch (error) { ctx.logger.error(`[pick-compensation] 补偿任务执行失败: ${error.message}`); } finally { ctx.app._pickCompensationRunning = false; } }, };