fix: display all matched materials when multiple matches found in BOM extraction
All checks were successful
NTFY Notification / notify (push) Successful in 3s

Fixed a bug where materials matching multiple BOM library records would not
appear in the BOM extraction output. Previously, only the first match was
extracted when success=True, but multiple matches set success=False, causing
all materials to be skipped.

Changes:
- Modified M09_BOMExtractor.MatchAllMaterialTypesWithValidation()
- Changed condition from checking 'success' to checking 'rowCount > 0'
- Added loop to process ALL matching rows instead of just the first one
- Moved BuildWorksheetHeaderMap() outside loop for performance
- Enhanced debug logging to show row processing details

Impact:
- "机芯" (Movement) and "边" (Edge) sheets now show all matched materials
- Users can see and manually resolve ambiguous matches in output
- Component sheet handling unchanged (uses different code path)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-02-26 11:06:53 +08:00
parent c4d7b248c4
commit 44d6bdb750
2 changed files with 182 additions and 15 deletions

View File

@@ -492,26 +492,32 @@ Private Function MatchAllMaterialTypesWithValidation( _
matchResult("rowCount") = bomMatchResult("rowCount")
Set matchResult("rowNums") = bomMatchResult("rowNums")
' 如果匹配成功,提取物料信息
If bomMatchResult("success") Then
Dim rowNum As Long
rowNum = bomMatchResult("rowNums")(1)
Debug.Print " -> 匹配行号: " & rowNum
' 提取物料信息(支持多条匹配)
If bomMatchResult("rowCount") > 0 Then
' 步骤1: 构建表头映射(只需构建一次)
Dim headerMap As Object
Set headerMap = M07_BOMMatcher.BuildWorksheetHeaderMap(ws)
Dim materialInfo As Object
Set materialInfo = M07_BOMMatcher.ExtractMaterialInfo(ws, rowNum, headerMap)
' 步骤2: 遍历所有匹配行
Dim i As Long
Dim rowNum As Long
For i = 1 To bomMatchResult("rowCount")
rowNum = bomMatchResult("rowNums")(i)
Debug.Print " -> 处理匹配行 " & i & "/" & bomMatchResult("rowCount") & ": 行号=" & rowNum
Debug.Print " -> 提取结果: 名称=[" & materialInfo("materialName") & "] 编码=[" & materialInfo("materialCode") & "] 数量=[" & materialInfo("materialQty") & "]"
' 步骤3: 提取物料信息
Dim materialInfo As Object
Set materialInfo = M07_BOMMatcher.ExtractMaterialInfo(ws, rowNum, headerMap)
If Not materialInfo Is Nothing Then
matchResult("materials").Add materialInfo
Debug.Print " -> 已添加到匹配结果"
Else
Debug.Print " -> ERROR: materialInfo为Nothing"
End If
If Not materialInfo Is Nothing Then
matchResult("materials").Add materialInfo
Debug.Print " 已添加: 名称=[" & materialInfo("materialName") & "] 编码=[" & materialInfo("materialCode") & "]"
Else
Debug.Print " ERROR: materialInfo为Nothing"
End If
Next i
Debug.Print " -> 共添加 " & matchResult("materials").Count & " 个物料"
End If
End If