WMS_MAIN/app/schedule/auto_outbound_order.js
liufumingren 025184904a 1
2026-06-14 19:03:58 +08:00

52 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* 自动化出库定时任务。
* 每分钟在单 worker 中扫描一次:当订单满足仓库配置的自动化出库条件时,
* 自动标记出库并将订单状态更新为已完成。
*
* 出库条件(由仓库 subject_config.auto_outbound_rules 控制):
* 1. 已复核:recheck_status = 'fin'
* 2. 已打包:pack_status = 'fin'
* 3. 已称重:wms_order_express.weighing_weight > 0
* 4. 已同步:sync_status = 'fin'
* 5. 已打印:print_status = 'fin'
* 6. 已拣货:pick_status = 'fin'
*
* 各条件是否必须可由仓库配置独立控制。
*/
module.exports = {
schedule: {
interval: '1m',
type: 'worker',
immediate: false,
disable: false,
},
/**
* 执行自动化出库任务。
*
* @param {Object} ctx Egg 上下文。
* @return {Promise<void>} 无返回值。
*/
async task(ctx) {
if (ctx.app._autoOutboundRunning) {
return;
}
ctx.app._autoOutboundRunning = true;
try {
const result = await ctx.service.systems.orderAutoOutbound.executeAutoOutbound();
ctx.logger.info(
`[auto-outbound-order] 本轮自动化出库完成,共处理 ${result && result.totalProcessed || 0} 条订单`
);
} catch (error) {
ctx.logger.error(`[auto-outbound-order] 自动化出库任务执行失败: ${error.message}`);
} finally {
ctx.app._autoOutboundRunning = false;
}
},
};