feat(fulfillment): 统一中文内部 SKU 履约路由
This commit is contained in:
@@ -118,6 +118,62 @@ async function main() {
|
||||
)
|
||||
).rows
|
||||
|
||||
checks.canonicalChannelDuplicates = (
|
||||
await query<CountRow>(
|
||||
`SELECT canonicalize_internal_sku(internal_sku) AS label, count(*)::int AS total
|
||||
FROM internal_sku_channels
|
||||
WHERE enabled = TRUE
|
||||
GROUP BY canonicalize_internal_sku(internal_sku), channel
|
||||
HAVING count(*) > 1
|
||||
ORDER BY count(*) DESC, label`,
|
||||
)
|
||||
).rows
|
||||
|
||||
checks.incompleteCarrierConfigs = (
|
||||
await query<CountRow>(
|
||||
`SELECT channel AS label, count(*)::int AS total
|
||||
FROM internal_sku_channels
|
||||
WHERE enabled = TRUE
|
||||
AND (
|
||||
(
|
||||
channel = 'work_order'
|
||||
AND (
|
||||
COALESCE(config_json->>'workRuleKey', '') = ''
|
||||
OR NOT EXISTS (
|
||||
SELECT 1 FROM work_product_rules rule
|
||||
WHERE rule.rule_key = config_json->>'workRuleKey'
|
||||
AND rule.enabled = TRUE
|
||||
)
|
||||
)
|
||||
)
|
||||
OR (
|
||||
channel = 'manual'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM manual_fulfillment_configs cfg
|
||||
WHERE cfg.enabled = TRUE
|
||||
AND canonicalize_internal_sku(cfg.sku_key)
|
||||
= canonicalize_internal_sku(internal_sku_channels.internal_sku)
|
||||
)
|
||||
)
|
||||
)
|
||||
GROUP BY channel ORDER BY count(*) DESC`,
|
||||
)
|
||||
).rows
|
||||
|
||||
checks.pendingWithoutChineseInternalSku = (
|
||||
await query<CountRow>(
|
||||
`SELECT 'pending_without_chinese_internal_sku' AS label, count(*)::int AS total
|
||||
FROM order_items oi
|
||||
JOIN orders o ON o.id = oi.order_id
|
||||
WHERE oi.fulfillment_status = 'pending'
|
||||
AND ($1::boolean OR o.shop_id NOT LIKE 'sim-%')
|
||||
AND COALESCE(resolve_internal_sku(
|
||||
oi.manual_sku_key, oi.sku_name, oi.sku_code
|
||||
), '') = ''`,
|
||||
[includeDemo],
|
||||
)
|
||||
).rows[0]
|
||||
|
||||
checks.enabledLegacyRules = (
|
||||
await query<CountRow>(
|
||||
`SELECT match_key_type || '/' || channel AS label, count(*)::int AS total
|
||||
@@ -202,6 +258,12 @@ async function main() {
|
||||
failed.push('存在同时挂载多个真实履约载体的已分配订单项')
|
||||
if ((checks.internalChannelConflicts as CountRow[]).length > 0)
|
||||
failed.push('存在多个非兜底主渠道')
|
||||
if ((checks.canonicalChannelDuplicates as CountRow[]).length > 0)
|
||||
failed.push('存在规范化后重复的内部 SKU 渠道配置')
|
||||
if ((checks.incompleteCarrierConfigs as CountRow[]).length > 0)
|
||||
failed.push('存在缺少 workRuleKey 或人工履约配置的启用渠道')
|
||||
if ((checks.pendingWithoutChineseInternalSku as CountRow).total > 0)
|
||||
failed.push('存在无法归一到中文内部 SKU 的 pending 订单项')
|
||||
if ((checks.enabledLegacyRules as CountRow[]).length > 0)
|
||||
failed.push('仍有启用的 sku_code 兼容规则,未完全收敛到内部 SKU')
|
||||
if ((checks.pendingWithoutReason as CountRow).total > 0)
|
||||
|
||||
Reference in New Issue
Block a user