All checks were successful
NTFY Notification / notify (push) Successful in 4s
Add a preprocessing step to the BOM Extraction System to enhance parameter extraction with mapping values from "对照表" worksheet. For azxs (安装形式) and lcfw (量程范围), the system now stores both the raw parsed value AND the mapped value from the lookup table, enabling flexible dual-value matching. Changes: - Create M06A_Mapper.bas: New module for value mapping - Load azxs/lcfw mappings from "对照表" worksheet - Return dual-value format "raw,mapped" (e.g., "A0,径向") - Support graceful degradation if "对照表" not found - Define constants locally to avoid VBA cross-module reference issues - Modify M06_ModelParser.bas: - Extract raw parameter values first - Apply mapping via M06A_Mapper if initialized - Store dual values for azxs and lcfw parameters - Modify M07_BOMMatcher.bas: - Update EvaluateCellCondition() to support dual-value matching - Split by comma and check if ANY value matches - Backward compatible with single-value parameters - Modify M09_BOMExtractor.bas: - Initialize M06A_Mapper during RunBOMExtraction() - Add WorksheetExists() helper function - Log warning if "对照表" worksheet not found - Define MAPPING_SHEET_NAME constant locally - Modify M04_Config.bas: - Add mapping table configuration constants - MAPPING_SHEET_NAME, MAPPING_COL_LCFW_KEY, etc. - Update CLAUDE.md: - Document new M06A_Mapper module - Update data flow diagram with mapping step - Document dual-value matching behavior - Update system architecture diagram - Update docs/RunBOMExtraction_运行机制详解.md: - Add M06A_Mapper to all diagrams and documentation - Add detailed value mapping section - Update sequence diagrams with mapping flow - Update parameter examples with dual-value format - Bump documentation version to 3.0 Example: Input: Product model "YTHN-100.A0.531.G123.M04.Y3" Parse: azxs="A0", lcfw="M04" Map: azxs="A0,径向", lcfw="M04,高压" Match: BOM库 with azxs="径向" OR "A0" → MATCH Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
211 lines
7.0 KiB
QBasic
211 lines
7.0 KiB
QBasic
' ==============================================================================
|
||
' 模块: M06A_Mapper
|
||
' 职责: 值映射模块,为BOM Extraction System提供azxs和lcfw参数映射
|
||
'
|
||
' 功能:
|
||
' - 从"对照表"工作表加载映射数据
|
||
' - 将原始值转换为"原始值,映射值"格式
|
||
' - 支持azxs(安装形式)和lcfw(量程范围)映射
|
||
'
|
||
' 使用场景:
|
||
' 产品型号解析后,调用映射器为参数添加映射值,支持双值匹配
|
||
'
|
||
' 示例:
|
||
' 输入: azxs="A0"
|
||
' 输出: azxs="A0,径向"
|
||
'
|
||
' BOM库中azxs="A0"或"径向"均可匹配成功
|
||
' ==============================================================================
|
||
Option Explicit
|
||
|
||
' 模块级常量 - 映射表配置
|
||
Private Const MAPPING_COL_LCFW_KEY As Long = 1 ' A列 - lcfw原始值
|
||
Private Const MAPPING_COL_LCFW_VAL As Long = 2 ' B列 - lcfw映射值
|
||
Private Const MAPPING_COL_AZXS_KEY As Long = 4 ' D列 - azxs原始值
|
||
Private Const MAPPING_COL_AZXS_VAL As Long = 5 ' E列 - azxs映射值
|
||
Private Const MAPPING_START_ROW As Long = 3 ' 数据起始行
|
||
|
||
' 模块级变量
|
||
Private g_LcfwMapping As Object ' Scripting.Dictionary - lcfw映射表
|
||
Private g_AzxsMapping As Object ' Scripting.Dictionary - azxs映射表
|
||
Private g_Logger As clsErrorLogger
|
||
Private g_IsInitialized As Boolean
|
||
|
||
' ------------------------------------------------------------------------------
|
||
' 初始化映射器
|
||
'
|
||
' 输入:
|
||
' logger - 错误记录器
|
||
' wsMapping - 对照表工作表
|
||
'
|
||
' 说明:
|
||
' 从对照表工作表加载lcfw和azxs映射数据
|
||
' - lcfw映射: A列:B列 (M01->低压, M12->高压)
|
||
' - azxs映射: D列:E列 (A0->径向, AT->径向, etc.)
|
||
' ------------------------------------------------------------------------------
|
||
Public Sub InitMapper(logger As clsErrorLogger, wsMapping As Worksheet)
|
||
Set g_Logger = logger
|
||
Set g_LcfwMapping = CreateObject("Scripting.Dictionary")
|
||
Set g_AzxsMapping = CreateObject("Scripting.Dictionary")
|
||
|
||
' 从[对照表]加载映射
|
||
Call LoadLcfwMapping(wsMapping)
|
||
Call LoadAzxsMapping(wsMapping)
|
||
|
||
g_IsInitialized = True
|
||
End Sub
|
||
|
||
' ------------------------------------------------------------------------------
|
||
' 检查是否已初始化
|
||
' ------------------------------------------------------------------------------
|
||
Public Function IsInitialized() As Boolean
|
||
IsInitialized = g_IsInitialized
|
||
End Function
|
||
|
||
' ------------------------------------------------------------------------------
|
||
' 映射azxs值
|
||
'
|
||
' 输入:
|
||
' rawValue - 原始azxs值(如"A0")
|
||
'
|
||
' 输出:
|
||
' String - "raw,mapped"格式(如"A0,径向")或原始值(如果未找到映射)
|
||
'
|
||
' 示例:
|
||
' MapAzxs("A0") = "A0,径向"
|
||
' MapAzxs("AT") = "AT,径向"
|
||
' MapAzxs("XX") = "XX" (未找到映射)
|
||
' ------------------------------------------------------------------------------
|
||
Public Function MapAzxs(ByVal rawValue As String) As String
|
||
rawValue = Trim(rawValue)
|
||
|
||
' 如果未初始化或值为空,直接返回原始值
|
||
If Not g_IsInitialized Or Len(rawValue) = 0 Then
|
||
MapAzxs = rawValue
|
||
Exit Function
|
||
End If
|
||
|
||
' 查找映射值
|
||
If g_AzxsMapping.Exists(rawValue) Then
|
||
Dim mappedValue As String
|
||
mappedValue = g_AzxsMapping(rawValue)
|
||
MapAzxs = rawValue & "," & mappedValue
|
||
Else
|
||
' 未找到映射,返回原始值
|
||
MapAzxs = rawValue
|
||
End If
|
||
End Function
|
||
|
||
' ------------------------------------------------------------------------------
|
||
' 映射lcfw值
|
||
'
|
||
' 输入:
|
||
' rawValue - 原始lcfw值(如"M01")
|
||
'
|
||
' 输出:
|
||
' String - "raw,mapped"格式(如"M01,低压")或原始值(如果未找到映射)
|
||
'
|
||
' 示例:
|
||
' MapLcfw("M01") = "M01,低压"
|
||
' MapLcfw("M12") = "M12,高压"
|
||
' MapLcfw("XX") = "XX" (未找到映射)
|
||
' ------------------------------------------------------------------------------
|
||
Public Function MapLcfw(ByVal rawValue As String) As String
|
||
rawValue = Trim(rawValue)
|
||
|
||
' 如果未初始化或值为空,直接返回原始值
|
||
If Not g_IsInitialized Or Len(rawValue) = 0 Then
|
||
MapLcfw = rawValue
|
||
Exit Function
|
||
End If
|
||
|
||
' 查找映射值
|
||
If g_LcfwMapping.Exists(rawValue) Then
|
||
Dim mappedValue As String
|
||
mappedValue = g_LcfwMapping(rawValue)
|
||
MapLcfw = rawValue & "," & mappedValue
|
||
Else
|
||
' 未找到映射,返回原始值
|
||
MapLcfw = rawValue
|
||
End If
|
||
End Function
|
||
|
||
' ------------------------------------------------------------------------------
|
||
' 加载lcfw映射(从A列:B列,列1:2)
|
||
'
|
||
' 数据格式:
|
||
' Row 3+: M01 | 低压
|
||
' M12 | 高压
|
||
' etc.
|
||
' ------------------------------------------------------------------------------
|
||
Private Sub LoadLcfwMapping(wsMapping As Worksheet)
|
||
Dim lastRow As Long
|
||
lastRow = wsMapping.Cells(wsMapping.Rows.count, 1).End(xlUp).row
|
||
|
||
Dim i As Long
|
||
Dim key As String, val As String
|
||
|
||
' 从第3行开始读取
|
||
For i = MAPPING_START_ROW To lastRow
|
||
key = Trim(CStr(wsMapping.Cells(i, MAPPING_COL_LCFW_KEY).Value))
|
||
val = Trim(CStr(wsMapping.Cells(i, MAPPING_COL_LCFW_VAL).Value))
|
||
|
||
If Len(key) > 0 And Len(val) > 0 Then
|
||
If Not g_LcfwMapping.Exists(key) Then
|
||
g_LcfwMapping.Add key, val
|
||
End If
|
||
End If
|
||
Next i
|
||
End Sub
|
||
|
||
' ------------------------------------------------------------------------------
|
||
' 加载azxs映射(从D列:E列,列4:5)
|
||
'
|
||
' 数据格式:
|
||
' Row 3+: A0 | 径向
|
||
' AT | 径向
|
||
' B0 | 下轴向
|
||
' etc.
|
||
' ------------------------------------------------------------------------------
|
||
Private Sub LoadAzxsMapping(wsMapping As Worksheet)
|
||
Dim lastRow As Long
|
||
lastRow = wsMapping.Cells(wsMapping.Rows.count, MAPPING_COL_AZXS_KEY).End(xlUp).row
|
||
|
||
Dim i As Long
|
||
Dim key As String, val As String
|
||
|
||
' 从第3行开始读取
|
||
For i = MAPPING_START_ROW To lastRow
|
||
key = Trim(CStr(wsMapping.Cells(i, MAPPING_COL_AZXS_KEY).Value))
|
||
val = Trim(CStr(wsMapping.Cells(i, MAPPING_COL_AZXS_VAL).Value))
|
||
|
||
If Len(key) > 0 And Len(val) > 0 Then
|
||
If Not g_AzxsMapping.Exists(key) Then
|
||
g_AzxsMapping.Add key, val
|
||
End If
|
||
End If
|
||
Next i
|
||
End Sub
|
||
|
||
' ------------------------------------------------------------------------------
|
||
' 测试辅助函数:获取lcfw映射值
|
||
' ------------------------------------------------------------------------------
|
||
Public Function GetLcfwMappedValue(key As String) As String
|
||
If g_LcfwMapping.Exists(key) Then
|
||
GetLcfwMappedValue = g_LcfwMapping(key)
|
||
Else
|
||
GetLcfwMappedValue = ""
|
||
End If
|
||
End Function
|
||
|
||
' ------------------------------------------------------------------------------
|
||
' 测试辅助函数:获取azxs映射值
|
||
' ------------------------------------------------------------------------------
|
||
Public Function GetAzxsMappedValue(key As String) As String
|
||
If g_AzxsMapping.Exists(key) Then
|
||
GetAzxsMappedValue = g_AzxsMapping(key)
|
||
Else
|
||
GetAzxsMappedValue = ""
|
||
End If
|
||
End Function
|