From 7fea57453189331caae7f26b4afc5797c1d39634 Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Thu, 26 Feb 2026 10:12:59 +0800 Subject: [PATCH] refactor: replace row index with production order number in error reports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../ClassModules/clsErrorLogger.cls | 12 +++++------ VBA_BOMConverter/Modules/M06_ModelParser.bas | 8 ++++---- VBA_BOMConverter/Modules/M07_BOMMatcher.bas | 4 ++-- .../Modules/M08_ComponentProcessor.bas | 18 ++++++++--------- VBA_BOMConverter/Modules/M09_BOMExtractor.bas | 20 ++++++++++--------- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/VBA_BOMConverter/ClassModules/clsErrorLogger.cls b/VBA_BOMConverter/ClassModules/clsErrorLogger.cls index 5312e4c..7c294b7 100644 --- a/VBA_BOMConverter/ClassModules/clsErrorLogger.cls +++ b/VBA_BOMConverter/ClassModules/clsErrorLogger.cls @@ -13,9 +13,9 @@ Private Sub Class_Initialize() End Sub ' 记录错误 -Public Sub Record(RowIndex As Long, SourceFunc As String, ErrorType As String, Desc As String, Context As String) - ' 使用数组存储单条错误信息:行号, 来源, 类型, 描述, 上下文 - pErrors.Add Array(RowIndex, SourceFunc, ErrorType, Desc, Context) +Public Sub Record(OrderNo As String, SourceFunc As String, ErrorType As String, Desc As String, Context As String) + ' 使用数组存储单条错误信息:生产订单号, 来源, 类型, 描述, 上下文 + pErrors.Add Array(OrderNo, SourceFunc, ErrorType, Desc, Context) End Sub ' 是否有错误 @@ -34,8 +34,8 @@ Public Property Get HasIssues() As Boolean End Property ' 记录警告 -Public Sub RecordWarning(RowIndex As Long, SourceFunc As String, WarningType As String, Desc As String, Context As String) - pWarnings.Add Array(RowIndex, SourceFunc, WarningType, Desc, Context) +Public Sub RecordWarning(OrderNo As String, SourceFunc As String, WarningType As String, Desc As String, Context As String) + pWarnings.Add Array(OrderNo, SourceFunc, WarningType, Desc, Context) End Sub ' 输出报告到新工作表 @@ -47,7 +47,7 @@ Public Sub PrintReport(targetWb As Workbook) 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").Interior.Color = RGB(217, 217, 217) diff --git a/VBA_BOMConverter/Modules/M06_ModelParser.bas b/VBA_BOMConverter/Modules/M06_ModelParser.bas index 463eac6..eb2d60c 100644 --- a/VBA_BOMConverter/Modules/M06_ModelParser.bas +++ b/VBA_BOMConverter/Modules/M06_ModelParser.bas @@ -62,7 +62,7 @@ Public Function ParseProductModel(ByVal modelString As String) As Object If Len(headerPart) = 0 Then If Not g_Logger Is Nothing Then - g_Logger.Record 0, "M06.ParseProductModel", "ModelParseError", _ + g_Logger.Record "", "M06.ParseProductModel", "ModelParseError", _ "无法提取表头部分,型号可能为空或格式错误", modelString End If Set ParseProductModel = params @@ -75,7 +75,7 @@ Public Function ParseProductModel(ByVal modelString As String) As Object If Not IsArray(segments) Then If Not g_Logger Is Nothing Then - g_Logger.Record 0, "M06.ParseProductModel", "ModelParseError", _ + g_Logger.Record "", "M06.ParseProductModel", "ModelParseError", _ "表头分割失败", headerPart End If Set ParseProductModel = params @@ -85,7 +85,7 @@ Public Function ParseProductModel(ByVal modelString As String) As Object ' 步骤3: 验证段数是否足够 If UBound(segments) - LBound(segments) + 1 < MODEL_HEADER_MIN_SEGMENTS 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 & "段,实际" & _ (UBound(segments) - LBound(segments) + 1) & "段", headerPart End If @@ -160,7 +160,7 @@ Public Function ParseProductModel(ByVal modelString As String) As Object ErrorHandler: If Not g_Logger Is Nothing Then - g_Logger.Record 0, "M06.ParseProductModel", "SystemError", _ + g_Logger.Record "", "M06.ParseProductModel", "SystemError", _ "解析过程发生错误: " & Err.Description, modelString End If Set ParseProductModel = CreateObject("Scripting.Dictionary") diff --git a/VBA_BOMConverter/Modules/M07_BOMMatcher.bas b/VBA_BOMConverter/Modules/M07_BOMMatcher.bas index 00bc5e9..572836a 100644 --- a/VBA_BOMConverter/Modules/M07_BOMMatcher.bas +++ b/VBA_BOMConverter/Modules/M07_BOMMatcher.bas @@ -141,7 +141,7 @@ Public Function MatchBOMRecord(ByVal ws As Worksheet, ByVal params As Object) As ErrorHandler: If Not g_Logger Is Nothing Then - g_Logger.Record 0, "M07.MatchBOMRecord", "SystemError", _ + g_Logger.Record "", "M07.MatchBOMRecord", "SystemError", _ "匹配过程发生错误: " & Err.Description, ws.Name End If @@ -430,7 +430,7 @@ Public Function ExtractMaterialInfo( _ ErrorHandler: If Not g_Logger Is Nothing Then - g_Logger.Record rowNum, "M07.ExtractMaterialInfo", "SystemError", _ + g_Logger.Record "", "M07.ExtractMaterialInfo", "SystemError", _ "提取物料信息失败: " & Err.Description, ws.Name End If Set ExtractMaterialInfo = CreateObject("Scripting.Dictionary") diff --git a/VBA_BOMConverter/Modules/M08_ComponentProcessor.bas b/VBA_BOMConverter/Modules/M08_ComponentProcessor.bas index c6c4fbf..0291208 100644 --- a/VBA_BOMConverter/Modules/M08_ComponentProcessor.bas +++ b/VBA_BOMConverter/Modules/M08_ComponentProcessor.bas @@ -77,7 +77,7 @@ Private Sub LoadInventoryData(ByVal inventoryWb As Workbook) If wsInventory Is Nothing Then ' 未找到现存量工作表,记录警告并使用空字典(所有库存视为0) If Not g_Logger Is Nothing Then - g_Logger.RecordWarning 0, "M08.LoadInventoryData", "InventorySheetMissing", _ + g_Logger.RecordWarning "", "M08.LoadInventoryData", "InventorySheetMissing", _ "未找到[" & INVENTORY_SHEET_NAME & "]工作表,所有部件库存将视为0", "" End If Exit Sub @@ -109,7 +109,7 @@ Private Sub LoadInventoryData(ByVal inventoryWb As Workbook) ErrorHandler: If Not g_Logger Is Nothing Then - g_Logger.RecordWarning 0, "M08.LoadInventoryData", "LoadError", _ + g_Logger.RecordWarning "", "M08.LoadInventoryData", "LoadError", _ "加载库存数据失败: " & Err.Description, "" End If End Sub @@ -197,7 +197,7 @@ Public Function ProcessComponentRecord( _ ErrorHandler: If Not logger Is Nothing Then - logger.Record matchedRowNum, "M08.ProcessComponentRecord", "SystemError", _ + logger.Record "", "M08.ProcessComponentRecord", "SystemError", _ "处理部件记录失败: " & Err.Description, "" End If @@ -291,7 +291,7 @@ Private Function CheckComponentInventory( _ If g_InventoryDict Is Nothing Or Not g_InventoryDict.Exists(componentCode) Then ' 未找到库存数据,记录警告并返回False(库存不足) If Not g_Logger Is Nothing Then - g_Logger.RecordWarning rowNum, "M08.CheckComponentInventory", "InventoryNotFound", _ + g_Logger.RecordWarning "", "M08.CheckComponentInventory", "InventoryNotFound", _ "部件[" & componentCode & "]未找到库存数据,视为库存不足", "" End If CheckComponentInventory = False @@ -321,7 +321,7 @@ Private Function CheckComponentInventory( _ Else ' 库存不足,记录错误 If Not g_Logger Is Nothing Then - g_Logger.Record rowNum, "M08.CheckComponentInventory", "InsufficientInventory", _ + g_Logger.Record "", "M08.CheckComponentInventory", "InsufficientInventory", _ "部件[" & componentCode & "]库存不足。库存=" & stockQty & ", 累计需求=" & totalDemand, "" End If CheckComponentInventory = False @@ -331,7 +331,7 @@ Private Function CheckComponentInventory( _ ErrorHandler: If Not g_Logger Is Nothing Then - g_Logger.Record rowNum, "M08.CheckComponentInventory", "SystemError", _ + g_Logger.Record "", "M08.CheckComponentInventory", "SystemError", _ "库存检查失败: " & Err.Description, "" End If ' 出错时返回False(库存不足) @@ -409,7 +409,7 @@ Private Function ExtractComponentInfo( _ ErrorHandler: If Not g_Logger Is Nothing Then - g_Logger.Record rowNum, "M08.ExtractComponentInfo", "SystemError", _ + g_Logger.Record "", "M08.ExtractComponentInfo", "SystemError", _ "提取部件信息失败: " & Err.Description, componentType End If Set ExtractComponentInfo = Nothing @@ -463,7 +463,7 @@ Private Function ExtractSubComponents( _ ErrorHandler: If Not g_Logger Is Nothing Then - g_Logger.Record rowNum, "M08.ExtractSubComponents", "SystemError", _ + g_Logger.Record "", "M08.ExtractSubComponents", "SystemError", _ "提取子件信息失败: " & Err.Description, "" End If Set ExtractSubComponents = New Collection @@ -559,7 +559,7 @@ Private Function ExtractSingleSubComponent( _ ErrorHandler: If Not g_Logger Is Nothing Then - g_Logger.Record rowNum, "M08.ExtractSingleSubComponent", "SystemError", _ + g_Logger.Record "", "M08.ExtractSingleSubComponent", "SystemError", _ "提取子件[" & subComponentType & "]失败: " & Err.Description, "" End If Set ExtractSingleSubComponent = Nothing diff --git a/VBA_BOMConverter/Modules/M09_BOMExtractor.bas b/VBA_BOMConverter/Modules/M09_BOMExtractor.bas index beae266..4a899d5 100644 --- a/VBA_BOMConverter/Modules/M09_BOMExtractor.bas +++ b/VBA_BOMConverter/Modules/M09_BOMExtractor.bas @@ -106,7 +106,7 @@ Public Function RunBOMExtraction() As String M06A_Mapper.InitMapper g_Logger, wsMapping Else If Not g_Logger Is Nothing Then - g_Logger.RecordWarning 0, "M09.RunBOMExtraction", "MappingTableMissing", _ + g_Logger.RecordWarning "", "M09.RunBOMExtraction", "MappingTableMissing", _ "未找到对照表工作表,azxs和lcfw将仅使用原始值匹配", "" End If End If @@ -355,7 +355,7 @@ Private Function ProcessSingleModel( _ ' 步骤2: 匹配所有物料类型(两阶段) Dim allMaterials As Collection Dim validation As Object - Set allMaterials = MatchAllMaterialTypesWithValidation(params, bomWb, logger, orderQty, validation) + Set allMaterials = MatchAllMaterialTypesWithValidation(params, bomWb, logger, orderQty, productionOrderNo, validation) ' 步骤3: 生成输出行 Dim remarks As String @@ -387,7 +387,7 @@ Private Function ProcessSingleModel( _ ErrorHandler: If Not logger Is Nothing Then - logger.Record 0, "M09.ProcessSingleModel", "SystemError", _ + logger.Record productionOrderNo, "M09.ProcessSingleModel", "SystemError", _ "处理型号[" & modelString & "]失败: " & Err.Description, "" End If @@ -422,6 +422,7 @@ Private Function MatchAllMaterialTypesWithValidation( _ ByVal bomWb As Workbook, _ ByVal logger As clsErrorLogger, _ ByVal orderQty As Long, _ + ByVal productionOrderNo As String, _ ByRef outValidation As Object _ ) As Collection On Error GoTo ErrorHandler @@ -523,7 +524,7 @@ Private Function MatchAllMaterialTypesWithValidation( _ ' Phase 2: 统一验证所有匹配结果 ' ======================================== Dim validationResult As Object - Set validationResult = ValidateAllMatchResults(resultsDict, logger, params) + Set validationResult = ValidateAllMatchResults(resultsDict, logger, params, productionOrderNo) ' ======================================== ' Phase 3: 根据验证结果生成最终物料集合 @@ -565,7 +566,7 @@ Private Function MatchAllMaterialTypesWithValidation( _ ErrorHandler: If Not logger Is Nothing Then - logger.Record 0, "M09.MatchAllMaterialTypesWithValidation", "SystemError", _ + logger.Record productionOrderNo, "M09.MatchAllMaterialTypesWithValidation", "SystemError", _ "匹配物料类型失败: " & Err.Description, "" End If @@ -606,7 +607,8 @@ End Function Private Function ValidateAllMatchResults( _ ByVal resultsDict As Object, _ ByVal logger As clsErrorLogger, _ - ByVal params As Object _ + ByVal params As Object, _ + ByVal productionOrderNo As String _ ) As Object On Error GoTo ErrorHandler @@ -850,12 +852,12 @@ Private Function ValidateAllMatchResults( _ ' ======================================== Dim err As Variant For Each err In errors - logger.Record 0, "M09.ValidateAllMatchResults", "BOMMatchError", CStr(err), "" + logger.Record productionOrderNo, "M09.ValidateAllMatchResults", "BOMMatchError", CStr(err), "" Next err Dim warn As Variant For Each warn In warnings - logger.RecordWarning 0, "M09.ValidateAllMatchResults", "ComponentConflict", CStr(warn), "" + logger.RecordWarning productionOrderNo, "M09.ValidateAllMatchResults", "ComponentConflict", CStr(warn), "" Next warn ' ======================================== @@ -874,7 +876,7 @@ Private Function ValidateAllMatchResults( _ ErrorHandler: If Not logger Is Nothing Then - logger.Record 0, "M09.ValidateAllMatchResults", "SystemError", _ + logger.Record productionOrderNo, "M09.ValidateAllMatchResults", "SystemError", _ "验证匹配结果失败: " & Err.Description, "" End If