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>
100 lines
3.2 KiB
Python
100 lines
3.2 KiB
Python
"""
|
|
Data Access Object for production contract data.
|
|
|
|
This module provides query operations for accessing production contract data
|
|
from the [productionContractData].[26年压力表合同数据] table.
|
|
"""
|
|
|
|
from typing import List, Dict, Any
|
|
from db.connection import get_connection
|
|
|
|
|
|
class ProductionContractDataDAO:
|
|
"""Data Access Object for production contract data queries"""
|
|
|
|
def __init__(self):
|
|
self.db = None
|
|
|
|
def __enter__(self):
|
|
"""Enter context manager and establish database connection"""
|
|
self.db = get_connection()
|
|
self.db.connect()
|
|
return self
|
|
|
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
"""Exit context manager and close database connection"""
|
|
if self.db:
|
|
self.db.disconnect()
|
|
|
|
def close(self):
|
|
"""Close database connection"""
|
|
if self.db:
|
|
self.db.disconnect()
|
|
|
|
def query_by_总排号(self, 总排号_list: List[str]) -> List[Dict[str, Any]]:
|
|
"""
|
|
Query production contract data by 总排号 list.
|
|
|
|
Args:
|
|
总排号_list: List of 总排号 values to query
|
|
|
|
Returns:
|
|
List of dictionaries containing 总排号, 生产订单号, 序号, 订单号, 客户名称, 产品型号
|
|
"""
|
|
if not 总排号_list:
|
|
return []
|
|
|
|
# SQL Server parameter limit requires batching
|
|
batch_size = 2000
|
|
all_results = []
|
|
|
|
for i in range(0, len(总排号_list), batch_size):
|
|
batch = 总排号_list[i:i + batch_size]
|
|
placeholders = ','.join(['?' for _ in batch])
|
|
sql = f"""
|
|
SELECT [总排号], [生产订单号], [序号], [订单号], [客户名称], [产品型号]
|
|
FROM [productionContractData].[26年压力表合同数据]
|
|
WHERE [总排号] IN ({placeholders})
|
|
ORDER BY [序号]
|
|
"""
|
|
|
|
with get_connection() as db:
|
|
results = db.execute_query(sql, tuple(batch))
|
|
all_results.extend(results)
|
|
|
|
return all_results
|
|
|
|
def get_source_numbers_by_总排号(self, 总排号_list: List[str]) -> List[str]:
|
|
"""
|
|
Extract unique 生产订单号 values by 总排号 list.
|
|
|
|
Args:
|
|
总排号_list: List of 总排号 values to query
|
|
|
|
Returns:
|
|
List of unique 生产订单号 values (SourceNumber)
|
|
"""
|
|
results = self.query_by_总排号(总排号_list)
|
|
# Extract unique 生产订单号 values, excluding None/null values
|
|
source_numbers = list(set(
|
|
[r['生产订单号'] for r in results if r.get('生产订单号')]
|
|
))
|
|
return source_numbers
|
|
|
|
def get_生产订单号_map(self, 总排号_list: List[str]) -> Dict[str, str]:
|
|
"""
|
|
Get mapping between 总排号 and 生产订单号.
|
|
|
|
Args:
|
|
总排号_list: List of 总排号 values to query
|
|
|
|
Returns:
|
|
Dictionary mapping 总排号 -> 生产订单号
|
|
"""
|
|
results = self.query_by_总排号(总排号_list)
|
|
return {
|
|
r['总排号']: r['生产订单号']
|
|
for r in results
|
|
if r.get('总排号') and r.get('生产订单号')
|
|
}
|