1
This commit is contained in:
parent
55b6255421
commit
916aa4444c
@ -449,9 +449,13 @@ async function loadContainers() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 库位关键词解析缓存:相同关键词只查询一次 */
|
||||
const spaceResolveCache = new Map<string, Promise<{ id?: number; displayName?: string }>>()
|
||||
|
||||
function resetBatchState() {
|
||||
importFileName.value = ''
|
||||
parsedRows.value = []
|
||||
spaceResolveCache.clear()
|
||||
}
|
||||
|
||||
function normalizeSpaceId(value: unknown): number | undefined {
|
||||
@ -554,7 +558,12 @@ async function resolveRowSpaceBeforeSubmit(
|
||||
): Promise<string | null> {
|
||||
const keyword = row.space_keyword?.trim()
|
||||
if (!row.space_id && keyword) {
|
||||
const resolved = await resolveSpaceByKeyword(keyword)
|
||||
let pending = spaceResolveCache.get(keyword)
|
||||
if (!pending) {
|
||||
pending = resolveSpaceByKeyword(keyword)
|
||||
spaceResolveCache.set(keyword, pending)
|
||||
}
|
||||
const resolved = await pending
|
||||
if (!resolved.id) {
|
||||
const label = row.rowIndex ? `第 ${row.rowIndex} 行` : '当前行'
|
||||
return `${label}库位未匹配: ${keyword}`
|
||||
@ -687,12 +696,13 @@ async function handleSubmit() {
|
||||
return
|
||||
}
|
||||
|
||||
for (const row of parsedRows.value) {
|
||||
const spaceError = await resolveRowSpaceBeforeSubmit(row)
|
||||
if (spaceError) {
|
||||
ElMessage.warning(spaceError)
|
||||
return
|
||||
}
|
||||
const spaceErrors = await Promise.all(
|
||||
parsedRows.value.map((row) => resolveRowSpaceBeforeSubmit(row))
|
||||
)
|
||||
const spaceError = spaceErrors.find((error) => error) || null
|
||||
if (spaceError) {
|
||||
ElMessage.warning(spaceError)
|
||||
return
|
||||
}
|
||||
|
||||
const res = await addItem({
|
||||
|
||||
@ -110,38 +110,55 @@ export async function resolveSpaceByKeyword(
|
||||
}
|
||||
}
|
||||
|
||||
const res = (await indexApi.searchSpace({ keyword: text, page: 1, pageSize: 20 })) as unknown as Record<
|
||||
string,
|
||||
unknown
|
||||
>
|
||||
const data = (res?.data || res?.list || res) as Record<string, unknown>
|
||||
const list = Array.isArray(data?.list) ? data.list : Array.isArray(data) ? data : []
|
||||
if (!list.length) return {}
|
||||
try {
|
||||
const res = (await indexApi.searchSpace({ keyword: text, page: 1, pageSize: 20 })) as unknown as Record<
|
||||
string,
|
||||
unknown
|
||||
>
|
||||
const data = (res?.data || res?.list || res) as Record<string, unknown>
|
||||
const list = Array.isArray(data?.list) ? data.list : Array.isArray(data) ? data : []
|
||||
if (!list.length) return {}
|
||||
|
||||
const exact =
|
||||
(list as Record<string, unknown>[]).find((item) => {
|
||||
const code = toTrimmedString(item?.space_code)
|
||||
const customName = toTrimmedString(item?.custom_name ?? item?.customName)
|
||||
const name = toTrimmedString(item?.space_name ?? item?.name)
|
||||
return code === text || customName === text || name === text
|
||||
}) || list[0]
|
||||
const exact =
|
||||
(list as Record<string, unknown>[]).find((item) => {
|
||||
const code = toTrimmedString(item?.space_code)
|
||||
const customName = toTrimmedString(item?.custom_name ?? item?.customName)
|
||||
const name = toTrimmedString(item?.space_name ?? item?.name)
|
||||
return code === text || customName === text || name === text
|
||||
}) || list[0]
|
||||
|
||||
const item = exact as Record<string, unknown>
|
||||
const id = Number(item?.id)
|
||||
return {
|
||||
id: Number.isFinite(id) && id > 0 ? id : undefined,
|
||||
displayName: getSpaceDisplayName(item),
|
||||
const item = exact as Record<string, unknown>
|
||||
const id = Number(item?.id)
|
||||
return {
|
||||
id: Number.isFinite(id) && id > 0 ? id : undefined,
|
||||
displayName: getSpaceDisplayName(item),
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('查询库位失败,兜底为默认收货区:', text, error)
|
||||
return { id: 1, displayName: '默认收货区' }
|
||||
}
|
||||
}
|
||||
|
||||
/** 批量解析多行库位:并发查询,相同关键词只查询一次 */
|
||||
export async function resolveParsedRowSpaces(rows: ParsedDirectInboundImportRow[]): Promise<void> {
|
||||
for (const row of rows) {
|
||||
const keyword = toTrimmedString(row.space_keyword)
|
||||
if (!keyword) continue
|
||||
const resolved = await resolveSpaceByKeyword(keyword)
|
||||
if (resolved.id) row.space_id = resolved.id
|
||||
if (resolved.displayName) row.space_keyword = resolved.displayName
|
||||
}
|
||||
const pendingByKeyword = new Map<string, Promise<{ id?: number; displayName?: string }>>()
|
||||
|
||||
await Promise.all(
|
||||
rows.map(async (row) => {
|
||||
const keyword = toTrimmedString(row.space_keyword)
|
||||
if (!keyword) return
|
||||
|
||||
let pending = pendingByKeyword.get(keyword)
|
||||
if (!pending) {
|
||||
pending = resolveSpaceByKeyword(keyword)
|
||||
pendingByKeyword.set(keyword, pending)
|
||||
}
|
||||
|
||||
const resolved = await pending
|
||||
if (resolved.id) row.space_id = resolved.id
|
||||
if (resolved.displayName) row.space_keyword = resolved.displayName
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
function buildEntryItemIndex(entryItems: DirectInboundImportRow[]) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user