refactor: update output fields in MainModule

- Add 生产订单号 field from column A of [产品订单] sheet
- Remove 表头型号 field from output
- Reorder columns to place 生产订单号 as first column
- Update ProcessSingleModel and CreateOutputRowArray signatures

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-02-03 09:45:28 +08:00
parent 8545177bd5
commit b412c55654

View File

@@ -73,13 +73,15 @@ Public Sub ProcessProductModels()
' 假设产品型号在第1列,从第2行开始 ' 假设产品型号在第1列,从第2行开始
For i = 2 To lastRow For i = 2 To lastRow
Dim orderNumber As String
orderNumber = Trim(inputSheet.Cells(i, 1).value) ' A列生产订单号
modelString = Trim(inputSheet.Cells(i, 2).value) modelString = Trim(inputSheet.Cells(i, 2).value)
Dim componentPriority As String Dim componentPriority As String
componentPriority = Trim(inputSheet.Cells(i, 5).value) ' E列部件优先 componentPriority = Trim(inputSheet.Cells(i, 5).value) ' E列部件优先
If modelString <> "" Then If modelString <> "" Then
' 处理单个型号,收集数据 ' 处理单个型号,收集数据
ProcessSingleModel modelString, componentPriority, BomExtractor, outputData ProcessSingleModel orderNumber, modelString, componentPriority, BomExtractor, outputData
processedCount = processedCount + 1 processedCount = processedCount + 1
End If End If
Next i Next i
@@ -111,12 +113,14 @@ End Sub
'===================================================================== '=====================================================================
' 过程: ProcessSingleModel ' 过程: ProcessSingleModel
' 功能: 处理单个产品型号,将数据添加到输出集合 ' 功能: 处理单个产品型号,将数据添加到输出集合
' 参数: modelString - 产品型号字符串 ' 参数: orderNumber - 生产订单号
' modelString - 产品型号字符串
' componentPriority - 部件优先标志("是"或"否" ' componentPriority - 部件优先标志("是"或"否"
' bomExtractor - BOM提取器对象 ' bomExtractor - BOM提取器对象
' outputData - 输出数据集合 ' outputData - 输出数据集合
'===================================================================== '=====================================================================
Private Sub ProcessSingleModel(modelString As String, _ Private Sub ProcessSingleModel(orderNumber As String, _
modelString As String, _
componentPriority As String, _ componentPriority As String, _
BomExtractor As BomExtractor, _ BomExtractor As BomExtractor, _
outputData As collection) outputData As collection)
@@ -140,7 +144,7 @@ Private Sub ProcessSingleModel(modelString As String, _
If Not parser.Parse(modelString) Then If Not parser.Parse(modelString) Then
' 解析失败 ' 解析失败
extractNote = "解析失败: " & parser.ErrorMessage extractNote = "解析失败: " & parser.ErrorMessage
outputData.Add CreateOutputRowArray(modelString, "", parser.Conditions, extractNote, Nothing) outputData.Add CreateOutputRowArray(orderNumber, modelString, parser.Conditions, extractNote, Nothing)
Exit Sub Exit Sub
End If End If
@@ -161,7 +165,7 @@ Private Sub ProcessSingleModel(modelString As String, _
If extractNote = "" Then If extractNote = "" Then
extractNote = "未匹配到任何物料" extractNote = "未匹配到任何物料"
End If End If
outputData.Add CreateOutputRowArray(modelString, parser.HeaderModel, parser.Conditions, extractNote, Nothing) outputData.Add CreateOutputRowArray(orderNumber, modelString, parser.Conditions, extractNote, Nothing)
Else Else
' 输出每个匹配的物料 ' 输出每个匹配的物料
Dim item As BomItem Dim item As BomItem
@@ -179,10 +183,10 @@ Private Sub ProcessSingleModel(modelString As String, _
End If End If
If isFirst Then If isFirst Then
outputData.Add CreateOutputRowArray(modelString, parser.HeaderModel, parser.Conditions, itemNote, item) outputData.Add CreateOutputRowArray(orderNumber, modelString, parser.Conditions, itemNote, item)
isFirst = False isFirst = False
Else Else
outputData.Add CreateOutputRowArray("", "", parser.Conditions, itemNote, item) outputData.Add CreateOutputRowArray("", modelString, parser.Conditions, itemNote, item)
End If End If
Next item Next item
End If End If
@@ -197,8 +201,8 @@ Private Sub WriteOutputHeader(ws As Worksheet)
Dim col As Long Dim col As Long
col = 1 col = 1
ws.Cells(1, col).value = "生产订单号": col = col + 1
ws.Cells(1, col).value = "产品型号": col = col + 1 ws.Cells(1, col).value = "产品型号": col = col + 1
ws.Cells(1, col).value = "表头型号": col = col + 1
' 写入条件字段表头 ' 写入条件字段表头
Dim Conditions() As String Dim Conditions() As String
@@ -225,15 +229,15 @@ End Sub
'===================================================================== '=====================================================================
' 函数: CreateOutputRowArray ' 函数: CreateOutputRowArray
' 功能: 创建输出行数据的数组 ' 功能: 创建输出行数据的数组
' 参数: FullModel - 完整型 ' 参数: orderNumber - 生产订单
' HeaderModel - 表头型号 ' FullModel - 完整型号
' Conditions - 条件字典 ' Conditions - 条件字典
' note - 备注 ' note - 备注
' item - BOM项(可为Nothing) ' item - BOM项(可为Nothing)
' 返回: Variant() - 行数据数组 ' 返回: Variant() - 行数据数组
'===================================================================== '=====================================================================
Private Function CreateOutputRowArray(FullModel As String, _ Private Function CreateOutputRowArray(orderNumber As String, _
HeaderModel As String, _ FullModel As String, _
Conditions As Object, _ Conditions As Object, _
note As String, _ note As String, _
item As BomItem) As Variant() item As BomItem) As Variant()
@@ -252,9 +256,9 @@ Private Function CreateOutputRowArray(FullModel As String, _
Dim col As Long Dim col As Long
col = 1 col = 1
' 产品型号和表头型号 ' 生产订单号和产品型号
rowData(col) = orderNumber: col = col + 1
rowData(col) = FullModel: col = col + 1 rowData(col) = FullModel: col = col + 1
rowData(col) = HeaderModel: col = col + 1
' 写入条件值 ' 写入条件值
Dim i As Long Dim i As Long