refactor: replace row index with production order number in error reports
All checks were successful
NTFY Notification / notify (push) Successful in 12s

Replace "原表行号" (original row number) field with "生产订单号" (production order number) in BOM Extraction System error reporting to improve traceability.

Changes:
- clsErrorLogger: Update Record/RecordWarning signatures to accept OrderNo (String) instead of RowIndex (Long)
- M09_BOMExtractor: Propagate productionOrderNo through validation chain for context-aware error reporting
- M06/M07/M08: Use empty string for system-level errors without production order context
- Error report header: Change column B from "原表行号" to "生产订单号"

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-02-26 10:12:59 +08:00
parent 8477792d41
commit 7fea574531
5 changed files with 32 additions and 30 deletions

View File

@@ -13,9 +13,9 @@ Private Sub Class_Initialize()
End Sub End Sub
' 记录错误 ' 记录错误
Public Sub Record(RowIndex As Long, SourceFunc As String, ErrorType As String, Desc As String, Context As String) Public Sub Record(OrderNo As String, SourceFunc As String, ErrorType As String, Desc As String, Context As String)
' 使用数组存储单条错误信息:号, 来源, 类型, 描述, 上下文 ' 使用数组存储单条错误信息:生产订单号, 来源, 类型, 描述, 上下文
pErrors.Add Array(RowIndex, SourceFunc, ErrorType, Desc, Context) pErrors.Add Array(OrderNo, SourceFunc, ErrorType, Desc, Context)
End Sub End Sub
' 是否有错误 ' 是否有错误
@@ -34,8 +34,8 @@ Public Property Get HasIssues() As Boolean
End Property End Property
' 记录警告 ' 记录警告
Public Sub RecordWarning(RowIndex As Long, SourceFunc As String, WarningType As String, Desc As String, Context As String) Public Sub RecordWarning(OrderNo As String, SourceFunc As String, WarningType As String, Desc As String, Context As String)
pWarnings.Add Array(RowIndex, SourceFunc, WarningType, Desc, Context) pWarnings.Add Array(OrderNo, SourceFunc, WarningType, Desc, Context)
End Sub End Sub
' '
@@ -47,7 +47,7 @@ Public Sub PrintReport(targetWb As Workbook)
ws.Name = "错误报告_" & Format(Now, "hhmmss") ws.Name = "错误报告_" & Format(Now, "hhmmss")
' ("类型") ' ("类型")
ws.Range("A1:F1").Value = Array("类型", "原表行号", "来源模块", "错误类型", "详细描述", "原始数据") ws.Range("A1:F1").Value = Array("类型", "生产订单号", "来源模块", "错误类型", "详细描述", "原始数据")
ws.Range("A1:F1").Font.Bold = True ws.Range("A1:F1").Font.Bold = True
ws.Range("A1:F1").Interior.Color = RGB(217, 217, 217) ws.Range("A1:F1").Interior.Color = RGB(217, 217, 217)

View File

@@ -62,7 +62,7 @@ Public Function ParseProductModel(ByVal modelString As String) As Object
If Len(headerPart) = 0 Then If Len(headerPart) = 0 Then
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record 0, "M06.ParseProductModel", "ModelParseError", _ g_Logger.Record "", "M06.ParseProductModel", "ModelParseError", _
"无法提取表头部分,型号可能为空或格式错误", modelString "无法提取表头部分,型号可能为空或格式错误", modelString
End If End If
Set ParseProductModel = params Set ParseProductModel = params
@@ -75,7 +75,7 @@ Public Function ParseProductModel(ByVal modelString As String) As Object
If Not IsArray(segments) Then If Not IsArray(segments) Then
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record 0, "M06.ParseProductModel", "ModelParseError", _ g_Logger.Record "", "M06.ParseProductModel", "ModelParseError", _
"表头分割失败", headerPart "表头分割失败", headerPart
End If End If
Set ParseProductModel = params Set ParseProductModel = params
@@ -85,7 +85,7 @@ Public Function ParseProductModel(ByVal modelString As String) As Object
' 步骤3: 验证段数是否足够 ' 步骤3: 验证段数是否足够
If UBound(segments) - LBound(segments) + 1 < MODEL_HEADER_MIN_SEGMENTS Then If UBound(segments) - LBound(segments) + 1 < MODEL_HEADER_MIN_SEGMENTS Then
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record 0, "M06.ParseProductModel", "ModelParseError", _ g_Logger.Record "", "M06.ParseProductModel", "ModelParseError", _
"表头段数不足,需要至少" & MODEL_HEADER_MIN_SEGMENTS & "段,实际" & _ "表头段数不足,需要至少" & MODEL_HEADER_MIN_SEGMENTS & "段,实际" & _
(UBound(segments) - LBound(segments) + 1) & "段", headerPart (UBound(segments) - LBound(segments) + 1) & "段", headerPart
End If End If
@@ -160,7 +160,7 @@ Public Function ParseProductModel(ByVal modelString As String) As Object
ErrorHandler: ErrorHandler:
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record 0, "M06.ParseProductModel", "SystemError", _ g_Logger.Record "", "M06.ParseProductModel", "SystemError", _
"解析过程发生错误: " & Err.Description, modelString "解析过程发生错误: " & Err.Description, modelString
End If End If
Set ParseProductModel = CreateObject("Scripting.Dictionary") Set ParseProductModel = CreateObject("Scripting.Dictionary")

View File

@@ -141,7 +141,7 @@ Public Function MatchBOMRecord(ByVal ws As Worksheet, ByVal params As Object) As
ErrorHandler: ErrorHandler:
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record 0, "M07.MatchBOMRecord", "SystemError", _ g_Logger.Record "", "M07.MatchBOMRecord", "SystemError", _
"匹配过程发生错误: " & Err.Description, ws.Name "匹配过程发生错误: " & Err.Description, ws.Name
End If End If
@@ -430,7 +430,7 @@ Public Function ExtractMaterialInfo( _
ErrorHandler: ErrorHandler:
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record rowNum, "M07.ExtractMaterialInfo", "SystemError", _ g_Logger.Record "", "M07.ExtractMaterialInfo", "SystemError", _
"提取物料信息失败: " & Err.Description, ws.Name "提取物料信息失败: " & Err.Description, ws.Name
End If End If
Set ExtractMaterialInfo = CreateObject("Scripting.Dictionary") Set ExtractMaterialInfo = CreateObject("Scripting.Dictionary")

View File

@@ -77,7 +77,7 @@ Private Sub LoadInventoryData(ByVal inventoryWb As Workbook)
If wsInventory Is Nothing Then If wsInventory Is Nothing Then
' 未找到现存量工作表记录警告并使用空字典所有库存视为0 ' 未找到现存量工作表记录警告并使用空字典所有库存视为0
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.RecordWarning 0, "M08.LoadInventoryData", "InventorySheetMissing", _ g_Logger.RecordWarning "", "M08.LoadInventoryData", "InventorySheetMissing", _
"未找到[" & INVENTORY_SHEET_NAME & "]工作表所有部件库存将视为0", "" "未找到[" & INVENTORY_SHEET_NAME & "]工作表所有部件库存将视为0", ""
End If End If
Exit Sub Exit Sub
@@ -109,7 +109,7 @@ Private Sub LoadInventoryData(ByVal inventoryWb As Workbook)
ErrorHandler: ErrorHandler:
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.RecordWarning 0, "M08.LoadInventoryData", "LoadError", _ g_Logger.RecordWarning "", "M08.LoadInventoryData", "LoadError", _
"加载库存数据失败: " & Err.Description, "" "加载库存数据失败: " & Err.Description, ""
End If End If
End Sub End Sub
@@ -197,7 +197,7 @@ Public Function ProcessComponentRecord( _
ErrorHandler: ErrorHandler:
If Not logger Is Nothing Then If Not logger Is Nothing Then
logger.Record matchedRowNum, "M08.ProcessComponentRecord", "SystemError", _ logger.Record "", "M08.ProcessComponentRecord", "SystemError", _
"处理部件记录失败: " & Err.Description, "" "处理部件记录失败: " & Err.Description, ""
End If End If
@@ -291,7 +291,7 @@ Private Function CheckComponentInventory( _
If g_InventoryDict Is Nothing Or Not g_InventoryDict.Exists(componentCode) Then If g_InventoryDict Is Nothing Or Not g_InventoryDict.Exists(componentCode) Then
' 未找到库存数据记录警告并返回False库存不足 ' 未找到库存数据记录警告并返回False库存不足
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.RecordWarning rowNum, "M08.CheckComponentInventory", "InventoryNotFound", _ g_Logger.RecordWarning "", "M08.CheckComponentInventory", "InventoryNotFound", _
"部件[" & componentCode & "]未找到库存数据,视为库存不足", "" "部件[" & componentCode & "]未找到库存数据,视为库存不足", ""
End If End If
CheckComponentInventory = False CheckComponentInventory = False
@@ -321,7 +321,7 @@ Private Function CheckComponentInventory( _
Else Else
' 库存不足,记录错误 ' 库存不足,记录错误
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record rowNum, "M08.CheckComponentInventory", "InsufficientInventory", _ g_Logger.Record "", "M08.CheckComponentInventory", "InsufficientInventory", _
"部件[" & componentCode & "]库存不足。库存=" & stockQty & ", 累计需求=" & totalDemand, "" "部件[" & componentCode & "]库存不足。库存=" & stockQty & ", 累计需求=" & totalDemand, ""
End If End If
CheckComponentInventory = False CheckComponentInventory = False
@@ -331,7 +331,7 @@ Private Function CheckComponentInventory( _
ErrorHandler: ErrorHandler:
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record rowNum, "M08.CheckComponentInventory", "SystemError", _ g_Logger.Record "", "M08.CheckComponentInventory", "SystemError", _
"库存检查失败: " & Err.Description, "" "库存检查失败: " & Err.Description, ""
End If End If
' 出错时返回False库存不足 ' 出错时返回False库存不足
@@ -409,7 +409,7 @@ Private Function ExtractComponentInfo( _
ErrorHandler: ErrorHandler:
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record rowNum, "M08.ExtractComponentInfo", "SystemError", _ g_Logger.Record "", "M08.ExtractComponentInfo", "SystemError", _
"提取部件信息失败: " & Err.Description, componentType "提取部件信息失败: " & Err.Description, componentType
End If End If
Set ExtractComponentInfo = Nothing Set ExtractComponentInfo = Nothing
@@ -463,7 +463,7 @@ Private Function ExtractSubComponents( _
ErrorHandler: ErrorHandler:
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record rowNum, "M08.ExtractSubComponents", "SystemError", _ g_Logger.Record "", "M08.ExtractSubComponents", "SystemError", _
"提取子件信息失败: " & Err.Description, "" "提取子件信息失败: " & Err.Description, ""
End If End If
Set ExtractSubComponents = New Collection Set ExtractSubComponents = New Collection
@@ -559,7 +559,7 @@ Private Function ExtractSingleSubComponent( _
ErrorHandler: ErrorHandler:
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record rowNum, "M08.ExtractSingleSubComponent", "SystemError", _ g_Logger.Record "", "M08.ExtractSingleSubComponent", "SystemError", _
"提取子件[" & subComponentType & "]失败: " & Err.Description, "" "提取子件[" & subComponentType & "]失败: " & Err.Description, ""
End If End If
Set ExtractSingleSubComponent = Nothing Set ExtractSingleSubComponent = Nothing

View File

@@ -106,7 +106,7 @@ Public Function RunBOMExtraction() As String
M06A_Mapper.InitMapper g_Logger, wsMapping M06A_Mapper.InitMapper g_Logger, wsMapping
Else Else
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.RecordWarning 0, "M09.RunBOMExtraction", "MappingTableMissing", _ g_Logger.RecordWarning "", "M09.RunBOMExtraction", "MappingTableMissing", _
"未找到对照表工作表azxs和lcfw将仅使用原始值匹配", "" "未找到对照表工作表azxs和lcfw将仅使用原始值匹配", ""
End If End If
End If End If
@@ -355,7 +355,7 @@ Private Function ProcessSingleModel( _
' 步骤2: 匹配所有物料类型(两阶段) ' 步骤2: 匹配所有物料类型(两阶段)
Dim allMaterials As Collection Dim allMaterials As Collection
Dim validation As Object Dim validation As Object
Set allMaterials = MatchAllMaterialTypesWithValidation(params, bomWb, logger, orderQty, validation) Set allMaterials = MatchAllMaterialTypesWithValidation(params, bomWb, logger, orderQty, productionOrderNo, validation)
' 步骤3: 生成输出行 ' 步骤3: 生成输出行
Dim remarks As String Dim remarks As String
@@ -387,7 +387,7 @@ Private Function ProcessSingleModel( _
ErrorHandler: ErrorHandler:
If Not logger Is Nothing Then If Not logger Is Nothing Then
logger.Record 0, "M09.ProcessSingleModel", "SystemError", _ logger.Record productionOrderNo, "M09.ProcessSingleModel", "SystemError", _
"处理型号[" & modelString & "]失败: " & Err.Description, "" "处理型号[" & modelString & "]失败: " & Err.Description, ""
End If End If
@@ -422,6 +422,7 @@ Private Function MatchAllMaterialTypesWithValidation( _
ByVal bomWb As Workbook, _ ByVal bomWb As Workbook, _
ByVal logger As clsErrorLogger, _ ByVal logger As clsErrorLogger, _
ByVal orderQty As Long, _ ByVal orderQty As Long, _
ByVal productionOrderNo As String, _
ByRef outValidation As Object _ ByRef outValidation As Object _
) As Collection ) As Collection
On Error GoTo ErrorHandler On Error GoTo ErrorHandler
@@ -523,7 +524,7 @@ Private Function MatchAllMaterialTypesWithValidation( _
' Phase 2: 统一验证所有匹配结果 ' Phase 2: 统一验证所有匹配结果
' ======================================== ' ========================================
Dim validationResult As Object Dim validationResult As Object
Set validationResult = ValidateAllMatchResults(resultsDict, logger, params) Set validationResult = ValidateAllMatchResults(resultsDict, logger, params, productionOrderNo)
' ======================================== ' ========================================
' Phase 3: 根据验证结果生成最终物料集合 ' Phase 3: 根据验证结果生成最终物料集合
@@ -565,7 +566,7 @@ Private Function MatchAllMaterialTypesWithValidation( _
ErrorHandler: ErrorHandler:
If Not logger Is Nothing Then If Not logger Is Nothing Then
logger.Record 0, "M09.MatchAllMaterialTypesWithValidation", "SystemError", _ logger.Record productionOrderNo, "M09.MatchAllMaterialTypesWithValidation", "SystemError", _
"匹配物料类型失败: " & Err.Description, "" "匹配物料类型失败: " & Err.Description, ""
End If End If
@@ -606,7 +607,8 @@ End Function
Private Function ValidateAllMatchResults( _ Private Function ValidateAllMatchResults( _
ByVal resultsDict As Object, _ ByVal resultsDict As Object, _
ByVal logger As clsErrorLogger, _ ByVal logger As clsErrorLogger, _
ByVal params As Object _ ByVal params As Object, _
ByVal productionOrderNo As String _
) As Object ) As Object
On Error GoTo ErrorHandler On Error GoTo ErrorHandler
@@ -850,12 +852,12 @@ Private Function ValidateAllMatchResults( _
' ======================================== ' ========================================
Dim err As Variant Dim err As Variant
For Each err In errors For Each err In errors
logger.Record 0, "M09.ValidateAllMatchResults", "BOMMatchError", CStr(err), "" logger.Record productionOrderNo, "M09.ValidateAllMatchResults", "BOMMatchError", CStr(err), ""
Next err Next err
Dim warn As Variant Dim warn As Variant
For Each warn In warnings For Each warn In warnings
logger.RecordWarning 0, "M09.ValidateAllMatchResults", "ComponentConflict", CStr(warn), "" logger.RecordWarning productionOrderNo, "M09.ValidateAllMatchResults", "ComponentConflict", CStr(warn), ""
Next warn Next warn
' ======================================== ' ========================================
@@ -874,7 +876,7 @@ Private Function ValidateAllMatchResults( _
ErrorHandler: ErrorHandler:
If Not logger Is Nothing Then If Not logger Is Nothing Then
logger.Record 0, "M09.ValidateAllMatchResults", "SystemError", _ logger.Record productionOrderNo, "M09.ValidateAllMatchResults", "SystemError", _
"验证匹配结果失败: " & Err.Description, "" "验证匹配结果失败: " & Err.Description, ""
End If End If