Commit Graph

53 Commits

Author SHA1 Message Date
Misaka_Company
fbd62fe390 feat: integrate Playwright download dialog into startup flow 2026-03-24 16:02:31 +08:00
Misaka_Company
6ad916998c feat: add IPC handlers for Playwright browser download 2026-03-24 15:41:09 +08:00
Misaka
26c05f3726 refactor: move ipc orchestration into application services 2026-03-21 10:40:36 +08:00
Misaka
2b4a09dabe fix: resolve lint and typecheck issues 2026-03-21 09:33:07 +08:00
Misaka
2fba07fd8f fix: restore full typecheck stability 2026-03-21 09:17:58 +08:00
Misaka
b979b73ba1 refactor: split validation handler responsibilities 2026-03-21 08:54:35 +08:00
Misaka
6ad9463e73 feat: rebuild portable auto-update flow 2026-03-20 21:20:28 +08:00
google-labs-jules[bot]
a020ee537d feat: Add Report Viewer Dialog to Cleaner Page
Added a new "View Reports" button to the CleanerPage which opens a new ReportViewerDialog. This dialog lists all available execution reports stored in S3 for the current user, or for all users if the current user is an admin.
The reports are downloaded as Markdown and rendered using react-markdown.
Added three new IPC channels to fetch and download reports using the existing RustfsService and S3Client.

Co-authored-by: luwamgere15-crypto <255338376+luwamgere15-crypto@users.noreply.github.com>
2026-03-17 23:03:13 +00:00
Misaka_Company
db44618ee5 feat(rustfs): integrate report upload into cleaner execution flow
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-03-17 15:48:50 +08:00
Misaka_Company
b289fb9624 fix: use updateProcessConcurrency to persist slider changes to config.yaml
- CleanerPage now uses updateProcessConcurrency instead of setProcessConcurrency
- This ensures slider changes are persisted to config.yaml via IPC
- Remove unused queryBatchSize and setProcessConcurrency from destructuring
2026-03-17 10:57:24 +08:00
test
6a2fba0e57 refactor(cleaner): batch query and controlled parallel order processing 2026-03-16 21:47:13 +08:00
Misaka_Company
ad8b3deb00 feat(order-resolver): add deduplication logic for production order number resolution
- Add P0: DISTINCT in SQL query to prevent database duplicates
- Add P1: Input layer deduplication to avoid redundant queries
- Add P2: Return layer deduplication in getValidOrderNumbers()
- Optimize resolve() to use batch query instead of loop queries
- Add getDeduplicationReport() for human-readable mapping summary
- Improve extraction logs to show deduplication statistics
- Only log merged mappings (multiple productionIDs → one order number)
- Remove duplicate marking as error (normal business scenario)
- Bump version to 1.0.1

Example log output:
  输入 5 个总排号 → 解析为 2 个唯一订单号(3 个重复已合并)
  重复合并详情:
    SC70202603120085 ← 26B12214、26B12213、26B12212 (共 3 个总排号)
    SC70202603120131 ← 26B12125、26B12126 (共 2 个总排号)
2026-03-16 16:02:52 +08:00
Misaka_Company
715dfb4d71 feat(cleaner): add automatic retry mechanism for failed orders
- Add retry logic with max 2 attempts per failed order
- Track retry statistics (retriedOrders, successfulRetries)
- Generate detailed retry report section in execution reports
- Display retry metrics in ExecutionReportDialog UI

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 15:59:10 +08:00
test
77fabf2018 fix(shared-state): clear shared Production IDs when input is cleared
Fixes a bug where clearing the order number input in the extraction page
did not clear the shared Production IDs in the main process. This caused
the data cleanup page to continue using stale data when filtering by
Production ID.

Changes:
- Add VALIDATION_CLEAR_SHARED_PRODUCTION_IDS IPC channel
- Register handler to clear shared Production IDs by sender ID
- Expose clearSharedProductionIds API in preload script
- Update ExtractorPage to call clear when order numbers are empty

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-08 21:58:56 +08:00
test
13187ddce1 feat(validation): add source number validation checks with localized error messages
Add validation to detect and report when no order numbers are found from Production IDs (either from shared inputs or file). Provides clear Chinese error messages to guide users when their inputs don't match any database records.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-08 19:18:54 +08:00
test
bcfe0eecca fix(a11y): improve focus restoration with timing fixes, validation, and error handling
Core improvements:
- Fix focus restoration timing by using queueMicrotask only (removed double-layer async)
- Add comprehensive error handling with dev-mode logging for all failure scenarios
- Validate element visibility (display: none, visibility: hidden) before restoring focus
- Check disabled state and implement fallback to nearest focusable ancestor
- Add findNearestFocusableElement() helper for robust fallback strategy
- Add tabindex="-1" to focusable selectors for better focus management
- Use preventScroll option when calling focus() to prevent scroll jumps

Additional fixes:
- Remove unnecessary type conversion in Modal.tsx
- Fix TypeScript unused variable errors in main process
- Clean up unused imports in bip-users-dao.ts
- Add ARIA attributes and focus management to LoginDialog
- Add triggerRef support to UserSelectionDialog and ExecutionReportDialog
- Refactor ExecutionReportDialog to use Modal component
- Improve MaterialTypeManagementDialog with focus management

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-08 18:29:39 +08:00
test
fba2c73782 feat(logging): Wave 3 - add comprehensive error serialization with stack traces
- Add error-utils module with serializeError and sanitizeError utilities
- Enhance IPC error handling to capture full error context including stack traces
- Add logError helper function for consistent error logging across the application
- Update console and file log formats to properly serialize error objects
- Replace all basic error logging in BIPUsersDAO with structured logError calls
- Add ErrorLike and SerializedError type interfaces for type safety

This improves debugging capability by preserving full error details in development
while sanitizing sensitive information in production logs.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-08 16:10:23 +08:00
test
c4fff84848 style: format code with Prettier
Apply Prettier formatting to maintain consistent code style across the codebase.
Changes include formatting improvements for:
- IPC handlers (database, file, material-type, resolver, user-erp-config, validation)
- Type definitions (ipc-api.types)
- React components (MaterialTypeManagementDialog)
- React hooks (useAuth, useCleaner, useValidation)
- Pages (SettingsPage)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-08 15:17:40 +08:00
test
6df16898da feat(logging): Wave 2 - integrate logging throughout application
This commit integrates the logging infrastructure across the entire application:

IPC Layer:
- Add logger-handler.ts with centralized IPC logging channels
- Integrate audit logging into auth, cleaner, extractor handlers
- Add structured logging for IPC operations and data flow

Service Layer:
- Add logger integration to ERP services (extractor, cleaner)
- Integrate logging into excel-parser and user DAO
- Add operation tracking and error logging

Renderer Layer:
- Add useLogger hook for component-level logging
- Update App.tsx with session and user activity logging
- Enable frontend audit trail for critical actions

Testing:
- Add comprehensive IPC logging integration tests
- Enhance unit test coverage for logger and audit-logger
- Add end-to-end logging flow validation

Types:
- Update preload type definitions for logging APIs

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-08 15:07:03 +08:00
test
8f3e5273e2 refactor(ipc): harden channels and unify IPC contracts 2026-03-08 12:35:00 +08:00
test
54a82200b6 refactor: complete migration from .env to YAML configuration
BREAKING CHANGE: Application now uses config.yaml instead of .env files

## Changes:
- Remove dotenv dependency from package.json
- Update all services to use ConfigManager for configuration
- Update tests to use fixed credentials instead of env vars
- Delete obsolete config-manager.test.ts (used old .env API)
- Update documentation (README.md, CLAUDE.md) to reflect new config system

## Configuration Architecture:
- ConfigManager: Centralized YAML configuration with Zod validation
- config.yaml location:
  - Development: Project root (easy to edit and version control)
  - Production: User AppData (persists across updates)
- ERP credentials: Stored in database (dbo_BIPUsers) per user
- Other settings: Stored in config.yaml (database, paths, extraction, etc.)

## Files Modified:
- package.json: Removed dotenv dependency
- cleaner-handler.ts: Use ConfigManager.getDatabaseType()
- run-migration.ts: Read from config.yaml instead of .env
- All integration tests: Use fixed test credentials
- tests/setup.ts: Removed dotenv loading
- README.md, CLAUDE.md: Updated documentation

Migration is complete. Application no longer depends on .env files.
2026-03-07 17:22:13 +08:00
test
73b8f2409a fix(validation): migrate DB config from env to ConfigManager
- Refactor getValidationDatabaseService() to use ConfigManager
- Refactor getTableName() to use ConfigManager.getDatabaseType()
- Replace all process.env.DB_TYPE references with ConfigManager API
- Simplify isSqlServer checks from 'sqlserver||mssql' to 'sqlserver'
- Preserve all business logic and dual-database support
- Typecheck passes successfully

Fixes issue where Cleaner page failed with 'Failed to connect to MySQL'
due to validation-handler.ts not being migrated in commit c13be9e
2026-03-07 15:14:15 +08:00
test
c7c192a703 chore(extractor): add error logging for ERP login failures
Added error message extraction and logging to improve user feedback and debugging when ERP login fails during material plan extraction.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-07 14:51:50 +08:00
test
c13be9e19a refactor: migrate configuration to YAML-based system 2026-03-07 11:30:09 +08:00
Misaka
48f1f51d76 refactor: remove unused UI and execution configuration
Remove unused configuration options that were not consumed by the UI:

- Remove UI configuration (UI_FONT_FAMILY, UI_FONT_SIZE, UI_PRODUCTION_ID_INPUT_WIDTH)
  - No UI components were using these settings
  - Settings page had no inputs for these options

- Remove execution configuration (EXECUTION_DRYRUN)
  - Dry run mode is controlled by Cleaner page UI toggle
  - State is managed via sessionStorage, not config file

Files modified:
- src/main/types/settings.types.ts: Remove UiConfig and ExecutionConfig interfaces
- src/main/services/config/config-manager.ts: Remove config read/write logic
- src/main/ipc/settings-handler.ts: Remove filtered fields
2026-03-05 22:02:53 +08:00
Misaka
5977254180 feat: migrate ERP configuration from .env to per-user database storage
- Moved ERP credentials (URL, username, password) from environment variables to dbo_BIPUsers table
- Each user now has their own ERP configuration stored in the database
- Added UserErpConfigService for managing per-user ERP settings
- Updated cleaner and extractor handlers to fetch ERP config from database instead of .env
- Removed ERP fields from ConfigManager UI editable fields
- Added new IPC handlers and preload APIs for user ERP config management
- Includes migration script to transfer existing .env ERP settings to database
- Added migration guide documentation

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-05 21:52:54 +08:00
Misaka_Company
a906f34ac2 feat: auto-generate markdown report after cleaner execution
- Add CleanerReportGenerator service to create execution reports
- Extend OrderCleanDetail with skippedMaterials for detailed tracking
- Record skip reasons for each material (protected range, pending qty, etc.)
- Generate timestamped markdown reports in logs/reports/ directory
- Reports include execution summary, order details, skip reasons, and errors
2026-03-05 16:19:40 +08:00
Misaka_Company
49ac29e70c Merge feature/cleaner-progress into dev
Merged progress indicator feature for cleaner execution:
- CleanerProgress type for tracking execution progress
- Progress calculation: (1 + i + j/Mᵢ)/(1+N) × 100
- cleaner.onProgress IPC event for real-time updates
- Enhanced ExecutionReportDialog with progress bar
- Progress state management in useCleaner hook
2026-03-05 13:28:34 +08:00
Misaka_Company
dc01896d8b feat: add progress indicator to cleaner execution report dialog
- Add CleanerProgress type for tracking execution progress
- Implement progress calculation: (1 + i + j/Mᵢ)/(1+N) × 100
  - Login complete: 1/(1+N) × 100
  - Per material: (1 + orderIndex + materialIdx/totalMaterials)/(1+totalOrders) × 100
- Add cleaner.onProgress IPC event for real-time progress updates
- Enhance ExecutionReportDialog with progress bar and status display
- Update useCleaner hook with progress state management
- Dialog opens immediately on execution start, showing progress then results
2026-03-05 13:25:04 +08:00
Misaka_Company
ba64c27457 feat: allow editing manager field in cleaner table
- Add inline editing for manager column (Admin users can double-click to select from dropdown)
- Auto-assign current user as manager when User checks a material
- Defer database writes until 'Confirm Delete' button is clicked
- Add updateManager IPC handler and DAO method
- Update preload API with updateManager method
2026-03-05 13:19:12 +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
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
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
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
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
9833552652 fix: support both MySQL and SQL Server in cleaner handler 2026-03-04 14:56:19 +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
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
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_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
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
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
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
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
Misaka
9caa38caa8 feat: implement settings interface with user permission control
New Features:
- Add SettingsPage component with Admin/User view differentiation
- Create ConfigManager service for .env file management
- Add IPC handlers for settings CRUD operations
- Implement connection testing for ERP and database
- Add settings navigation to main app

Files Created:
- src/main/types/settings.types.ts - Type definitions
- src/main/services/config/config-manager.ts - Config service
- src/main/ipc/settings-handler.ts - IPC handlers
- src/renderer/src/pages/SettingsPage.tsx - React UI component

Files Modified:
- src/main/ipc/index.ts - Register settings handlers
- src/preload/index.ts - Expose settings API
- src/preload/index.d.ts - Add SettingsAPI type
- src/renderer/src/App.tsx - Add settings navigation

Co-Authored-By: Claude (qwen3.5-plus) <noreply@anthropic.com>
2026-03-01 20:51:29 +08:00
Misaka
0f1e0a8908 feat: implement material validation UI in CleanerPage
New Features:
- Material validation from database (full table or filtered by ProductionID)
- Checkbox selection for materials to delete with auto-select for marked items
- Manager-based filtering (Admin only)
- Two-phase deletion: confirm (mark in DB) + execute (delete from ERP)
- Export results to CSV
- Hide/show checked items feature (User mode)
- Share Production IDs between ExtractorPage and CleanerPage
- Persist page state using sessionStorage

Bug Fixes:
- Fix MySQL query rowCount for INSERT/UPDATE/DELETE operations
- Add AUTO_INCREMENT to MaterialsToBeDeleted.ID (preserved 43 records)
- Add UNIQUE constraint on MaterialsToBeDeleted.MaterialCode

Files Added:
- src/main/ipc/validation-handler.ts
- src/main/types/validation.types.ts
- src/main/services/database/materials-to-be-deleted-dao.ts
- src/main/services/database/discrete-material-plan-dao.ts

Files Modified:
- src/renderer/src/pages/CleanerPage.tsx (complete rewrite)
- src/renderer/src/pages/ExtractorPage.tsx
- src/renderer/src/App.tsx (add navigation tabs)
- src/main/services/database/mysql.ts
- src/preload/index.ts + index.d.ts
2026-03-01 19:15:38 +08:00
Misaka
829851e3ca feat: implement user authentication system
- Add SessionManager for managing user sessions (singleton pattern)
- Add BIPUsersDAO for database authentication
- Add LoginDialog component for username/password login
- Add UserSelectionDialog component for admin user selection
- Support silent login by computer name
- Implement main page with navigation to Extractor and Cleaner

Database:
- Table: dbo_BIPUsers
- Fields: UserName, Password, UserType, ComputerNmae

UI Flow:
1. Silent login on startup via computer name
2. Show login dialog if silent login fails
3. Display main page with user info and navigation
4. Support logout and re-login
2026-03-01 17:46:15 +08:00