Commit Graph

231 Commits

Author SHA1 Message Date
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
Misaka_Company
74ddef2d7b fix: clear shared Production IDs before setting new ones
Fixed material validation always using historical order numbers instead of
current input. The setSharedProductionIds function was accumulating IDs
without clearing old ones, causing validation to use all previously entered
order numbers.

Changes:
- Added sharedProductionIds.clear() before adding new IDs
- Ensures Set only contains the latest order numbers from extractor page

This fixes the root cause where changing the order number in the extractor
page would not update the validation data source, as old IDs were never
removed from the shared Set.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-03 10:01:05 +08:00
Misaka_Company
edf696ab39 docs: fix Mermaid syntax error in settings save flow diagram
Replace pipe character in dbType union notation with 'or' to resolve Mermaid parse error.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-03 09:11:35 +08:00
Misaka_Company
6ec422f357 docs: add UI flow analysis documentation and update gitignore
Add documentation for extractor start button and settings save button flows with detailed Mermaid diagrams. Also add logs directory to gitignore.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-03 09:06:33 +08:00
Misaka
a05c8a9037 feat: add TypeORM, logger, schemas, hooks and stores
- Add TypeORM integration with data-source, entities and repositories
- Add logger service for structured logging
- Add Zod validation schemas for auth, cleaner and extractor
- Add custom React hooks (useAuth, useCleaner, useExtractor, useValidation)
- Add Zustand stores (useAppStore, useUserStore)
- Add UI components (Button, Modal, Toast)
- Add error types and ErpBrowserManager
- Refactor IPC handlers and services
- Add unit tests for new modules

Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
2026-03-02 23:10:15 +08:00
Misaka_Company
982fb8fde6 fix: correct material name type keyword matching logic
Reverse the inclusion check to properly match when materialName contains typeKeyword.materialName (e.g., "ABC123_SPECIAL" contains "ABC123").

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-02 16:20:11 +08:00
Misaka_Company
11aec6d238 docs: fix Mermaid diagram syntax in deleteByMaterialCodes flow
- Remove problematic edge labels with special characters
- Move database type identifiers into node labels
- Replace ellipsis with clearer text descriptions
- Fix parse error caused by spaces and special chars in edge labels

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-02 13:17:38 +08:00
Misaka_Company
9fbf75a8a0 docs: add confirm deletion button flow analysis to cleaner validation docs
Add comprehensive documentation for the "确认删除 (同步数据库)" button
flow, including:

- Core flow overview with Mermaid diagram
- Frontend interaction layer analysis (handleConfirmDeletion)
- IPC handler layer details (upsertBatch, delete handlers)
- Database DAO layer implementation with MySQL vs SQL Server differences
- Data flow diagram showing all layers
- Key data structures and error handling
- Comparison table with validation status flow

The document now covers both core business flows in the cleaner page:
1. Get and validate material status (read operation)
2. Confirm deletion/sync to database (write operation)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-02 12:49:31 +08:00
Misaka_Company
10e07cdf93 docs: add cleaner validation flow analysis with Mermaid diagrams
Add comprehensive technical documentation for the cleaner page
"get validation status" functionality, including:
- Complete flow analysis from UI click to database queries
- Mermaid flowcharts and sequence diagrams
- Material matching algorithm (priority-based)
- Database interaction details (MySQL/SQL Server)
- IPC handler logic
- Shared Production IDs mechanism

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-02 12:29:53 +08:00
Misaka_Company
1aa2abdb43 fix: resolve SQL Server table name mapping and variable naming conflicts
- Fix getTableName() to handle generic schema_tablename pattern
- Convert schema_tablename to [schema].[tablename] for SQL Server
- Replace hardcoded productionContractData table name with helper function
- Fix variable naming conflict: rename 'sql' to 'sqlString' to avoid shadowing mssql module import
- Apply fixes to discrete-material-plan-dao, materials-to-be-deleted-dao, and bip-users-dao

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-02 12:15:11 +08:00
Misaka_Company
679366a4b0 Merge branch 'jules-refactor-ui-tailwind-6294750740902394972' 2026-03-02 11:15:17 +08:00
Misaka_Company
02bc6b24d6 fix: enable text input in extractor page order number textarea
Remove global user-select: none style that was preventing text input
and add explicit user-select: text to the textarea element.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-02 11:13:36 +08:00
Misaka_Company
05d856309f feat: add SQL Server support and refactor database layer for multi-database compatibility
- Add SqlServerService integration alongside existing MySQL support
- Refactor DAOs (DiscreteMaterialPlanDAO, MaterialsToBeDeletedDAO, BipUsersDAO) to support both MySQL and SQL Server
- Update validation handler to dynamically select database service based on DB_TYPE environment variable
- Add connection pooling and proper connection management for SQL Server
- Update package-lock.json dependency peer flags

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