Commit Graph

38 Commits

Author SHA1 Message Date
Misaka_Company
167fa2893f feat: support multiple managers in DiscreteMaterialPlanCleaner
- Add get_materials_to_delete_by_managers() function in db/materials_to_delete.py
  - Supports querying by single manager, multiple managers, or all managers
  - Uses IN clause for multi-manager queries
- Refactor DiscreteMaterialPlanCleaner to accept manager_names parameter
  - Accepts str, List[str], or None (for all managers)
  - Automatically normalizes parameter types in __init__
  - Updates preload_data() with appropriate log messages

Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
2026-02-26 10:01:48 +08:00
Misaka
c5f48eb7c8 style: format code in discrete material cleaner
Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
2026-02-25 22:38:36 +08:00
Misaka
7819570ef3 feat: support both productionID and order number input formats
- Add identify_input_type() function to detect input format:
  - production_id: 2-digit + 1-letter + serial (e.g., 25A1, 25A12345)
  - order_number: SC + 14 digits (e.g., SC70202602120120)

- Refactor MaterialStatusValidator to intelligently handle both input
  types in validate_from_database() and validate_from_database_enhanced()

- Update log messages to reflect the new dual-input capability

Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
2026-02-25 22:29:51 +08:00
Misaka_Company
0a2c3c55c6 feat: add wait mechanisms for delete and save operations in discrete material cleaner
This change adds robust wait mechanisms to prevent race conditions when
performing delete and save operations in the ERP system.

Changes:
- Add row number change detection after delete to confirm completion
- Add save button disappearance detection to confirm save completion
- Add row number range check (7000-8000) to skip specific rows
- Enable previously commented save button click
- Improve logging with detailed status messages
- Add timeout handling (10s for delete, 60s for save)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-25 11:45:31 +08:00
Misaka
de25841364 style: apply code formatting to discrete_material_plan_cleaner.py
Apply consistent code formatting including:
- Single quotes to double quotes for string literals
- Multi-line formatting for long expressions
- Trailing whitespace cleanup
- Blank line adjustments for PEP 8 compliance

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-24 22:23:34 +08:00
Misaka
f2bbcfc426 Merge branch 'mysql' into dev
Resolved merge conflict in utils/material_status_validator.py by keeping
both deduplication statistics and error messages for empty results.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-24 20:44:52 +08:00
Misaka
24053c6a3b feat: implement unified logging system for GUI components
Add centralized logging mechanism that simultaneously outputs to console
and GUI log components, improving code maintainability and consistency.

Changes:
- Add gui/log_config.py for centralized logging configuration
- Add gui/widgets/log_handler.py as bridge between logging and LogText
- Integrate unified logging into DataExtractionTab and MaterialValidationTab
- Initialize logging system in MainWindow on startup
- Improve error messages in material_status_validator for empty results
- Add documentation for logging mechanism and refactoring

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-24 20:31:59 +08:00
Misaka_Company
19dfe5b09e refactor: rename Chinese-named Python files to English
Rename utility files to use English names for better cross-platform compatibility:
- utils/离散备料计划维护数据提取.py → utils/discrete_material_plan_extractor.py
- utils/离散备料计划维护数据清理.py → utils/discrete_material_plan_cleaner.py

Update all import statements across the codebase and documentation references.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-24 17:35:23 +08:00
Misaka_Company
7a8a38a3b6 refactor: improve discrete material plan processing logic with better status handling
- Restructure conditional flow to check status before detail count
- Add handling for orders with no material plan data
- Add handling for completed orders (status=完成)
- Add warning for orders with unrecognized status
- Fix deletion condition to check for non-zero pending quantity

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-24 17:13:56 +08:00
Misaka_Company
e5f6f4ee0c feat: add MaterialCode-based deduplication to material validation queries
Implement database-level deduplication using ROW_NUMBER() window function
to remove duplicate material records based on MaterialCode field.

Changes:
- Add query_all_distinct_by_material_code() to deduplicate full table results
- Add query_by_source_numbers_distinct() to deduplicate filtered results
- Update validator to use new deduplication methods with statistics logging
- Retention strategy: keep earliest record (CreateDate ASC, SequenceNumber ASC)

Benefits:
- Reduces data redundancy from 54,358 to 1,679 records (96.91% reduction)
- Improves validation result readability by removing duplicate materials
- Maintains backward compatibility with existing query methods

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-24 16:22:35 +08:00
Misaka_Company
ac94b1cb82 refactor: clean up code by removing redundant comments and docstrings
- Remove unused imports (redirect_stdout) from data_extraction_tab.py
- Update docstring to reflect stability fixes in data_extraction_tab.py
- Strip excessive inline comments while preserving essential ones
- Improve code readability by reducing visual noise

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-13 15:19:05 +08:00
Misaka_Company
ed7eaf038b refactor: optimize performance and code quality with significant improvements
Performance optimizations:
- Pre-load database materials into HashSet (O(1) lookup) instead of O(n) per material query
- Add 60s safety timeout on loading waits to prevent deadlocks
- Simplify navigation loop with while True pattern

Code quality improvements:
- Replace print-based logging with proper logging module
- Add _get_input_value() helper to reduce duplication
- Move all imports to top of file (re, time, TimeoutError)
- Remove redundant docstrings and consolidate logic
- Add detailed module docstring explaining optimizations

Bug fixes:
- Fix iframe variable naming conflicts (detail_main_frame, detail_inner_frame)
- Add error handling for individual order processing failures
- Simplify setup_query_interface() logic
- Change password to placeholder for security

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-13 13:57:59 +08:00
Misaka_Company
82819ae9d1 refactor: improve button navigation logic with proper state detection
- Add button-wrapper element locator for accessing action/navigation buttons
- Create dedicated button objects (delete, next material, collapse)
- Add _is_button_enabled() method using Playwright's is_enabled()
- Replace index-based navigation with button state-driven loop
- Add row number change detection to wait for data loading
- Simplify navigation logic with explicit button click handling

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-13 13:06:17 +08:00
Misaka_Company
35b568d647 feat: add cumulative pending quantity validation before material deletion
Added validation to check if cumulative pending quantity is empty before allowing material deletion, with appropriate emoji indicators for delete eligibility.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-10 17:57:03 +08:00
Misaka_Company
cff5e78c1d refactor: optimize material deletion with exact code matching and database queries
- Change from fuzzy material name matching to exact material code matching
- Migrate from MaterialsTypeToBeDeleted to MaterialsToBeDeleted table
- Add should_delete_material() for on-demand database queries
- Remove in-memory material list loading to reduce memory footprint
- Update documentation to reflect new matching logic
- Remove main scripts from git tracking (contain user-specific config)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-10 10:53:53 +08:00
Misaka_Company
cd21e54abf feat: add material deletion confirmation with checkbox UI
- Add MaterialsToBeDeletedDAO for managing material deletion records by MaterialCode
- Add MaterialValidationResult dataclass for enhanced validation results
- Add CheckboxTreeview component with selectable checkbox functionality
- Refactor material validation UI with new columns: select, material name, code, spec, model, manager
- Add double-click to edit manager name functionality
- Add select all/deselect all buttons
- Add confirm deletion button to write selected records to database
- Prioritize MaterialsToBeDeleted.ManagerName over type-based matching when displaying
- Export results to Excel with selection state

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-06 16:40:28 +08:00
Misaka_Company
0ef1b86f12 refactor: rename MaterialsToBeDeleted to MaterialsTypeToBeDeleted
Rename database table and related classes from MaterialsToBeDeleted to MaterialsTypeToBeDeleted for better semantic clarity.

Changes:
- Rename MaterialsToBeDeletedDAO class to MaterialsTypeToBeDeletedDAO
- Update all SQL queries to reference MaterialsTypeToBeDeleted table
- Update import statement in material_status_validator.py
- Update documentation comments

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-06 14:15:51 +08:00
Misaka_Company
2096a51f55 feat: add database-driven material validation with multi-mode support
This commit enhances the material validation functionality to support
database-driven workflows alongside the existing Excel-based approach.

## New Features

### DAO Layer
- Add ProductionContractDataDAO for querying production contract data
- Add MaterialsToBeDeletedDAO with full CRUD operations
- Enhance DiscreteMaterialPlanDAO with query_all(), query_by_source_numbers(),
  and get_unique_material_names() methods

### Validation Modes
Support for 4 validation modes in MaterialValidationTab:
1. Database Full - Query all materials from DiscreteMaterialPlanData
2. Database Filtered - Query by ProductionID.txt file
3. Excel Existing - Validate from existing Excel file
4. Excel Full - Complete workflow with ERP extraction

### Configuration
- Add ValidationConfig dataclass with data_source, batch_size, match_mode,
  enable_crud_operations, and default_manager fields
- Update ConfigLoader to support validation configuration
- Add validation settings section in SettingsTab GUI

### Query Chain
Implementation of full query chain:
ProductionID.txt (总排号) → productionContractData (生产订单号) →
DiscreteMaterialPlanData (SourceNumber) → MaterialName →
MaterialsToBeDeleted comparison

## Backward Compatibility
All existing Excel-based validation methods remain unchanged, ensuring
no breaking changes for existing workflows.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-06 13:08:31 +08:00
Misaka_Company
53a1e33e45 feat: add SQL Server database persistence for extracted material plan data
Add optional database persistence feature that automatically saves extracted
discrete material plan data to SQL Server. Users can enable this feature in
the settings tab.

Changes:
- Add enable_db_persistence flag to ExtractionConfig (default: disabled)
- Create DiscreteMaterialPlanDAO for database operations with REPLACE pattern
- Update progress tracking to include database persistence stage (90-100%)
- Add database persistence checkbox in settings UI
- Remove verbose logging checkbox from data extraction UI (config-only now)
- Update extraction workflow to save merged DataFrame to database

Progress weights adjusted:
- download: 65% -> 60%
- database: 10% (new stage)
- Other stages adjusted accordingly

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-06 12:21:58 +08:00
Misaka_Company
3180ccacb8 feat: enhance progress reporting granularity in data extraction workflow
- Break down query phase into 3 detailed steps (read file, query database, complete)
- Split download batch process into 7 granular steps per batch (clear, fill, search, wait, select, configure, download)
- Divide conversion phase into 2 steps per file plus 3 final steps (merge, cleanup)
- Add 'action' parameter to all progress reports for better categorization
- Improve user feedback with more detailed status messages and completion indicators

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-05 15:17:18 +08:00
Misaka_Company
2ca53f6a55 style: normalize code formatting across the codebase
- Standardize quote style (single to double quotes)
- Improve code formatting consistency
- Apply formatting to utilities, GUI components, and tools
- Update imports and docstrings for consistency

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-05 14:56:35 +08:00
Misaka_Company
13bc4520bf refactor: centralize configuration management with type-safe schema
Major changes:
- Add dataclass-based configuration schema with validation (config/schema.py)
- Create centralized config loader and default values (config/defaults.py, config/loader.py)
- Remove duplicate database_config.py, merge into unified structure
- Consolidate browser settings into ERP config
- Add batch_size parameter support to extractor

Bug fixes:
- Fix settings save error by updating config paths (browser.* → erp.*)
- Fix batch_size not being applied in data extraction

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-05 14:27:28 +08:00
Misaka_Company
885d87dff8 feat: add progress callback mechanism for real-time updates in data extraction
- Add ProgressInfo and ProgressCalculator classes for structured progress tracking
- Implement RealtimeOutput for immediate log display without buffering
- Add progress callback support to DiscreteMaterialPlanExtractor
- Use queue-based thread-safe communication for GUI progress updates
- Fix log output issue where all content appeared at once after completion

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-05 14:06:30 +08:00
Misaka_Company
c9e68a2bf0 fix: handle large dataset queries and type conversion
- Add batch processing to production order query to handle SQL Server's 2100 parameter limit
- Fix material name column index from Q to R column
- Add string type conversion to prevent TypeError in material matching

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-05 11:28:33 +08:00
Misaka_Company
c6b97443e5 feat: add material status validation tool
Add MaterialStatusValidator tool to check material status and match materials to be deleted:
- Add get_all_materials_to_delete() function to fetch all materials from database
- Add utils/material_status_validator.py with MaterialStatusValidator class
- Add validate_material_status.py script to run the validation
- Delete obsolete materialDelete.py file

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-05 10:11:13 +08:00
Misaka_Company
a78afe383f fix: adjust footer detection logic in excel converter
Changed footer detection to look ahead at the next row instead of the current row, and simplified to only check for '制单人'.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-05 08:39:18 +08:00
Misaka_Company
c176063bfa feat: add material matching logic for discrete material plan cleaner
- Add db/materials_to_delete.py for querying materials to delete by manager
- Add manager_name parameter to DiscreteMaterialPlanCleaner
- Implement material keyword matching logic in process_order
- Update file paths from orderID.txt to ProductionID.txt

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-23 16:50:14 +08:00
Misaka_Company
902ff9b831 refactor: use database for production order queries
- Add db/production_order_query.py component for querying production orders
- Replace file-based orderID.txt with database-driven approach
- Read ProductionID.txt (总排号) and query [26年压力表合同数据] table
- Update both extraction and cleaning scripts to use new component
- Change parameter: order_id_file → production_id_file

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-23 16:06:40 +08:00
Misaka_Company
4b0a882b69 refactor: improve material code input selection
Replace the class-based locator strategy with a text-based filter using regex to accurately identify the material code input field. This change targets elements matching "材料编码" followed by 11 digits, increasing reliability. Also uncommented page2.pause() to assist with debugging the iteration loop.
2026-01-23 14:30:35 +08:00
Misaka_Company
ebd53b168e refactor: improve locator precision and data extraction
Refine element selection by introducing a specific parent container `.card-table-side-box` to enhance locator accuracy. Replace the previous text-parsing approach for material codes with direct input value retrieval. Additionally, add support for extracting cumulative pending and outbound quantities to improve data completeness.
2026-01-23 13:52:52 +08:00
Misaka_Company
cf88800444 feat: Check preparation status before cleaning data
Added logic to extract and validate the "Material Preparation Status" (备料状态) before modifying discrete material plans.

The cleanup process now only proceeds if the status is "审批通过" (Approval Passed). Orders with other statuses are skipped to prevent errors during modification. This change also includes code cleanup by removing commented-out debug statements.
2026-01-23 11:11:22 +08:00
Misaka_Company
201f65d715 feat: implement material plan data cleaning automation
Remove manual exit prompt in main script to allow automated execution.
Add logic in DiscreteMaterialPlanCleaner to navigate the "Material Plan" popup, handling nested iframes and waiting for data to load. Implement iteration over material details to extract codes and names, handling cases where no details exist.
2026-01-22 18:14:56 +08:00
Misaka_Company
8708709cac feat: add discrete material plan data cleaning tool
Implement a new automation script and utility to handle the cleaning of
discrete material plan maintenance data.

- Add main_clean.py as the primary entry point, configuring the cleaner
  instance and reading order IDs.
- Add DiscreteMaterialPlanCleaner in utils/ utilizing Playwright to automate
  browser interactions.
- Implement logic for user authentication (login/logout), UI setup for
  queries, and processing individual orders.
- Include verbose logging and debug mode support for troubleshooting.
2026-01-22 15:55:38 +08:00
Misaka_Company
92d4572985 Refactor ExcelConverter to streamline logging and enhance summary reporting 2026-01-16 15:59:25 +08:00
Misaka_Company
bb9348d12b Refactor DiscreteMaterialPlanExtractor to use logout function from auth module and update headless mode in main script 2026-01-16 15:20:05 +08:00
Misaka_Company
93f986260e Add logout functionality to DiscreteMaterialPlanExtractor for improved session management 2026-01-16 14:59:18 +08:00
Misaka_Company
51cba4caee Refactor main script to utilize DiscreteMaterialPlanExtractor for data extraction and streamline order processing 2026-01-16 13:51:20 +08:00
Misaka_Company
4d441be304 Add ExcelConverter module and demo script for Excel data transformation 2026-01-16 12:51:06 +08:00