fix: component worksheet rowCount false positive validation error
Some checks failed
NTFY Notification / notify (push) Failing after 3s
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:
@@ -37,67 +37,61 @@ End Sub
|
||||
' wsComponent - "部件"工作表
|
||||
' params - 从产品型号中提取的参数字典
|
||||
' logger - 错误记录器
|
||||
' matchedRowNum - 匹配到的行号(由调用者传入,避免重复匹配)
|
||||
'
|
||||
' 输出:
|
||||
' Collection - 物料集合
|
||||
' 每个元素是一个字典,包含: materialName, materialCode, materialQty, materialType, remarks
|
||||
'
|
||||
' 逻辑流程:
|
||||
' 1. 在"部件"工作表中查找匹配记录
|
||||
' 2. 如果恰好匹配1条:
|
||||
' a. 检查"部件"物料库存
|
||||
' b. 如果有库存,返回部件物料
|
||||
' c. 如果无库存,提取子件(接头+弹性元件)
|
||||
' 3. 如果未匹配或多条匹配,记录错误
|
||||
' 1. 使用传入的matchedRowNum定位匹配记录
|
||||
' 2. 检查"部件"物料库存
|
||||
' 3. 如果有库存,返回部件物料
|
||||
' 4. 如果无库存,提取子件(接头+弹性元件)
|
||||
'
|
||||
' 示例:
|
||||
' Set materials = ProcessComponentRecord(wsComponent, params, logger)
|
||||
' Set materials = ProcessComponentRecord(wsComponent, params, logger, 5)
|
||||
' ' materials(1) - 部件物料 或 接头物料
|
||||
' ' materials(2) - 弹性元件物料(如果选择子件)
|
||||
' ------------------------------------------------------------------------------
|
||||
Public Function ProcessComponentRecord( _
|
||||
ByVal wsComponent As Worksheet, _
|
||||
ByVal params As Object, _
|
||||
ByVal logger As clsErrorLogger _
|
||||
ByVal logger As clsErrorLogger, _
|
||||
ByVal matchedRowNum As Long _
|
||||
) As Collection
|
||||
On Error GoTo ErrorHandler
|
||||
|
||||
Dim materials As Collection
|
||||
Set materials = New Collection
|
||||
|
||||
' 步骤1: 在"部件"工作表中查找匹配记录
|
||||
Dim matchResult As Object
|
||||
Set matchResult = M07_BOMMatcher.MatchBOMRecord(wsComponent, params)
|
||||
|
||||
' 步骤2: 判断匹配结果
|
||||
If Not matchResult("success") Then
|
||||
' 匹配失败(0条或多条),记录错误
|
||||
' 步骤1: 验证传入的行号
|
||||
If matchedRowNum <= 0 Then
|
||||
' 无效行号,返回错误物料
|
||||
Dim errorMaterial As Object
|
||||
Set errorMaterial = CreateObject("Scripting.Dictionary")
|
||||
errorMaterial("materialType") = "部件"
|
||||
errorMaterial("materialName") = ""
|
||||
errorMaterial("materialCode") = ""
|
||||
errorMaterial("materialQty") = 0
|
||||
errorMaterial("remarks") = matchResult("message")
|
||||
errorMaterial("remarks") = "无效的匹配行号"
|
||||
materials.Add errorMaterial
|
||||
|
||||
Set ProcessComponentRecord = materials
|
||||
Exit Function
|
||||
End If
|
||||
|
||||
' 步骤3: 获取匹配的行号
|
||||
Dim rowNum As Long
|
||||
rowNum = matchResult("rowNums")(1)
|
||||
' 步骤2: 使用传入的行号
|
||||
|
||||
' 步骤4: 构建表头映射
|
||||
' 步骤3: 构建表头映射
|
||||
Dim headerMap As Object
|
||||
Set headerMap = M07_BOMMatcher.BuildWorksheetHeaderMap(wsComponent)
|
||||
|
||||
' 步骤5: 检查部件库存
|
||||
If CheckComponentInventory(wsComponent, rowNum, headerMap) Then
|
||||
' 步骤4: 检查部件库存
|
||||
If CheckComponentInventory(wsComponent, matchedRowNum, headerMap) Then
|
||||
' 库存充足,返回部件物料
|
||||
Dim componentInfo As Object
|
||||
Set componentInfo = ExtractComponentInfo(wsComponent, rowNum, headerMap, "部件")
|
||||
Set componentInfo = ExtractComponentInfo(wsComponent, matchedRowNum, headerMap, "部件")
|
||||
|
||||
If Not componentInfo Is Nothing Then
|
||||
materials.Add componentInfo
|
||||
@@ -105,7 +99,7 @@ Public Function ProcessComponentRecord( _
|
||||
Else
|
||||
' 库存不足,提取子件(接头+弹性元件)
|
||||
Dim subComponents As Collection
|
||||
Set subComponents = ExtractSubComponents(wsComponent, rowNum, headerMap)
|
||||
Set subComponents = ExtractSubComponents(wsComponent, matchedRowNum, headerMap)
|
||||
|
||||
Dim subComp As Variant
|
||||
For Each subComp In subComponents
|
||||
@@ -118,7 +112,7 @@ Public Function ProcessComponentRecord( _
|
||||
|
||||
ErrorHandler:
|
||||
If Not logger Is Nothing Then
|
||||
logger.Record 0, "M08.ProcessComponentRecord", "SystemError", _
|
||||
logger.Record matchedRowNum, "M08.ProcessComponentRecord", "SystemError", _
|
||||
"处理部件记录失败: " & Err.Description, ""
|
||||
End If
|
||||
|
||||
|
||||
Reference in New Issue
Block a user