oms/backend/app/schedule/orderDeliveryPush.js
liufumingren 11e7b26ced feat(backend): 发货单模块与 WMS 定时推送队列
- 发货单主表/明细表(order_deliveries / order_delivery_items)控制器与模型
- 表头金额与明细派生字段重算(utils/recalcOrderDelivery.js)
- 状态流转:审核/驳回/取消/恢复/作废、批量审核、批量切换仓库
- 审核入队 + 定时推送:service/orderDeliveryPush.js(乐观锁 CAS 防重、失败重试上限 3 次、业务失败退回待审核)+ schedule/orderDeliveryPush.js
- 收件人 AI 智能识别(service/ai.js,DeepSeek)
- 相关迁移:建表、站内字段、明细表、订单类型默认值、快递字典、菜单种子、历史数据搬迁
2026-09-13 02:23:47 +08:00

35 lines
1.2 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';
/**
* 发货单推送队列:每 30 秒扫描「已审核(2)」的单据并递交 WMS(deliveryorder.create)
*
* 说明:
* - 审核只入队(1→2),由本定时任务异步推送,避免集中审核时把对方服务打满
* - 单条失败处理见 app/service/orderDeliveryPush.js:对方明确失败立即退回「待审核(1)」;
* 无响应/超时最多尝试 3 次(每次间隔 >= 20s),仍未成功同样退回「待审核(1)」
* - 并发安全:服务层用 pushed_at 做乐观锁抢占,多 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.orderDeliveryPush.processPending();
if (stat.scanned > 0) {
ctx.logger.info(
`[delivery-push] 本轮扫描 ${stat.scanned} 条:成功 ${stat.pushed},失败 ${stat.failed},待重试 ${stat.retry},跳过 ${stat.skipped}`
);
}
return stat;
},
};