oms/backend/app/schedule/orderArchive.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

34 lines
1.1 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';
/**
* 订单自动归档:每日凌晨 3:00 执行,把创建时间超过 3 个月的订单从状态表迁入历史表。
*
* 迁移口径与手工归档一致(app/service/orderStatus.js#archiveExpired):
* - 物理迁移:状态表删除 + 历史表插入,写入 archived_at(归档时间)与 transferred_at(转入时间);
* - 同步更新索引表 order_index 的 current_table/current_status 为 history;
* - 定时任务无主体上下文,按主体分组跨主体处理(每次单表最多 ARCHIVE_BATCH_LIMIT 条)。
*/
const { ORDER_ARCHIVE_MONTHS } = require('../lib/orderStatus');
module.exports = {
schedule: {
// 秒 分 时 日 月 周 —— 每天 03:00:00
cron: '0 0 3 * * *',
type: 'worker',
disable: false,
},
async task(ctx) {
const result = await ctx.service.orderStatus.archiveExpired({ months: ORDER_ARCHIVE_MONTHS });
if (result.count > 0) {
ctx.logger.info(
'[order-archive] 已归档超期订单 %d 条(阈值 %s,明细 %j)',
result.count,
result.threshold,
result.by_status
);
}
return result;
},
};