Add comprehensive AGENTS.md documentation files across the project structure to document the agent architecture and capabilities. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
143 lines
4.2 KiB
Markdown
143 lines
4.2 KiB
Markdown
# Modules Knowledge Base
|
||
|
||
**Scope:** `VBA/Modules/` - Procedural workflows and entry points
|
||
|
||
## OVERVIEW
|
||
|
||
4 modules: `MainModule` (main workflow), `BIPUploadModule` (upload results), `ComponentInventoryCheckModule` (inventory check), `TestModule` (testing utilities).
|
||
|
||
## STRUCTURE
|
||
|
||
```
|
||
Modules/
|
||
├── MainModule.bas # Main entry point + orchestration
|
||
├── BIPUploadModule.bas # Upload to BIP system
|
||
├── ComponentInventoryCheckModule.bas # Component inventory verification
|
||
└── TestModule.bas # Testing utilities
|
||
```
|
||
|
||
## WHERE TO LOOK
|
||
|
||
| Task | Location | Notes |
|
||
|------|----------|-------|
|
||
| Run BOM extraction | `MainModule.bas` | `ProcessProductModels()` |
|
||
| Upload results | `BIPUploadModule.bas` | BIP system integration |
|
||
| Check inventory | `ComponentInventoryCheckModule.bas` | Component count verification |
|
||
| Test parsing | `TestModule.bas` | Unit test utilities |
|
||
|
||
## CODE MAP
|
||
|
||
### MainModule
|
||
| Function | Role |
|
||
|----------|------|
|
||
| `ProcessProductModels()` | Main entry point, orchestrates workflow |
|
||
| `ProcessSingleModel()` | Process one model, collect output |
|
||
| `CreateOutputRowArray()` | Build row data array |
|
||
| `WriteBatchData()` | Bulk write to worksheet |
|
||
| `GetInputSheet()` | Get `产品订单` sheet |
|
||
| `GetBomSheet()` | Get `平台配置清单` sheet |
|
||
| `CreateOutputSheet()` | Create/reset `BOM 提取结果` |
|
||
|
||
### BIPUploadModule
|
||
| Function | Role |
|
||
|----------|------|
|
||
| `UploadToBIP()` | Upload BOM results to BIP system |
|
||
|
||
### ComponentInventoryCheckModule
|
||
| Function | Role |
|
||
|----------|------|
|
||
| `CheckComponentInventory()` | Verify component counts match |
|
||
|
||
## CONVENTIONS
|
||
|
||
### Module Structure
|
||
```vba
|
||
Option Explicit
|
||
|
||
' Constants
|
||
Private Const CONDITION_CONFIG = "azxs,安装形式|bkxs,表壳形式|..."
|
||
|
||
' Public entry points
|
||
Public Sub MainEntryPoint()
|
||
On Error GoTo ErrorHandler
|
||
' Orchestration
|
||
Exit Sub
|
||
ErrorHandler:
|
||
MsgBox "Error: " & Err.Description
|
||
End Sub
|
||
|
||
' Private helpers
|
||
Private Sub HelperFunction()
|
||
' Implementation
|
||
End Sub
|
||
```
|
||
|
||
### Workflow Pattern
|
||
1. Get input sheet (`产品订单`)
|
||
2. Get BOM sheet (`平台配置清单`)
|
||
3. Create output sheet (`BOM 提取结果`)
|
||
4. Initialize `BomExtractor`, load data
|
||
5. Loop through models, call `ProcessSingleModel()`
|
||
6. Batch write results
|
||
7. Format output, show message
|
||
|
||
### Batch Output Pattern
|
||
```vba
|
||
' Collect in Collection
|
||
Dim outputData As Collection
|
||
Set outputData = New Collection
|
||
|
||
' Add arrays
|
||
outputData.Add CreateOutputRowArray(...)
|
||
|
||
' Convert to 2D array
|
||
ReDim resultData(1 To rowCount, 1 To colCount)
|
||
' Fill array...
|
||
|
||
' Single write
|
||
ws.Range("A2").Resize(rowCount, colCount).Value = resultData
|
||
```
|
||
|
||
## ANTI-PATTERNS (THIS PROJECT)
|
||
|
||
- **NEVER** hardcode sheet names — use `GetInputSheet()`, `GetBomSheet()` helpers
|
||
- **NEVER** write row-by-row — always batch write via 2D array
|
||
- **NEVER** skip error handling — all public subs use `On Error GoTo ErrorHandler`
|
||
- **DO NOT** change output column order — must match header definition in `WriteOutputHeader()`
|
||
|
||
## UNIQUE STYLES
|
||
|
||
### Condition Config Constant
|
||
```vba
|
||
Private Const CONDITION_CONFIG = "azxs,安装形式|bkxs,表壳形式|gclj,过程连接|jycz,接液材质|lcfw,量程范围|fjgn,附加功能"
|
||
```
|
||
Format: `code,label|code,label|...` — parsed dynamically for header generation.
|
||
|
||
### Component Priority Flag
|
||
From column E of input sheet:
|
||
- "是" (or "1", "TRUE") → include all categories
|
||
- "否" (or "0", "FALSE") → exclude "部件" (components) category
|
||
|
||
### Output Row Structure
|
||
```
|
||
Column 1: 生产订单号 (order number)
|
||
Column 2: 产品型号 (full model)
|
||
Columns 3-8: 6 conditions (azxs, bkxs, gclj, jycz, lcfw, fjgn)
|
||
Columns 9-16: BOM fields (行号,模块,代号,名称,数量,类别,66 代码,备注)
|
||
```
|
||
|
||
## NOTES
|
||
|
||
### Output Sheet Formatting
|
||
- Row 1: Bold, gray background (RGB 217,217,217), centered
|
||
- Data starts at row 2
|
||
- AutoFit columns (commented out in current code)
|
||
|
||
### Error Messages
|
||
- Parse failure: `"解析失败:" + error`
|
||
- No match: `"未匹配到任何物料"`
|
||
- Multi-match: `"类别[X] 匹配到多条物料(N 条)"` — outputs all but flags
|
||
|
||
### Performance
|
||
Batch write via `Range.Value = resultData` is 10-100x faster than cell-by-cell writes for large datasets.
|