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:
@@ -6,16 +6,15 @@ Option Explicit
|
||||
|
||||
' ========================================
|
||||
' 示例1: 根据型号生成完整的领料清单
|
||||
' ⭐ v2.0 更新:使用新的 LoadData(wsPlatform) 接口
|
||||
' ========================================
|
||||
Sub Example1_GeneratePickingListByModel()
|
||||
Dim bomMgr As New clsBOMManager
|
||||
Dim wsConfig As Worksheet
|
||||
Dim wsPlatform As Worksheet
|
||||
|
||||
' 加载配置
|
||||
Set wsConfig = ThisWorkbook.Worksheets("领料配置")
|
||||
Set wsPlatform = ThisWorkbook.Worksheets("平台配置清单")
|
||||
bomMgr.LoadData wsConfig, wsPlatform
|
||||
bomMgr.LoadData wsPlatform
|
||||
|
||||
' 产品型号
|
||||
Dim modelStr As String
|
||||
@@ -101,16 +100,15 @@ End Sub
|
||||
|
||||
' ========================================
|
||||
' 示例2: 批量处理多个型号
|
||||
' ⭐ v2.0 更新:使用新的 LoadData(wsPlatform) 接口
|
||||
' ========================================
|
||||
Sub Example2_BatchProcessModels()
|
||||
Dim bomMgr As New clsBOMManager
|
||||
Dim wsConfig As Worksheet
|
||||
Dim wsPlatform As Worksheet
|
||||
|
||||
' 加载配置
|
||||
Set wsConfig = ThisWorkbook.Worksheets("领料配置")
|
||||
Set wsPlatform = ThisWorkbook.Worksheets("平台配置清单")
|
||||
bomMgr.LoadData wsConfig, wsPlatform
|
||||
bomMgr.LoadData wsPlatform
|
||||
|
||||
' 型号列表
|
||||
Dim models() As String
|
||||
@@ -299,16 +297,15 @@ End Sub
|
||||
|
||||
' ========================================
|
||||
' 示例5: 验证物料选择条件的有效性
|
||||
' ⭐ v2.0 更新:使用新的 LoadData(wsPlatform) 接口
|
||||
' ========================================
|
||||
Sub Example5_ValidateMaterialConditions()
|
||||
Dim bomMgr As New clsBOMManager
|
||||
Dim wsConfig As Worksheet
|
||||
Dim wsPlatform As Worksheet
|
||||
|
||||
' 加载配置
|
||||
Set wsConfig = ThisWorkbook.Worksheets("领料配置")
|
||||
Set wsPlatform = ThisWorkbook.Worksheets("平台配置清单")
|
||||
bomMgr.LoadData wsConfig, wsPlatform
|
||||
bomMgr.LoadData wsPlatform
|
||||
|
||||
' 创建验证结果表
|
||||
Dim wsValidation As Worksheet
|
||||
@@ -378,16 +375,15 @@ End Sub
|
||||
|
||||
' ========================================
|
||||
' 示例6: 对比启用/禁用自动降级的效果
|
||||
' ⭐ v2.0 更新:使用新的 LoadData(wsPlatform) 接口
|
||||
' ========================================
|
||||
Sub Example6_CompareAutoFallback()
|
||||
Dim bomMgr As New clsBOMManager
|
||||
Dim wsConfig As Worksheet
|
||||
Dim wsPlatform As Worksheet
|
||||
|
||||
' 加载配置
|
||||
Set wsConfig = ThisWorkbook.Worksheets("领料配置")
|
||||
Set wsPlatform = ThisWorkbook.Worksheets("平台配置清单")
|
||||
bomMgr.LoadData wsConfig, wsPlatform
|
||||
bomMgr.LoadData wsPlatform
|
||||
|
||||
' 产品型号(使用可能导致类别缺失的型号)
|
||||
Dim modelStr As String
|
||||
@@ -503,16 +499,16 @@ End Sub
|
||||
|
||||
' ========================================
|
||||
' 示例7: 测试GetValidMaterialsByModel方法 (使用内置的缺失列表)
|
||||
' ⭐ v2.0 更新:使用新的 LoadData(wsPlatform) 接口
|
||||
' 完整性检查使用"类别选用条件"动态判断需要的类别
|
||||
' ========================================
|
||||
Sub Example7_TestGetValidMaterialsByModel()
|
||||
Dim bomMgr As New clsBOMManager
|
||||
Dim wsConfig As Worksheet
|
||||
Dim wsPlatform As Worksheet
|
||||
|
||||
' 加载配置
|
||||
Set wsConfig = ThisWorkbook.Worksheets("领料配置")
|
||||
Set wsPlatform = ThisWorkbook.Worksheets("平台配置清单")
|
||||
bomMgr.LoadData wsConfig, wsPlatform
|
||||
bomMgr.LoadData wsPlatform
|
||||
|
||||
' 创建测试结果工作表
|
||||
Dim wsTest As Worksheet
|
||||
@@ -635,24 +631,19 @@ End Sub
|
||||
|
||||
' ========================================
|
||||
' 示例8: 批量处理产品订单,生成物料清单
|
||||
' ⭐ v2.0 更新:使用新的 LoadData(wsPlatform) 接口
|
||||
' ========================================
|
||||
Sub Example8_BatchProcessOrders()
|
||||
Dim bomMgr As New clsBOMManager
|
||||
Dim wsConfig As Worksheet
|
||||
Dim wsPlatform As Worksheet
|
||||
Dim wsOrders As Worksheet
|
||||
Dim wsOutput As Worksheet
|
||||
|
||||
' 加载配置
|
||||
On Error Resume Next
|
||||
Set wsConfig = ThisWorkbook.Worksheets("领料配置")
|
||||
Set wsPlatform = ThisWorkbook.Worksheets("平台配置清单")
|
||||
Set wsOrders = ThisWorkbook.Worksheets("产品订单")
|
||||
|
||||
If wsConfig Is Nothing Then
|
||||
MsgBox "找不到工作表: 领料配置", vbCritical
|
||||
Exit Sub
|
||||
End If
|
||||
If wsPlatform Is Nothing Then
|
||||
MsgBox "找不到工作表: 平台配置清单", vbCritical
|
||||
Exit Sub
|
||||
@@ -663,7 +654,7 @@ Sub Example8_BatchProcessOrders()
|
||||
End If
|
||||
On Error GoTo 0
|
||||
|
||||
bomMgr.LoadData wsConfig, wsPlatform
|
||||
bomMgr.LoadData wsPlatform
|
||||
|
||||
' 读取订单数据
|
||||
Dim lastRow As Long
|
||||
@@ -808,28 +799,33 @@ End Sub
|
||||
' 功能:
|
||||
' 1. 提取型号条件
|
||||
' 2. 校验模块数量(如果是3个模块则报错)
|
||||
' 3. 校验类别完整性(如果缺失类别则报错)
|
||||
' 3. 校验类别完整性(如果缺失类别则报错,使用类别选用条件判断)
|
||||
' 4. 生成BOM清单
|
||||
'
|
||||
' ⭐ v2.0 更新:
|
||||
' - 移除 [领料配置] 表依赖
|
||||
' - 使用新的 LoadData(wsPlatform) 接口(单参数)
|
||||
' - 完整性检查使用"类别选用条件"动态判断需要的类别
|
||||
' ========================================
|
||||
Sub Example9_BatchProcessOrders_WithCheck()
|
||||
Dim bomMgr As New clsBOMManager
|
||||
Dim wsConfig As Worksheet, wsPlatform As Worksheet, wsOrders As Worksheet, wsOutput As Worksheet
|
||||
Dim wsPlatform As Worksheet, wsOrders As Worksheet, wsOutput As Worksheet
|
||||
Dim parser As clsModelParser
|
||||
Dim extractor As clsConditionExtractor
|
||||
|
||||
' 1. 初始化与加载数据
|
||||
On Error Resume Next
|
||||
Set wsConfig = ThisWorkbook.Worksheets("领料配置")
|
||||
Set wsPlatform = ThisWorkbook.Worksheets("平台配置清单")
|
||||
Set wsOrders = ThisWorkbook.Worksheets("产品订单")
|
||||
On Error GoTo 0
|
||||
|
||||
If wsConfig Is Nothing Or wsPlatform Is Nothing Or wsOrders Is Nothing Then
|
||||
MsgBox "错误:缺少必要的工作表 (领料配置/平台配置清单/产品订单)", vbCritical
|
||||
If wsPlatform Is Nothing Or wsOrders Is Nothing Then
|
||||
MsgBox "错误:缺少必要的工作表 (平台配置清单/产品订单)", vbCritical
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
bomMgr.LoadData wsConfig, wsPlatform
|
||||
' ⭐ 使用新接口:只需要一个参数
|
||||
bomMgr.LoadData wsPlatform
|
||||
|
||||
' 2. 准备输出容器
|
||||
Dim outputData As collection
|
||||
|
||||
Reference in New Issue
Block a user