fix: update modules to use new LoadData interface and fix completeness check logic
Changes:
1. Update all modules to use LoadData(wsPlatform) instead of LoadData(wsConfig, wsPlatform)
- modModelParserExamples.bas: Update 7 example procedures
- modBOMProcessor.bas: Update 4 procedures
- modModelParserTest.bas: Update 2 test procedures
2. Fix completeness check logic in GetValidMaterialsByModel
- Only check root categories to avoid duplicate checking of subcategories
- Previously, all required categories (including subcategories) were checked,
causing subcategories to be added to missing list multiple times
- Now only checks categories with ParentCategoryName = ""
- CheckCategoryCompleteness already recursively checks all subcategories
3. Improve completeness judgment logic for categories with subcategories
- Method 1: Parent category has 1 matching material → Complete
- Method 2: Parent category has 0 matching materials, but all subcategories are complete → Complete
- Other cases → Incomplete
Impact:
- Fixes "category missing" errors in Example9_BatchProcessOrders_WithCheck
- Eliminates duplicate entries in missing categories list
- Properly handles category hierarchy where parent categories are satisfied through subcategories
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -806,7 +806,10 @@ Public Function GetValidMaterialsByModel(modelStr As String) As collection
|
||||
Dim requiredCats As collection
|
||||
Set requiredCats = GetRequiredCategories(conditions)
|
||||
|
||||
' ⭐ 第二步: 只检查需要的类别的完整性
|
||||
' ⭐ 第二步: 只检查需要的根类别的完整性
|
||||
' 说明: 不检查所有需要的类别,而是只检查根类别
|
||||
' 因为 CheckCategoryCompleteness 会递归检查子类别
|
||||
' 如果检查所有类别(包括子类别),会导致重复检查和重复添加到 missingCats
|
||||
isComplete = True
|
||||
|
||||
Dim reqCat As clsCategory
|
||||
@@ -814,9 +817,13 @@ Public Function GetValidMaterialsByModel(modelStr As String) As collection
|
||||
For i = 1 To requiredCats.Count
|
||||
Set reqCat = requiredCats(i)
|
||||
|
||||
' 检查该类别及其子类别的完整性
|
||||
Dim catResult As Object
|
||||
Set catResult = CheckCategoryCompleteness(reqCat, matcher, conditions)
|
||||
' ⭐ 关键修正: 只检查根类别(无父类别的类别)
|
||||
' 这样可以避免对"部件"及其子类别"接头"、"弹性元件"都进行检查
|
||||
' 否则会导致子类别被重复添加到缺失列表
|
||||
If reqCat.ParentCategoryName = "" Then
|
||||
' 检查该根类别及其所有子类别的完整性
|
||||
Dim catResult As Object
|
||||
Set catResult = CheckCategoryCompleteness(reqCat, matcher, conditions)
|
||||
|
||||
' 1. 合并匹配到的物料
|
||||
Dim mat As clsMaterialItem
|
||||
@@ -826,18 +833,19 @@ Public Function GetValidMaterialsByModel(modelStr As String) As collection
|
||||
allMaterials.Add mat
|
||||
Next mat
|
||||
|
||||
' 2. 合并缺失的类别
|
||||
Dim missingCollection As collection
|
||||
Set missingCollection = catResult("Missing")
|
||||
Dim missingCatName As Variant
|
||||
For Each missingCatName In missingCollection
|
||||
allMissingCats.Add missingCatName
|
||||
Next missingCatName
|
||||
' 2. 合并缺失的类别
|
||||
Dim missingCollection As collection
|
||||
Set missingCollection = catResult("Missing")
|
||||
Dim missingCatName As Variant
|
||||
For Each missingCatName In missingCollection
|
||||
allMissingCats.Add missingCatName
|
||||
Next missingCatName
|
||||
|
||||
' 3. 检查完整性状态
|
||||
If Not catResult("IsComplete") Then
|
||||
isComplete = False
|
||||
End If
|
||||
' 3. 检查完整性状态
|
||||
If Not catResult("IsComplete") Then
|
||||
isComplete = False
|
||||
End If
|
||||
End If ' ⭐ 结束 If reqCat.ParentCategoryName = "" 的判断
|
||||
Next i
|
||||
|
||||
' 返回结果
|
||||
@@ -914,13 +922,17 @@ Private Function CheckCategoryCompleteness(cat As clsCategory, _
|
||||
Else
|
||||
' ========================================
|
||||
' 情况2: 有子类别
|
||||
' 完整性判断规则:
|
||||
' - 方式一: 父类别有1个匹配物料 → 完整
|
||||
' - 方式二: 父类别无匹配物料, 但所有子类别都完整 → 完整
|
||||
' - 其他情况 → 不完整
|
||||
' ========================================
|
||||
If matchCount = 1 Then
|
||||
' 父类别有且仅有1个物料, 使用父类别 -> 完整
|
||||
' 方式一: 父类别有且仅有1个物料, 使用父类别 -> 完整
|
||||
isComplete = True
|
||||
' 不需要检查子类别了,missingCats 保持为空
|
||||
ElseIf matchCount = 0 Then
|
||||
' 父类别无匹配物料, 必须降级检查所有子类别
|
||||
' 方式二: 父类别无匹配物料, 必须降级检查所有子类别
|
||||
|
||||
' 清空当前物料集合(确保没东西), 准备收集子类别结果
|
||||
Set materials = New collection
|
||||
@@ -943,7 +955,7 @@ Private Function CheckCategoryCompleteness(cat As clsCategory, _
|
||||
materials.Add subMaterials(k)
|
||||
Next k
|
||||
|
||||
' b) 合并子类别缺失列表 (关键步骤)
|
||||
' b) 合并子类别缺失列表
|
||||
Dim subMissing As collection
|
||||
Set subMissing = subResult("Missing")
|
||||
Dim item As Variant
|
||||
@@ -956,9 +968,14 @@ Private Function CheckCategoryCompleteness(cat As clsCategory, _
|
||||
isComplete = False
|
||||
End If
|
||||
Next j
|
||||
|
||||
' ⭐ 关键修正: 如果所有子类别都完整, 父类别不应该被标记为缺失
|
||||
' 只有当父类别是叶子类别且没有物料时, 才应该被标记为缺失
|
||||
' 对于有子类别的父类别, 只要所有子类别都完整, 父类别就是完整的
|
||||
Else
|
||||
' 父类别有 >1 个匹配, 视为不完整(冲突)
|
||||
isComplete = False
|
||||
' 父类别有多个匹配, 这种情况下不应该标记为缺失(而是配置错误)
|
||||
End If
|
||||
End If
|
||||
|
||||
|
||||
Reference in New Issue
Block a user