diff --git a/furniture-3d-system/src/server/services/bom-costing/bom-costing-category-skills.integration.test.ts b/furniture-3d-system/src/server/services/bom-costing/bom-costing-category-skills.integration.test.ts index 81cef894..c73dde37 100644 --- a/furniture-3d-system/src/server/services/bom-costing/bom-costing-category-skills.integration.test.ts +++ b/furniture-3d-system/src/server/services/bom-costing/bom-costing-category-skills.integration.test.ts @@ -91,10 +91,10 @@ const CATEGORY_FIXTURES: CategoryAcceptanceFixture[] = [ title: '厨房落地置物架', expectedSkill: 'STORAGE_RACK', skus: [ - { externalSkuId: 'rk-a1', name: '碳钢 固定脚 4层置物架', expectedStructureDifferences: ['TIER_COUNT_4'], expectedCostDifference: 'MATERIAL_STEEL' }, - { externalSkuId: 'rk-a2', name: '白蜡木 固定脚 4层置物架', expectedStructureDifferences: ['TIER_COUNT_4'], expectedCostDifference: 'MATERIAL_ASH_WOOD' }, + { externalSkuId: 'rk-a1', name: '碳钢 固定脚 4层置物架', expectedStructureDifferences: ['FIXED_BASE', 'TIER_COUNT_4'], expectedCostDifference: 'MATERIAL_STEEL' }, + { externalSkuId: 'rk-a2', name: '白蜡木 固定脚 4层置物架', expectedStructureDifferences: ['FIXED_BASE', 'TIER_COUNT_4'], expectedCostDifference: 'MATERIAL_ASH_WOOD' }, { externalSkuId: 'rk-b1', name: '碳钢 带轮 4层置物架', expectedStructureDifferences: ['CASTER_BASE', 'TIER_COUNT_4'], expectedCostDifference: 'MATERIAL_STEEL' }, - { externalSkuId: 'rk-c1', name: '碳钢 固定脚 5层置物架', expectedStructureDifferences: ['TIER_COUNT_5'], expectedCostDifference: 'MATERIAL_STEEL' }, + { externalSkuId: 'rk-c1', name: '碳钢 固定脚 5层置物架', expectedStructureDifferences: ['FIXED_BASE', 'TIER_COUNT_5'], expectedCostDifference: 'MATERIAL_STEEL' }, ], expectedStructureGroupCount: 3, expectedStructureComponents: { diff --git a/furniture-3d-system/src/server/services/bom-costing/bom-costing-mobile-rattan-storage-rack.integration.test.ts b/furniture-3d-system/src/server/services/bom-costing/bom-costing-mobile-rattan-storage-rack.integration.test.ts new file mode 100644 index 00000000..4494a344 --- /dev/null +++ b/furniture-3d-system/src/server/services/bom-costing/bom-costing-mobile-rattan-storage-rack.integration.test.ts @@ -0,0 +1,573 @@ +/** @jest-environment node */ + +import { + BOM_COSTING_FACT_SCHEMA_VERSION, + type BomCostingSourceFactSnapshot, +} from '@/lib/bom-costing/fact-contracts' +import type { BomCostingMultimodalProviderConfig } from './bom-costing-multimodal-gateway' +import { buildStructuredBomCostingAnalysis } from './bom-costing-structure-blueprint' +import { + buildBomCostingCategoryGroupingKeys, + buildBomCostingCategorySkillContext, + selectBomCostingCategorySkill, +} from './category-skills' +import { buildDeterministicStructureBlueprint } from './bom-costing-structure-knowledge' +import { + PRODUCTION_MOBILE_RATTAN_STORAGE_RACK_2_SKUS, + buildProductionMobileRattanStorageRack2FactSnapshot, + buildProductionMobileRattanStorageRack2Snapshot, +} from './test-fixtures/production-mobile-rattan-storage-rack-2.fixture' + +const config: BomCostingMultimodalProviderConfig = { + baseUrl: 'https://ai.example.com/v1', + apiKey: 'test-key', + model: 'test-vision', +} + +function streamingResponse(content: string) { + return new Response( + `data: ${JSON.stringify({ + id: 'call-storage-rack-v2', + model: 'test-vision', + choices: [{ delta: { content }, finish_reason: null }], + })}\n\ndata: ${JSON.stringify({ + id: 'call-storage-rack-v2', + model: 'test-vision', + choices: [{ delta: {}, finish_reason: 'stop' }], + })}\n\ndata: [DONE]\n\n`, + { status: 200, headers: { 'Content-Type': 'text/event-stream' } }, + ) +} + +describe('BOM v7 移动藤编双层置物架生产形态回归', () => { + afterEach(() => { + jest.restoreAllMocks() + }) + + it('两个真实 SKU 共用移动双层拓扑和橡木成本族,藤编/不锈钢只进入精确槽位', () => { + const snapshot = buildProductionMobileRattanStorageRack2Snapshot() + const factSnapshot = buildProductionMobileRattanStorageRack2FactSnapshot() + const selection = selectBomCostingCategorySkill( + buildBomCostingCategorySkillContext({ snapshot, factSnapshot }), + ) + + expect(selection.status).toBe('SUPPORTED') + expect(selection.skill?.code).toBe('STORAGE_RACK') + expect(selection.skill?.version).toBe('bom-category-skill/storage-rack/v2') + + const groupings = snapshot.skus.map((sku) => buildBomCostingCategoryGroupingKeys({ + skill: selection.skill!, + snapshot, + sku, + factSnapshot, + })) + expect(groupings).toHaveLength(PRODUCTION_MOBILE_RATTAN_STORAGE_RACK_2_SKUS.length) + for (const grouping of groupings) { + expect(grouping.structureDifferenceKeys).toEqual([ + 'CASTER_BASE', + 'MOBILE_TROLLEY_RACK', + 'TIER_COUNT_2', + ]) + expect(grouping).toMatchObject({ + costDifferenceKeys: ['MATERIAL_OAK'], + materialFamily: '橡木', + grade: 'fas级', + }) + } + expect(groupings[0]?.structureGroupKey).toBe(groupings[1]?.structureGroupKey) + expect(groupings[0]?.costGroupKey).toBe(groupings[1]?.costGroupKey) + + const blueprint = buildDeterministicStructureBlueprint({ + snapshot, + factSnapshot, + requestedCategorySkillId: 'STORAGE_RACK', + }) + expect(blueprint.supportStatus).toBe('SUPPORTED') + expect(blueprint.categorySkill).toMatchObject({ + requestedSkillId: 'STORAGE_RACK', + selectedSkillId: 'STORAGE_RACK', + selectedSkillVersion: 'bom-category-skill/storage-rack/v2', + selectionMode: 'USER_OVERRIDE', + }) + expect(blueprint.structureGroups).toHaveLength(1) + + const group = blueprint.structureGroups[0]! + expect(group.skuIds.sort()).toEqual( + PRODUCTION_MOBILE_RATTAN_STORAGE_RACK_2_SKUS + .map((sku) => sku.externalSkuId) + .sort(), + ) + expect(group.structureDifferenceKeys).toEqual([ + 'CASTER_BASE', + 'MOBILE_TROLLEY_RACK', + 'TIER_COUNT_2', + ]) + expect(group.costFamilies).toEqual([ + expect.objectContaining({ + materialFamily: '橡木', + grade: 'fas级', + skuIds: PRODUCTION_MOBILE_RATTAN_STORAGE_RACK_2_SKUS + .map((sku) => sku.externalSkuId), + }), + ]) + + const slotsByKey = new Map(group.componentSlots.map((slot) => [ + slot.componentKey, + slot, + ] as const)) + expect([...slotsByKey.keys()]).toEqual(expect.arrayContaining([ + 'surface-upper-tray', + 'frame-lower-basket', + 'cover-rattan-panel', + 'support-metal-upright', + 'support-push-handle', + 'motion-caster', + 'hardware-connectors', + ])) + expect([...slotsByKey.keys()]).not.toEqual(expect.arrayContaining([ + 'support-upright', + 'partition-shelf', + 'support-cross-brace', + 'hardware-feet', + ])) + expect(slotsByKey.get('surface-upper-tray')).toMatchObject({ + required: true, + category: 'BOARD', + unit: '块', + primaryMaterialSlot: true, + quantityPolicy: { baseQuantity: 1 }, + }) + expect(slotsByKey.get('surface-upper-tray')?.evidenceFactIds).toEqual( + expect.arrayContaining(['IMG_0002_fact_001', 'IMG_0002_fact_002']), + ) + expect(slotsByKey.get('frame-lower-basket')).toMatchObject({ + required: true, + category: 'ACCESSORY', + unit: '套', + primaryMaterialSlot: false, + quantityPolicy: { baseQuantity: 1 }, + }) + expect(slotsByKey.get('frame-lower-basket')?.evidenceFactIds) + .toContain('IMG_0039_fact_002') + expect(slotsByKey.get('cover-rattan-panel')).toMatchObject({ + required: true, + category: 'ACCESSORY', + quantityPolicy: { baseQuantity: 1 }, + }) + expect(slotsByKey.get('cover-rattan-panel')?.evidenceFactIds) + .toContain('IMG_0013_fact_001') + expect(slotsByKey.get('support-metal-upright')).toMatchObject({ + required: true, + category: 'STEEL', + quantityPolicy: { baseQuantity: 4 }, + }) + expect(slotsByKey.get('support-metal-upright')?.evidenceFactIds) + .toContain('IMG_0039_fact_003') + expect(slotsByKey.get('motion-caster')).toMatchObject({ + required: true, + category: 'ACCESSORY', + quantityPolicy: { baseQuantity: 4 }, + }) + expect(slotsByKey.get('motion-caster')?.evidenceFactIds) + .toContain('IMG_0013_fact_006') + + expect(group.relations).toEqual(expect.arrayContaining([ + expect.objectContaining({ + relationType: 'SUPPORTS', + fromComponentKey: 'support-metal-upright', + toComponentKey: 'surface-upper-tray', + }), + expect.objectContaining({ + relationType: 'SUPPORTS', + fromComponentKey: 'support-metal-upright', + toComponentKey: 'frame-lower-basket', + }), + expect.objectContaining({ + relationType: 'COVERS', + fromComponentKey: 'cover-rattan-panel', + toComponentKey: 'frame-lower-basket', + }), + expect.objectContaining({ + relationType: 'MOVES_WITH', + fromComponentKey: 'motion-caster', + toComponentKey: 'support-metal-upright', + }), + ])) + }) + + it('离线回退穿透生成两 SKU 最终 BOM,且钢件和附件无事实尺寸时保持空三轴', async () => { + const snapshot = buildProductionMobileRattanStorageRack2Snapshot() + const factSnapshot = buildProductionMobileRattanStorageRack2FactSnapshot() + jest.spyOn(global, 'fetch').mockRejectedValue(new Error('offline fixture')) + + const { result, trace } = await buildStructuredBomCostingAnalysis({ + config, + sourceUrl: snapshot.detailUrl, + snapshot, + factSnapshot, + requestedCategorySkillId: 'STORAGE_RACK', + }) + + expect(trace.fallbackSkuIds.slice().sort()).toEqual( + PRODUCTION_MOBILE_RATTAN_STORAGE_RACK_2_SKUS + .map((sku) => sku.externalSkuId) + .sort(), + ) + expect(result.skus).toHaveLength(PRODUCTION_MOBILE_RATTAN_STORAGE_RACK_2_SKUS.length) + for (const fixtureSku of PRODUCTION_MOBILE_RATTAN_STORAGE_RACK_2_SKUS) { + const sku = result.skus.find((candidate) => ( + candidate.externalSkuId === fixtureSku.externalSkuId + ))! + expect(sku.dimensions).toMatchObject({ + lengthMm: 632.5, + widthMm: 382, + heightMm: 735, + }) + expect(sku.attributes).toMatchObject({ + structureAnalysisStatus: 'PENDING_REVIEW', + }) + + const linesByKey = new Map(sku.bomLines.map((line) => [ + line.externalLineId, + line, + ] as const)) + expect(linesByKey.get('surface-upper-tray')).toMatchObject({ + quantity: 1, + unit: '块', + lengthMm: 560, + widthMm: 310, + heightMm: undefined, + materialName: '橡木', + }) + expect(linesByKey.get('frame-lower-basket')).toMatchObject({ + quantity: 1, + unit: '套', + materialName: '橡木', + }) + expect(linesByKey.get('cover-rattan-panel')).toMatchObject({ + quantity: 1, + unit: '套', + materialName: '藤编', + }) + expect(linesByKey.get('support-metal-upright')).toMatchObject({ + quantity: 4, + unit: '根', + materialName: '不锈钢', + }) + expect(linesByKey.get('support-push-handle')).toMatchObject({ + quantity: 1, + unit: '件', + materialName: '不锈钢', + }) + expect(linesByKey.get('motion-caster')).toMatchObject({ + quantity: 4, + unit: '个', + }) + expect([...linesByKey.keys()]).not.toEqual(expect.arrayContaining([ + 'support-upright', + 'partition-shelf', + 'support-cross-brace', + 'hardware-feet', + ])) + + for (const line of sku.bomLines.filter((candidate) => ( + candidate.category === 'ACCESSORY' || candidate.category === 'STEEL' + ))) { + expect(line).toEqual(expect.objectContaining({ + lengthMm: undefined, + widthMm: undefined, + heightMm: undefined, + })) + } + } + }) + + it('完整但恶意的模型尺寸不能覆盖事实几何,也不能污染无尺寸附件和钢件', async () => { + const snapshot = buildProductionMobileRattanStorageRack2Snapshot() + const factSnapshot = buildProductionMobileRattanStorageRack2FactSnapshot() + jest.spyOn(global, 'fetch').mockImplementation(async (_url, init) => { + const body = JSON.parse(String(init?.body)) as { + messages: Array<{ + content: string | Array<{ type: string; text?: string }> + }> + } + const content = body.messages[1]?.content ?? '{}' + const text = typeof content === 'string' + ? content + : content.find((entry) => entry.type === 'text')?.text ?? '{}' + const payload = JSON.parse(text) as { + outputContractVersion?: string + questions?: Array<{ questionId: string }> + sku?: Array<[string, string, string, Record]> + slots?: Array<[string, string, string]> + } + if (payload.outputContractVersion === 'structure-verification/v1') { + return streamingResponse(JSON.stringify({ + questionResults: (payload.questions ?? []).map((question) => ({ + questionId: question.questionId, + status: 'RESOLVED', + finding: '保持原结构合同', + evidenceFactIds: [], + confidence: 0.9, + })), + componentUpdates: [], + })) + } + return streamingResponse(JSON.stringify({ + skus: (payload.sku ?? []).map((sku) => ({ + sku: sku[0], + d: [9_999, 8_888, 7_777], + lines: (payload.slots ?? []).map((slot) => ([ + slot[0], + 99, + '恶意单位', + 9_999, + 8_888, + 7_777, + '恶意材质', + [], + ])), + })), + })) + }) + + const { result, trace } = await buildStructuredBomCostingAnalysis({ + config, + sourceUrl: snapshot.detailUrl, + snapshot, + factSnapshot, + requestedCategorySkillId: 'STORAGE_RACK', + }) + + expect(trace.fallbackSkuIds).toEqual([]) + for (const sku of result.skus) { + expect(sku.dimensions).toMatchObject({ + lengthMm: 632.5, + widthMm: 382, + heightMm: 735, + }) + const linesByKey = new Map(sku.bomLines.map((line) => [ + line.externalLineId, + line, + ] as const)) + expect(linesByKey.get('surface-upper-tray')).toMatchObject({ + quantity: 1, + unit: '块', + lengthMm: 560, + widthMm: 310, + heightMm: undefined, + materialName: '橡木', + }) + expect(linesByKey.get('frame-lower-basket')).toMatchObject({ + quantity: 1, + unit: '套', + materialName: '橡木', + }) + expect(linesByKey.get('cover-rattan-panel')).toMatchObject({ + quantity: 1, + unit: '套', + materialName: '藤编', + }) + expect(linesByKey.get('support-metal-upright')).toMatchObject({ + quantity: 4, + unit: '根', + materialName: '不锈钢', + }) + expect(linesByKey.get('support-push-handle')).toMatchObject({ + quantity: 1, + unit: '件', + materialName: '不锈钢', + }) + expect(linesByKey.get('motion-caster')).toMatchObject({ + quantity: 4, + unit: '个', + }) + for (const line of sku.bomLines.filter((candidate) => ( + candidate.category === 'ACCESSORY' || candidate.category === 'STEEL' + ))) { + expect(line).toEqual(expect.objectContaining({ + lengthMm: undefined, + widthMm: undefined, + heightMm: undefined, + })) + } + expect(sku.bomLines.filter((line) => ( + ['BOARD', 'STEEL', 'ACCESSORY'].includes(line.category) && ( + line.lengthMm === 9_999 || + line.widthMm === 8_888 || + line.heightMm === 7_777 || + line.quantity === 99 || + line.unit === '恶意单位' || + line.materialName === '恶意材质' + ) + )).map((line) => line.externalLineId)).toEqual([]) + } + }) + + it('只有可信商品级“双层置物”事实的普通木架仍使用层板、木立柱和固定脚', () => { + const snapshot = buildProductionMobileRattanStorageRack2Snapshot() + snapshot.title = '全实木普通开放式置物架' + snapshot.skus = snapshot.skus.slice(0, 1).map((sku) => ({ + ...sku, + name: '橡木 固定脚 双层置物架', + size: '橡木 固定脚 双层置物架', + attributes: { 规格: '橡木 固定脚 双层置物架' }, + })) + const factSnapshot: BomCostingSourceFactSnapshot = { + schemaVersion: BOM_COSTING_FACT_SCHEMA_VERSION, + imageFacts: [{ + imageId: 'ordinary-double-tier-rack', + sourceImageUrl: 'https://fixture.invalid/images/ordinary-double-tier-rack.jpg', + kind: 'DETAIL', + label: '普通双层木架', + externalSkuIds: [], + observedTexts: ['双层置物'], + facts: [{ + factId: 'ordinary-double-tier-structure', + kind: 'STRUCTURE', + subject: '置物层', + value: '双层置物', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.99, + }], + }], + failedImages: [], + extractedAt: '2026-08-13T00:00:00.000Z', + } + + const blueprint = buildDeterministicStructureBlueprint({ + snapshot, + factSnapshot, + requestedCategorySkillId: 'STORAGE_RACK', + }) + const group = blueprint.structureGroups[0]! + expect(group.structureDifferenceKeys).toEqual(['FIXED_BASE', 'TIER_COUNT_2']) + const slotsByKey = new Map(group.componentSlots.map((slot) => [ + slot.componentKey, + slot, + ] as const)) + expect([...slotsByKey.keys()]).toEqual(expect.arrayContaining([ + 'support-upright', + 'partition-shelf', + 'support-cross-brace', + 'hardware-feet', + ])) + expect(slotsByKey.get('partition-shelf')?.quantityPolicy.baseQuantity).toBe(2) + expect([...slotsByKey.keys()]).not.toEqual(expect.arrayContaining([ + 'surface-upper-tray', + 'frame-lower-basket', + 'cover-rattan-panel', + 'support-metal-upright', + 'support-push-handle', + 'motion-caster', + ])) + }) + + it('固定脚 SKU 优先于商品级脚轮摘要,不能同时生成脚轮和固定脚', () => { + const snapshot = buildProductionMobileRattanStorageRack2Snapshot() + snapshot.title = '厨房落地置物架 多款可选' + snapshot.skus = snapshot.skus.slice(0, 1).map((sku) => ({ + ...sku, + name: '白蜡木 固定脚 4层置物架', + size: '白蜡木 固定脚 4层置物架', + attributes: { 规格: '白蜡木 固定脚 4层置物架' }, + })) + const factSnapshot: BomCostingSourceFactSnapshot = { + schemaVersion: BOM_COSTING_FACT_SCHEMA_VERSION, + imageFacts: [{ + imageId: 'product-wide-caster-summary', + sourceImageUrl: 'https://fixture.invalid/images/product-wide-caster-summary.jpg', + kind: 'DETAIL', + label: '多款脚轮摘要', + externalSkuIds: [], + observedTexts: ['部分款式带脚轮'], + facts: [{ + factId: 'product-wide-caster-fact', + kind: 'MECHANISM', + subject: '可选底座', + value: '底部配置脚轮', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.99, + }], + }], + failedImages: [], + extractedAt: '2026-08-13T00:00:00.000Z', + } + + const blueprint = buildDeterministicStructureBlueprint({ + snapshot, + factSnapshot, + requestedCategorySkillId: 'STORAGE_RACK', + }) + const group = blueprint.structureGroups[0]! + expect(group.structureDifferenceKeys).toEqual(['FIXED_BASE', 'TIER_COUNT_4']) + const requiredKeys = group.componentSlots + .filter((slot) => slot.required) + .map((slot) => slot.componentKey) + expect(requiredKeys).toContain('hardware-feet') + expect(requiredKeys).not.toContain('motion-caster') + }) + + it.each([ + { basis: 'VISUAL_ESTIMATE' as const, confidence: 0.99, label: '目测估计' }, + { basis: 'IMAGE' as const, confidence: 0.54, label: '低置信图片事实' }, + ])('$label 不能把移动推车复合拓扑扩散到普通木架', ({ basis, confidence }) => { + const snapshot = buildProductionMobileRattanStorageRack2Snapshot() + snapshot.title = '全实木普通开放式置物架' + snapshot.skus = snapshot.skus.slice(0, 1).map((sku) => ({ + ...sku, + name: '橡木 固定脚 3层置物架', + size: '橡木 固定脚 3层置物架', + attributes: { 规格: '橡木 固定脚 3层置物架' }, + })) + const factSnapshot: BomCostingSourceFactSnapshot = { + schemaVersion: BOM_COSTING_FACT_SCHEMA_VERSION, + imageFacts: [{ + imageId: 'untrusted-mobile-trolley-topology', + sourceImageUrl: 'https://fixture.invalid/images/untrusted-mobile-trolley-topology.jpg', + kind: 'DETAIL', + label: '不可信推车形态', + externalSkuIds: [], + observedTexts: [], + facts: [{ + factId: 'untrusted-mobile-trolley-fact', + kind: 'STRUCTURE', + subject: '产品整体结构', + value: '上层托盘和下层置物篮由金属管架支撑,底部安装脚轮', + relatedSkuIds: [], + basis, + confidence, + }], + }], + failedImages: [], + extractedAt: '2026-08-13T00:00:00.000Z', + } + + const blueprint = buildDeterministicStructureBlueprint({ + snapshot, + factSnapshot, + requestedCategorySkillId: 'STORAGE_RACK', + }) + const group = blueprint.structureGroups[0]! + expect(group.structureDifferenceKeys).toEqual(['FIXED_BASE', 'TIER_COUNT_3']) + const requiredKeys = group.componentSlots + .filter((slot) => slot.required) + .map((slot) => slot.componentKey) + expect(requiredKeys).toEqual(expect.arrayContaining([ + 'support-upright', + 'partition-shelf', + 'support-cross-brace', + 'hardware-feet', + ])) + expect(requiredKeys).not.toEqual(expect.arrayContaining([ + 'surface-upper-tray', + 'frame-lower-basket', + 'cover-rattan-panel', + 'support-metal-upright', + 'support-push-handle', + 'motion-caster', + ])) + }) +}) diff --git a/furniture-3d-system/src/server/services/bom-costing/bom-costing-processing.service.test.ts b/furniture-3d-system/src/server/services/bom-costing/bom-costing-processing.service.test.ts index 8edf5fe1..80470eca 100644 --- a/furniture-3d-system/src/server/services/bom-costing/bom-costing-processing.service.test.ts +++ b/furniture-3d-system/src/server/services/bom-costing/bom-costing-processing.service.test.ts @@ -218,11 +218,11 @@ const supportedV3AnalysisResult = { schemaVersion: 'competitor-analysis/v3' as const, structureBlueprint: { schemaVersion: 'structure-blueprint/v2' as const, - knowledgeVersion: 'structure-priors/2026-08-13-v6', + knowledgeVersion: 'structure-priors/2026-08-13-v7', supportStatus: 'SUPPORTED' as const, categorySkill: { selectedSkillId: 'TABLE', - selectedSkillVersion: 'bom-category-skill/table/v1', + selectedSkillVersion: 'bom-category-skill/table/v2', selectionMode: 'AUTO_SINGLE' as const, requiredEvidenceCoverage: 0.55, candidates: [], diff --git a/furniture-3d-system/src/server/services/bom-costing/bom-costing-production-27.integration.test.ts b/furniture-3d-system/src/server/services/bom-costing/bom-costing-production-27.integration.test.ts index 91ebfe10..4719d490 100644 --- a/furniture-3d-system/src/server/services/bom-costing/bom-costing-production-27.integration.test.ts +++ b/furniture-3d-system/src/server/services/bom-costing/bom-costing-production-27.integration.test.ts @@ -276,7 +276,7 @@ async function runStructurePipeline(orderedFixture: readonly ProductionWardrobe2 } const checkpoint = readBomCostingStructureCheckpoint({ kind: 'BOM_COSTING_STRUCTURE_CHECKPOINT', - version: 10, + version: 11, sourceSkuIds: snapshot.skus.map((sku) => sku.externalSkuId), blueprint, completedGroupKeys: [], diff --git a/furniture-3d-system/src/server/services/bom-costing/bom-costing-structure-blueprint.test.ts b/furniture-3d-system/src/server/services/bom-costing/bom-costing-structure-blueprint.test.ts index 8deaae77..2696f80b 100644 --- a/furniture-3d-system/src/server/services/bom-costing/bom-costing-structure-blueprint.test.ts +++ b/furniture-3d-system/src/server/services/bom-costing/bom-costing-structure-blueprint.test.ts @@ -199,7 +199,7 @@ describe('BOM v7 结构蓝图与 SKU 展开', () => { }, ) - it('当前 v8/v2 检查点可恢复,旧比较事实激活合同 v7 检查点失效', async () => { + it('当前 v11/v2 检查点可恢复,旧 v10 检查点失效', async () => { const snapshot = snapshotWithSkus(1) const factSnapshot = { schemaVersion: BOM_COSTING_FACT_SCHEMA_VERSION, @@ -222,7 +222,7 @@ describe('BOM v7 结构蓝图与 SKU 展开', () => { const group = blueprint.structureGroups[0]! const checkpointValue = { kind: 'BOM_COSTING_STRUCTURE_CHECKPOINT', - version: 10, + version: 11, sourceSkuIds: ['sku-1'], blueprint, completedGroupKeys: [group.structureGroupKey], @@ -246,7 +246,7 @@ describe('BOM v7 结构蓝图与 SKU 展开', () => { } expect(readBomCostingStructureCheckpoint({ ...checkpointValue, - version: 7, + version: 10, })).toBeNull() expect(readBomCostingStructureCheckpoint({ ...checkpointValue, @@ -307,7 +307,7 @@ describe('BOM v7 结构蓝图与 SKU 展开', () => { ) const checkpoint = readBomCostingStructureCheckpoint({ kind: 'BOM_COSTING_STRUCTURE_CHECKPOINT', - version: 10, + version: 11, sourceSkuIds: snapshot.skus.map((sku) => sku.externalSkuId), blueprint, completedGroupKeys: blueprint.structureGroups.map((group) => group.structureGroupKey), diff --git a/furniture-3d-system/src/server/services/bom-costing/bom-costing-structure-blueprint.ts b/furniture-3d-system/src/server/services/bom-costing/bom-costing-structure-blueprint.ts index af745e83..aa1857c8 100644 --- a/furniture-3d-system/src/server/services/bom-costing/bom-costing-structure-blueprint.ts +++ b/furniture-3d-system/src/server/services/bom-costing/bom-costing-structure-blueprint.ts @@ -140,9 +140,9 @@ const instantiationPayloadSchema = z.object({ const BOM_COSTING_STRUCTURE_CHECKPOINT_KIND = 'BOM_COSTING_STRUCTURE_CHECKPOINT' as const -// Version 9 invalidates instantiated SKU lines created before component-scoped -// material facts and primary-material inheritance were strictly separated. -const BOM_COSTING_STRUCTURE_CHECKPOINT_VERSION = 10 as const +// Version 11 invalidates instantiated lines created before the storage-trolley +// and split-table component/geometry contracts were made explicit. +const BOM_COSTING_STRUCTURE_CHECKPOINT_VERSION = 11 as const const bomCostingStructureCheckpointSchema = z.object({ kind: z.literal(BOM_COSTING_STRUCTURE_CHECKPOINT_KIND), @@ -801,7 +801,9 @@ const MATERIAL_DESCRIPTOR_PATTERNS = [ { pattern: /FAS\s*级?\s*橡木/i, descriptor: 'FAS级橡木', family: 'OAK' }, { pattern: /橡胶木/i, descriptor: '橡胶木', family: 'RUBBER_WOOD' }, { pattern: /胡桃木/i, descriptor: '胡桃木', family: 'WALNUT' }, - { pattern: /橡木/i, descriptor: '橡木', family: 'OAK' }, + { pattern: /南洋橡木芯板/i, descriptor: '南洋橡木芯板', family: 'OAK_CORE_BOARD' }, + { pattern: /楹木芯板|楹木/i, descriptor: '楹木芯板', family: 'YING_WOOD_CORE_BOARD' }, + { pattern: /橡木(?!芯板)/i, descriptor: '橡木', family: 'OAK' }, { pattern: /碳化杨木/i, descriptor: '碳化杨木', family: 'POPLAR' }, { pattern: /杨木/i, descriptor: '杨木', family: 'POPLAR' }, { pattern: /松木/i, descriptor: '松木', family: 'PINE' }, @@ -810,9 +812,11 @@ const MATERIAL_DESCRIPTOR_PATTERNS = [ { pattern: /密度板/i, descriptor: '密度板', family: 'MDF' }, { pattern: /刨花板/i, descriptor: '刨花板', family: 'PARTICLE_BOARD' }, { pattern: /实木/i, descriptor: '实木', family: 'SOLID_WOOD' }, + { pattern: /冷轧钢/i, descriptor: '冷轧钢', family: 'COLD_ROLLED_STEEL' }, { pattern: /不锈钢/i, descriptor: '不锈钢', family: 'STAINLESS_STEEL' }, { pattern: /碳钢/i, descriptor: '碳钢', family: 'CARBON_STEEL' }, { pattern: /铝合金/i, descriptor: '铝合金', family: 'ALUMINUM' }, + { pattern: /藤编|天然藤|藤条/i, descriptor: '藤编', family: 'RATTAN' }, ] as const function materialDescriptorsFromText(text: string) { @@ -867,7 +871,7 @@ function canInheritPrimaryMaterial( type MaterialFactRecord = ReturnType[number] const PRIMARY_MATERIAL_SUBJECT = - /主材|主体材质|主体材料|主要材质|主料|柜体材质|框架材质|台面材质|座面材质/i + /主材|主体材质|主体材料|主要材质|主料|柜体材质|台面材质|桌板材质|桌面板材|桌面及产品用料|座面材质/i const AUXILIARY_MATERIAL_SUBJECT = /辅材|辅助材质|次要材质|包材|包装材质/i const COMPONENT_MATERIAL_TERM_GROUPS = [ @@ -878,7 +882,7 @@ const COMPONENT_MATERIAL_TERM_GROUPS = [ ['层板', '隔板', '搁板', '置物板'], ['门板', '柜门'], ['抽屉', '抽盒'], - ['桌面', '台面'], + ['桌面', '台面', '桌板'], ['桌腿', '支腿', '椅腿', '凳腿', '腿架', '底座', '立柱', '侧架', '支柱'], ['围板', '横撑', '斜撑', '桌架', '下框', '座框', '拉条'], ['延伸板', '活动桌板'], @@ -892,6 +896,18 @@ const COMPONENT_MATERIAL_TERM_GROUPS = [ ['轨道', '导轨'], ['铰链', '合页'], ['脚轮', '万向轮', '刹车轮'], + ['托盘', '置物盘', '上层台面'], + ['置物篮', '篮筐', '篮体', '置物框'], + ['藤编面板', '藤编篮侧面面板', '编织面', '篮侧面板'], + ['框架', '管架', '金属支架', '支撑杆'], + ['推行把手', '金属拉手', '推行杆'], + ['洞洞板', '挂孔板'], + ['网篮', '金属篮'], + ['理线盒', '走线盒'], + ['小挂钩'], + ['大挂钩'], + ['翻盖板', '后段板', '后侧盖板'], + ['X形桌架', 'X型桌架', 'X形侧架', 'X型侧架'], ] as const function materialFactText(record: MaterialFactRecord) { @@ -1139,8 +1155,56 @@ function hasExplicitSquareModuleEvidence(input: { }) } +function resolveTrustedSlotDimensionMm(input: { + slot: BomCostingStructureBlueprintV2['structureGroups'][number]['componentSlots'][number] + sku: MarketSkuSnapshot + factSnapshot: BomCostingSourceFactSnapshot + subjectPattern: RegExp +}) { + const allowedIds = new Set(input.slot.evidenceFactIds) + const values = listBomCostingFactRecords(input.factSnapshot) + .filter((record) => ( + allowedIds.has(record.factId) && + record.fact.kind === 'DIMENSION' && + record.fact.basis !== 'VISUAL_ESTIMATE' && + record.fact.confidence >= 0.75 && + factAppliesToSku(record, input.sku.externalSkuId) && + input.subjectPattern.test(record.fact.subject) + )) + .map(factMillimeters) + .filter((value): value is number => Boolean(value)) + const uniqueValues = Array.from(new Set(values)) + return uniqueValues.length === 1 ? uniqueValues[0] : undefined +} + +function resolveRearTopDepthMm(input: { + sku: MarketSkuSnapshot + factSnapshot: BomCostingSourceFactSnapshot + outerDepthMm?: number +}) { + if (!input.outerDepthMm) return undefined + const values = listBomCostingFactRecords(input.factSnapshot) + .filter((record) => { + if ( + record.fact.kind !== 'DIMENSION' || + record.fact.basis === 'VISUAL_ESTIMATE' || + record.fact.confidence < 0.75 || + !factAppliesToSku(record, input.sku.externalSkuId) + ) return false + const context = `${record.fact.subject} ${record.fact.value}` + return /后侧|后段|翻盖|理线区|加宽区域/.test(context) && /深/.test(context) + }) + .map(factMillimeters) + .filter((value): value is number => Boolean( + value && value > 0 && value < input.outerDepthMm!, + )) + const uniqueValues = Array.from(new Set(values)) + return uniqueValues.length === 1 ? uniqueValues[0] : undefined +} + function deterministicBoardGeometry(input: { slot: BomCostingStructureBlueprintV2['structureGroups'][number]['componentSlots'][number] + structureDifferenceKeys: readonly string[] quantity: number dimensions: { lengthMm?: number; widthMm?: number; heightMm?: number } internalDepthMm?: number @@ -1154,6 +1218,14 @@ function deterministicBoardGeometry(input: { const depth = input.internalDepthMm ?? input.dimensions.widthMm const height = input.dimensions.heightMm const verifiedHorizontal = input.verifiedDimensions.lengthMm + const hasSplitRearTop = input.structureDifferenceKeys.includes('SPLIT_REAR_FLIP_TOP') + const rearTopDepthMm = hasSplitRearTop + ? resolveRearTopDepthMm({ + sku: input.sku, + factSnapshot: input.factSnapshot, + outerDepthMm: input.dimensions.widthMm, + }) + : undefined switch (input.slot.componentKey) { case 'enclosure-side': return { lengthMm: height, widthMm: depth } case 'enclosure-top': @@ -1170,8 +1242,34 @@ function deterministicBoardGeometry(input: { : undefined, widthMm: depth, } - case 'surface-main': + case 'surface-main': return hasSplitRearTop + ? rearTopDepthMm && input.dimensions.widthMm + ? { + lengthMm: horizontal, + widthMm: input.dimensions.widthMm - rearTopDepthMm, + } + : {} + : { lengthMm: horizontal, widthMm: depth } + case 'surface-rear-flip-panel': return hasSplitRearTop + ? rearTopDepthMm + ? { lengthMm: horizontal, widthMm: rearTopDepthMm } + : {} + : {} case 'partition-shelf': return { lengthMm: horizontal, widthMm: depth } + case 'surface-upper-tray': return { + lengthMm: resolveTrustedSlotDimensionMm({ + slot: input.slot, + sku: input.sku, + factSnapshot: input.factSnapshot, + subjectPattern: /(?:托盘|台面).*(?:长度|长)|(?:长度|长).*(?:托盘|台面)/, + }), + widthMm: resolveTrustedSlotDimensionMm({ + slot: input.slot, + sku: input.sku, + factSnapshot: input.factSnapshot, + subjectPattern: /(?:托盘|台面).*(?:宽度|宽|深度|深)|(?:宽度|宽|深度|深).*(?:托盘|台面)/, + }), + } case 'module-horizontal-panel': return { // A module's top/bottom panel uses the explicitly observed module width // and depth. Model dimensions must not turn the whole product height into @@ -1253,6 +1351,7 @@ function normalizeInstantiatedSku(input: { const geometry = slot.category === 'BOARD' ? deterministicBoardGeometry({ slot, + structureDifferenceKeys: input.group.structureDifferenceKeys, quantity, dimensions, internalDepthMm, @@ -1266,7 +1365,18 @@ function normalizeInstantiatedSku(input: { const deterministicFaceGeometryOnly = [ 'module-side-panel', 'module-horizontal-panel', - ].includes(slot.componentKey) + 'surface-upper-tray', + 'surface-rear-flip-panel', + ].includes(slot.componentKey) || ( + slot.componentKey === 'surface-main' && + input.group.structureDifferenceKeys.includes('SPLIT_REAR_FLIP_TOP') + ) + // Steel and accessory dimensions are component specifications, never a + // safe inference from the product envelope. Until a trusted direct fact + // is wired for a component, the model must not invent a cut length, + // wheel size, fitting envelope, or accessory dimensions. + const factOnlyGeometry = deterministicFaceGeometryOnly || + slot.category === 'STEEL' || slot.category === 'ACCESSORY' const explicitThicknessMm = slot.category === 'BOARD' ? resolveSlotThicknessMm({ slot, sku: input.sku, factSnapshot: input.factSnapshot }) : undefined @@ -1296,13 +1406,13 @@ function normalizeInstantiatedSku(input: { // but cannot override dimensions derived from the SKU's outer size. lengthMm: slot.category === 'BOARD' ? geometry.lengthMm ?? (deterministicFaceGeometryOnly ? undefined : modelLine?.lengthMm) - : modelLine?.lengthMm, + : factOnlyGeometry ? undefined : modelLine?.lengthMm, widthMm: slot.category === 'BOARD' ? geometry.widthMm ?? (deterministicFaceGeometryOnly ? undefined : modelLine?.widthMm) - : modelLine?.widthMm, + : factOnlyGeometry ? undefined : modelLine?.widthMm, heightMm: slot.category === 'BOARD' ? explicitThicknessMm ?? (deterministicFaceGeometryOnly ? undefined : modelLine?.heightMm) - : modelLine?.heightMm, + : factOnlyGeometry ? undefined : modelLine?.heightMm, descriptor, evidenceFactIds: ['BOARD', 'STEEL', 'ACCESSORY'].includes(slot.category) ? sanitizePhysicalMaterialEvidenceFactIds({ diff --git a/furniture-3d-system/src/server/services/bom-costing/bom-costing-structure-knowledge.ts b/furniture-3d-system/src/server/services/bom-costing/bom-costing-structure-knowledge.ts index a54fe75c..6bc6663d 100644 --- a/furniture-3d-system/src/server/services/bom-costing/bom-costing-structure-knowledge.ts +++ b/furniture-3d-system/src/server/services/bom-costing/bom-costing-structure-knowledge.ts @@ -26,7 +26,7 @@ import { } from './category-skills' export const BOM_COSTING_STRUCTURE_KNOWLEDGE_VERSION = - 'structure-priors/2026-08-13-v6' as const + 'structure-priors/2026-08-13-v7' as const export type BomCostingStructureSlotPrior = BomCostingCategoryComponentDefinition @@ -65,7 +65,10 @@ function findSlotFacts( return listBomCostingFactRecords(facts) .flatMap((record): SlotFactMatch[] => { if (!bomCostingFactAppliesToAnySku(record, skuIds)) return [] - if (!slot.keywords.some((keyword) => factTextForSlot(record).includes(normalize(keyword)))) return [] + const bindingKeywords = record.fact.kind === 'MATERIAL' + ? [...slot.keywords, ...(slot.materialKeywords ?? [])] + : slot.keywords + if (!bindingKeywords.some((keyword) => factTextForSlot(record).includes(normalize(keyword)))) return [] const scopedSkuIds = getBomCostingFactScopedSkuIds(record) const directEvidence = record.fact.basis !== 'VISUAL_ESTIMATE' const isSkuSpecific = scopedSkuIds.length === 1 && skuIdSet.has(scopedSkuIds[0]!) @@ -133,6 +136,9 @@ function hasGroupScopedActivationEvidence( // resolved by the category Skill into structureDifferenceKeys; raw // comparison prose must never activate an optional component directly. record.fact.kind === 'SKU_DIFFERENCE' || + // Material evidence may describe an already selected component, but a + // material name alone cannot prove that optional topology exists. + record.fact.kind === 'MATERIAL' || record.fact.basis === 'VISUAL_ESTIMATE' || record.fact.confidence < 0.55 ) continue diff --git a/furniture-3d-system/src/server/services/bom-costing/bom-costing-titan-a3-table.integration.test.ts b/furniture-3d-system/src/server/services/bom-costing/bom-costing-titan-a3-table.integration.test.ts new file mode 100644 index 00000000..96789bc8 --- /dev/null +++ b/furniture-3d-system/src/server/services/bom-costing/bom-costing-titan-a3-table.integration.test.ts @@ -0,0 +1,330 @@ +/** @jest-environment node */ + +import type { BomCostingMultimodalProviderConfig } from './bom-costing-multimodal-gateway' +import { buildStructuredBomCostingAnalysis } from './bom-costing-structure-blueprint' +import { + buildBomCostingCategoryGroupingKeys, + buildBomCostingCategorySkillContext, + selectBomCostingCategorySkill, +} from './category-skills' +import { buildDeterministicStructureBlueprint } from './bom-costing-structure-knowledge' +import { + PRODUCTION_TITAN_A3_REQUIRED_COMPONENT_KEYS, + PRODUCTION_TITAN_A3_STRUCTURE_DIFFERENCE_KEYS, + PRODUCTION_TITAN_A3_TABLE_6_SKUS, + buildProductionTitanA3Table6FactSnapshot, + buildProductionTitanA3Table6Snapshot, +} from './test-fixtures/production-titan-a3-table-6.fixture' + +const config: BomCostingMultimodalProviderConfig = { + baseUrl: 'https://ai.example.com/v1', + apiKey: 'test-key', + model: 'test-vision', +} + +describe('BOM TABLE v2 泰坦 A3 六 SKU 生产形态回归', () => { + afterEach(() => { + jest.restoreAllMocks() + }) + + it('六个真实 SKU 共用完整结构,按两种表面拆成本族且主材冲突保持未决', () => { + const snapshot = buildProductionTitanA3Table6Snapshot() + const factSnapshot = buildProductionTitanA3Table6FactSnapshot() + const selection = selectBomCostingCategorySkill( + buildBomCostingCategorySkillContext({ snapshot, factSnapshot }), + ) + + expect(selection.status).toBe('SUPPORTED') + expect(selection.skill).toMatchObject({ + code: 'TABLE', + version: 'bom-category-skill/table/v2', + }) + + const groupingBySkuId = new Map(snapshot.skus.map((sku) => [ + sku.externalSkuId, + buildBomCostingCategoryGroupingKeys({ + skill: selection.skill!, + snapshot, + sku, + factSnapshot, + }), + ] as const)) + expect(groupingBySkuId.size).toBe(PRODUCTION_TITAN_A3_TABLE_6_SKUS.length) + expect(new Set(Array.from(groupingBySkuId.values()).map( + (grouping) => grouping.structureGroupKey, + )).size).toBe(1) + + for (const grouping of groupingBySkuId.values()) { + expect(grouping.structureDifferenceKeys) + .toEqual(PRODUCTION_TITAN_A3_STRUCTURE_DIFFERENCE_KEYS) + expect(grouping.materialFamily).toBe('') + expect(grouping.costDifferenceKeys).not.toEqual(expect.arrayContaining([ + 'MATERIAL_YING_WOOD_CORE_BOARD', + 'MATERIAL_OAK_CORE_BOARD', + 'MATERIAL_OAK', + 'MATERIAL_STEEL', + ])) + expect(grouping.grade).toBe('enf级') + } + + const blackSkuIds = PRODUCTION_TITAN_A3_TABLE_6_SKUS + .filter((sku) => sku.finish === '黑色碳纤维纹') + .map((sku) => sku.externalSkuId) + .sort() + const whiteSkuIds = PRODUCTION_TITAN_A3_TABLE_6_SKUS + .filter((sku) => sku.finish === '珍珠白') + .map((sku) => sku.externalSkuId) + .sort() + expect(Array.from(groupingBySkuId.entries()) + .filter(([, grouping]) => grouping.finish === '黑色碳纤维纹') + .map(([skuId]) => skuId) + .sort()).toEqual(blackSkuIds) + expect(Array.from(groupingBySkuId.entries()) + .filter(([, grouping]) => grouping.finish === '珍珠白') + .map(([skuId]) => skuId) + .sort()).toEqual(whiteSkuIds) + + const blueprint = buildDeterministicStructureBlueprint({ snapshot, factSnapshot }) + expect(blueprint.supportStatus).toBe('SUPPORTED') + expect(blueprint.categorySkill).toMatchObject({ + selectedSkillId: 'TABLE', + selectedSkillVersion: 'bom-category-skill/table/v2', + }) + expect(blueprint.structureGroups).toHaveLength(1) + const group = blueprint.structureGroups[0]! + expect(group.skuIds.slice().sort()).toEqual( + PRODUCTION_TITAN_A3_TABLE_6_SKUS.map((sku) => sku.externalSkuId).sort(), + ) + expect(group.structureDifferenceKeys) + .toEqual(PRODUCTION_TITAN_A3_STRUCTURE_DIFFERENCE_KEYS) + expect(group.costFamilies).toHaveLength(2) + expect(group.costFamilies.map((family) => family.finish).sort()) + .toEqual(['珍珠白', '黑色碳纤维纹'].sort()) + expect(group.costFamilies.every((family) => ( + family.grade === 'enf级' && family.materialFamily === '' + ))).toBe(true) + + const requiredSlots = group.componentSlots.filter((slot) => slot.required) + expect(requiredSlots).toHaveLength(PRODUCTION_TITAN_A3_REQUIRED_COMPONENT_KEYS.length) + expect(requiredSlots.map((slot) => slot.componentKey).sort()) + .toEqual([...PRODUCTION_TITAN_A3_REQUIRED_COMPONENT_KEYS].sort()) + expect(requiredSlots.map((slot) => slot.componentKey)).not.toEqual(expect.arrayContaining([ + 'support-leg', + 'support-apron', + ])) + expect(group.unresolvedQuestions).toHaveLength(0) + + const slotsByKey = new Map(requiredSlots.map((slot) => [slot.componentKey, slot] as const)) + expect(slotsByKey.get('support-x-side-frame')?.quantityPolicy.baseQuantity).toBe(2) + expect(slotsByKey.get('support-x-crossbar')?.quantityPolicy.baseQuantity).toBe(1) + expect(slotsByKey.get('hardware-pegboard-hook-small')?.quantityPolicy.baseQuantity).toBe(2) + expect(slotsByKey.get('hardware-pegboard-hook-large')?.quantityPolicy.baseQuantity).toBe(2) + expect(group.relations).toEqual(expect.arrayContaining([ + expect.objectContaining({ + fromComponentKey: 'support-x-side-frame', + toComponentKey: 'surface-main', + }), + expect.objectContaining({ + fromComponentKey: 'support-x-crossbar', + toComponentKey: 'support-x-side-frame', + }), + expect.objectContaining({ + fromComponentKey: 'motion-rear-flip-hinge', + toComponentKey: 'surface-rear-flip-panel', + }), + ])) + }) + + it('离线回退也按 12cm 后段深度拆桌板,且不为钢架和附件猜几何', async () => { + const snapshot = buildProductionTitanA3Table6Snapshot() + const factSnapshot = buildProductionTitanA3Table6FactSnapshot() + jest.spyOn(global, 'fetch').mockRejectedValue(new Error('offline fixture')) + + const { result, trace } = await buildStructuredBomCostingAnalysis({ + config, + sourceUrl: snapshot.detailUrl, + snapshot, + factSnapshot, + }) + + expect(trace.fallbackSkuIds.slice().sort()).toEqual( + PRODUCTION_TITAN_A3_TABLE_6_SKUS.map((sku) => sku.externalSkuId).sort(), + ) + expect(result.skus).toHaveLength(PRODUCTION_TITAN_A3_TABLE_6_SKUS.length) + for (const fixtureSku of PRODUCTION_TITAN_A3_TABLE_6_SKUS) { + const sku = result.skus.find((candidate) => ( + candidate.externalSkuId === fixtureSku.externalSkuId + ))! + expect(sku.dimensions).toMatchObject({ + lengthMm: fixtureSku.lengthMm, + widthMm: fixtureSku.depthMm, + heightMm: fixtureSku.heightMm, + }) + expect(sku.bomLines).toHaveLength(PRODUCTION_TITAN_A3_REQUIRED_COMPONENT_KEYS.length) + const linesByKey = new Map(sku.bomLines.map((line) => [line.externalLineId, line] as const)) + expect(linesByKey.get('surface-main')).toMatchObject({ + quantity: 1, + unit: '块', + lengthMm: fixtureSku.lengthMm, + widthMm: 630, + }) + expect(linesByKey.get('surface-rear-flip-panel')).toMatchObject({ + quantity: 1, + unit: '块', + lengthMm: fixtureSku.lengthMm, + widthMm: 120, + }) + expect(linesByKey.get('support-x-side-frame')).toMatchObject({ + quantity: 2, + unit: '组', + materialName: '冷轧钢', + }) + expect(linesByKey.get('support-x-crossbar')).toMatchObject({ + quantity: 1, + unit: '根', + }) + expect(linesByKey.get('hardware-pegboard-hook-small')).toMatchObject({ + quantity: 2, + unit: '个', + }) + expect(linesByKey.get('hardware-pegboard-hook-large')).toMatchObject({ + quantity: 2, + unit: '个', + }) + + for (const componentKey of [ + 'support-x-side-frame', + 'support-x-crossbar', + 'motion-rear-flip-hinge', + 'storage-pegboard', + 'storage-metal-mesh-basket', + 'hardware-cable-box', + 'hardware-pegboard-hook-small', + 'hardware-pegboard-hook-large', + ]) { + expect(linesByKey.get(componentKey)).toEqual(expect.objectContaining({ + lengthMm: undefined, + widthMm: undefined, + heightMm: undefined, + })) + } + expect(linesByKey.get('support-x-crossbar')?.materialName).toBeUndefined() + expect(linesByKey.get('storage-metal-mesh-basket')?.materialName).toBeUndefined() + expect(linesByKey.get('storage-pegboard')?.materialName).toBeUndefined() + expect(linesByKey.get('surface-main')?.materialName).toBeUndefined() + expect(linesByKey.get('surface-rear-flip-panel')?.materialName).toBeUndefined() + } + }) + + it('只有泛翻盖、网格纹和黑白颜色词时不生成泰坦专属槽位', () => { + const snapshot = buildProductionTitanA3Table6Snapshot() + snapshot.title = '黑白网格纹电脑桌 搭配翻盖手机壳展示图' + snapshot.skus = snapshot.skus.slice(0, 1).map((sku) => ({ + ...sku, + name: '黑白网格纹普通四腿电脑桌', + size: '1400×750×750mm', + attributes: { 规格: '1400×750×750mm', 颜色: '黑白' }, + })) + const factSnapshot = buildProductionTitanA3Table6FactSnapshot() + factSnapshot.imageFacts = [] + + const selection = selectBomCostingCategorySkill( + buildBomCostingCategorySkillContext({ snapshot, factSnapshot }), + ) + expect(selection.skill?.code).toBe('TABLE') + const grouping = buildBomCostingCategoryGroupingKeys({ + skill: selection.skill!, + snapshot, + sku: snapshot.skus[0]!, + factSnapshot, + }) + expect(grouping.structureDifferenceKeys).not.toEqual(expect.arrayContaining([ + ...PRODUCTION_TITAN_A3_STRUCTURE_DIFFERENCE_KEYS, + ])) + + const requiredKeys = buildDeterministicStructureBlueprint({ snapshot, factSnapshot }) + .structureGroups[0]!.componentSlots + .filter((slot) => slot.required) + .map((slot) => slot.componentKey) + expect(requiredKeys).not.toEqual(expect.arrayContaining([ + 'support-x-side-frame', + 'support-x-crossbar', + 'surface-rear-flip-panel', + 'motion-rear-flip-hinge', + 'storage-pegboard', + 'storage-metal-mesh-basket', + 'hardware-cable-box', + 'hardware-pegboard-hook-small', + 'hardware-pegboard-hook-large', + ])) + }) + + it('普通四腿桌的桌腿材质事实只赋材质,不激活 X 形桌架拓扑', () => { + const snapshot = buildProductionTitanA3Table6Snapshot() + snapshot.title = '冷轧钢四腿电脑桌' + snapshot.skus = snapshot.skus.slice(0, 1).map((sku) => ({ + ...sku, + name: '冷轧钢四腿普通电脑桌', + })) + const factSnapshot = buildProductionTitanA3Table6FactSnapshot() + factSnapshot.imageFacts = factSnapshot.imageFacts.map((imageFact) => ({ + ...imageFact, + facts: imageFact.facts.filter((fact) => ( + fact.factId === 'titan-a3-leg-material' || + fact.factId.startsWith('titan-a3-size-') + )), + })) + + const selection = selectBomCostingCategorySkill( + buildBomCostingCategorySkillContext({ snapshot, factSnapshot }), + ) + const tableCandidate = selection.candidates.find((candidate) => candidate.code === 'TABLE')! + expect(tableCandidate.structureDraft.components.map((component) => component.componentKey)) + .not.toEqual(expect.arrayContaining(['support-x-side-frame', 'support-x-crossbar'])) + expect(tableCandidate.structureDraft.relations).not.toEqual(expect.arrayContaining([ + expect.objectContaining({ status: 'DANGLING' }), + ])) + + const blueprint = buildDeterministicStructureBlueprint({ snapshot, factSnapshot }) + const group = blueprint.structureGroups[0]! + expect(group.structureDifferenceKeys).toContain('FOUR_LEG_BASE') + expect(group.structureDifferenceKeys).not.toContain('METAL_X_FRAME_BASE') + const requiredKeys = group.componentSlots + .filter((slot) => slot.required) + .map((slot) => slot.componentKey) + expect(requiredKeys).toEqual(expect.arrayContaining(['support-leg', 'support-apron'])) + expect(requiredKeys).not.toEqual(expect.arrayContaining([ + 'support-x-side-frame', + 'support-x-crossbar', + ])) + }) + + it('缺少可信后段深度时两块桌板都保持不可下料,不拿整机深度或模型猜测补齐', async () => { + const snapshot = buildProductionTitanA3Table6Snapshot() + snapshot.skus = snapshot.skus.slice(0, 1) + const factSnapshot = buildProductionTitanA3Table6FactSnapshot() + factSnapshot.imageFacts = factSnapshot.imageFacts.map((imageFact) => ({ + ...imageFact, + facts: imageFact.facts.filter((fact) => fact.factId !== 'titan-a3-rear-depth'), + })) + jest.spyOn(global, 'fetch').mockRejectedValue(new Error('offline fixture')) + + const { result } = await buildStructuredBomCostingAnalysis({ + config, + sourceUrl: snapshot.detailUrl, + snapshot, + factSnapshot, + }) + + const linesByKey = new Map(result.skus[0]!.bomLines.map((line) => [ + line.externalLineId, + line, + ] as const)) + for (const componentKey of ['surface-main', 'surface-rear-flip-panel']) { + expect(linesByKey.get(componentKey)).toEqual(expect.objectContaining({ + lengthMm: undefined, + widthMm: undefined, + })) + } + }) +}) diff --git a/furniture-3d-system/src/server/services/bom-costing/bom-costing.service.test.ts b/furniture-3d-system/src/server/services/bom-costing/bom-costing.service.test.ts index 7605ad29..2c1f3380 100644 --- a/furniture-3d-system/src/server/services/bom-costing/bom-costing.service.test.ts +++ b/furniture-3d-system/src/server/services/bom-costing/bom-costing.service.test.ts @@ -799,15 +799,35 @@ describe('BomCostingService', () => { }) }) - it('全局 ruleset 已是 v7 时,柜体 Skill v1 仍标记为旧结果并隐藏成本', async () => { + it.each([ + { + caseId: 'case-cabinet-skill-v1', + skillId: 'CABINET_BOOKSHELF', + skillVersion: 'bom-category-skill/cabinet-bookshelf/v1', + }, + { + caseId: 'case-storage-rack-skill-v1', + skillId: 'STORAGE_RACK', + skillVersion: 'bom-category-skill/storage-rack/v1', + }, + { + caseId: 'case-table-skill-v1', + skillId: 'TABLE', + skillVersion: 'bom-category-skill/table/v1', + }, + ])('全局 ruleset 已是 v7 时,$caseId 仍标记为旧结果并隐藏成本', async ({ + caseId, + skillId, + skillVersion, + }) => { jest.spyOn(bomCostingRepository, 'listCases').mockResolvedValue([ buildReadyCaseSummaryRecord({ - caseId: 'case-cabinet-skill-v1', + caseId, analysisRuns: [{ revision: 1, status: 'READY', - resolvedCategorySkillId: 'CABINET_BOOKSHELF', - resolvedCategorySkillVersion: 'bom-category-skill/cabinet-bookshelf/v1', + resolvedCategorySkillId: skillId, + resolvedCategorySkillVersion: skillVersion, resolvedStructureKnowledgeVersion: BOM_COSTING_STRUCTURE_KNOWLEDGE_VERSION, }], }), @@ -878,6 +898,16 @@ describe('BomCostingService', () => { skillId: 'WARDROBE', skillVersion: 'bom-category-skill/wardrobe/v1', }, + { + caseId: 'case-storage-rack-skill-v2', + skillId: 'STORAGE_RACK', + skillVersion: 'bom-category-skill/storage-rack/v2', + }, + { + caseId: 'case-table-skill-v2', + skillId: 'TABLE', + skillVersion: 'bom-category-skill/table/v2', + }, ])('$caseId 使用当前 Skill 版本时保持可编辑并展示成本', async ({ caseId, skillId, @@ -905,6 +935,10 @@ describe('BomCostingService', () => { }) it.each([ + { + label: '旧 v6', + knowledgeVersion: 'structure-priors/2026-08-13-v6', + }, { label: '旧 v4', knowledgeVersion: 'structure-priors/2026-08-13-v4', diff --git a/furniture-3d-system/src/server/services/bom-costing/category-skills/registry.ts b/furniture-3d-system/src/server/services/bom-costing/category-skills/registry.ts index 1aa67ed2..1ad47d11 100644 --- a/furniture-3d-system/src/server/services/bom-costing/category-skills/registry.ts +++ b/furniture-3d-system/src/server/services/bom-costing/category-skills/registry.ts @@ -121,7 +121,7 @@ interface SkuGroupingFactEvidence { materialOnly: boolean } -const PRIMARY_MATERIAL_ROLE = /(?:主材|主体材质|主体材料|主要材质|主料|柜体材质|框架材质|台面材质|座面材质)/ +const PRIMARY_MATERIAL_ROLE = /(?:主材|主体材质|主体材料|主要材质|主料|柜体材质|台面材质|桌板材质|桌面板材|桌面及产品用料|座面材质)/ const AUXILIARY_MATERIAL_ROLE = /(?:辅材|辅助材质|次要材质|背板材质|抽屉材质|五金材质|连接件材质|包材|包装材质)/ function readMaterialRole(subject: string): MaterialRole { @@ -211,6 +211,19 @@ function buildPublicMaterialText(input: BomCostingCategoryGroupingInput) { return normalizeText(input.snapshot.title) } +function buildPublicMaterialFactText(input: BomCostingCategoryGroupingInput) { + if (!input.factSnapshot) return '' + return normalizeText(listBomCostingFactRecords(input.factSnapshot) + .filter((record) => ( + isBomCostingFactUnscoped(record) && + record.fact.kind === 'MATERIAL' && + record.fact.basis !== 'VISUAL_ESTIMATE' && + record.fact.confidence >= 0.75 + )) + .map(({ fact }) => `${fact.subject} ${fact.value}`) + .join(' ')) +} + export function buildBomCostingCategorySkillContext(input: { snapshot: BomCostingCategorySkillContext['snapshot'] factSnapshot?: BomCostingCategorySkillContext['factSnapshot'] @@ -313,9 +326,15 @@ function buildCandidateStructureDraft( context: BomCostingCategorySkillContext, definitionIssues: readonly string[], ): BomCostingCategoryCandidateStructureDraft { + const topologyFactText = normalizeText(context.factSnapshot + ? listBomCostingFactRecords(context.factSnapshot) + .filter(({ fact }) => fact.kind !== 'MATERIAL') + .map(({ fact }) => `${fact.subject} ${fact.value} ${fact.note ?? ''}`) + .join(' ') + : '') const skuAndFactText = normalizeText([ ...context.skuTexts.values(), - context.factText, + topologyFactText, ].join(' ')) const evidenceText = normalizeText([ context.productText, @@ -931,6 +950,8 @@ function readMaterialFamily(costKeys: readonly string[]) { const mapping: Record = { MATERIAL_ASH_WOOD: '白蜡木', MATERIAL_OAK: '橡木', + MATERIAL_YING_WOOD_CORE_BOARD: '楹木芯板', + MATERIAL_OAK_CORE_BOARD: '南洋橡木芯板', MATERIAL_RUBBER_WOOD: '橡胶木', MATERIAL_PINE: '松木', MATERIAL_POPLAR: '杨木', @@ -942,6 +963,7 @@ function readMaterialFamily(costKeys: readonly string[]) { function readGradeValues(text: string) { return unique([ + ...Array.from(text.matchAll(/enf级?/gi), () => 'enf级'), ...Array.from(text.matchAll(/fas级/gi), (match) => match[0]), ...Array.from(text.matchAll(/[abc]级/gi), (match) => match[0]), ...Array.from(text.matchAll(/一级/gi), (match) => match[0]), @@ -955,6 +977,8 @@ function readGrade(text: string) { function readFinishValues(text: string) { return unique([ + ...Array.from(text.matchAll(/黑色?碳纤维纹/gi), () => '黑色碳纤维纹'), + ...Array.from(text.matchAll(/珍珠白/gi), () => '珍珠白'), ...Array.from(text.matchAll(/木蜡油/gi), (match) => match[0]), ...Array.from(text.matchAll(/清漆/gi), (match) => match[0]), ...Array.from(text.matchAll(/开放漆/gi), (match) => match[0]), @@ -978,6 +1002,7 @@ export function buildBomCostingCategoryGroupingKeys( const skuText = `${skuIdentityText}${skuFactText}` const publicText = buildTrustedProductWideStructureText(input) const publicMaterialText = buildPublicMaterialText(input) + const publicMaterialFactText = buildPublicMaterialFactText(input) const differences = resolveDifferences( input.skill, skuIdentityText, @@ -995,7 +1020,7 @@ export function buildBomCostingCategoryGroupingKeys( const costToken = costDifferences.map((difference) => difference.token).join('.') || 'base' const prefix = input.skill.code.toLocaleLowerCase('en-US').replace(/_/g, '-') const materialFamily = readMaterialFamily(costDifferences.map((difference) => difference.differenceKey)) - const publicGrades = readGradeValues(publicText) + const publicGrades = readGradeValues(`${publicText} ${publicMaterialFactText}`) const publicFinishes = readFinishValues(publicText) const grade = readGrade(skuText) || (publicGrades.length === 1 ? publicGrades[0]! : '') const finish = readFinish(skuText) || (publicFinishes.length === 1 ? publicFinishes[0]! : '') diff --git a/furniture-3d-system/src/server/services/bom-costing/category-skills/shared.ts b/furniture-3d-system/src/server/services/bom-costing/category-skills/shared.ts index 7d51bc8e..2eff3a45 100644 --- a/furniture-3d-system/src/server/services/bom-costing/category-skills/shared.ts +++ b/furniture-3d-system/src/server/services/bom-costing/category-skills/shared.ts @@ -67,10 +67,29 @@ export const COMMON_MATERIAL_DIFFERENCES = [ token: 'oak', groupKind: 'COST', terms: ['橡木', '白橡', '红橡'], + excludedTerms: ['橡木芯板', '南洋橡木芯板'], exclusiveGroup: 'MATERIAL', priority: 90, description: '橡木材质进入独立成本组。', }, + { + differenceKey: 'MATERIAL_YING_WOOD_CORE_BOARD', + token: 'ying-wood-core-board', + groupKind: 'COST', + terms: ['楹木芯板', '楹木'], + exclusiveGroup: 'MATERIAL', + priority: 120, + description: '楹木或楹木芯板进入独立成本组,不与橡木实木混用。', + }, + { + differenceKey: 'MATERIAL_OAK_CORE_BOARD', + token: 'oak-core-board', + groupKind: 'COST', + terms: ['南洋橡木芯板', '橡木芯板'], + exclusiveGroup: 'MATERIAL', + priority: 125, + description: '南洋橡木芯板进入独立成本组,不冒充橡木实木。', + }, { differenceKey: 'MATERIAL_RUBBER_WOOD', token: 'rubber-wood', @@ -125,6 +144,9 @@ export const COMMON_HISTORICAL_FEATURES = [ terms: [ '白蜡木', '橡木', + '楹木', + '楹木芯板', + '南洋橡木芯板', '橡胶木', '松木', '杨木', diff --git a/furniture-3d-system/src/server/services/bom-costing/category-skills/storage-rack.skill.test.ts b/furniture-3d-system/src/server/services/bom-costing/category-skills/storage-rack.skill.test.ts new file mode 100644 index 00000000..aa6ba72a --- /dev/null +++ b/furniture-3d-system/src/server/services/bom-costing/category-skills/storage-rack.skill.test.ts @@ -0,0 +1,122 @@ +/** @jest-environment node */ + +import { getBomCostingCategorySkillDefinitionIssues } from './registry' +import { storageRackCategorySkill } from './storage-rack.skill' + +describe('置物架品类 Skill v2', () => { + it('只用可信的组合拓扑切换移动双层推车主体', () => { + expect(storageRackCategorySkill.version).toBe('bom-category-skill/storage-rack/v2') + expect(getBomCostingCategorySkillDefinitionIssues(storageRackCategorySkill)).toEqual([]) + + const mobileDifference = storageRackCategorySkill.differences.find( + (difference) => difference.differenceKey === 'MOBILE_TROLLEY_RACK', + ) + expect(mobileDifference).toMatchObject({ + exclusiveGroup: 'RACK_BODY_MODE', + priority: 220, + allowProductWide: true, + }) + expect(mobileDifference?.terms).toEqual(expect.arrayContaining([ + '上层托盘和下层置物篮由金属管架支撑', + '橡木置物板和篮筐安装于不锈钢框架上', + ])) + expect(mobileDifference?.terms).not.toEqual(expect.arrayContaining([ + '移动推车', + '移动边几', + '双层置物', + '金属框架', + '藤编', + ])) + + const tierTwo = storageRackCategorySkill.differences.find( + (difference) => difference.differenceKey === 'TIER_COUNT_2', + ) + expect(tierTwo).toMatchObject({ + exclusiveGroup: 'TIER_COUNT', + allowProductWide: true, + }) + expect(tierTwo?.terms).toContain('双层置物') + }) + + it('移动推车以一个可裁切上托盘、一个复合篮框和独立藤编/金属槽位表达', () => { + const requiredByKey = new Map(storageRackCategorySkill.requiredComponents.map( + (component) => [component.componentKey, component] as const, + )) + for (const componentKey of [ + 'support-upright', + 'partition-shelf', + 'support-cross-brace', + ]) { + expect(requiredByKey.get(componentKey)?.excludedWhenStructureKeys) + .toEqual(['MOBILE_TROLLEY_RACK']) + } + + const optionalByKey = new Map(storageRackCategorySkill.optionalComponents.map( + (component) => [component.componentKey, component] as const, + )) + expect(optionalByKey.get('surface-upper-tray')).toMatchObject({ + role: 'SURFACE', + category: 'BOARD', + unit: '块', + stableQuantity: 1, + primaryMaterialSlot: true, + requiredWhenStructureKeys: ['MOBILE_TROLLEY_RACK'], + }) + expect(optionalByKey.get('frame-lower-basket')).toMatchObject({ + role: 'ENCLOSURE', + category: 'ACCESSORY', + unit: '套', + stableQuantity: 1, + requiredWhenStructureKeys: ['MOBILE_TROLLEY_RACK'], + }) + expect(optionalByKey.get('frame-lower-basket')).not.toHaveProperty( + 'primaryMaterialSlot', + ) + expect(optionalByKey.get('cover-rattan-panel')).toMatchObject({ + role: 'COVER', + category: 'ACCESSORY', + unit: '套', + stableQuantity: 1, + requiredWhenStructureKeys: ['MOBILE_TROLLEY_RACK'], + }) + expect(optionalByKey.get('support-metal-upright')).toMatchObject({ + role: 'SUPPORT', + category: 'STEEL', + unit: '根', + stableQuantity: 4, + requiredWhenStructureKeys: ['MOBILE_TROLLEY_RACK'], + }) + expect(optionalByKey.get('support-push-handle')).toMatchObject({ + category: 'STEEL', + stableQuantity: 1, + requiredWhenStructureKeys: ['MOBILE_TROLLEY_RACK'], + }) + }) + + it('脚轮与固定脚互斥,带轮结构直接排除固定脚槽位', () => { + const fixedBase = storageRackCategorySkill.differences.find( + (difference) => difference.differenceKey === 'FIXED_BASE', + ) + const casterBase = storageRackCategorySkill.differences.find( + (difference) => difference.differenceKey === 'CASTER_BASE', + ) + expect(fixedBase).toMatchObject({ + exclusiveGroup: 'MOBILITY_BASE', + priority: 220, + }) + expect(casterBase).toMatchObject({ + exclusiveGroup: 'MOBILITY_BASE', + priority: 200, + allowProductWide: true, + }) + expect(storageRackCategorySkill.requiredComponents.find( + (component) => component.componentKey === 'hardware-feet', + )?.excludedWhenStructureKeys).toEqual(['CASTER_BASE']) + expect(storageRackCategorySkill.optionalComponents.find( + (component) => component.componentKey === 'motion-caster', + )).toMatchObject({ + stableQuantity: 4, + requiredWhenStructureKeys: ['CASTER_BASE'], + }) + }) +}) diff --git a/furniture-3d-system/src/server/services/bom-costing/category-skills/storage-rack.skill.ts b/furniture-3d-system/src/server/services/bom-costing/category-skills/storage-rack.skill.ts index 41effd3c..86d407e9 100644 --- a/furniture-3d-system/src/server/services/bom-costing/category-skills/storage-rack.skill.ts +++ b/furniture-3d-system/src/server/services/bom-costing/category-skills/storage-rack.skill.ts @@ -10,21 +10,33 @@ const tierDifferences = [2, 3, 4, 5, 6, 7, 8].map((count) => ({ differenceKey: `TIER_COUNT_${count}`, token: `tier-${count}`, groupKind: 'STRUCTURE' as const, - terms: [`${count}层`, `${count}层架`, `${count}层置物架`], + terms: count === 2 + ? [ + '2层', + '2层架', + '2层置物架', + '二层置物架', + '双层置物', + '上层托盘和下层置物篮', + '上层托盘与下层置物篮', + ] + : [`${count}层`, `${count}层架`, `${count}层置物架`], exclusiveGroup: 'TIER_COUNT', priority: 100 + count, + ...(count === 2 ? { allowProductWide: true as const } : {}), description: `明确 ${count} 层时形成独立结构组。`, })) export const storageRackCategorySkill = { code: 'STORAGE_RACK', label: '置物架', - version: 'bom-category-skill/storage-rack/v1', + version: 'bom-category-skill/storage-rack/v2', priority: 350, minimumScore: 12, minimumMargin: 3, positiveSignals: [ { signalKey: 'storage-rack-explicit', terms: ['置物架', '储物架', '收纳架', '层架', '货架', '花架', '展示架'], weight: 22, reason: '商品明确属于开放式置物架。' }, + { signalKey: 'mobile-storage-trolley-topology', terms: ['上层托盘', '下层置物篮', '脚轮'], weight: 34, match: 'ALL', reason: '上层托盘、下层置物篮和脚轮共同构成移动置物推车,不按普通桌类处理。' }, { signalKey: 'rack-context', terms: ['厨房架', '浴室架', '桌面架', '落地架', '墙上架'], weight: 12, reason: '出现置物架典型使用形态。' }, { signalKey: 'rack-structure', terms: ['立柱', '层板', '横撑', '斜撑'], weight: 6, reason: '出现开放层架结构。' }, ], @@ -34,42 +46,59 @@ export const storageRackCategorySkill = { { signalKey: 'exclude-soft-rack', terms: ['布艺置物架', '塑料置物架'], weight: 25, reason: '软体或塑料成品不适用硬体架 Skill。', hard: true }, ], requiredComponents: [ - { componentKey: 'support-upright', role: 'SUPPORT', category: 'BOARD', partName: '立柱或侧架', stableQuantity: 4, unit: '件', quantityRule: '基础开放架固定 4 根立柱;双侧架结构组固定 2 组。', dimensionRule: '高度随整机高度,截面和壁厚必须单独取证。', materialScope: '木质或金属支撑。', keywords: ['立柱', '侧架', '支架'], quantityByStructureKey: { SIDE_FRAME: 2 } }, - { componentKey: 'partition-shelf', role: 'PARTITION', category: 'BOARD', partName: '置物层板', stableQuantity: 3, unit: '块', primaryMaterialSlot: true, quantityRule: '基础组固定 3 层;明确层数形成独立结构组。', dimensionRule: '长宽按层架开口与整机深度。', materialScope: '木质、板材或金属层板。', keywords: ['层板', '置物板', '搁板'], quantityByStructureKey: Object.fromEntries([2, 3, 4, 5, 6, 7, 8].map((count) => [`TIER_COUNT_${count}`, count])) }, - { componentKey: 'support-cross-brace', role: 'SUPPORT', category: 'STEEL', partName: '横撑与稳定件', stableQuantity: 2, unit: '件', quantityRule: '基础组固定 2 件横撑;斜撑结构按独立组冻结。', dimensionRule: '按立柱间净距和稳定关系推导。', materialScope: '木横撑、金属管或拉条。', keywords: ['横撑', '斜撑', '拉条'] }, - { componentKey: 'hardware-feet', role: 'HARDWARE', category: 'ACCESSORY', partName: '脚垫或调平脚', stableQuantity: 4, unit: '个', quantityRule: '按基础支撑点固定 4 个;侧架结构需专属事实调整。', dimensionRule: '规格无证据时待复核。', materialScope: '脚垫、调平脚和端塞。', keywords: ['脚垫', '调平脚', '端塞'] }, + { componentKey: 'support-upright', role: 'SUPPORT', category: 'BOARD', partName: '立柱或侧架', stableQuantity: 4, unit: '件', quantityRule: '基础开放架固定 4 根立柱;双侧架结构组固定 2 组。', dimensionRule: '高度随整机高度,截面和壁厚必须单独取证。', materialScope: '木质或金属支撑。', keywords: ['立柱', '侧架', '支架'], quantityByStructureKey: { SIDE_FRAME: 2 }, excludedWhenStructureKeys: ['MOBILE_TROLLEY_RACK'] }, + { componentKey: 'partition-shelf', role: 'PARTITION', category: 'BOARD', partName: '置物层板', stableQuantity: 3, unit: '块', primaryMaterialSlot: true, quantityRule: '基础组固定 3 层;明确层数形成独立结构组。', dimensionRule: '长宽按层架开口与整机深度。', materialScope: '木质、板材或金属层板。', keywords: ['层板', '置物板', '搁板'], quantityByStructureKey: Object.fromEntries([2, 3, 4, 5, 6, 7, 8].map((count) => [`TIER_COUNT_${count}`, count])), excludedWhenStructureKeys: ['MOBILE_TROLLEY_RACK'] }, + { componentKey: 'support-cross-brace', role: 'SUPPORT', category: 'STEEL', partName: '横撑与稳定件', stableQuantity: 2, unit: '件', quantityRule: '基础组固定 2 件横撑;斜撑结构按独立组冻结。', dimensionRule: '按立柱间净距和稳定关系推导。', materialScope: '木横撑、金属管或拉条。', keywords: ['横撑', '斜撑', '拉条'], excludedWhenStructureKeys: ['MOBILE_TROLLEY_RACK'] }, + { componentKey: 'hardware-feet', role: 'HARDWARE', category: 'ACCESSORY', partName: '脚垫或调平脚', stableQuantity: 4, unit: '个', quantityRule: '按基础支撑点固定 4 个;明确脚轮结构时不得同时生成固定脚。', dimensionRule: '规格无证据时待复核。', materialScope: '脚垫、调平脚和端塞。', keywords: ['脚垫', '调平脚', '端塞'], excludedWhenStructureKeys: ['CASTER_BASE'] }, CONNECTOR_COMPONENT, ...COMMON_COST_COMPONENTS, ], optionalComponents: [ - { componentKey: 'motion-caster', role: 'MOTION', category: 'ACCESSORY', partName: '脚轮组件', stableQuantity: 4, unit: '个', quantityRule: '带轮结构组固定 4 个;刹车轮分配需专属事实。', dimensionRule: '轮径和安装高度无证据时待复核。', materialScope: '脚轮、安装板和紧固件。', keywords: ['脚轮', '万向轮', '刹车轮'], requiredWhenStructureKeys: ['CASTER_BASE'] }, + { componentKey: 'surface-upper-tray', role: 'SURFACE', category: 'BOARD', partName: '上层木质托盘', stableQuantity: 1, unit: '块', primaryMaterialSlot: true, quantityRule: '移动双层置物推车固定 1 块上层托盘;拼板数量必须引用当前 SKU 事实。', dimensionRule: '长宽优先采用上层台面或托盘直接标注,不得用包含把手和框架的整机外廓替代。', materialScope: '上层托盘木质主体;没有更精确的槽位材质事实时继承整品木质 costFamily。', keywords: ['上层托盘', '上层台面', '台面净尺寸', '顶部台面尺寸', '托盘净尺寸', '木质托盘'], requiredWhenStructureKeys: ['MOBILE_TROLLEY_RACK'] }, + { componentKey: 'frame-lower-basket', role: 'ENCLOSURE', category: 'ACCESSORY', partName: '下层木质置物篮框', stableQuantity: 1, unit: '套', quantityRule: '移动双层置物推车固定 1 套下层置物篮木框;没有逐板事实时不得猜测拆板数量。', dimensionRule: '按下层篮筐直接尺寸或整套规格计价;仅有整机尺寸时保持待复核,禁止展开成虚构板件。', materialScope: '只绑定下层篮筐木材的精确事实;不得无证据继承整品 costFamily,藤编侧面由独立槽位计价。', keywords: ['下层篮筐木材', '下层置物篮', '下层置物框', '篮筐木材', '置物篮木框'], requiredWhenStructureKeys: ['MOBILE_TROLLEY_RACK'] }, + { componentKey: 'cover-rattan-panel', role: 'COVER', category: 'ACCESSORY', partName: '下层置物篮藤编面板', stableQuantity: 1, unit: '套', quantityRule: '生产移动双层置物推车按 1 套藤编篮侧面冻结;具体片数没有直接事实时不得拆分。', dimensionRule: '按篮筐侧面展开范围计价;长宽或展开面积没有直接证据时待复核。', materialScope: '仅绑定藤编、藤条或藤席事实,不得继承整品橡木或不锈钢材质。', keywords: ['藤编篮侧面面板', '藤编面板', '透气藤编', '藤条', '藤席'], requiredWhenStructureKeys: ['MOBILE_TROLLEY_RACK'] }, + { componentKey: 'support-metal-upright', role: 'SUPPORT', category: 'STEEL', partName: '不锈钢管状立柱与框架', stableQuantity: 4, unit: '根', quantityRule: '移动双层置物推车按四个落地支承点冻结 4 根金属立柱;框架分段数没有直接事实时不得扩大。', dimensionRule: '按金属管真实连续长度或明确分段长度计价,不得把整机高度重复计入每段框架。', materialScope: '不锈钢、碳钢或其他明确标注的金属框架,不得继承木质 costFamily。', keywords: ['框架材质', '金属管架', '金属管状立柱', '不锈钢框架', '不锈钢管', '金属立柱'], requiredWhenStructureKeys: ['MOBILE_TROLLEY_RACK'] }, + { componentKey: 'support-push-handle', role: 'SUPPORT', category: 'STEEL', partName: '推车把手', stableQuantity: 1, unit: '件', quantityRule: '明确移动双层推车拓扑固定 1 件把手;与立柱一体成型时仍只计实际材料长度,不重复计件。', dimensionRule: '按把手直接尺寸或金属管展开长度计价;无直接证据时待复核。', materialScope: '与金属框架一致,需绑定把手或框架材质事实。', keywords: ['推车把手', '扶手', '把手', '手柄'], materialKeywords: ['框架材质'], requiredWhenStructureKeys: ['MOBILE_TROLLEY_RACK'] }, + { componentKey: 'motion-caster', role: 'MOTION', category: 'ACCESSORY', partName: '脚轮组件', stableQuantity: 4, unit: '个', quantityRule: '带轮结构组固定 4 个;刹车轮分配需专属事实。', dimensionRule: '轮径和安装高度无证据时待复核。', materialScope: '仅绑定脚轮、安装板和紧固件事实,不继承木材或框架金属。', keywords: ['脚轮', '万向轮', '刹车轮', '移动轮'], requiredWhenStructureKeys: ['CASTER_BASE'] }, { componentKey: 'hardware-wall-mount', role: 'HARDWARE', category: 'ACCESSORY', partName: '上墙固定组件', stableQuantity: 1, unit: '套', quantityRule: '壁挂结构组固定 1 套。', dimensionRule: '安装孔距和墙体紧固件需按现场确认。', materialScope: '挂码、膨胀件和紧固件。', keywords: ['壁挂', '上墙', '挂墙'], requiredWhenStructureKeys: ['WALL_MOUNTED'] }, { componentKey: 'hardware-shelf-support', role: 'HARDWARE', category: 'ACCESSORY', partName: '可调层板托', stableQuantity: 4, unit: '个', quantityRule: '每块可调层板至少 4 个支承点;层板数量按当前组冻结。', dimensionRule: '孔距和规格无证据时待复核。', materialScope: '层板托和排孔件。', keywords: ['可调层板', '层板托', '排孔'], requiredWhenStructureKeys: ['ADJUSTABLE_SHELF'] }, ], relations: [ { relationType: 'SUPPORTS', fromComponentKey: 'support-upright', toComponentKey: 'partition-shelf', rule: '每块层板必须由立柱或侧架支承。' }, { relationType: 'CONNECTS', fromComponentKey: 'support-cross-brace', toComponentKey: 'support-upright', rule: '横撑或斜撑连接立柱并提供侧向稳定。' }, - { relationType: 'SUPPORTS', fromComponentKey: 'hardware-feet', toComponentKey: 'support-upright', rule: '脚垫或调平脚承接每个落地支撑点。' }, - { relationType: 'MOVES_WITH', fromComponentKey: 'motion-caster', toComponentKey: 'support-upright', rule: '脚轮安装在对应支撑点。' }, + { relationType: 'SUPPORTS', fromComponentKey: 'hardware-feet', toComponentKey: 'support-upright', rule: '普通固定架的脚垫或调平脚承接每个落地支撑点。' }, + { relationType: 'MOVES_WITH', fromComponentKey: 'motion-caster', toComponentKey: 'support-upright', rule: '普通带轮架的脚轮安装在对应支撑点。' }, + { relationType: 'SUPPORTS', fromComponentKey: 'support-metal-upright', toComponentKey: 'surface-upper-tray', rule: '移动双层置物推车的金属框架必须支承上层托盘。' }, + { relationType: 'SUPPORTS', fromComponentKey: 'support-metal-upright', toComponentKey: 'frame-lower-basket', rule: '移动双层置物推车的金属框架必须支承下层置物篮。' }, + { relationType: 'COVERS', fromComponentKey: 'cover-rattan-panel', toComponentKey: 'frame-lower-basket', rule: '藤编面板只覆盖下层置物篮侧面,不覆盖上层木质托盘。' }, + { relationType: 'CONNECTS', fromComponentKey: 'support-push-handle', toComponentKey: 'support-metal-upright', rule: '推车把手连接到金属框架,不能作为额外木质立柱。' }, + { relationType: 'CONNECTS', fromComponentKey: 'hardware-connectors', toComponentKey: 'support-metal-upright', rule: '连接件将金属框架与上下层木质主体可靠连接。' }, + { relationType: 'MOVES_WITH', fromComponentKey: 'motion-caster', toComponentKey: 'support-metal-upright', rule: '移动推车的四个脚轮安装在金属框架落地支承点。' }, + { relationType: 'SUPPORTS', fromComponentKey: 'hardware-feet', toComponentKey: 'support-metal-upright', rule: '无脚轮的同类金属框架由固定脚承接落地支承点。' }, { relationType: 'CONNECTS', fromComponentKey: 'hardware-wall-mount', toComponentKey: 'support-upright', rule: '壁挂组件将主体固定到墙体。' }, ], differences: [ ...tierDifferences, + { differenceKey: 'MOBILE_TROLLEY_RACK', token: 'mobile-trolley-rack', groupKind: 'STRUCTURE', terms: ['上层托盘和下层置物篮由金属管架支撑', '上层托盘与下层置物篮由金属管架支撑', '上层托盘通过两侧金属管状支架与下层置物箱连接', '上层托盘、下层置物篮和金属支撑框架组成', '橡木置物板和篮筐安装于不锈钢框架上', '上层托盘、下层置物框、金属管状立柱及推车把手'], excludedTerms: ['普通开放层架', '全木立柱层架'], exclusiveGroup: 'RACK_BODY_MODE', priority: 220, allowProductWide: true, description: '上层木托盘、下层置物篮由金属框架连接的移动推车主体;不得套用普通开放层架的立柱、层板和横撑。' }, { differenceKey: 'SIDE_FRAME', token: 'side-frame', groupKind: 'STRUCTURE', terms: ['双侧架', '两侧支架', '侧框架'], description: '双侧架结构按两组侧架冻结。' }, - { differenceKey: 'CASTER_BASE', token: 'caster', groupKind: 'STRUCTURE', terms: ['带轮', '脚轮', '万向轮', '推车式'], description: '脚轮替代固定脚,改变支撑附件。' }, + { differenceKey: 'FIXED_BASE', token: 'fixed-base', groupKind: 'STRUCTURE', terms: ['固定脚', '无脚轮', '不带脚轮'], exclusiveGroup: 'MOBILITY_BASE', priority: 220, description: '明确固定式底座时不得启用脚轮。' }, + { differenceKey: 'CASTER_BASE', token: 'caster-base', groupKind: 'STRUCTURE', terms: ['带轮', '四个脚轮', '四个万向脚轮', '底部安装脚轮', '底部配置脚轮', '脚轮', '万向轮', '刹车轮'], excludedTerms: ['固定脚', '无脚轮', '不带脚轮'], exclusiveGroup: 'MOBILITY_BASE', priority: 200, allowProductWide: true, description: '脚轮替代固定脚;商品级可信脚轮事实可应用于全部真实 SKU。' }, { differenceKey: 'WALL_MOUNTED', token: 'wall-mounted', groupKind: 'STRUCTURE', terms: ['壁挂', '挂墙', '上墙置物架'], description: '壁挂式需要专用固定组件。' }, { differenceKey: 'ADJUSTABLE_SHELF', token: 'adjustable', groupKind: 'STRUCTURE', terms: ['可调层板', '层高可调', '自由调节'], description: '可调层板需要层板托和排孔。' }, { differenceKey: 'FOLDING_RACK', token: 'folding', groupKind: 'STRUCTURE', terms: ['折叠置物架', '可折叠'], description: '折叠结构必须独立建组并复核转轴和锁止。' }, ...COMMON_MATERIAL_DIFFERENCES, ], validations: [ - { validationKey: 'rack-shelf-support', severity: 'ERROR', rule: '每块层板必须有立柱、侧架或墙体固定支承。', componentKeys: ['partition-shelf', 'support-upright', 'hardware-wall-mount'] }, - { validationKey: 'rack-stability', severity: 'ERROR', rule: '落地架必须有横撑、斜撑或等效稳定结构。', componentKeys: ['support-upright', 'support-cross-brace'] }, + { validationKey: 'rack-shelf-support', severity: 'ERROR', rule: '普通开放架的每块层板必须有立柱、侧架或墙体固定支承。', componentKeys: ['partition-shelf', 'support-upright', 'hardware-wall-mount'] }, + { validationKey: 'rack-stability', severity: 'ERROR', rule: '普通落地架必须有横撑、斜撑或等效稳定结构。', componentKeys: ['support-upright', 'support-cross-brace'] }, { validationKey: 'rack-stable-count', severity: 'ERROR', rule: '同结构组层板和支撑数量冻结;模型不能无 SKU 专属 factId 改数。', componentKeys: ['partition-shelf', 'support-upright'] }, + { validationKey: 'mobile-trolley-rack-closure', severity: 'ERROR', rule: '移动双层置物推车必须由上层托盘、下层篮筐、金属立柱框架和把手闭合;藤编面板只属于下层篮筐。', componentKeys: ['surface-upper-tray', 'frame-lower-basket', 'cover-rattan-panel', 'support-metal-upright', 'support-push-handle'] }, + { validationKey: 'mobile-trolley-caster-binding', severity: 'ERROR', rule: '明确 CASTER_BASE 时固定脚必须被排除,四个脚轮只安装到金属框架落地支承点。', componentKeys: ['motion-caster', 'support-metal-upright', 'hardware-feet'] }, ], historicalFeatures: [ { featureKey: 'rack-tier-count', label: '层数', kind: 'STRUCTURE', terms: ['层', '层板'], description: '历史候选必须优先同层数。' }, { featureKey: 'rack-installation', label: '落地/壁挂/带轮', kind: 'STRUCTURE', terms: ['落地', '壁挂', '带轮', '脚轮'], description: '安装形态决定支撑和五金。' }, + { featureKey: 'rack-body-mode', label: '普通层架/移动双层推车', kind: 'STRUCTURE', terms: ['上层托盘', '下层置物篮', '金属框架', '普通层架'], description: '历史候选必须保持主体拓扑一致,不能用普通木架替代双层推车。' }, { featureKey: 'rack-load-structure', label: '承重结构', kind: 'QUALITY', terms: ['承重', '横撑', '斜撑'], description: '承重营销值不能反推精确规格,但用于历史异常检查。' }, ...COMMON_HISTORICAL_FEATURES, ], diff --git a/furniture-3d-system/src/server/services/bom-costing/category-skills/table.skill.test.ts b/furniture-3d-system/src/server/services/bom-costing/category-skills/table.skill.test.ts new file mode 100644 index 00000000..25b5c6d2 --- /dev/null +++ b/furniture-3d-system/src/server/services/bom-costing/category-skills/table.skill.test.ts @@ -0,0 +1,143 @@ +/** @jest-environment node */ + +import { tableCategorySkill } from './table.skill' + +describe('桌类品类 Skill v2', () => { + it('X 形钢架明确替换默认桌腿和下框,并冻结两侧架与横撑数量', () => { + expect(tableCategorySkill.version).toBe('bom-category-skill/table/v2') + + const requiredByKey = new Map(tableCategorySkill.requiredComponents.map( + (component) => [component.componentKey, component] as const, + )) + expect(requiredByKey.get('support-leg')?.excludedWhenStructureKeys) + .toEqual(['METAL_X_FRAME_BASE']) + expect(requiredByKey.get('support-apron')?.excludedWhenStructureKeys) + .toEqual(['METAL_X_FRAME_BASE']) + + const optionalByKey = new Map(tableCategorySkill.optionalComponents.map( + (component) => [component.componentKey, component] as const, + )) + expect(optionalByKey.get('support-x-side-frame')).toMatchObject({ + category: 'STEEL', + stableQuantity: 2, + unit: '组', + materialKeywords: ['桌腿材质'], + requiredWhenStructureKeys: ['METAL_X_FRAME_BASE'], + }) + expect(optionalByKey.get('support-x-side-frame')?.keywords) + .not.toContain('桌腿材质') + expect(optionalByKey.get('support-x-crossbar')).toMatchObject({ + category: 'STEEL', + stableQuantity: 1, + unit: '根', + requiredWhenStructureKeys: ['METAL_X_FRAME_BASE'], + }) + expect(optionalByKey.get('support-x-side-frame')?.dimensionRule) + .toContain('不得复制整机高、长或宽') + expect(optionalByKey.get('support-x-crossbar')?.dimensionRule) + .toContain('不得以整机长度代替') + + expect(tableCategorySkill.differences.find( + (difference) => difference.differenceKey === 'METAL_X_FRAME_BASE', + )).toMatchObject({ + exclusiveGroup: 'BASE_STYLE', + allowProductWide: true, + priority: 200, + }) + }) + + it('二段翻盖桌面与六类收纳附件均由各自结构差异独立激活', () => { + const optionalByKey = new Map(tableCategorySkill.optionalComponents.map( + (component) => [component.componentKey, component] as const, + )) + expect(optionalByKey.get('surface-rear-flip-panel')).toMatchObject({ + category: 'BOARD', + primaryMaterialSlot: true, + stableQuantity: 1, + requiredWhenStructureKeys: ['SPLIT_REAR_FLIP_TOP'], + }) + expect(optionalByKey.get('motion-rear-flip-hinge')).toMatchObject({ + category: 'ACCESSORY', + stableQuantity: 1, + requiredWhenStructureKeys: ['SPLIT_REAR_FLIP_TOP'], + }) + expect(optionalByKey.get('storage-pegboard')).toMatchObject({ + category: 'ACCESSORY', + stableQuantity: 1, + requiredWhenStructureKeys: ['PEGBOARD_STORAGE'], + }) + expect(optionalByKey.get('storage-metal-mesh-basket')).toMatchObject({ + category: 'STEEL', + stableQuantity: 1, + requiredWhenStructureKeys: ['UNDERDESK_MESH_BASKET'], + }) + expect(optionalByKey.get('hardware-cable-box')).toMatchObject({ + category: 'ACCESSORY', + stableQuantity: 1, + requiredWhenStructureKeys: ['CABLE_MANAGEMENT_BOX'], + }) + expect(optionalByKey.get('hardware-pegboard-hook-small')).toMatchObject({ + stableQuantity: 2, + unit: '个', + requiredWhenStructureKeys: ['SMALL_HOOK_PAIR'], + }) + expect(optionalByKey.get('hardware-pegboard-hook-large')).toMatchObject({ + stableQuantity: 2, + unit: '个', + requiredWhenStructureKeys: ['LARGE_HOOK_PAIR'], + }) + + for (const differenceKey of [ + 'SPLIT_REAR_FLIP_TOP', + 'PEGBOARD_STORAGE', + 'UNDERDESK_MESH_BASKET', + 'CABLE_MANAGEMENT_BOX', + 'SMALL_HOOK_PAIR', + 'LARGE_HOOK_PAIR', + ]) { + expect(tableCategorySkill.differences.find( + (difference) => difference.differenceKey === differenceKey, + )).toEqual(expect.objectContaining({ + allowProductWide: true, + exclusiveGroup: expect.any(String), + })) + } + + expect(optionalByKey.get('storage-metal-mesh-basket')?.materialScope) + .toContain('桌腿冷轧钢不自动扩散到网篮') + expect(optionalByKey.get('storage-pegboard')?.materialScope) + .toContain('不得继承桌面芯板或 X 形钢架材质') + }) + + it('楹木芯板与南洋橡木芯板是独立候选,不把橡木芯板声明成实木橡木', () => { + expect(tableCategorySkill.differences.find( + (difference) => difference.differenceKey === 'MATERIAL_YING_WOOD_CORE_BOARD', + )).toMatchObject({ + groupKind: 'COST', + exclusiveGroup: 'MATERIAL', + token: 'ying-wood-core-board', + }) + expect(tableCategorySkill.differences.find( + (difference) => difference.differenceKey === 'MATERIAL_OAK_CORE_BOARD', + )).toMatchObject({ + groupKind: 'COST', + exclusiveGroup: 'MATERIAL', + token: 'oak-core-board', + }) + }) + + it('保留普通四腿、伸缩桌旧合同,且 Skill 不携带任何价格猜测', () => { + expect(tableCategorySkill.differences.find( + (difference) => difference.differenceKey === 'FOUR_LEG_BASE', + )).toMatchObject({ exclusiveGroup: 'BASE_STYLE' }) + expect(tableCategorySkill.optionalComponents.find( + (component) => component.componentKey === 'motion-extension', + )?.requiredWhenStructureKeys).toEqual(['EXTENSION_TABLE']) + expect(tableCategorySkill.optionalComponents.find( + (component) => component.componentKey === 'surface-extension-leaf', + )?.requiredWhenStructureKeys).toEqual(['EXTENSION_TABLE']) + expect(JSON.stringify(tableCategorySkill)).not.toMatch( + /unitCost|unitPrice|estimateAmount|costAmount/, + ) + }) +}) diff --git a/furniture-3d-system/src/server/services/bom-costing/category-skills/table.skill.ts b/furniture-3d-system/src/server/services/bom-costing/category-skills/table.skill.ts index fd6ed1fe..2f17fbb2 100644 --- a/furniture-3d-system/src/server/services/bom-costing/category-skills/table.skill.ts +++ b/furniture-3d-system/src/server/services/bom-costing/category-skills/table.skill.ts @@ -9,7 +9,7 @@ import type { BomCostingCategorySkill } from './types' export const tableCategorySkill = { code: 'TABLE', label: '桌类', - version: 'bom-category-skill/table/v1', + version: 'bom-category-skill/table/v2', priority: 300, minimumScore: 12, minimumMargin: 8, @@ -24,13 +24,22 @@ export const tableCategorySkill = { { signalKey: 'exclude-soft-table', terms: ['折叠布桌', '充气桌'], weight: 30, reason: '软体或充气产品不适用硬体桌 Skill。', hard: true }, ], requiredComponents: [ - { componentKey: 'surface-main', role: 'SURFACE', category: 'BOARD', partName: '主桌面', stableQuantity: 1, unit: '块', primaryMaterialSlot: true, quantityRule: '普通桌结构组固定 1 块;拼接、折叠或延伸结构必须独立分组。', dimensionRule: '长宽以 SKU 外形和明确桌面标注为先;板厚独立取证。', materialScope: '当前 SKU 的桌面主体材质。', keywords: ['台面', '桌面', '面板'] }, - { componentKey: 'support-leg', role: 'SUPPORT', category: 'BOARD', partName: '桌腿或主体底座', stableQuantity: 4, unit: '件', quantityRule: '普通四腿桌固定 4 件;中柱底座结构组固定 1 件。', dimensionRule: '由桌高和连接关系推导,不复制整机长宽。', materialScope: '木质或金属承重支撑。', keywords: ['桌腿', '支腿', '底座', '中柱'], quantityByStructureKey: { PEDESTAL_BASE: 1, TRESTLE_BASE: 2 } }, - { componentKey: 'support-apron', role: 'SUPPORT', category: 'BOARD', partName: '桌面下框与横撑', stableQuantity: 1, unit: '套', quantityRule: '同一支撑结构组固定 1 套。', dimensionRule: '按桌面下方连接边界推导。', materialScope: '围板、横撑或金属桌架。', keywords: ['围板', '横撑', '桌架', '下框'] }, + { componentKey: 'surface-main', role: 'SURFACE', category: 'BOARD', partName: '主桌面或分段前桌板', stableQuantity: 1, unit: '块', primaryMaterialSlot: true, quantityRule: '普通桌结构组固定 1 块;二段桌面结构中固定为前段主桌板,后段翻盖板单列。', dimensionRule: '普通桌长宽以 SKU 外形和明确桌面标注为先;二段桌面只有取得后段深度直接事实后才以整桌深度减后段深度,板厚独立取证。', materialScope: '当前 SKU 的桌面主体材质;不得继承桌架或收纳附件材质。', keywords: ['台面', '桌面', '桌板', '面板', '前段板件', '前桌板'] }, + { componentKey: 'support-leg', role: 'SUPPORT', category: 'BOARD', partName: '桌腿或主体底座', stableQuantity: 4, unit: '件', quantityRule: '普通四腿桌固定 4 件;中柱底座结构组固定 1 件。', dimensionRule: '由桌高和连接关系推导,不复制整机长宽。', materialScope: '木质或金属承重支撑。', keywords: ['桌腿', '支腿', '底座', '中柱'], excludedWhenStructureKeys: ['METAL_X_FRAME_BASE'], quantityByStructureKey: { PEDESTAL_BASE: 1, TRESTLE_BASE: 2 } }, + { componentKey: 'support-apron', role: 'SUPPORT', category: 'BOARD', partName: '桌面下框与横撑', stableQuantity: 1, unit: '套', quantityRule: '同一支撑结构组固定 1 套。', dimensionRule: '按桌面下方连接边界推导。', materialScope: '围板、横撑或金属桌架。', keywords: ['围板', '横撑', '桌架', '下框'], excludedWhenStructureKeys: ['METAL_X_FRAME_BASE'] }, CONNECTOR_COMPONENT, ...COMMON_COST_COMPONENTS, ], optionalComponents: [ + { componentKey: 'support-x-side-frame', role: 'SUPPORT', category: 'STEEL', partName: 'X 形侧桌架', stableQuantity: 2, unit: '组', quantityRule: '明确为两侧 X 形承重桌架时固定 2 组;不得按图片猜成若干根独立钢管。', dimensionRule: '钢管长度、截面和壁厚必须有部件直接事实,不得复制整机高、长或宽。', materialScope: 'X 形桌腿或侧桌架的明确金属材质;不得扩散给网篮、洞洞板或其他附件。', keywords: ['X形桌架', 'X型桌架', 'X形桌腿', 'X型桌腿', 'X形交叉支撑', 'X形交叉腿架'], materialKeywords: ['桌腿材质'], requiredWhenStructureKeys: ['METAL_X_FRAME_BASE'] }, + { componentKey: 'support-x-crossbar', role: 'SUPPORT', category: 'STEEL', partName: 'X 形桌架连接横撑', stableQuantity: 1, unit: '根', quantityRule: '两侧 X 形桌架之间明确可见或标注的连接横撑固定 1 根;更多横撑必须有 SKU 专属数量事实。', dimensionRule: '横撑真实长度、截面和壁厚必须直接取证,不得以整机长度代替。', materialScope: '桌架横撑或连接杆的明确材质;桌腿材质不自动扩散到横撑。', keywords: ['桌架连接横撑', '底部连接横杆', '连接横杆', '连接杆', '横撑'], requiredWhenStructureKeys: ['METAL_X_FRAME_BASE'] }, + { componentKey: 'surface-rear-flip-panel', role: 'SURFACE', category: 'BOARD', partName: '桌面后段翻盖板', stableQuantity: 1, unit: '块', primaryMaterialSlot: true, quantityRule: '二段桌面后侧翻盖结构固定 1 块;多个盖板必须有 SKU 专属数量事实。', dimensionRule: '只有后段深度与前后分段方向均有直接事实时,才按 SKU 桌长和后段深度展开;否则相关尺寸留空。', materialScope: '后段翻盖板主体材质;可继承单一明确桌面主材,不得继承桌架材质。', keywords: ['桌面后侧盖板', '后段翻盖板', '可向上翻起的长条盖板', '翻盖理线区'], requiredWhenStructureKeys: ['SPLIT_REAR_FLIP_TOP'] }, + { componentKey: 'motion-rear-flip-hinge', role: 'MOTION', category: 'ACCESSORY', partName: '后段翻盖铰接机构', stableQuantity: 1, unit: '套', quantityRule: '后段翻盖结构固定 1 套铰接机构;单个铰链数量和型号必须直接取证。', dimensionRule: '不得用桌长猜测长铰链或转轴长度;型号、长度和孔位无证据时留空。', materialScope: '翻盖铰链、转轴、限位与紧固件,不继承桌板或桌架主材。', keywords: ['翻盖铰链', '铰接机构', '旋转连接件', '转轴', '合页'], requiredWhenStructureKeys: ['SPLIT_REAR_FLIP_TOP'] }, + { componentKey: 'storage-pegboard', role: 'OTHER', category: 'ACCESSORY', partName: '桌下收纳洞洞板', stableQuantity: 1, unit: '件', quantityRule: '明确包含洞洞板收纳组件时固定 1 件;孔位数量不作为部件数量。', dimensionRule: '长宽、厚度与孔距必须使用洞洞板直接尺寸事实,不得复制整机尺寸。', materialScope: '洞洞板自身明确材质和表面处理;不得继承桌面芯板或 X 形钢架材质。', keywords: ['洞洞板', '穿孔收纳板'], requiredWhenStructureKeys: ['PEGBOARD_STORAGE'] }, + { componentKey: 'storage-metal-mesh-basket', role: 'OTHER', category: 'STEEL', partName: '桌下金属网篮', stableQuantity: 1, unit: '件', quantityRule: '明确包含桌下金属网篮时固定 1 件。', dimensionRule: '网篮长宽高、线径和网孔必须直接取证,不得使用整机深度或桌长。', materialScope: '只接受网篮部件明确标注的金属、钢种或表面处理;桌腿冷轧钢不自动扩散到网篮。', keywords: ['金属网篮', '金属网格收纳篮', '桌下收纳篮'], requiredWhenStructureKeys: ['UNDERDESK_MESH_BASKET'] }, + { componentKey: 'hardware-cable-box', role: 'HARDWARE', category: 'ACCESSORY', partName: '桌下理线盒', stableQuantity: 1, unit: '个', quantityRule: '配件清单明确理线盒 1 个时固定 1 个。', dimensionRule: '理线盒尺寸、板厚和孔位必须有部件直接事实,不得复制桌面尺寸。', materialScope: '理线盒自身材质与表面处理,不继承桌架或桌面材质。', keywords: ['理线盒', '走线盒'], requiredWhenStructureKeys: ['CABLE_MANAGEMENT_BOX'] }, + { componentKey: 'hardware-pegboard-hook-small', role: 'HARDWARE', category: 'ACCESSORY', partName: '洞洞板小挂钩', stableQuantity: 2, unit: '个', quantityRule: '配件清单明确小挂钩 2 个时固定 2 个;不得由大挂钩或泛挂钩事实补出。', dimensionRule: '长度、线径和承载规格必须直接取证。', materialScope: '小挂钩自身材质与表面处理。', keywords: ['小挂钩'], requiredWhenStructureKeys: ['SMALL_HOOK_PAIR'] }, + { componentKey: 'hardware-pegboard-hook-large', role: 'HARDWARE', category: 'ACCESSORY', partName: '洞洞板大挂钩', stableQuantity: 2, unit: '个', quantityRule: '配件清单明确大挂钩 2 个时固定 2 个;不得由小挂钩或泛挂钩事实补出。', dimensionRule: '长度、线径和承载规格必须直接取证。', materialScope: '大挂钩自身材质与表面处理。', keywords: ['大挂钩'], requiredWhenStructureKeys: ['LARGE_HOOK_PAIR'] }, { componentKey: 'motion-extension', role: 'MOTION', category: 'ACCESSORY', partName: '伸缩与锁止机构', stableQuantity: 1, unit: '套', quantityRule: '伸缩桌结构组固定 1 套。', dimensionRule: '需核对收拢和展开尺寸、轨道行程及锁止位置。', materialScope: '伸缩轨、联动件、锁止和限位件。', keywords: ['伸缩', '延伸', '拉伸', '锁止'], requiredWhenStructureKeys: ['EXTENSION_TABLE'] }, { componentKey: 'surface-extension-leaf', role: 'SURFACE', category: 'BOARD', partName: '延伸桌板', stableQuantity: 1, unit: '块', primaryMaterialSlot: true, quantityRule: '伸缩桌结构组固定 1 块;多块延伸板需 SKU 专属事实。', dimensionRule: '按展开前后长度差和桌面宽度推导。', materialScope: '通常与主桌面同材质,仍需确认。', keywords: ['延伸板', '活动桌板', '加长板'], requiredWhenStructureKeys: ['EXTENSION_TABLE'] }, { componentKey: 'motion-folding', role: 'MOTION', category: 'ACCESSORY', partName: '折叠铰接机构', stableQuantity: 1, unit: '套', quantityRule: '折叠桌结构组固定 1 套。', dimensionRule: '核对折叠轴、锁止和展开支撑。', materialScope: '铰链、转轴、锁止和紧固件。', keywords: ['折叠', '合页', '转轴'], requiredWhenStructureKeys: ['FOLDING_TABLE'] }, @@ -41,6 +50,9 @@ export const tableCategorySkill = { relations: [ { relationType: 'SUPPORTS', fromComponentKey: 'support-leg', toComponentKey: 'surface-main', rule: '桌腿或底座必须承托主桌面。' }, { relationType: 'CONNECTS', fromComponentKey: 'support-apron', toComponentKey: 'support-leg', rule: '下框与横撑连接支撑并稳定桌面。' }, + { relationType: 'SUPPORTS', fromComponentKey: 'support-x-side-frame', toComponentKey: 'surface-main', rule: '两侧 X 形桌架共同承托主桌面。' }, + { relationType: 'CONNECTS', fromComponentKey: 'support-x-crossbar', toComponentKey: 'support-x-side-frame', rule: '连接横撑闭合两侧 X 形桌架。' }, + { relationType: 'MOVES_WITH', fromComponentKey: 'motion-rear-flip-hinge', toComponentKey: 'surface-rear-flip-panel', rule: '后段翻盖板必须关联铰接机构。' }, { relationType: 'MOVES_WITH', fromComponentKey: 'motion-extension', toComponentKey: 'surface-extension-leaf', rule: '延伸桌板必须关联伸缩与锁止机构。' }, { relationType: 'MOVES_WITH', fromComponentKey: 'motion-drawer', toComponentKey: 'drawer-box', rule: '抽屉盒必须关联成对导轨。' }, { relationType: 'SUPPORTS', fromComponentKey: 'support-leg', toComponentKey: 'partition-shelf', rule: '桌下层板由腿架或横撑支承。' }, @@ -49,6 +61,13 @@ export const tableCategorySkill = { { differenceKey: 'FOUR_LEG_BASE', token: 'four-leg', groupKind: 'STRUCTURE', terms: ['四腿', '四脚', '4腿', '4脚'], exclusiveGroup: 'BASE_STYLE', priority: 100, description: '四腿结构形成独立支撑组。' }, { differenceKey: 'PEDESTAL_BASE', token: 'pedestal', groupKind: 'STRUCTURE', terms: ['中柱', '单柱', '圆盘底座', '喇叭脚'], exclusiveGroup: 'BASE_STYLE', priority: 110, description: '中柱底座改变支撑数量。' }, { differenceKey: 'TRESTLE_BASE', token: 'trestle', groupKind: 'STRUCTURE', terms: ['双底座', '双支架', '板式桌腿'], exclusiveGroup: 'BASE_STYLE', priority: 105, description: '双支架底座改变支撑数量。' }, + { differenceKey: 'METAL_X_FRAME_BASE', token: 'metal-x-frame', groupKind: 'STRUCTURE', terms: ['X形桌架', 'X型桌架', 'X形桌腿', 'X型桌腿', 'X形交叉支撑', 'X型交叉支撑', 'X形交叉腿架', '两侧X形桌架'], excludedTerms: ['非X形', '非X型', 'T形桌架', '一字形桌架'], exclusiveGroup: 'BASE_STYLE', priority: 200, allowProductWide: true, description: '两侧 X 形金属桌架与连接横撑替换默认桌腿和下框,金属管规格仍必须直接取证。' }, + { differenceKey: 'SPLIT_REAR_FLIP_TOP', token: 'split-rear-flip-top', groupKind: 'STRUCTURE', terms: ['二段分板设计', '二段分段设计', '前后两段板件', '桌面由前后两段板件分隔', '桌面后侧盖板', '后段翻盖', '翻盖理线区'], excludedTerms: ['一体整板桌面', '无翻盖'], exclusiveGroup: 'TABLETOP_LAYOUT', priority: 200, allowProductWide: true, description: '前段主桌板与后段翻盖板必须分开计量,并单列铰接机构。' }, + { differenceKey: 'PEGBOARD_STORAGE', token: 'pegboard-storage', groupKind: 'STRUCTURE', terms: ['洞洞板', '穿孔收纳板'], excludedTerms: ['不含洞洞板', '无洞洞板'], exclusiveGroup: 'TABLE_PEGBOARD_MODE', priority: 150, allowProductWide: true, description: '洞洞板是独立收纳部件,不能并入桌面或主体连接五金。' }, + { differenceKey: 'UNDERDESK_MESH_BASKET', token: 'underdesk-mesh-basket', groupKind: 'STRUCTURE', terms: ['金属网篮', '金属网格收纳篮', '桌下收纳篮'], excludedTerms: ['不含网篮', '无网篮'], exclusiveGroup: 'UNDERDESK_BASKET_MODE', priority: 150, allowProductWide: true, description: '桌下金属网篮形成独立收纳部件。' }, + { differenceKey: 'CABLE_MANAGEMENT_BOX', token: 'cable-management-box', groupKind: 'STRUCTURE', terms: ['理线盒', '走线盒'], excludedTerms: ['不含理线盒', '无理线盒'], exclusiveGroup: 'CABLE_BOX_MODE', priority: 150, allowProductWide: true, description: '理线盒按独立配件计量,不能由泛理线宣传推断。' }, + { differenceKey: 'SMALL_HOOK_PAIR', token: 'small-hook-pair', groupKind: 'STRUCTURE', terms: ['小挂钩*2', '小挂钩×2', '小挂钩2个', '2个小挂钩'], excludedTerms: ['不含小挂钩', '无小挂钩'], exclusiveGroup: 'SMALL_HOOK_MODE', priority: 150, allowProductWide: true, description: '只有明确配件清单才能生成两个小挂钩。' }, + { differenceKey: 'LARGE_HOOK_PAIR', token: 'large-hook-pair', groupKind: 'STRUCTURE', terms: ['大挂钩*2', '大挂钩×2', '大挂钩2个', '2个大挂钩'], excludedTerms: ['不含大挂钩', '无大挂钩'], exclusiveGroup: 'LARGE_HOOK_MODE', priority: 150, allowProductWide: true, description: '只有明确配件清单才能生成两个大挂钩。' }, { differenceKey: 'EXTENSION_TABLE', token: 'extension', groupKind: 'STRUCTURE', terms: ['伸缩桌', '可伸缩', '延伸桌', '拉伸桌'], description: '伸缩机构和延伸桌板改变拓扑。' }, { differenceKey: 'FOLDING_TABLE', token: 'folding', groupKind: 'STRUCTURE', terms: ['折叠桌', '可折叠', '折叠桌面'], description: '折叠机构改变拓扑。' }, { differenceKey: 'DRAWER_PRESENT', token: 'drawer', groupKind: 'STRUCTURE', terms: ['带抽屉', '抽屉款', '桌下抽'], excludedTerms: ['无抽屉', '不带抽屉'], description: '桌下抽屉增加盒体与导轨。' }, @@ -57,13 +76,17 @@ export const tableCategorySkill = { ...COMMON_MATERIAL_DIFFERENCES, ], validations: [ - { validationKey: 'table-support', severity: 'ERROR', rule: '主桌面必须由桌腿、底座或桌架承托。', componentKeys: ['surface-main', 'support-leg', 'support-apron'] }, - { validationKey: 'table-stable-count', severity: 'ERROR', rule: '同结构组桌面和支撑数量冻结;模型不能无 SKU 专属 factId 改数。', componentKeys: ['surface-main', 'support-leg', 'support-apron'] }, + { validationKey: 'table-support', severity: 'ERROR', rule: '主桌面必须由桌腿、底座或 X 形桌架承托。', componentKeys: ['surface-main', 'support-leg', 'support-apron', 'support-x-side-frame', 'support-x-crossbar'] }, + { validationKey: 'table-stable-count', severity: 'ERROR', rule: '同结构组桌面和支撑数量冻结;模型不能无 SKU 专属 factId 改数。', componentKeys: ['surface-main', 'support-leg', 'support-apron', 'support-x-side-frame', 'support-x-crossbar'] }, + { validationKey: 'table-x-frame-closure', severity: 'ERROR', rule: 'X 形钢架结构必须以两侧桌架和连接横撑闭合,并排除默认桌腿与下框。', componentKeys: ['support-x-side-frame', 'support-x-crossbar'] }, + { validationKey: 'table-split-rear-flip-closure', severity: 'ERROR', rule: '二段翻盖桌面必须同时包含后段翻盖板和铰接机构;主桌面属于桌类公共主体。', componentKeys: ['surface-rear-flip-panel', 'motion-rear-flip-hinge'] }, + { validationKey: 'table-storage-accessories', severity: 'WARNING', rule: '洞洞板、网篮、理线盒及大小挂钩必须分别由自己的明确结构事实激活。', componentKeys: ['storage-pegboard', 'storage-metal-mesh-basket', 'hardware-cable-box', 'hardware-pegboard-hook-small', 'hardware-pegboard-hook-large'] }, { validationKey: 'table-motion', severity: 'ERROR', rule: '活动桌板必须关联伸缩、折叠和锁止机构。', componentKeys: ['surface-extension-leaf', 'motion-extension', 'motion-folding'] }, ], historicalFeatures: [ - { featureKey: 'table-base-style', label: '桌架形式', kind: 'STRUCTURE', terms: ['四腿', '中柱', '双底座', '板式桌腿'], description: '历史候选先匹配支撑形式。' }, - { featureKey: 'table-motion', label: '活动桌面机构', kind: 'STRUCTURE', terms: ['伸缩', '折叠', '延伸'], description: '普通桌与活动桌不能直接互用结构成本。' }, + { featureKey: 'table-base-style', label: '桌架形式', kind: 'STRUCTURE', terms: ['四腿', '中柱', '双底座', '板式桌腿', 'X形桌架'], description: '历史候选先匹配支撑形式;X 形金属架不能复用默认板式腿架。' }, + { featureKey: 'table-motion', label: '活动桌面机构', kind: 'STRUCTURE', terms: ['伸缩', '折叠', '延伸', '二段分板', '后段翻盖'], description: '普通桌与活动桌不能直接互用结构成本。' }, + { featureKey: 'table-storage-system', label: '桌面收纳系统', kind: 'STRUCTURE', terms: ['洞洞板', '金属网篮', '理线盒', '小挂钩', '大挂钩'], description: '收纳附件组成必须逐项匹配,不能按桌体总价迁移。' }, { featureKey: 'table-set', label: '桌椅套装组成', kind: 'COST', terms: ['桌椅套装', '一桌'], description: '套餐件数必须单独核对。' }, ...COMMON_HISTORICAL_FEATURES, ], diff --git a/furniture-3d-system/src/server/services/bom-costing/category-skills/types.ts b/furniture-3d-system/src/server/services/bom-costing/category-skills/types.ts index a14350f0..2a2fbfca 100644 --- a/furniture-3d-system/src/server/services/bom-costing/category-skills/types.ts +++ b/furniture-3d-system/src/server/services/bom-costing/category-skills/types.ts @@ -65,6 +65,11 @@ export interface BomCostingCategoryComponentDefinition { dimensionRule: string materialScope: string keywords: readonly string[] + /** + * Component names that may bind a MATERIAL fact after topology selection. + * They never activate an optional component on their own. + */ + materialKeywords?: readonly string[] stableQuantity: number unit: string /** diff --git a/furniture-3d-system/src/server/services/bom-costing/test-fixtures/production-mobile-rattan-storage-rack-2.fixture.ts b/furniture-3d-system/src/server/services/bom-costing/test-fixtures/production-mobile-rattan-storage-rack-2.fixture.ts new file mode 100644 index 00000000..239b7e8f --- /dev/null +++ b/furniture-3d-system/src/server/services/bom-costing/test-fixtures/production-mobile-rattan-storage-rack-2.fixture.ts @@ -0,0 +1,241 @@ +import { + BOM_COSTING_FACT_SCHEMA_VERSION, + type BomCostingSourceFactSnapshot, +} from '@/lib/bom-costing/fact-contracts' +import type { MarketDetailSnapshot } from '../market-detail-client' + +export const PRODUCTION_MOBILE_RATTAN_STORAGE_RACK_TITLE = + '源氏木语实木边几客厅中古风双层置物小茶几橡木胡桃色移动推车' + +export const PRODUCTION_MOBILE_RATTAN_STORAGE_RACK_2_SKUS = [ + { + externalSkuId: '6035231233476', + name: '(胡桃色)0.63米移动边几(632.5*382*735mm)H01JI0003', + }, + { + externalSkuId: '6064658921418', + name: '(原木色)0.63米移动边几(632.5*382*735mm)Y01JI0003', + }, +] as const + +export function buildProductionMobileRattanStorageRack2Snapshot(): MarketDetailSnapshot { + return { + itemId: 'production-mobile-rattan-storage-rack-2', + channel: 'taobao', + title: PRODUCTION_MOBILE_RATTAN_STORAGE_RACK_TITLE, + shopName: '脱敏生产店铺', + detailUrl: 'https://fixture.invalid/items/production-mobile-rattan-storage-rack-2', + mainImages: [], + detailImages: [], + skuImages: [], + requestId: 'request-production-mobile-rattan-storage-rack-2', + skus: PRODUCTION_MOBILE_RATTAN_STORAGE_RACK_2_SKUS.map((sku) => ({ + ...sku, + size: '632.5*382*735mm;0.63米', + imageUrl: null, + attributes: { 颜色分类: sku.name }, + priceRaw: null, + originalPriceRaw: null, + quantity: null, + })), + } +} + +export function buildProductionMobileRattanStorageRack2FactSnapshot(): BomCostingSourceFactSnapshot { + return { + schemaVersion: BOM_COSTING_FACT_SCHEMA_VERSION, + imageFacts: [ + { + imageId: 'IMG_0013', + sourceImageUrl: 'https://fixture.invalid/images/IMG_0013.jpg', + kind: 'DETAIL', + label: '移动双层置物结构详情图', + externalSkuIds: [], + observedTexts: ['双层置物', '透气藤编', '四个万向脚轮'], + facts: [ + { + factId: 'IMG_0013_fact_001', + kind: 'MATERIAL', + subject: '藤编篮侧面面板', + value: '透气藤编', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.99, + }, + { + factId: 'IMG_0013_fact_003', + kind: 'STRUCTURE', + subject: '置物层', + value: '双层置物', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.99, + }, + { + factId: 'IMG_0013_fact_004', + kind: 'STRUCTURE', + subject: '产品整体结构', + value: '上层托盘和下层置物篮由金属管架支撑', + relatedSkuIds: [], + basis: 'IMAGE', + confidence: 0.97, + }, + { + factId: 'IMG_0013_fact_005', + kind: 'PART', + subject: '主要组成', + value: '上层托盘、下层置物框、金属管状立柱及推车把手', + relatedSkuIds: [], + basis: 'IMAGE', + confidence: 0.96, + }, + { + factId: 'IMG_0013_fact_006', + kind: 'MECHANISM', + subject: '底部脚轮', + value: '底部安装四个万向脚轮', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.99, + }, + ], + }, + { + imageId: 'IMG_0039', + sourceImageUrl: 'https://fixture.invalid/images/IMG_0039.jpg', + kind: 'DETAIL', + label: '产品材质说明图', + externalSkuIds: [], + observedTexts: ['北美FAS级红橡木', '框架 不锈钢', '藤编'], + facts: [ + { + factId: 'IMG_0039_fact_001', + kind: 'MATERIAL', + subject: '产品主材', + value: '主材—北美FAS级红橡木', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.99, + }, + { + factId: 'IMG_0039_fact_002', + kind: 'MATERIAL', + subject: '下层篮筐木材', + value: '主材 橡木', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.99, + }, + { + factId: 'IMG_0039_fact_003', + kind: 'MATERIAL', + subject: '框架材质', + value: '框架 不锈钢', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.99, + }, + { + factId: 'IMG_0039_fact_008', + kind: 'STRUCTURE', + subject: '材质与结构关系', + value: '橡木置物板和篮筐安装于不锈钢框架上', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.98, + }, + ], + }, + { + imageId: 'IMG_0002', + sourceImageUrl: 'https://fixture.invalid/images/IMG_0002.jpg', + kind: 'DETAIL', + label: '上层台面尺寸图', + externalSkuIds: [], + observedTexts: ['上层台面 56cm', '31cm'], + facts: [ + { + factId: 'IMG_0002_fact_001', + kind: 'DIMENSION', + subject: '上层台面长度', + value: '56cm', + numericValue: 56, + unit: 'cm', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.91, + }, + { + factId: 'IMG_0002_fact_002', + kind: 'DIMENSION', + subject: '上层台面宽度', + value: '31cm', + numericValue: 31, + unit: 'cm', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.91, + }, + ], + }, + { + imageId: 'IMG_SKU_6035231233476', + sourceImageUrl: 'https://fixture.invalid/images/IMG_SKU_6035231233476.jpg', + kind: 'SKU', + label: 'SKU图:6035231233476', + externalSkuIds: ['6035231233476'], + observedTexts: ['橡木-胡桃色', '632.5*382*735mm'], + facts: [ + { + factId: 'SKU_6035231233476_fact_material', + kind: 'MATERIAL', + subject: '产品材质与颜色', + value: '橡木-胡桃色', + relatedSkuIds: ['6035231233476'], + basis: 'SOURCE_TEXT', + confidence: 0.99, + }, + { + factId: 'SKU_6035231233476_fact_size', + kind: 'DIMENSION', + subject: '整机尺寸', + value: '632.5*382*735mm', + relatedSkuIds: ['6035231233476'], + basis: 'SOURCE_TEXT', + confidence: 0.99, + }, + ], + }, + { + imageId: 'IMG_SKU_6064658921418', + sourceImageUrl: 'https://fixture.invalid/images/IMG_SKU_6064658921418.jpg', + kind: 'SKU', + label: 'SKU图:6064658921418', + externalSkuIds: ['6064658921418'], + observedTexts: ['橡木', '632.5*382*735mm'], + facts: [ + { + factId: 'SKU_6064658921418_fact_material', + kind: 'MATERIAL', + subject: '边几木质部件', + value: '橡木', + relatedSkuIds: ['6064658921418'], + basis: 'SOURCE_TEXT', + confidence: 0.99, + }, + { + factId: 'SKU_6064658921418_fact_size', + kind: 'DIMENSION', + subject: '整机尺寸', + value: '632.5*382*735mm', + relatedSkuIds: ['6064658921418'], + basis: 'SOURCE_TEXT', + confidence: 0.99, + }, + ], + }, + ], + failedImages: [], + extractedAt: '2026-08-13T00:00:00.000Z', + } +} diff --git a/furniture-3d-system/src/server/services/bom-costing/test-fixtures/production-titan-a3-table-6.fixture.ts b/furniture-3d-system/src/server/services/bom-costing/test-fixtures/production-titan-a3-table-6.fixture.ts new file mode 100644 index 00000000..709432be --- /dev/null +++ b/furniture-3d-system/src/server/services/bom-costing/test-fixtures/production-titan-a3-table-6.fixture.ts @@ -0,0 +1,243 @@ +import { + BOM_COSTING_FACT_SCHEMA_VERSION, + type BomCostingSourceFactSnapshot, +} from '@/lib/bom-costing/fact-contracts' +import type { MarketDetailSnapshot } from '../market-detail-client' + +export const PRODUCTION_TITAN_A3_TABLE_CASE_ID = 'cmsinlds50254inm7u424dgra' +export const PRODUCTION_TITAN_A3_TABLE_TITLE = + '京东京造泰坦A3电竞桌台式电脑桌子实木ENF级家用书桌办公桌碳纤维纹1.4m' + +export interface ProductionTitanA3TableSku { + externalSkuId: string + name: string + lengthMm: 1200 | 1400 | 1600 + depthMm: 750 + heightMm: 750 + finish: '黑色碳纤维纹' | '珍珠白' +} + +export const PRODUCTION_TITAN_A3_TABLE_6_SKUS = [ + { externalSkuId: '100295797814', name: '1.4*0.75m 黑色碳纤维纹', lengthMm: 1400, depthMm: 750, heightMm: 750, finish: '黑色碳纤维纹' }, + { externalSkuId: '100221647309', name: '1.2*0.75m 黑色碳纤维纹', lengthMm: 1200, depthMm: 750, heightMm: 750, finish: '黑色碳纤维纹' }, + { externalSkuId: '100295797812', name: '1.6*0.75m 黑色碳纤维纹', lengthMm: 1600, depthMm: 750, heightMm: 750, finish: '黑色碳纤维纹' }, + { externalSkuId: '100343570758', name: '1.4*0.75m 珍珠白', lengthMm: 1400, depthMm: 750, heightMm: 750, finish: '珍珠白' }, + { externalSkuId: '100343569534', name: '1.2*0.75m 珍珠白', lengthMm: 1200, depthMm: 750, heightMm: 750, finish: '珍珠白' }, + { externalSkuId: '100356472042', name: '1.6*0.75m 珍珠白', lengthMm: 1600, depthMm: 750, heightMm: 750, finish: '珍珠白' }, +] as const satisfies readonly ProductionTitanA3TableSku[] + +export const PRODUCTION_TITAN_A3_STRUCTURE_DIFFERENCE_KEYS = [ + 'CABLE_MANAGEMENT_BOX', + 'LARGE_HOOK_PAIR', + 'METAL_X_FRAME_BASE', + 'PEGBOARD_STORAGE', + 'SMALL_HOOK_PAIR', + 'SPLIT_REAR_FLIP_TOP', + 'UNDERDESK_MESH_BASKET', +] as const + +export const PRODUCTION_TITAN_A3_REQUIRED_COMPONENT_KEYS = [ + 'surface-main', + 'hardware-connectors', + 'processing-main', + 'labor-assembly', + 'packaging-set', + 'support-x-side-frame', + 'support-x-crossbar', + 'surface-rear-flip-panel', + 'motion-rear-flip-hinge', + 'storage-pegboard', + 'storage-metal-mesh-basket', + 'hardware-cable-box', + 'hardware-pegboard-hook-small', + 'hardware-pegboard-hook-large', +] as const + +export function buildProductionTitanA3Table6Snapshot(): MarketDetailSnapshot { + return { + itemId: 'production-titan-a3-table-6', + channel: 'jd', + title: PRODUCTION_TITAN_A3_TABLE_TITLE, + shopName: '脱敏生产店铺', + detailUrl: 'https://fixture.invalid/items/production-titan-a3-table-6', + mainImages: [], + detailImages: [], + skuImages: [], + requestId: 'request-production-titan-a3-table-6', + skus: PRODUCTION_TITAN_A3_TABLE_6_SKUS.map((sku) => ({ + externalSkuId: sku.externalSkuId, + name: sku.name, + size: `${sku.lengthMm}×${sku.depthMm}×${sku.heightMm}mm`, + imageUrl: null, + attributes: { + 规格: `${sku.lengthMm}×${sku.depthMm}×${sku.heightMm}mm`, + 颜色: sku.finish, + }, + priceRaw: null, + originalPriceRaw: null, + quantity: null, + })), + } +} + +export function buildProductionTitanA3Table6FactSnapshot(): BomCostingSourceFactSnapshot { + return { + schemaVersion: BOM_COSTING_FACT_SCHEMA_VERSION, + imageFacts: [{ + imageId: 'titan-a3-product-structure', + sourceImageUrl: 'https://fixture.invalid/images/titan-a3-product-structure.jpg', + kind: 'DETAIL', + label: '泰坦 A3 公共结构与配件图', + externalSkuIds: [], + observedTexts: [ + '二段分板设计', + '桌面后侧翻盖', + '洞洞板', + '金属网篮', + '理线盒*1、小挂钩*2、大挂钩*2', + 'X形冷轧钢桌架', + ], + facts: [{ + factId: 'titan-a3-split-top', + kind: 'STRUCTURE', + subject: '桌体结构', + value: '二段分板设计,可见桌面由前后两段板件分隔', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.96, + }, { + factId: 'titan-a3-rear-flip-panel', + kind: 'PART', + subject: '桌面后侧盖板', + value: '可向上翻起的长条盖板', + relatedSkuIds: [], + basis: 'IMAGE', + confidence: 0.97, + }, { + factId: 'titan-a3-rear-depth', + kind: 'DIMENSION', + subject: '桌面后侧翻盖理线区深度', + value: '约12cm', + numericValue: 12, + unit: 'cm', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.90, + }, { + factId: 'titan-a3-rear-hinge', + kind: 'HARDWARE', + subject: '桌面后侧盖板铰接机构', + value: '连续长条旋转连接件', + relatedSkuIds: [], + basis: 'IMAGE', + confidence: 0.74, + }, { + factId: 'titan-a3-x-frame', + kind: 'STRUCTURE', + subject: '桌架结构', + value: '两侧X形交叉腿架,并由底部连接横杆连接', + relatedSkuIds: [], + basis: 'IMAGE', + confidence: 0.95, + }, { + factId: 'titan-a3-pegboard', + kind: 'PART', + subject: '桌面后侧收纳部件', + value: '洞洞板', + relatedSkuIds: [], + basis: 'IMAGE', + confidence: 0.98, + }, { + factId: 'titan-a3-mesh-basket', + kind: 'PART', + subject: '桌面下方收纳部件', + value: '金属网篮', + relatedSkuIds: [], + basis: 'IMAGE', + confidence: 0.95, + }, { + factId: 'titan-a3-cable-box', + kind: 'PART', + subject: '理线盒', + value: '理线盒*1', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.98, + }, { + factId: 'titan-a3-small-hooks', + kind: 'PART', + subject: '配件清单', + value: '小挂钩*2', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.98, + }, { + factId: 'titan-a3-large-hooks', + kind: 'PART', + subject: '配件清单', + value: '大挂钩*2', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.98, + }, { + factId: 'titan-a3-main-connectors', + kind: 'HARDWARE', + subject: '主体连接五金', + value: '螺钉与连接件1套', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.90, + }, { + factId: 'titan-a3-leg-material', + kind: 'MATERIAL', + subject: '桌腿材质', + value: '冷轧钢', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.98, + }, { + factId: 'titan-a3-ying-wood', + kind: 'MATERIAL', + subject: '桌面及产品用料', + value: 'ENF级楹木', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.98, + }, { + factId: 'titan-a3-oak-core-board', + kind: 'MATERIAL', + subject: '桌板材质', + value: 'ENF级南洋橡木芯板', + relatedSkuIds: [], + basis: 'SOURCE_TEXT', + confidence: 0.98, + }], + }, ...PRODUCTION_TITAN_A3_TABLE_6_SKUS.map((sku) => ({ + imageId: `titan-a3-sku-${sku.externalSkuId}`, + sourceImageUrl: `https://fixture.invalid/images/titan-a3-sku-${sku.externalSkuId}.jpg`, + kind: 'SKU' as const, + label: `SKU图:${sku.externalSkuId}`, + externalSkuIds: [sku.externalSkuId], + observedTexts: [sku.name, `${sku.lengthMm}×${sku.depthMm}×${sku.heightMm}mm`], + facts: [{ + factId: `titan-a3-size-${sku.externalSkuId}`, + kind: 'DIMENSION' as const, + subject: '整机尺寸', + value: `${sku.lengthMm}×${sku.depthMm}×${sku.heightMm}mm`, + relatedSkuIds: [sku.externalSkuId], + basis: 'SOURCE_TEXT' as const, + confidence: 0.99, + }, { + factId: `titan-a3-finish-${sku.externalSkuId}`, + kind: 'PROCESS' as const, + subject: '桌板表面', + value: sku.finish, + relatedSkuIds: [sku.externalSkuId], + basis: 'SOURCE_TEXT' as const, + confidence: 0.98, + }], + }))], + failedImages: [], + extractedAt: '2026-08-13T00:00:00.000Z', + } +}