oms/backend/app/schedule/orderWmsPush.js
liufumingren 6c03a20364 feat(backend): 订单状态分表、WMS 推送与归档
- 新增 order_index 索引表 + 6 张同构状态表(待审核/异常/委外中/配送/已作废/已取消)与历史表,
  订单 ID 全局唯一,状态由业务事务推动:审核、驳回、取消、作废、恢复、归档
- 明细表 order_status_items、收件人文本智能解析、批量切换仓库/店铺并刷新快照
- WMS deliveryorder.create 推送(单条/批量)、推送失败定时重试、订单归档定时任务
- 迁移:建表、旧发货单数据迁入新表、菜单合并与迁移记录清理
- routes / swagger contract 补充订单状态接口

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-30 23:06:18 +08:00

36 lines
1.6 KiB
JavaScript
Raw Permalink 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';
/**
* 订单推送队列:每 30 秒扫描「待推送」的订单并递交 WMS(deliveryorder.create,ORDER 组)
*
* 说明(与老发货单推送口径一致,数据落在新表 order_status_queued → order_status_outsourcing):
* - 审核只入队(待审核 → 待推送),由本定时任务异步推送,避免集中审核时把对方服务打满
* - 推送成功:流转「委外中」(写 wms_status/wms_order_no/pushed_at 与推送结果),等仓库回传确认才转「配送」
* - 失败处理见 app/service/orderWms.js:对方明确失败或连续 3 次无响应/超时 → 转「异常」并释放锁定库存
* - **前置缺失也转「异常」**(无仓库 / 无店铺 / 仓库无启用接口 / 无明细):否则这类单据会永远卡在待推送队列里
* - 并发安全:服务层用 pushed_at 做乐观锁抢占(CAS),多 worker 下同一单只会被推送一次
*/
module.exports = {
schedule: {
interval: '30s',
type: 'worker',
immediate: false,
disable: false,
},
/**
* 扫描并推送待推送订单
* @param {Egg.Context} ctx egg context(定时任务上下文)
* @return {Promise<Object>} 本轮统计
*/
async task(ctx) {
const stat = await ctx.service.orderWms.processPending();
if (stat.scanned > 0) {
ctx.logger.info(
`[order-wms] 本轮扫描 ${stat.scanned} 条:成功 ${stat.pushed},失败 ${stat.failed},转异常(前置缺失) ${stat.aborted},待重试 ${stat.retry},跳过 ${stat.skipped}`
);
}
return stat;
},
};