feat: add component priority exclusion feature
Add support for excluding "部件" category based on component priority flag: - BomExtractor: Add exclude categories functionality - Add pExcludeCategories collection member - Add SetExcludeCategories() and ClearExcludeCategories() methods - Modify DetermineRequiredCategories() to skip excluded categories - BIPUploadModule: Read and use component priority field - Read component priority from column E of [产品订单] worksheet - Pass component priority to ProcessSingleOrder() - When priority is "否"/"0"/"FALSE", exclude "部件" category - Only extract sub-category materials when component priority is disabled Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@ Private pMatchedItems As collection ' 匹配的BOM项
|
|||||||
Private pRequiredCategories As collection ' 需要的类别
|
Private pRequiredCategories As collection ' 需要的类别
|
||||||
Private pCategoryHierarchy As Object ' 类别层次结构 Dictionary(子类别->父类别)
|
Private pCategoryHierarchy As Object ' 类别层次结构 Dictionary(子类别->父类别)
|
||||||
Private pErrorMessages As collection
|
Private pErrorMessages As collection
|
||||||
|
Private pExcludeCategories As collection ' 需要排除的类别
|
||||||
|
|
||||||
'=====================================================================
|
'=====================================================================
|
||||||
' 方法: Class_Initialize
|
' 方法: Class_Initialize
|
||||||
@@ -26,6 +27,7 @@ Private Sub Class_Initialize()
|
|||||||
Set pRequiredCategories = New collection
|
Set pRequiredCategories = New collection
|
||||||
Set pCategoryHierarchy = CreateObject("Scripting.Dictionary")
|
Set pCategoryHierarchy = CreateObject("Scripting.Dictionary")
|
||||||
Set pErrorMessages = New collection
|
Set pErrorMessages = New collection
|
||||||
|
Set pExcludeCategories = New collection
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
'=====================================================================
|
'=====================================================================
|
||||||
@@ -93,6 +95,23 @@ ErrorHandler:
|
|||||||
LoadBomData = False
|
LoadBomData = False
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
'=====================================================================
|
||||||
|
' 方法: SetExcludeCategories
|
||||||
|
' 功能: 设置需要排除的类别
|
||||||
|
' 参数: categories - 类别集合
|
||||||
|
'=====================================================================
|
||||||
|
Public Sub SetExcludeCategories(categories As collection)
|
||||||
|
Set pExcludeCategories = categories
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'=====================================================================
|
||||||
|
' 方法: ClearExcludeCategories
|
||||||
|
' 功能: 清空排除类别列表
|
||||||
|
'=====================================================================
|
||||||
|
Public Sub ClearExcludeCategories()
|
||||||
|
Set pExcludeCategories = New collection
|
||||||
|
End Sub
|
||||||
|
|
||||||
'=====================================================================
|
'=====================================================================
|
||||||
' 方法: ExtractBom
|
' 方法: ExtractBom
|
||||||
' 功能: 根据产品条件提取BOM
|
' 功能: 根据产品条件提取BOM
|
||||||
@@ -141,20 +160,34 @@ Private Sub DetermineRequiredCategories(productConditions As Object)
|
|||||||
' 遍历所有有效物料,获取唯一类别
|
' 遍历所有有效物料,获取唯一类别
|
||||||
For Each item In pAllItems
|
For Each item In pAllItems
|
||||||
If item.IsValidItem Then
|
If item.IsValidItem Then
|
||||||
' 检查类别选用条件
|
' 检查是否在排除列表中
|
||||||
Dim categoryRequired As Boolean
|
Dim isExcluded As Boolean
|
||||||
If Trim(item.CategoryCondition) = "" Then
|
isExcluded = False
|
||||||
' 无条件,必需类别
|
Dim excludeCat As Variant
|
||||||
categoryRequired = True
|
For Each excludeCat In pExcludeCategories
|
||||||
Else
|
If item.category = CStr(excludeCat) Then
|
||||||
' 有条件,评估条件
|
isExcluded = True
|
||||||
categoryRequired = pConditionEvaluator.Evaluate(item.CategoryCondition, productConditions)
|
Exit For
|
||||||
End If
|
End If
|
||||||
|
Next excludeCat
|
||||||
|
|
||||||
If categoryRequired Then
|
' 如果不在排除列表中,继续处理
|
||||||
If Not uniqueCategories.Exists(item.category) Then
|
If Not isExcluded Then
|
||||||
uniqueCategories.Add item.category, True
|
' 检查类别选用条件
|
||||||
pRequiredCategories.Add item.category
|
Dim categoryRequired As Boolean
|
||||||
|
If Trim(item.CategoryCondition) = "" Then
|
||||||
|
' 无条件,必需类别
|
||||||
|
categoryRequired = True
|
||||||
|
Else
|
||||||
|
' 有条件,评估条件
|
||||||
|
categoryRequired = pConditionEvaluator.Evaluate(item.CategoryCondition, productConditions)
|
||||||
|
End If
|
||||||
|
|
||||||
|
If categoryRequired Then
|
||||||
|
If Not uniqueCategories.Exists(item.category) Then
|
||||||
|
uniqueCategories.Add item.category, True
|
||||||
|
pRequiredCategories.Add item.category
|
||||||
|
End If
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
|
|||||||
@@ -91,11 +91,13 @@ Public Sub ProcessOrdersToBIP()
|
|||||||
Dim productModel As String
|
Dim productModel As String
|
||||||
Dim quantity As String
|
Dim quantity As String
|
||||||
Dim productCode As String
|
Dim productCode As String
|
||||||
|
Dim componentPriority As String
|
||||||
|
|
||||||
orderNumber = Trim(orderSheet.Cells(i, 1).value) ' A列:生产订单号
|
orderNumber = Trim(orderSheet.Cells(i, 1).value) ' A列:生产订单号
|
||||||
productModel = Trim(orderSheet.Cells(i, 2).value) ' B列:产品型号
|
productModel = Trim(orderSheet.Cells(i, 2).value) ' B列:产品型号
|
||||||
quantity = Trim(orderSheet.Cells(i, 3).value) ' C列:数量
|
quantity = Trim(orderSheet.Cells(i, 3).value) ' C列:数量
|
||||||
productCode = Trim(orderSheet.Cells(i, 4).value) ' D列:产品编码
|
productCode = Trim(orderSheet.Cells(i, 4).value) ' D列:产品编码
|
||||||
|
componentPriority = Trim(orderSheet.Cells(i, 5).value) ' E列:部件优先
|
||||||
|
|
||||||
' 跳过空行
|
' 跳过空行
|
||||||
If orderNumber = "" And productModel = "" Then
|
If orderNumber = "" And productModel = "" Then
|
||||||
@@ -122,7 +124,7 @@ Public Sub ProcessOrdersToBIP()
|
|||||||
|
|
||||||
' 处理单个订单
|
' 处理单个订单
|
||||||
outputRow = ProcessSingleOrder(orderNumber, productModel, quantity, productCode, _
|
outputRow = ProcessSingleOrder(orderNumber, productModel, quantity, productCode, _
|
||||||
BomExtractor, bipSheet, outputRow)
|
componentPriority, BomExtractor, bipSheet, outputRow)
|
||||||
processedCount = processedCount + 1
|
processedCount = processedCount + 1
|
||||||
|
|
||||||
ContinueLoop:
|
ContinueLoop:
|
||||||
@@ -155,6 +157,7 @@ End Sub
|
|||||||
' productModel - 产品型号
|
' productModel - 产品型号
|
||||||
' quantity - 生产数量
|
' quantity - 生产数量
|
||||||
' productCode - 产品编码
|
' productCode - 产品编码
|
||||||
|
' componentPriority - 部件优先标志("是"或"否")
|
||||||
' BomExtractor - BOM提取器对象
|
' BomExtractor - BOM提取器对象
|
||||||
' bipSheet - BIP上传模板工作表
|
' bipSheet - BIP上传模板工作表
|
||||||
' startRow - 起始行号
|
' startRow - 起始行号
|
||||||
@@ -164,6 +167,7 @@ Private Function ProcessSingleOrder(orderNumber As String, _
|
|||||||
productModel As String, _
|
productModel As String, _
|
||||||
quantity As String, _
|
quantity As String, _
|
||||||
productCode As String, _
|
productCode As String, _
|
||||||
|
componentPriority As String, _
|
||||||
BomExtractor As BomExtractor, _
|
BomExtractor As BomExtractor, _
|
||||||
bipSheet As Worksheet, _
|
bipSheet As Worksheet, _
|
||||||
startRow As Long) As Long
|
startRow As Long) As Long
|
||||||
@@ -172,6 +176,14 @@ Private Function ProcessSingleOrder(orderNumber As String, _
|
|||||||
Dim currentRow As Long
|
Dim currentRow As Long
|
||||||
currentRow = startRow
|
currentRow = startRow
|
||||||
|
|
||||||
|
' 根据部件优先设置排除类别
|
||||||
|
BomExtractor.ClearExcludeCategories
|
||||||
|
If UCase(componentPriority) = "否" Or componentPriority = "0" Or componentPriority = "FALSE" Then
|
||||||
|
Dim excludeCats As New collection
|
||||||
|
excludeCats.Add "部件"
|
||||||
|
BomExtractor.SetExcludeCategories excludeCats
|
||||||
|
End If
|
||||||
|
|
||||||
' 解析产品型号
|
' 解析产品型号
|
||||||
Dim parser As ProductModelParser
|
Dim parser As ProductModelParser
|
||||||
Set parser = New ProductModelParser
|
Set parser = New ProductModelParser
|
||||||
|
|||||||
Reference in New Issue
Block a user