fix(bom): honor unitless internal dimensions

This commit is contained in:
WuYongJie 2026-08-11 05:58:26 +08:00
parent 27ed15f55a
commit 9383233130
2 changed files with 18 additions and 3 deletions

View File

@ -227,6 +227,14 @@ describe('BOM v6 结构蓝图与 SKU 展开', () => {
relatedSkuIds: [], relatedSkuIds: [],
basis: 'IMAGE', basis: 'IMAGE',
confidence: 0.9, confidence: 0.9,
}, {
factId: 'fact-inner-depth',
kind: 'DIMENSION',
subject: '柜体内部深度',
value: '内深48',
relatedSkuIds: [],
basis: 'SOURCE_TEXT',
confidence: 0.96,
}, { }, {
factId: 'fact-top', factId: 'fact-top',
kind: 'PART', kind: 'PART',
@ -329,8 +337,8 @@ describe('BOM v6 结构蓝图与 SKU 展开', () => {
const lastTop = output.result.skus.at(-1)?.bomLines.find( const lastTop = output.result.skus.at(-1)?.bomLines.find(
(line) => line.externalLineId === 'enclosure-top', (line) => line.externalLineId === 'enclosure-top',
) )
expect(firstTop).toMatchObject({ lengthMm: 1_400, widthMm: 620 }) expect(firstTop).toMatchObject({ lengthMm: 1_400, widthMm: 480 })
expect(lastTop).toMatchObject({ lengthMm: 2_000, widthMm: 620 }) expect(lastTop).toMatchObject({ lengthMm: 2_000, widthMm: 480 })
expect(instantiationRequests).toHaveLength(7) expect(instantiationRequests).toHaveLength(7)
for (const request of instantiationRequests) { for (const request of instantiationRequests) {
expect(request.sku).toHaveLength(1) expect(request.sku).toHaveLength(1)

View File

@ -694,7 +694,14 @@ function resolveInternalDepthMm(input: {
if (!factAppliesToSku(record, input.sku.externalSkuId)) continue if (!factAppliesToSku(record, input.sku.externalSkuId)) continue
const context = `${record.fact.subject} ${record.fact.value}` const context = `${record.fact.subject} ${record.fact.value}`
if (!/内深|内部深|有效深/.test(context)) continue if (!/内深|内部深|有效深/.test(context)) continue
const value = factMillimeters(record) const unitlessValue = context.match(
/(?:内深|内部深|有效深)[^0-9]{0,8}([0-9]+(?:\.[0-9]+)?)/,
)?.[1]
const value = factMillimeters(record) ?? (
unitlessValue
? toMillimeters(Number(unitlessValue), record.fact.unit)
: undefined
)
if (value && (!input.outerDepthMm || value <= input.outerDepthMm)) return value if (value && (!input.outerDepthMm || value <= input.outerDepthMm)) return value
} }
return input.outerDepthMm return input.outerDepthMm