feat: add production order number column to BOM extraction output
All checks were successful
NTFY Notification / notify (push) Successful in 4s
All checks were successful
NTFY Notification / notify (push) Successful in 4s
- Add 生产订单号 as the first column in output (13 columns total) - Read production order number from column A of input worksheet - Only display production order number on first row for each product model - Set material code column to text format to preserve leading zeros - Update OutputColumns enum indices in M04_Config.bas - Update ReadInputModels to return 2 columns (order number + model) - Update ProcessSingleModel, GenerateMaterialRow, GenerateErrorRow signatures - Update WriteExtractionResults to write 13 columns with text formatting Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -28,18 +28,19 @@ Public Const INPUT_COL_PRODUCT_MODEL As String = "产品型号"
|
|||||||
|
|
||||||
' 输出列枚举
|
' 输出列枚举
|
||||||
Public Enum OutputColumns
|
Public Enum OutputColumns
|
||||||
oc_OriginalModel = 1 ' 原始产品型号
|
oc_ProductionOrderNo = 1 ' 生产订单号
|
||||||
oc_Azxs = 2 ' 安装形式
|
oc_OriginalModel = 2 ' 原始产品型号
|
||||||
oc_Bkxs = 3 ' 表壳形式
|
oc_Azxs = 3 ' 安装形式
|
||||||
oc_Gclj = 4 ' 过程连接
|
oc_Bkxs = 4 ' 表壳形式
|
||||||
oc_Jycz = 5 ' 接液材质
|
oc_Gclj = 5 ' 过程连接
|
||||||
oc_Lcfw = 6 ' 量程范围
|
oc_Jycz = 6 ' 接液材质
|
||||||
oc_Fjgn = 7 ' 附加功能
|
oc_Lcfw = 7 ' 量程范围
|
||||||
oc_MaterialType = 8 ' 物料类型
|
oc_Fjgn = 8 ' 附加功能
|
||||||
oc_MaterialName = 9 ' 物料名称
|
oc_MaterialType = 9 ' 物料类型
|
||||||
oc_MaterialCode = 10 ' 物料编码
|
oc_MaterialName = 10 ' 物料名称
|
||||||
oc_MaterialQty = 11 ' 物料数量
|
oc_MaterialCode = 11 ' 物料编码
|
||||||
oc_Remarks = 12 ' 提取备注
|
oc_MaterialQty = 12 ' 物料数量
|
||||||
|
oc_Remarks = 13 ' 提取备注
|
||||||
End Enum
|
End Enum
|
||||||
|
|
||||||
' 型号解析常量
|
' 型号解析常量
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
'
|
'
|
||||||
' 输出格式:
|
' 输出格式:
|
||||||
' - 纵向展开格式,每个物料一行
|
' - 纵向展开格式,每个物料一行
|
||||||
' - 列: 原始产品型号, azxs, bkxs, gclj, jycz, lcfw, fjgn,
|
' - 列: 生产订单号, 原始产品型号, azxs, bkxs, gclj, jycz, lcfw, fjgn,
|
||||||
' 物料类型, 物料名称, 物料编码, 物料数量, 提取备注
|
' 物料类型, 物料名称, 物料编码, 物料数量, 提取备注
|
||||||
' ==============================================================================
|
' ==============================================================================
|
||||||
Option Explicit
|
Option Explicit
|
||||||
@@ -127,11 +127,14 @@ Public Function RunBOMExtraction() As String
|
|||||||
End If
|
End If
|
||||||
|
|
||||||
' 处理单个型号
|
' 处理单个型号
|
||||||
|
Dim productionOrderNo As String
|
||||||
Dim modelString As String
|
Dim modelString As String
|
||||||
modelString = CStr(inputModels(i, 1))
|
|
||||||
|
productionOrderNo = CStr(inputModels(i, 1)) ' Column A: 生产订单号
|
||||||
|
modelString = CStr(inputModels(i, 2)) ' Column B: 产品型号
|
||||||
|
|
||||||
Dim modelResults As Collection
|
Dim modelResults As Collection
|
||||||
Set modelResults = ProcessSingleModel(modelString, g_BOMWorkbook, g_Logger)
|
Set modelResults = ProcessSingleModel(modelString, g_BOMWorkbook, g_Logger, productionOrderNo)
|
||||||
|
|
||||||
' 合并结果
|
' 合并结果
|
||||||
Dim result As Variant
|
Dim result As Variant
|
||||||
@@ -164,7 +167,7 @@ Public Function RunBOMExtraction() As String
|
|||||||
errorCount = 0
|
errorCount = 0
|
||||||
|
|
||||||
For Each result In allResults
|
For Each result In allResults
|
||||||
If Len(CStr(result(12))) = 0 Then ' 第12列是备注
|
If Len(CStr(result(13))) = 0 Then ' 第13列是备注
|
||||||
successCount = successCount + 1
|
successCount = successCount + 1
|
||||||
Else
|
Else
|
||||||
errorCount = errorCount + 1
|
errorCount = errorCount + 1
|
||||||
@@ -283,7 +286,7 @@ Private Function ReadInputModels(ByVal ws As Worksheet) As Variant
|
|||||||
Dim colIdx As Long
|
Dim colIdx As Long
|
||||||
colIdx = headerCell.Column
|
colIdx = headerCell.Column
|
||||||
|
|
||||||
' 查找最后一行
|
' 查找最后一行(基于产品型号列)
|
||||||
Dim lastRow As Long
|
Dim lastRow As Long
|
||||||
lastRow = ws.Cells(ws.Rows.count, colIdx).End(xlUp).row
|
lastRow = ws.Cells(ws.Rows.count, colIdx).End(xlUp).row
|
||||||
|
|
||||||
@@ -292,8 +295,9 @@ Private Function ReadInputModels(ByVal ws As Worksheet) As Variant
|
|||||||
Exit Function
|
Exit Function
|
||||||
End If
|
End If
|
||||||
|
|
||||||
' 读取数据到数组
|
' 读取数据到数组(返回2列:生产订单号、产品型号)
|
||||||
ReadInputModels = ws.Range(ws.Cells(2, colIdx), ws.Cells(lastRow, colIdx)).Value
|
' 假设生产订单号在A列(列1),产品型号在colIdx列
|
||||||
|
ReadInputModels = ws.Range(ws.Cells(2, 1), ws.Cells(lastRow, colIdx)).Value
|
||||||
Exit Function
|
Exit Function
|
||||||
|
|
||||||
ErrorHandler:
|
ErrorHandler:
|
||||||
@@ -321,7 +325,8 @@ End Function
|
|||||||
Private Function ProcessSingleModel( _
|
Private Function ProcessSingleModel( _
|
||||||
ByVal modelString As String, _
|
ByVal modelString As String, _
|
||||||
ByVal bomWb As Workbook, _
|
ByVal bomWb As Workbook, _
|
||||||
ByVal logger As clsErrorLogger _
|
ByVal logger As clsErrorLogger, _
|
||||||
|
ByVal productionOrderNo As String _
|
||||||
) As Collection
|
) As Collection
|
||||||
On Error GoTo ErrorHandler
|
On Error GoTo ErrorHandler
|
||||||
|
|
||||||
@@ -335,7 +340,7 @@ Private Function ProcessSingleModel( _
|
|||||||
' 检查解析是否成功
|
' 检查解析是否成功
|
||||||
If params.count = 0 Then
|
If params.count = 0 Then
|
||||||
' 解析失败,添加错误行
|
' 解析失败,添加错误行
|
||||||
results.Add GenerateErrorRow(modelString, "型号解析失败:型号格式不正确或缺少必要字段")
|
results.Add GenerateErrorRow(modelString, "型号解析失败:型号格式不正确或缺少必要字段", productionOrderNo, True)
|
||||||
Set ProcessSingleModel = results
|
Set ProcessSingleModel = results
|
||||||
Exit Function
|
Exit Function
|
||||||
End If
|
End If
|
||||||
@@ -353,16 +358,21 @@ Private Function ProcessSingleModel( _
|
|||||||
remarks = validation("message")
|
remarks = validation("message")
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
' 生成物料行(第一条显示生产订单号,其余不显示)
|
||||||
|
Dim isFirstRow As Boolean
|
||||||
|
isFirstRow = True
|
||||||
|
|
||||||
Dim mat As Variant
|
Dim mat As Variant
|
||||||
For Each mat In allMaterials
|
For Each mat In allMaterials
|
||||||
Dim outputRow As Variant
|
Dim outputRow As Variant
|
||||||
outputRow = GenerateMaterialRow(modelString, params, mat, remarks)
|
outputRow = GenerateMaterialRow(modelString, params, mat, remarks, productionOrderNo, isFirstRow)
|
||||||
results.Add outputRow
|
results.Add outputRow
|
||||||
|
isFirstRow = False
|
||||||
Next mat
|
Next mat
|
||||||
|
|
||||||
' 如果没有匹配到任何物料,添加错误行
|
' 如果没有匹配到任何物料,添加错误行
|
||||||
If allMaterials.count = 0 Then
|
If allMaterials.count = 0 Then
|
||||||
results.Add GenerateErrorRow(modelString, "未匹配到任何物料")
|
results.Add GenerateErrorRow(modelString, "未匹配到任何物料", productionOrderNo, True)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Set ProcessSingleModel = results
|
Set ProcessSingleModel = results
|
||||||
@@ -374,7 +384,7 @@ ErrorHandler:
|
|||||||
"处理型号[" & modelString & "]失败: " & Err.Description, ""
|
"处理型号[" & modelString & "]失败: " & Err.Description, ""
|
||||||
End If
|
End If
|
||||||
|
|
||||||
results.Add GenerateErrorRow(modelString, "系统错误: " & Err.Description)
|
results.Add GenerateErrorRow(modelString, "系统错误: " & Err.Description, productionOrderNo, True)
|
||||||
Set ProcessSingleModel = results
|
Set ProcessSingleModel = results
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
@@ -888,52 +898,64 @@ End Function
|
|||||||
' params - 参数字典
|
' params - 参数字典
|
||||||
' material - 物料信息字典
|
' material - 物料信息字典
|
||||||
' remarks - 备注信息
|
' remarks - 备注信息
|
||||||
|
' productionOrderNo - 生产订单号
|
||||||
|
' isFirstRow - 是否为第一条记录(用于控制生产订单号显示)
|
||||||
'
|
'
|
||||||
' 输出:
|
' 输出:
|
||||||
' Variant - 包含12列数据的数组
|
' Variant - 包含13列数据的数组
|
||||||
'
|
'
|
||||||
' 列定义:
|
' 列定义:
|
||||||
' 1: 原始产品型号
|
' 1: 生产订单号(仅第一条记录显示)
|
||||||
' 2: azxs
|
' 2: 原始产品型号
|
||||||
' 3: bkxs
|
' 3: azxs
|
||||||
' 4: gclj
|
' 4: bkxs
|
||||||
' 5: jycz
|
' 5: gclj
|
||||||
' 6: lcfw
|
' 6: jycz
|
||||||
' 7: fjgn
|
' 7: lcfw
|
||||||
' 8: 物料类型
|
' 8: fjgn
|
||||||
' 9: 物料名称
|
' 9: 物料类型
|
||||||
' 10: 物料编码
|
' 10: 物料名称
|
||||||
' 11: 物料数量
|
' 11: 物料编码
|
||||||
' 12: 提取备注
|
' 12: 物料数量
|
||||||
|
' 13: 提取备注
|
||||||
' ------------------------------------------------------------------------------
|
' ------------------------------------------------------------------------------
|
||||||
Private Function GenerateMaterialRow( _
|
Private Function GenerateMaterialRow( _
|
||||||
ByVal modelString As String, _
|
ByVal modelString As String, _
|
||||||
ByVal params As Object, _
|
ByVal params As Object, _
|
||||||
ByVal material As Object, _
|
ByVal material As Object, _
|
||||||
ByVal remarks As String _
|
ByVal remarks As String, _
|
||||||
|
ByVal productionOrderNo As String, _
|
||||||
|
ByVal isFirstRow As Boolean _
|
||||||
) As Variant
|
) As Variant
|
||||||
Dim result(1 To 12) As Variant
|
Dim result(1 To 13) As Variant
|
||||||
|
|
||||||
' 第1列: 原始产品型号
|
' 第1列: 生产订单号(仅第一条记录显示)
|
||||||
result(1) = modelString
|
If isFirstRow Then
|
||||||
|
result(1) = productionOrderNo
|
||||||
|
Else
|
||||||
|
result(1) = ""
|
||||||
|
End If
|
||||||
|
|
||||||
' 第2-7列: 参数值
|
' 第2列: 原始产品型号
|
||||||
result(2) = GetParamValue(params, "azxs")
|
result(2) = modelString
|
||||||
result(3) = GetParamValue(params, "bkxs")
|
|
||||||
result(4) = GetParamValue(params, "gclj")
|
|
||||||
result(5) = GetParamValue(params, "jycz")
|
|
||||||
result(6) = GetParamValue(params, "lcfw")
|
|
||||||
result(7) = GetParamValue(params, "fjgn")
|
|
||||||
|
|
||||||
' 第8-11列: 物料信息
|
' 第3-8列: 参数值
|
||||||
result(8) = GetMaterialValue(material, "materialType")
|
result(3) = GetParamValue(params, "azxs")
|
||||||
result(9) = GetMaterialValue(material, "materialName")
|
result(4) = GetParamValue(params, "bkxs")
|
||||||
result(10) = GetMaterialValue(material, "materialCode")
|
result(5) = GetParamValue(params, "gclj")
|
||||||
result(11) = GetMaterialValue(material, "materialQty")
|
result(6) = GetParamValue(params, "jycz")
|
||||||
|
result(7) = GetParamValue(params, "lcfw")
|
||||||
|
result(8) = GetParamValue(params, "fjgn")
|
||||||
|
|
||||||
' 第12列: 备注
|
' 第9-12列: 物料信息
|
||||||
result(12) = remarks & " " & GetMaterialValue(material, "remarks")
|
result(9) = GetMaterialValue(material, "materialType")
|
||||||
result(12) = Trim(result(12))
|
result(10) = GetMaterialValue(material, "materialName")
|
||||||
|
result(11) = GetMaterialValue(material, "materialCode")
|
||||||
|
result(12) = GetMaterialValue(material, "materialQty")
|
||||||
|
|
||||||
|
' 第13列: 备注
|
||||||
|
result(13) = remarks & " " & GetMaterialValue(material, "remarks")
|
||||||
|
result(13) = Trim(result(13))
|
||||||
|
|
||||||
GenerateMaterialRow = result
|
GenerateMaterialRow = result
|
||||||
End Function
|
End Function
|
||||||
@@ -944,23 +966,28 @@ End Function
|
|||||||
' 输入:
|
' 输入:
|
||||||
' modelString - 原始产品型号
|
' modelString - 原始产品型号
|
||||||
' errorMessage - 错误消息
|
' errorMessage - 错误消息
|
||||||
|
' productionOrderNo - 生产订单号
|
||||||
|
' isFirstRow - 是否为第一条记录(错误行总是显示生产订单号)
|
||||||
'
|
'
|
||||||
' 输出:
|
' 输出:
|
||||||
' Variant - 包含12列数据的数组(仅型号和备注有值)
|
' Variant - 包含13列数据的数组(仅生产订单号、型号和备注有值)
|
||||||
' ------------------------------------------------------------------------------
|
' ------------------------------------------------------------------------------
|
||||||
Private Function GenerateErrorRow( _
|
Private Function GenerateErrorRow( _
|
||||||
ByVal modelString As String, _
|
ByVal modelString As String, _
|
||||||
ByVal errorMessage As String _
|
ByVal errorMessage As String, _
|
||||||
|
ByVal productionOrderNo As String, _
|
||||||
|
ByVal isFirstRow As Boolean _
|
||||||
) As Variant
|
) As Variant
|
||||||
Dim result(1 To 12) As Variant
|
Dim result(1 To 13) As Variant
|
||||||
Dim i As Long
|
Dim i As Long
|
||||||
|
|
||||||
For i = 1 To 12
|
For i = 1 To 13
|
||||||
result(i) = ""
|
result(i) = ""
|
||||||
Next i
|
Next i
|
||||||
|
|
||||||
result(1) = modelString
|
result(1) = productionOrderNo
|
||||||
result(12) = "错误: " & errorMessage
|
result(2) = modelString
|
||||||
|
result(13) = "错误: " & errorMessage
|
||||||
|
|
||||||
GenerateErrorRow = result
|
GenerateErrorRow = result
|
||||||
End Function
|
End Function
|
||||||
@@ -1021,16 +1048,16 @@ Private Function WriteExtractionResults(ByVal results As Collection) As Workshee
|
|||||||
|
|
||||||
' 写入表头
|
' 写入表头
|
||||||
Dim headers As Variant
|
Dim headers As Variant
|
||||||
headers = Array("原始产品型号", "azxs", "bkxs", "gclj", "jycz", "lcfw", "fjgn", _
|
headers = Array("生产订单号", "原始产品型号", "azxs", "bkxs", "gclj", "jycz", "lcfw", "fjgn", _
|
||||||
"物料类型", "物料名称", "物料编码", "物料数量", "提取备注")
|
"物料类型", "物料名称", "物料编码", "物料数量", "提取备注")
|
||||||
|
|
||||||
Dim c As Long
|
Dim c As Long
|
||||||
For c = 1 To 12
|
For c = 1 To 13
|
||||||
ws.Cells(1, c).Value = headers(c - 1)
|
ws.Cells(1, c).Value = headers(c - 1)
|
||||||
Next c
|
Next c
|
||||||
|
|
||||||
' 格式化表头
|
' 格式化表头
|
||||||
With ws.Range("A1:L1")
|
With ws.Range("A1:M1")
|
||||||
.Font.Bold = True
|
.Font.Bold = True
|
||||||
.Interior.Color = RGB(217, 217, 217)
|
.Interior.Color = RGB(217, 217, 217)
|
||||||
.HorizontalAlignment = xlCenter
|
.HorizontalAlignment = xlCenter
|
||||||
@@ -1038,8 +1065,12 @@ Private Function WriteExtractionResults(ByVal results As Collection) As Workshee
|
|||||||
|
|
||||||
' 写入数据
|
' 写入数据
|
||||||
If results.count > 0 Then
|
If results.count > 0 Then
|
||||||
|
' 先设置物料编码列(第11列,K列)为文本格式
|
||||||
|
ws.Range("K2:K" & (results.count + 1)).NumberFormat = "@"
|
||||||
|
|
||||||
|
' 准备输出数组
|
||||||
Dim outputArr() As Variant
|
Dim outputArr() As Variant
|
||||||
ReDim outputArr(1 To results.count, 1 To 12)
|
ReDim outputArr(1 To results.count, 1 To 13)
|
||||||
|
|
||||||
Dim i As Long
|
Dim i As Long
|
||||||
Dim result As Variant
|
Dim result As Variant
|
||||||
@@ -1048,15 +1079,15 @@ Private Function WriteExtractionResults(ByVal results As Collection) As Workshee
|
|||||||
result = results(i)
|
result = results(i)
|
||||||
|
|
||||||
Dim j As Long
|
Dim j As Long
|
||||||
For j = 1 To 12
|
For j = 1 To 13
|
||||||
outputArr(i, j) = result(j)
|
outputArr(i, j) = result(j)
|
||||||
Next j
|
Next j
|
||||||
Next i
|
Next i
|
||||||
|
|
||||||
ws.Range("A2").Resize(results.count, 12).Value = outputArr
|
ws.Range("A2").Resize(results.count, 13).Value = outputArr
|
||||||
|
|
||||||
' 格式化数据区域
|
' 格式化数据区域
|
||||||
With ws.Range("A2:L" & (results.count + 1))
|
With ws.Range("A2:M" & (results.count + 1))
|
||||||
.Borders.LineStyle = xlContinuous
|
.Borders.LineStyle = xlContinuous
|
||||||
.Borders.Weight = xlThin
|
.Borders.Weight = xlThin
|
||||||
End With
|
End With
|
||||||
@@ -1064,13 +1095,13 @@ Private Function WriteExtractionResults(ByVal results As Collection) As Workshee
|
|||||||
' 如果有错误备注,标红;如果有警告,标黄
|
' 如果有错误备注,标红;如果有警告,标黄
|
||||||
For i = 1 To results.count
|
For i = 1 To results.count
|
||||||
Dim remarkText As String
|
Dim remarkText As String
|
||||||
remarkText = CStr(outputArr(i, 12))
|
remarkText = CStr(outputArr(i, 13))
|
||||||
|
|
||||||
If Len(remarkText) > 0 Then
|
If Len(remarkText) > 0 Then
|
||||||
If InStr(remarkText, "错误") > 0 Then
|
If InStr(remarkText, "错误") > 0 Then
|
||||||
ws.Cells(i + 1, 12).Interior.Color = RGB(255, 200, 200)
|
ws.Cells(i + 1, 13).Interior.Color = RGB(255, 200, 200)
|
||||||
ElseIf InStr(remarkText, "警告") > 0 Or InStr(remarkText, "已忽略") > 0 Then
|
ElseIf InStr(remarkText, "警告") > 0 Or InStr(remarkText, "已忽略") > 0 Then
|
||||||
ws.Cells(i + 1, 12).Interior.Color = RGB(255, 255, 200)
|
ws.Cells(i + 1, 13).Interior.Color = RGB(255, 255, 200)
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
Next i
|
Next i
|
||||||
|
|||||||
Reference in New Issue
Block a user