fix: component worksheet rowCount false positive validation error
Some checks failed
NTFY Notification / notify (push) Failing after 3s

Fix critical bug in BOM matching validation: when [部件] worksheet matches 1 record
but returns 2 sub-components, system incorrectly reports "matched 2 records".

Root Cause:
- matchResult("rowCount") incorrectly used componentMaterials.count (material count)
- instead of bomMatchResult("rowCount") (worksheet row count)
- Caused 1-row match returning 2 sub-components to be misreported as "2 matches"

Solution:
1. M08_ComponentProcessor.ProcessComponentRecord: Add matchedRowNum parameter,
   receive matched row number from caller, avoid redundant internal matching

2. M09_BOMExtractor: Implement two-phase matching flow
   - Phase 1: Call MatchBOMRecord to get standard match result (with correct rowCount)
   - Phase 2: If match succeeds, call ProcessComponentRecord to process component logic
   - matchResult("rowCount") always uses standard match's rowCount (worksheet row count)

Fix Results:
- Scenario 1: [部件] matches 1 row, returns 1 component → rowCount=1 
- Scenario 2: [部件] matches 1 row, returns 2 sub-components → rowCount=1  (no false positive)
- Scenario 3: [部件] matches 0 rows → rowCount=0, correct error 
- Scenario 4: [部件] matches 2+ rows → rowCount=2, correct error 

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-02-12 15:54:50 +08:00
parent 8271958adf
commit 78241f2b8d
3 changed files with 252 additions and 32 deletions

View File

@@ -415,18 +415,33 @@ Private Function MatchAllMaterialTypesWithValidation( _
Set matchResult("materials") = New Collection
' "部件"工作表特殊处理
Dim componentMaterials As Collection
If sheetName = BOMLIB_SHEET_COMPONENT Then
Debug.Print " -> 使用部件处理逻辑"
Dim componentMaterials As Collection
Set componentMaterials = M08_ComponentProcessor.ProcessComponentRecord( _
ws, params, logger)
' 步骤1: 先调用标准匹配获取匹配行数(这是工作表匹配的行数,不是物料数量)
Dim bomMatchResult As Object
Set bomMatchResult = M07_BOMMatcher.MatchBOMRecord(ws, params)
Debug.Print " -> 返回物料数: " & componentMaterials.count
Debug.Print " -> 标准匹配: success=" & bomMatchResult("success") & ", rowCount=" & bomMatchResult("rowCount")
matchResult("success") = (componentMaterials.count > 0)
matchResult("rowCount") = componentMaterials.count
' 步骤2: 如果标准匹配成功,调用部件处理器
Set componentMaterials = New Collection
If bomMatchResult("success") Then
Set componentMaterials = M08_ComponentProcessor.ProcessComponentRecord( _
ws, params, logger, bomMatchResult("rowNums")(1))
Debug.Print " -> 返回物料数: " & componentMaterials.count
End If
' 步骤3: 创建匹配结果对象使用标准匹配的rowCount工作表行数不是物料数
matchResult("success") = bomMatchResult("success")
matchResult("rowCount") = bomMatchResult("rowCount") ' ✅ 关键修复使用标准匹配的rowCount
Set matchResult("rowNums") = bomMatchResult("rowNums")
' 步骤4: 添加物料到匹配结果
Dim compMat As Variant
For Each compMat In componentMaterials
Debug.Print " [" & compMat("materialType") & "] 名称=[" & compMat("materialName") & "] 编码=[" & compMat("materialCode") & "]"
@@ -434,7 +449,6 @@ Private Function MatchAllMaterialTypesWithValidation( _
Next compMat
Else
' 其他工作表使用标准匹配逻辑
Dim bomMatchResult As Object
Set bomMatchResult = M07_BOMMatcher.MatchBOMRecord(ws, params)
Debug.Print " -> 匹配结果: " & bomMatchResult("success") & ", 行数: " & bomMatchResult("rowCount")