修复(接单平台): 优化商品名来源选项查询
来源下拉改读订单原始 provider,避免扫描 work_orders 大 JSON 导致超时;保留已配置来源合并逻辑并补充回归测试。
This commit is contained in:
@@ -3,6 +3,7 @@ import test from 'node:test'
|
||||
|
||||
import {
|
||||
buildWorkerProductNameSuffixDisplayConfig,
|
||||
mergeWorkerProductNameSuffixSourceOptions,
|
||||
normalizeProductNameSuffixText,
|
||||
normalizeWorkerProductNameSuffixConfig,
|
||||
} from './worker-product-name-suffix-service.js'
|
||||
@@ -141,3 +142,15 @@ test('打手端展示配置:只下发启用项且不带备注', () => {
|
||||
)
|
||||
assert.deepEqual(buildWorkerProductNameSuffixDisplayConfig({ items: [] }), { items: [] })
|
||||
})
|
||||
|
||||
test('来源选项:合并订单来源与已配置来源,大小写不敏感去重并保留配置值', () => {
|
||||
assert.deepEqual(
|
||||
mergeWorkerProductNameSuffixSourceOptions(['91kaquan', 'pdd', ' '], {
|
||||
items: [
|
||||
{ source: 'douyin_mashida', suffix: '抖音', enabled: false, note: '' },
|
||||
{ source: '91KAQUAN', suffix: '重复', enabled: false, note: '' },
|
||||
],
|
||||
}),
|
||||
['91kaquan', 'douyin_mashida', 'pdd'],
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { APP_CONFIG_KEYS } from '../../config/app-config-keys.js'
|
||||
import { listWorkOrderSourceProviders } from '../../repositories/worker-platform/work-order-query-repo.js'
|
||||
import { listOrderSourceProviders } from '../../repositories/worker-platform/work-order-query-repo.js'
|
||||
import type { JsonObject } from '../../types/json.js'
|
||||
import { readAppConfigEntry, saveAppConfigEntry } from '../config/app-config-store.js'
|
||||
|
||||
@@ -114,10 +114,18 @@ export function getWorkerProductNameSuffixDisplayConfig(): WorkerProductNameSuff
|
||||
return buildWorkerProductNameSuffixDisplayConfig(getWorkerProductNameSuffixConfig())
|
||||
}
|
||||
|
||||
/** 后台来源下拉选项:工单资料里出现过的来源 + 已配置但暂时没有工单的来源。 */
|
||||
/** 后台来源下拉选项:订单原始来源 + 已配置但暂时没有订单的来源。 */
|
||||
export async function listWorkerProductNameSuffixSourceOptions(): Promise<{ items: string[] }> {
|
||||
const providers = await listWorkOrderSourceProviders()
|
||||
const providers = await listOrderSourceProviders()
|
||||
const config = getWorkerProductNameSuffixConfig()
|
||||
return { items: mergeWorkerProductNameSuffixSourceOptions(providers, config) }
|
||||
}
|
||||
|
||||
/** 合并订单来源与已配置来源,按大小写不敏感去重,保留首次出现的展示值。 */
|
||||
export function mergeWorkerProductNameSuffixSourceOptions(
|
||||
providers: readonly string[],
|
||||
config: WorkerProductNameSuffixConfig,
|
||||
): string[] {
|
||||
const seen = new Map<string, string>()
|
||||
for (const value of [...providers, ...config.items.map((item) => item.source)]) {
|
||||
const text = String(value ?? '').trim()
|
||||
@@ -125,7 +133,7 @@ export async function listWorkerProductNameSuffixSourceOptions(): Promise<{ item
|
||||
const key = text.toLowerCase()
|
||||
if (!seen.has(key)) seen.set(key, text)
|
||||
}
|
||||
return { items: [...seen.values()].sort((a, b) => a.localeCompare(b)) }
|
||||
return [...seen.values()].sort((a, b) => a.localeCompare(b))
|
||||
}
|
||||
|
||||
/** 后缀只保留括号内的文字:用户填了外层全角/半角括号时自动剥离。 */
|
||||
|
||||
Reference in New Issue
Block a user