Files
AutoBOM/VBA/Modules/M01_Main.bas
Misaka_Company 3a93459002
All checks were successful
NTFY Notification / notify (push) Successful in 5s
feat: add preprocessing module for BOM condition transformation
Add M05_PreProcessor module to handle value mapping and condition
simplification for "接头" category before parsing.

Features:
- Value mapping: azxs codes (A0/AT/AH→径向, B0/BT/BZ/BH→下轴向,
  Z0/ZT/ZZ/ZH→中轴向) and lcfw ranges (M01-M11→低压, M12-M16→高压)
- OR condition merging: automatically removes duplicate OR segments
- Smart parentheses handling: removes parentheses for single atoms,
  preserves them when needed for logical structure
- Recursive nested expression processing
- Graceful degradation when "对照表" worksheet is missing

Integration:
- Modified M01_Main to initialize preprocessor after M03_Logic
- Preprocessing applied only for "接头" category
- Updated M99_TestRunner with 8 comprehensive test cases
- All tests passing (50 total: 42 core + 8 preprocessing)

Documentation:
- Added detailed flow documentation for Test_PP_06_FullIntegration
  with mermaid diagrams in docs/Test_PP_06_FullIntegration_流程详解.md
- Updated CLAUDE.md with preprocessing module description and
  documentation guidelines (docs/ vs reference_docs/)

Example transformation:
  Input:  gclj=M16 AND (azxs=A0 OR azxs=AT) AND (lcfw=M01 OR lcfw=M15)
  Output: gclj=M16 AND azxs=径向 AND (lcfw=低压 OR lcfw=高压)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-09 16:24:41 +08:00

127 lines
4.1 KiB
QBasic
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
' ==============================================================================
' 模块: M01_Main
' 职责: 程序入口调度器UI交互(进度条)
' ==============================================================================
Option Explicit
Public Sub RunBOMConversion()
Dim wsSrc As Worksheet
Dim arrData As Variant
Dim logger As New clsErrorLogger
Dim i As Long
' 使用 Dictionary 替代 Collection 来存储类别,方便查找
Dim catData As Object
Set catData = CreateObject("Scripting.Dictionary")
' 1. 环境初始化
On Error GoTo MainErrorHandler
'Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
' 2. 检查工作表
On Error Resume Next
Set wsSrc = ActiveWorkbook.Sheets("平台配置清单")
On Error GoTo MainErrorHandler
If wsSrc Is Nothing Then
MsgBox "错误:未找到名为 '平台配置清单' 的工作表。", vbCritical
GoTo ExitHandler
End If
' 读取数据
Application.StatusBar = "正在读取源数据..."
arrData = M02_DataIO.ReadSourceData(wsSrc)
If IsEmpty(arrData) Then
MsgBox "未找到数据。", vbExclamation
GoTo ExitHandler
End If
' 3. 初始化逻辑模块
M03_Logic.InitLogic logger
' 3.1 初始化预处理模块
Dim wsMapping As Worksheet
On Error Resume Next
Set wsMapping = ActiveWorkbook.Sheets("对照表")
On Error GoTo MainErrorHandler
If wsMapping Is Nothing Then
MsgBox "警告:未找到 [对照表] 工作表,预处理功能将禁用。", vbExclamation
Else
M05_PreProcessor.InitPreProcessor logger, wsMapping
End If
' 4. 主循环
Dim rowIdx As Long
Dim strCat As String, strCond As String
Dim colResult As Collection
Dim itm As Variant
Dim baseInfo As Variant
Dim totalRows As Long
Dim pct As Long
totalRows = UBound(arrData, 1)
For i = 1 To totalRows
rowIdx = M04_Config.SRC_START_ROW + i - 1
strCat = Trim(CStr(arrData(i, M04_Config.COL_IDX_CAT)))
' --- 进度条更新 ---
pct = CLng((i / totalRows) * 100)
Application.StatusBar = "正在处理: " & pct & "% | 行: " & rowIdx & " | 类别: " & strCat
If i Mod 10 = 0 Then DoEvents ' 每10行刷新一次界面防止卡顿但不过度拖慢速度
' ------------------
' 忽略空类别
If Len(strCat) > 0 Then
strCond = CStr(arrData(i, M04_Config.COL_IDX_COND))
If IsEmpty(arrData(i, M04_Config.COL_IDX_COND)) Then strCond = ""
' 4.1 预处理条件(仅对"接头"类别)
If Len(strCond) > 0 And M05_PreProcessor.IsInitialized() Then
strCond = M05_PreProcessor.PreprocessCondition(strCond, strCat, rowIdx)
End If
' 解析
Set colResult = M03_Logic.ParseRule(strCond, rowIdx)
If Not colResult Is Nothing Then
If Not catData.Exists(strCat) Then
catData.Add strCat, New Collection
End If
' 基础信息: 代号, 名称, 数量
baseInfo = Array(arrData(i, M04_Config.COL_IDX_CODE), _
arrData(i, M04_Config.COL_IDX_NAME), _
arrData(i, M04_Config.COL_IDX_QTY))
' 将展开的记录存入
For Each itm In colResult
catData(strCat).Add Array(itm, baseInfo)
Next itm
End If
End If
Next i
' 5. 输出
Application.StatusBar = "正在生成新工作簿..."
M02_DataIO.WriteCategoryToNewBook catData
' 6. 错误报告
If logger.HasErrors Then
logger.PrintReport ActiveWorkbook
MsgBox "转换完成,但发现部分数据存在逻辑冲突,已生成错误报告。", vbExclamation
End If
ExitHandler:
' 清理状态
Application.StatusBar = False
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Exit Sub
MainErrorHandler:
MsgBox "发生运行时错误: " & Err.Description, vbCritical
Resume ExitHandler
End Sub