All checks were successful
NTFY Notification / notify (push) Successful in 11s
Standardize all VBA property and method names to lowercase for consistent code style: - Err object: Err.Description → err.Description, Err.Number → err.Number - Collection properties: .Count → .count - Range properties: .Rows.Count → .Rows.count, .Row → .row - Dictionary methods: .Keys → .keys, .Exists → .exists - Worksheet properties: .Sheets.Count → .Sheets.count - Fix typo: Thisworkbook.Path → ThisWorkbook.Path VBA is case-insensitive, but consistent lowercase convention improves readability. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
210 lines
7.0 KiB
QBasic
210 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 |