Commit Graph

93 Commits

Author SHA1 Message Date
Misaka_Company
e0d7559cf7 Fix: Hide progress display when clearing order numbers and remove progress text from LogPanel 2026-03-05 10:12:09 +08:00
Misaka
302018f631 Feat: Add extraction complete status indicator with success message 2026-03-04 22:56:00 +08:00
Misaka
e49191d531 Add .gitattributes to enforce consistent line endings 2026-03-04 22:19:06 +08:00
Misaka
2dea1f9556 Feat: Add segmented progress bar for data extractor with dynamic phase calculation
- Add ExtractionProgress type with phase, batch, and subProgress fields
- Implement dynamic progress calculation: 1 (login) + N (batches) + 2 (merge/import)
- Create SegmentedProgressBar component with 4 colored phases (purple/blue/amber/green)
- Show batch-level progress during download phase (e.g., 批次 1/10)
- Display sub-progress during login phase (连接数据库/解析订单号/登录 ERP)
- Update IPC handler and extractor services to report detailed progress
- Add phase status indicators (completed/active/pending) with color-coded dots
2026-03-04 22:16:47 +08:00
Misaka
4494351e52 Merge branch 'dev' into extractor-page-refactoring-11498013679550826416 2026-03-04 21:03:21 +08:00
Misaka
9e1b5530ea Feat: Add real-time progress and logging to data extractor
- Implement IPC event system for pushing progress updates from main to renderer
- Add Zustand store for centralized extractor state management
- Refactor useExtractor hook to use store pattern
- Add chromium-bidi dependency and externalize Playwright for build compatibility
- Show detailed logs during extraction (DB connection, order resolution, ERP login, data import)
2026-03-04 20:51:54 +08:00
google-labs-jules[bot]
743d830b0d Refactor CleanerPage with custom hook useCleaner
* Extracted state management and IPC actions from `CleanerPage.tsx` into a custom hook `useCleaner.ts`.
* `CleanerPage.tsx` is now much more focused on UI layout and rendering.
* Addressed code responsibilities issue, minimizing the size of the component file from nearly 500 lines to just the necessary UI structure.
* Verified no regressions via type checking and application building.

Co-authored-by: luwamgere15-crypto <255338376+luwamgere15-crypto@users.noreply.github.com>
2026-03-04 12:18:35 +00:00
google-labs-jules[bot]
dcd3c6a571 Refactor ExtractorPage with custom hooks and UI components
* Extract logic and state management from `ExtractorPage.tsx` into a custom hook `useExtractor.ts`.
* Extract log rendering logic and auto-scrolling into a separate `LogPanel.tsx` component.
* `ExtractorPage.tsx` is now significantly smaller, focused purely on presentation.
* Verified no regressions via type checking and application building.

Co-authored-by: luwamgere15-crypto <255338376+luwamgere15-crypto@users.noreply.github.com>
2026-03-04 12:11:56 +00:00
Misaka
9939201ca1 Fix: Add chromium-bidi dependency and externalize Playwright to resolve module loading errors 2026-03-04 20:04:48 +08:00
google-labs-jules[bot]
fed76b4fe0 Refactor ExtractorPage with custom hooks and UI components
* Extract logic and state management from `ExtractorPage.tsx` into a custom hook `useExtractor.ts`.
* Extract log rendering logic and auto-scrolling into a separate `LogPanel.tsx` component.
* `ExtractorPage.tsx` is now significantly smaller, focused purely on presentation.
* Verified no regressions via type checking and application building.

Co-authored-by: luwamgere15-crypto <255338376+luwamgere15-crypto@users.noreply.github.com>
2026-03-04 11:18:04 +00:00
Misaka_Company
bfa2445c76 fix: add batch processing to prevent SQL Server 2100 parameter limit error
- Add batch processing in getSourceNumbersFromInputs() with 2000 batch size
- Reduce batch size from 2000 to 1500 in queryBySourceNumbers() and queryBySourceNumbersDistinct()
- Add batch processing to queryByPlanNumbers() and getUniqueMaterialNames()
- Fixes issue where large order quantities caused parameter limit exceeded error
2026-03-04 18:05:35 +08:00
Misaka_Company
b62ae10650 feat: add headless mode toggle and improve CleanerPage layout
- Add headless mode setting with session persistence in CleanerPage
- Move execution settings (dry-run, headless) to dropdown menu
- Improve responsive layout for admin/non-admin users
- Fix home page content overflow issue
2026-03-04 17:46:40 +08:00
Misaka_Company
974eaac6dd docs: update extractor-start-button-flow.md to v1.3
- Add file merging functionality (ExcelParser merges batch files)
- Add database auto-import feature (DataImportService)
- Update architecture diagrams to include ExtractorCore separation
- Update sequence diagram with 76-step workflow
- Add DataImportService and DiscreteMaterialPlanDAO to flow
- Document ImportResult type and import statistics
- Update error handling to include merge and import errors
- Add temporary file cleanup after merging
2026-03-04 17:01:50 +08:00
Misaka_Company
2f5dc7607d fix: disable TLS encryption by default to avoid ServerName IP address warning
- Set encrypt: false as default for SQL Server connections
- Fixes DEP0123 deprecation warning when connecting via IP address (VPN tunnel)
- trustServerCertificate option still configurable via environment variable
- Affects 6 files: sql-server.ts, bip-users-dao.ts, database/index.ts,
  database/data-source.ts, cleaner-handler.ts, validation-handler.ts
2026-03-04 16:53:58 +08:00
Misaka_Company
a06276127d fix: resolve Chinese character encoding issue in console output
- Set console code page to UTF-8 (65001) in build scripts
- Fix garbled Chinese characters in winston logger output
2026-03-04 16:24:13 +08:00
Misaka_Company
29cb79abfd style: improve UI layout and styling
- Increase default window width from 900 to 1200
- Beautify clear button in OrderNumberInput with icon and hover effects
- Simplify ExtractorPage layout by removing collapsible sidebar
- Center settings form controls horizontally in SettingsPage
2026-03-04 16:06:00 +08:00
Misaka_Company
dc3d577f6f refactor: optimize ExtractorPage layout and UX
- Use OrderNumberInput component with format statistics
- Add collapsible sidebar with smooth animation
- Improve log system with level-based coloring and auto-scroll
- Remove result display cards for cleaner interface
- Add file:openPath IPC handler for opening files in explorer
2026-03-04 15:52:41 +08:00
Misaka_Company
50041d2a7b fix: remove validationResults check from cleaner execute button
Allow execute button to be clickable by default, relying on backend validation instead of frontend disabled state
2026-03-04 15:14:59 +08:00
Misaka_Company
9833552652 fix: support both MySQL and SQL Server in cleaner handler 2026-03-04 14:56:19 +08:00
Misaka_Company
8dbdf6f394 docs: move IMPLEMENTATION_PLAN.md to docs/plans directory
Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
2026-03-04 14:27:01 +08:00
Misaka_Company
c61776a1ff style: apply Prettier formatting across codebase
Apply consistent code formatting using Prettier to improve code readability
and maintain style consistency throughout the project.

Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
2026-03-04 14:24:16 +08:00
Misaka_Company
88c8c256e2 fix: resolve TypeScript type errors across codebase
- Add experimentalDecorators support in tsconfig.node.json for TypeORM entities
- Fix mssql module import in order-resolver.ts (static vs dynamic import)
- Extend ISqlType parameter types in sql-server.ts for NVarChar compatibility
- Fix variable naming and type assertions in bip-users-dao.ts
- Add proper type assertions for IPC call results in renderer hooks
  (useAuth, useCleaner, useExtractor, useValidation)
- Add definite assignment assertions in config-manager.ts
2026-03-04 14:03:23 +08:00
Misaka_Company
5497e86b58 fix: adjust batch size for SQL Server parameter limit (2100 max params)
- 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
2026-03-04 13:24:50 +08:00
Misaka_Company
63ea81e0d6 feat: add automatic database import after ERP data extraction
- 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>
2026-03-04 12:50:27 +08:00
Misaka_Company
abe51d17fa fix: resolve production ID case-sensitivity and SQL Server compatibility issues
- 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>
2026-03-04 11:27:37 +08:00
Misaka_Company
240e3838ba fix: correct Excel header for product unit from "单位" to "产品单位"
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>
2026-03-04 09:52:08 +08:00
Misaka
c384513273 Merge branch 'feature/export-cleaner-data' into dev 2026-03-03 22:52:43 +08:00
Misaka
e23cf71f78 feat: add material type management feature
- Add MaterialTypeManagementDialog component for managing material type keywords
- Add MaterialsTypeToBeDeletedDAO for database operations
- Add material-type-handler IPC handlers
- Update CleanerPage with type management button
- Add database fix scripts for AUTO_INCREMENT
- Update documentation for settings partial save and validation flow

Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
2026-03-03 22:51:11 +08:00
Misaka
7aa1abbc22 fix: resolve ExcelJS dynamic import and merge file save errors
- 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>
2026-03-03 22:46:23 +08:00
Misaka
879dccaa09 feat: add export validation results to Excel feature
Add export functionality to CleanerPage that allows users to export
the currently displayed validation results to an Excel file.

- Add ExportResultItem and ExportResultResponse types
- Create ResultExporter service using ExcelJS
- Register cleaner:exportResults IPC handler
- Add exportResults method to preload API
- Connect export button in CleanerPage to export handler

Export features:
- Exports filtered results (respecting manager/visibility filters)
- Includes selection status column
- Saves to app data directory/exports/校验结果.xlsx

Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
2026-03-03 22:29:52 +08:00
Misaka
e13bb15969 feat: implement Excel merge functionality for data extraction
- 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>
2026-03-03 21:32:11 +08:00
Misaka
00b120c762 docs: update extractor-start-button-flow.md for database architecture changes
- Update version to 1.2
- Add database factory pattern documentation
- Add IDatabaseService interface documentation
- Update architecture diagram with Database Layer (MySQL/SQL Server)
- Update sequence diagram with DatabaseFactory and IDatabaseService
- Fix Mermaid syntax (replace <br/> with multiline strings)
- Update error handling flowchart for dual database support
- Add DB_TYPE environment variable documentation

Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
2026-03-03 20:55:56 +08:00
Misaka
0040ca7521 refactor: abstract database layer to support MySQL and SQL Server
- Add IDatabaseService interface with unified query(transaction) methods
- Create DatabaseFactory for centralized database service creation
- Modify MySqlService and SqlServerService to implement IDatabaseService
- Unify SqlServerService.query() to accept array params (internally converts to @p0, @p1...)
- Refactor OrderNumberResolver to use IDatabaseService
- Refactor DiscreteMaterialPlanDAO to use DatabaseFactory
- Refactor MaterialsToBeDeletedDAO to use DatabaseFactory
- Update IPC handlers to use DatabaseFactory.create()
- Add database.types.ts with shared type definitions

This enables switching between MySQL and SQL Server via DB_TYPE env variable.

Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
2026-03-03 20:18:20 +08:00
Misaka
6698d82d6b docs: update extractor-start-button-flow.md to match current implementation
- Update version to 1.1 with new related files list
- Fix sequence diagram step numbers and add IPC serialization note
- Add note about progress state not receiving backend updates
- Add code references for real-time sync useEffect and preload API
- Update summary with custom error types and sessionStorage details
- Add new section for known limitations and pending features
- Document progress update and file merge as unimplemented

Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
2026-03-03 19:01:48 +08:00
Misaka_Company
b98cd46237 feat: merge settings partial save feature
Features:
- Partial settings save with deep merge
- Backup and rollback mechanism
- UI field whitelist validation
- Defensive programming in settings page

Safety:
- Auto-backup before save
- Automatic rollback on failure
- Field validation at both client and server
2026-03-03 17:15:03 +08:00
Misaka_Company
baaa031dac debug: add logging to savePartialSettings for troubleshooting 2026-03-03 15:51:47 +08:00
Misaka_Company
816060444c fix: correct cache key format to match .env file structure
The root cause of config overwrites was key mismatch:
- .env file uses: ERP_URL, DB_TYPE, DB_NAME (underscore uppercase)
- Code was using: erp.url, database.dbType (dot notation)

Fixed in three methods:
- saveAllSettings() - now sets cache with correct keys
- resetToDefaults() - now uses correct keys
- save() - now reads cache with correct keys

This ensures partial save preserves unmodified fields.
2026-03-03 15:42:40 +08:00
Misaka_Company
73a49f9de3 docs: add settings partial save feature documentation
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-03 15:12:39 +08:00
Misaka_Company
4d8df61187 feat: send only ERP fields from settings page (defensive programming) 2026-03-03 15:05:40 +08:00
Misaka_Company
a967050058 feat: update settings handler to use savePartialSettings
- Change parameter type from SettingsData to Partial<SettingsData>
- Call savePartialSettings() instead of saveAllSettings()
- Return detailed error messages from savePartialSettings
- Add logging for sections being saved

This change enables partial settings save functionality, allowing
the UI to save only specific settings sections without requiring
the complete settings object.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-03 14:57:06 +08:00
Misaka_Company
f3be0ad01d feat: implement savePartialSettings with validation and rollback
Implements the core savePartialSettings method that:
- Validates fields against UI_EDITABLE_FIELDS whitelist
- Deep merges partial updates with current settings
- Creates backup before saving
- Restores backup on save failure
- Reloads .env file to populate cache with correct keys

Added comprehensive tests:
- Partial update preserves existing fields
- Rejects non-whitelisted fields
- Handles nested object updates
- Restores backup on save failure

Fixed cache key inconsistency bug by clearing cache in loadEnvFile()
and reloading after save to ensure proper cache population.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-03 14:36:50 +08:00
Misaka_Company
7e37a9b1fc fix: use proper logger in ConfigManager backup/restore methods
Replace console.log/console.error with proper logger usage in
backupEnvFile and restoreBackup methods. Use the existing 'log' logger
created with createLogger('ConfigManager') following the same pattern
used in other methods.

Changes:
- Import createLogger and create log instance
- Replace console.log with log.debug in backupEnvFile
- Replace console.error with log.error in both methods
- Pass error and path metadata as objects for structured logging
- Fix test to use correct backup path (process.cwd() + src/main/.env.backup)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-03 14:04:42 +08:00
Misaka_Company
b5ef38f486 feat: add backup and restore mechanism to ConfigManager 2026-03-03 13:50:36 +08:00
Misaka_Company
c06880e946 fix: resolve code quality issues in utility functions
- Fix TypeScript type error in deepMerge recursive call with proper type assertions
- Remove unused type imports (ErpConfig, DatabaseConfig, PathsConfig, ExtractionConfig, ValidationConfig, UiConfig, ExecutionConfig)
- Fix line endings (CRLF to LF) via Prettier format

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-03 12:53:46 +08:00
Misaka_Company
765fb95644 feat: add deep merge and validation utility functions to ConfigManager
This commit adds utility functions to support partial settings save functionality:
- isObject: Type guard for plain objects
- deepMerge: Recursively merges objects, preserving unspecified fields
- validateEditableFields: Validates settings against UI editable field whitelist
- UI_EDITABLE_FIELDS: Whitelist of fields modifiable through UI

A failing test is included to verify the deep merge behavior.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-03 12:42:34 +08:00
Misaka_Company
429357ae8c docs: add implementation plan for settings partial save feature
- 8 detailed tasks with step-by-step instructions
- TDD approach with failing tests first
- Complete code snippets provided
- Manual testing procedures included
- Estimated 2-3 hours implementation time
2026-03-03 12:25:59 +08:00
Misaka_Company
79934a58d0 docs: add settings partial save design document
- Problem: Settings page overwrites unmodified .env fields
- Solution: Deep merge + whitelist validation approach
- Added backup mechanism for safe rollback
- Designed extensible whitelist for future UI expansion
2026-03-03 12:24:27 +08:00
Misaka_Company
b942b2fb15 Merge branch 'fix/cleaner-user-scope' into dev
Fix User scope isolation issue in CleanerPage:

- User users can no longer affect other users' data via "取消" button
- "确认删除" only processes visible filteredResults for non-Admin users
- Admin behavior unchanged (can manage all data)
- Prevents cross-user data interference

Committed: 6ecf03c
2026-03-03 11:14:26 +08:00
Misaka_Company
6ecf03ce11 fix: scope User operations to visible data only in CleanerPage
Fix critical bug where non-Admin users could affect other users' data
when using "取消" (Uncheck All) and "确认删除" (Confirm Deletion) buttons.

Problem:
- User users see only their filtered materials in table (filteredResults)
- "取消" button was unchecking ALL materials in validationResults
- "确认删除" was processing ALL materials, not just visible ones
- This caused User A to delete/modify User B's invisible data

Solution:
1. Modified "取消" button to only uncheck visible filteredResults
   - Now removes selectedItems only for visible material codes
   - Preserves selections for other users' invisible data

2. Modified handleConfirmDeletion to process only visible items for non-Admin users
   - Admin: processes all validationResults (unchanged behavior)
   - User: processes only filteredResults (scoped to their data)

Security Impact:
- Prevents cross-user data interference
- Ensures User scope isolation
- Maintains Admin full access to all data

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-03 11:13:39 +08:00
Misaka_Company
77311edce0 feat: add user override match for material validation in cleaner page
Add Priority 3 matching logic that allows User type users to override
material assignments with their own typeKeywords from MaterialsTypeToBeDeleted.

Changes:
- Add session manager integration to get current user context
- Implement Priority 3: User Override Match (only for non-admin users)
- Filter typeKeywords by current username and force override on match
- Maintain existing Priority 1 (exact match) and Priority 2 (type match) behavior
- Admin users bypass override logic and see original matching results
- Update cleaner-validation-flow.md with new matching algorithm flow

This ensures User users see materials assigned to themselves first when
their configured typeKeywords match, while Admin users maintain full visibility.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-03 10:45:25 +08:00