优化履约路由回退策略

This commit is contained in:
yml2213
2026-08-11 11:38:47 +08:00
parent 3d747aa5aa
commit e72c936986
2 changed files with 42 additions and 1 deletions
@@ -94,6 +94,34 @@ test('resolveFulfillmentRoute 商品规则可以强制走 feifei', () => {
assert.equal(result.reason, '命中商品路由规则')
})
test('resolveFulfillmentRoute 商品规则目标不可用时回退全局优先级', () => {
const result = resolveFulfillmentRoute({
productName: '套装-糯粉咩咩',
candidates: [
{ executorKey: 'kuaishou_ct_assisted', available: true },
{ executorKey: 'kuaishou_feifei', available: true },
{ executorKey: 'affiliate_dash', available: false, reason: '未命中 affiliate-dash sku 映射' },
],
config: normalizeFulfillmentRoutingConfig({
rules: [
{
enabled: true,
productName: '套装-糯粉咩咩',
executorKey: 'affiliate_dash',
priority: 200,
},
],
}),
})
assert.equal(result.selectedExecutorKey, 'kuaishou_ct_assisted')
assert.equal(result.reason, '商品路由规则目标不可用,按全局优先级回退')
assert.deepEqual(result.skipped[0], {
executorKey: 'affiliate_dash',
reason: '未命中 affiliate-dash sku 映射',
})
})
test('resolveFulfillmentRoute 商品规则可以强制转人工', () => {
const result = resolveFulfillmentRoute({
productName: '临时停用商品',
@@ -185,9 +185,22 @@ export function resolveFulfillmentRoute({
return selected
}
const fallback = resolveByExecutorPriority({
priority: normalizedConfig.defaultExecutorPriority.filter(
(executorKey) => executorKey !== matchedRule.executorKey,
),
candidates: normalizedCandidates,
config: normalizedConfig,
skipped,
reasonPrefix: '商品路由规则目标不可用,按全局优先级回退',
})
if (fallback.selectedExecutorKey) {
return fallback
}
return {
...selected,
reason: selected.reason || '商品路由规则目标通道不可用',
reason: selected.reason || '商品路由规则目标通道不可用,且未命中其他履约通道',
}
}