fix(pdd): 匹配诊断对齐 out_sku_sn,并加速拼多多订单号搜索
匹配测试/结构化规则补读商家编码,诊断日志标出缺失字段;订单/任务/工单关键词支持带连字符的 PDD order_sn 走索引快路径。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -56,6 +56,38 @@ test('订单列表保留订单号和精确 SKU 旧筛选参数兼容', async ()
|
||||
assert.deepEqual(calls[0]?.params, ['%26245%', 'SKU-1'])
|
||||
})
|
||||
|
||||
test('订单列表关键词为拼多多 order_sn 时走平台订单号索引快路径', async () => {
|
||||
const calls: Array<{ sql: string; params: unknown[] }> = []
|
||||
const orderSn = '260915-091435834962130'
|
||||
|
||||
await listOrdersWithExecutor(createExecutor(calls, 0), {
|
||||
keyword: orderSn,
|
||||
})
|
||||
|
||||
assert.match(
|
||||
calls[0]?.sql || '',
|
||||
/o\.platform_order_id = \$1 OR o\.platform_order_id LIKE \$1 \|\| '%'/s,
|
||||
)
|
||||
assert.doesNotMatch(calls[0]?.sql || '', /oi\.sku_code/i)
|
||||
assert.doesNotMatch(calls[0]?.sql || '', /item_snapshot_json/i)
|
||||
assert.deepEqual(calls[0]?.params, [orderSn])
|
||||
})
|
||||
|
||||
test('订单列表 platformOrderId 为拼多多 order_sn 时走索引快路径', async () => {
|
||||
const calls: Array<{ sql: string; params: unknown[] }> = []
|
||||
const orderSn = '260915-091435834962130'
|
||||
|
||||
await listOrdersWithExecutor(createExecutor(calls, 0), {
|
||||
platformOrderId: orderSn,
|
||||
})
|
||||
|
||||
assert.match(
|
||||
calls[0]?.sql || '',
|
||||
/o\.platform_order_id = \$1 OR o\.platform_order_id LIKE \$1 \|\| '%'/s,
|
||||
)
|
||||
assert.deepEqual(calls[0]?.params, [orderSn])
|
||||
})
|
||||
|
||||
function createExecutor(
|
||||
calls: Array<{ sql: string; params: unknown[] }>,
|
||||
total: number,
|
||||
|
||||
@@ -7,6 +7,7 @@ import type {
|
||||
OrderUpdateInput,
|
||||
} from '../types/repository/inputs.js'
|
||||
import type { OrderListQueryResult, OrderListRow, OrderRow } from '../types/repository/rows.js'
|
||||
import { isPlatformOrderIdLookupKeyword } from '../utils/platform-order-id.js'
|
||||
|
||||
export type OrderQueryExecutor = <T extends QueryResultRow = QueryResultRow>(
|
||||
text: string,
|
||||
@@ -251,9 +252,9 @@ export async function listOrdersWithExecutor(
|
||||
|
||||
if (keyword) {
|
||||
const trimmedKeyword = String(keyword).trim()
|
||||
const isPureOrderNo = /^\d{6,}$/.test(trimmedKeyword)
|
||||
const isOrderNoLookup = isPlatformOrderIdLookupKeyword(trimmedKeyword)
|
||||
|
||||
if (isPureOrderNo) {
|
||||
if (isOrderNoLookup) {
|
||||
params.push(trimmedKeyword)
|
||||
const paramIndex = `$${params.length}`
|
||||
filters.push(
|
||||
@@ -299,8 +300,17 @@ export async function listOrdersWithExecutor(
|
||||
}
|
||||
|
||||
if (platformOrderId) {
|
||||
params.push(`%${platformOrderId}%`)
|
||||
filters.push(`o.platform_order_id ILIKE $${params.length}`)
|
||||
const trimmedPlatformOrderId = String(platformOrderId).trim()
|
||||
if (isPlatformOrderIdLookupKeyword(trimmedPlatformOrderId)) {
|
||||
params.push(trimmedPlatformOrderId)
|
||||
const paramIndex = `$${params.length}`
|
||||
filters.push(
|
||||
`(o.platform_order_id = ${paramIndex} OR o.platform_order_id LIKE ${paramIndex} || '%')`,
|
||||
)
|
||||
} else {
|
||||
params.push(`%${trimmedPlatformOrderId}%`)
|
||||
filters.push(`o.platform_order_id ILIKE $${params.length}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (payStatus) {
|
||||
|
||||
@@ -62,6 +62,20 @@ test('任务列表关键词为纯数字时智能路由到平台订单号索引
|
||||
assert.deepEqual(result.params, ['20247230034021572'])
|
||||
})
|
||||
|
||||
test('任务列表关键词为拼多多 order_sn 时智能路由到平台订单号索引条件', () => {
|
||||
const result = buildTaskListFilters({
|
||||
keyword: '260915-091435834962130',
|
||||
})
|
||||
|
||||
assert.match(
|
||||
result.whereClause,
|
||||
/ft\.platform_order_id = \$1 OR ft\.platform_order_id LIKE \$1 \|\| '%'/s,
|
||||
)
|
||||
assert.doesNotMatch(result.whereClause, /oi\.sku_code/i)
|
||||
assert.doesNotMatch(result.whereClause, /item_snapshot_json/i)
|
||||
assert.deepEqual(result.params, ['260915-091435834962130'])
|
||||
})
|
||||
|
||||
test('任务列表关键词为 DT 任务号时智能路由到任务号索引条件', () => {
|
||||
const result = buildTaskListFilters({
|
||||
keyword: 'DT881aa66294cc',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { query, withTransaction } from '../db/client.js'
|
||||
import type { PoolClient } from 'pg'
|
||||
|
||||
import { isPlatformOrderIdLookupKeyword } from '../utils/platform-order-id.js'
|
||||
import { normalizeTimestampIso } from '../utils/time.js'
|
||||
import type {
|
||||
TaskCreateInput,
|
||||
@@ -471,10 +472,10 @@ export function buildTaskListFilters({
|
||||
|
||||
if (keyword) {
|
||||
const trimmedKeyword = String(keyword).trim()
|
||||
const isPureOrderNo = /^\d{6,}$/.test(trimmedKeyword)
|
||||
const isOrderNoLookup = isPlatformOrderIdLookupKeyword(trimmedKeyword)
|
||||
const isTaskNo = /^DT[a-zA-Z0-9_-]+$/i.test(trimmedKeyword)
|
||||
|
||||
if (isPureOrderNo) {
|
||||
if (isOrderNoLookup) {
|
||||
params.push(trimmedKeyword)
|
||||
const paramIndex = `$${params.length}`
|
||||
filters.push(
|
||||
@@ -510,8 +511,17 @@ export function buildTaskListFilters({
|
||||
}
|
||||
|
||||
if (platformOrderId) {
|
||||
params.push(`%${platformOrderId}%`)
|
||||
filters.push(`ft.platform_order_id ILIKE $${params.length}`)
|
||||
const trimmedPlatformOrderId = String(platformOrderId).trim()
|
||||
if (isPlatformOrderIdLookupKeyword(trimmedPlatformOrderId)) {
|
||||
params.push(trimmedPlatformOrderId)
|
||||
const paramIndex = `$${params.length}`
|
||||
filters.push(
|
||||
`(ft.platform_order_id = ${paramIndex} OR ft.platform_order_id LIKE ${paramIndex} || '%')`,
|
||||
)
|
||||
} else {
|
||||
params.push(`%${trimmedPlatformOrderId}%`)
|
||||
filters.push(`ft.platform_order_id ILIKE $${params.length}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (taskNo) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
normalizeWorkOrderAcceptanceMode,
|
||||
WORK_ORDER_GIFT_PHASE,
|
||||
} from '../../domain/work-order-acceptance-mode.js'
|
||||
import { isPlatformOrderIdLookupKeyword } from '../../utils/platform-order-id.js'
|
||||
export const WORK_ORDER_SELECT = `
|
||||
SELECT
|
||||
wo.*,
|
||||
@@ -819,8 +820,7 @@ export function buildWorkOrderWhere({
|
||||
filters.push(`wo.id = $${params.length}`)
|
||||
}
|
||||
if (normalizedKeyword) {
|
||||
const isPureOrderNo = /^\d{6,}$/.test(normalizedKeyword)
|
||||
if (isPureOrderNo) {
|
||||
if (isPlatformOrderIdLookupKeyword(normalizedKeyword)) {
|
||||
params.push(normalizedKeyword)
|
||||
const paramIndex = `$${params.length}`
|
||||
filters.push(
|
||||
|
||||
Reference in New Issue
Block a user