perf(delivery): 配送表补回传相关索引,导出补回传状态与失败原因列
明确口径:发货回传失败**不转表**——进了配送说明仓库已打包发货,是既成事实, 必须在配送表可见/可导出,只在表内标记 external_send_status,由「配送异常」视图处理。 - 迁移 20261107060000:加 `idx_delivery_send_scan (external_send_status, external_send_at)`, 覆盖定时任务 `status IN (0,2) AND times < 3 ORDER BY external_send_at`; 列表筛选沿用已有的 `(principal_id, external_send_status)`,EXPLAIN 确认两条都命中索引 - 订单导出补三列:回传平台状态(中文)、回传重试次数、回传失败原因 - 文档记录「不转表 + 索引 + 归档」的口径 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
91e90cc7e2
commit
bc2aa988ae
@ -276,8 +276,15 @@ function buildResult({ from, wh, columns, orderBy = 'id DESC', leadRepl = [] })
|
||||
/* ==================== 各导出类型的列定义 ==================== */
|
||||
|
||||
/** 订单状态表列(8 张状态表列名一致,多状态导出时 UNION ALL 后再筛选) */
|
||||
const ORDER_COLUMNS = [
|
||||
{ key: 'id', header: 'ID' },
|
||||
/** 回传外部打单平台状态文案(与 service/externalSendSync.js 的 SEND_STATUS 对齐) */
|
||||
const EXTERNAL_SEND_STATUS_LABELS = {
|
||||
0: '待同步外部',
|
||||
1: '已同步外部',
|
||||
2: '同步失败待重试',
|
||||
3: '同步异常',
|
||||
};
|
||||
|
||||
const ORDER_COLUMNS = [{ key: 'id', header: 'ID' },
|
||||
{ key: 'order_no', header: '订单号' },
|
||||
{ key: 'parent_order_no', header: '来源订单号' },
|
||||
{ key: 'oaid_order_source_code', header: '平台订单号' },
|
||||
@ -305,6 +312,10 @@ const ORDER_COLUMNS = [
|
||||
{ key: 'express_codes', header: '运单号集合', format: jsonText },
|
||||
{ key: 'wms_status', header: 'WMS状态' },
|
||||
{ key: 'wms_order_no', header: 'WMS单号' },
|
||||
// 回传外部打单平台(配送视图/配送异常视图关注;其它状态表同名字段恒为默认值)
|
||||
{ key: 'external_send_status', header: '回传平台状态', format: labels(EXTERNAL_SEND_STATUS_LABELS) },
|
||||
{ key: 'external_send_times', header: '回传重试次数' },
|
||||
{ key: 'external_send_error', header: '回传失败原因' },
|
||||
{ key: 'operator_name', header: '操作人' },
|
||||
{ key: 'audit_time', header: '审核时间' },
|
||||
{ key: 'pushed_at', header: '推送时间' },
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 配送表补「回传平台」相关索引。
|
||||
*
|
||||
* 背景:发货回传失败的单**不转表**(进了配送说明仓库已打包发货,必须在配送视图可见/可导出),
|
||||
* 只在配送表里标记 `external_send_status`(0待同步 1已同步 2待重试 3异常)。
|
||||
* 配送表会持续变大,因此把「扫描待重试」和「配送异常视图」两条查询的索引补齐:
|
||||
*
|
||||
* 1) 定时任务(每 2 分钟):
|
||||
* WHERE external_send_status IN (0,2) AND external_send_times < 3
|
||||
* ORDER BY external_send_at ASC LIMIT 50
|
||||
* → 需要 `(external_send_status, external_send_at)` 才能既不回表排序又只扫待办行
|
||||
* 2) 配送异常视图:principal_id + external_send_status IN (2,3)
|
||||
* → 已有 `idx_delivery_external_send_status (principal_id, external_send_status)` 覆盖
|
||||
*/
|
||||
module.exports = {
|
||||
async up(queryInterface) {
|
||||
await queryInterface.addIndex('order_status_delivery', [ 'external_send_status', 'external_send_at' ], {
|
||||
name: 'idx_delivery_send_scan',
|
||||
});
|
||||
},
|
||||
|
||||
async down(queryInterface) {
|
||||
await queryInterface.removeIndex('order_status_delivery', 'idx_delivery_send_scan');
|
||||
},
|
||||
};
|
||||
@ -94,6 +94,15 @@ OMS 实现:
|
||||
| traceId 缓存 | `getUserInfo` 按账号缓存(批量内只调 1 次),不再逐单取 |
|
||||
| 取号侧同理 | `dgj.resolveTraceId()` 实例级缓存 5 分钟,批量取号不再每单一次 `getUserInfo` |
|
||||
|
||||
**失败单不转表**:进了配送说明仓库已打包发货,是既成事实,必须留在配送表可见/可导出;
|
||||
只在配送表标记 `external_send_status`(2 待重试 / 3 同步异常),由「配送异常」视图筛出来处理。
|
||||
表变大靠索引和归档兜底:
|
||||
|
||||
| 措施 | 说明 |
|
||||
|---|---|
|
||||
| 索引 | `idx_delivery_external_send_status (principal_id, external_send_status)` 覆盖列表筛选;`idx_delivery_send_scan (external_send_status, external_send_at)` 覆盖定时任务扫描 |
|
||||
| 归档 | 超期(默认 3 个月,`ORDER_ARCHIVE_MONTHS`)自动转「历史」表,仍可查可导 |
|
||||
|
||||
状态字段(配送表 `order_status_delivery`,所有状态表 + 历史表同构):
|
||||
|
||||
| 字段 | 说明 |
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user