refactor: replace row index with production order number in error reports
All checks were successful
NTFY Notification / notify (push) Successful in 12s
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:
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user