- SQL Server has a maximum of 2100 parameters per query
- Each record has 28 columns, so max batch is ~71 records (2000/28)
- Fixed syntax error: removed extra closing brace in extractor.ts
- Added debug logging for batch insert parameters
- Add DataImportService for reading Excel and importing to database
- Extend DiscreteMaterialPlanDAO with deleteBySourceNumbers and batchInsert
- Auto-trigger database write after successful Excel merge
- Support batch delete by SourceNumber and batch insert (1000/batch)
- Update ExtractorPage UI to show import results
- Fix SQL Server query to handle undefined recordset for DELETE/INSERT
Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
- Add getTableName() method to convert MySQL table names to SQL Server format
- Use queryWithParams with sql.NVarChar for proper SQL Server parameter handling
- Implement case-insensitive matching for production IDs (e.g., 26b10433 vs 26B10433)
- Align resolver logic with validation-handler.ts for consistent database queries
Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
The product unit column header was incorrectly showing "单位" instead of
"产品单位", causing confusion with the material unit column which also
uses "单位". Fixed in both extractor.ts and excel-parser.ts.
Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
- Fix "Workbook is not a constructor" error by handling ESM/CommonJS module format
- Add try-catch around saveMergedOrders to capture and report errors
- Return parsed recordCount even when save fails so users see actual data count
- Add detailed logging throughout merge process for debugging
- Clean up temporary batch files after merge completion
Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
- Add mergeFiles() method in ExtractorService to combine downloaded batch files
- Add saveMergedOrders() method to output full 31-column Excel format
- Update recordCount to return actual material record count
- Add missing field mappings in OrderHeader type and ExcelParser:
- factory, materialStatus, planNumber, materialType
- department, remark, createDate, approveDate
- Output file named with timestamp: merged_YYYYMMDDHHMMSS.xlsx
Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
This commit completes the core ERP automation functionality, migrating
from Python Playwright to TypeScript while maintaining full compatibility
with the original implementation.
**ERP Authentication Service (erp-auth.ts):**
- Implement login() with role-based locators for form elements
- Add SSL certificate bypass for internal VPN network
- Handle force login confirmation dialogs
- Return session with mainFrame reference for subsequent operations
- Add session lifecycle management (close, getSession, isActive)
**Data Extractor Service (extractor.ts):**
- Implement precise nested iframe navigation (#forwardFrame → #mainiframe)
- Add batch processing support for multiple order numbers
- Implement order number filling with comma separation
- Handle material selection and download workflows
- Successfully tested with 300 orders in 5 batches
**Excel Parser Service (excel-parser.ts):**
- Fix ExcelJS 1-indexed array access (row[1] for 序号, row[2] for 材料编码)
- Add dynamic table header search to handle empty row skipping
- Add field mapping: "来源单号" → "productionOrder"
- Implement saveAsExcel() method compatible with Python format
- Validate compatibility: 527 rows, 69 orders matching Python output
**Type Definitions (erp.types.ts):**
- Add headless property to ErpConfig for browser mode control
- Add mainFrame reference to ErpSession for frame reuse
**Integration Tests (extractor.test.ts):**
- Modify tests to use independent auth services for isolation
- Add test with 300 orders and batch size 70
- All tests passing with real ERP data
**Test Configuration (vitest.config.ts):**
- Add setupFiles configuration for environment variable loading
**Testing Results:**
- ✅ Successfully logs in to ERP system
- ✅ Processes 300 orders in 5 batches (43.59 seconds)
- ✅ Downloads 5 Excel files (347.62 KB total)
- ✅ Parses 2,131 material plans from 280 unique orders
- ✅ Excel output matches Python format exactly
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Implement Task 3.1: Core Extractor Logic with TDD approach.
Changes:
- Add ExtractorService class with batch processing and download support
- Update ERP_LOCATORS with extractor-specific selectors from Python reference
- Add integration tests for single and multiple order extraction
- Add unit tests for batch creation logic
- Update existing tests to skip gracefully without ERP credentials
Features:
- Navigate to discrete material plan page with nested iframes
- Setup query interface (search icon, order query, limit settings)
- Batch download with configurable batch size (default: 100)
- Progress callback support for real-time updates
- Error handling for individual batch failures
- File download handling with proper wait strategies
Reference: playwrite/utils/discrete_material_plan_extractor.py
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>