- 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>
59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
"""
|
|
生产订单号查询组件
|
|
从 ProductionID.txt 读取总排号,查询数据库获取生产订单号
|
|
"""
|
|
from db.connection import get_connection
|
|
|
|
|
|
def read_production_ids(file_path):
|
|
"""
|
|
读取 ProductionID.txt 文件,获取总排号列表
|
|
|
|
Args:
|
|
file_path: ProductionID.txt 文件路径
|
|
|
|
Returns:
|
|
总排号列表
|
|
"""
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|
# 去除空白行和空格
|
|
production_ids = [line.strip() for line in f if line.strip()]
|
|
return production_ids
|
|
|
|
|
|
def query_production_order_numbers(production_ids):
|
|
"""
|
|
根据总排号列表,从数据库查询生产订单号
|
|
|
|
Args:
|
|
production_ids: 总排号列表
|
|
|
|
Returns:
|
|
生产订单号列表
|
|
"""
|
|
if not production_ids:
|
|
return []
|
|
|
|
# SQL Server 限制每个查询最多 2100 个参数
|
|
BATCH_SIZE = 2000
|
|
all_results = []
|
|
|
|
# 分批查询
|
|
for i in range(0, len(production_ids), BATCH_SIZE):
|
|
batch = production_ids[i:i + BATCH_SIZE]
|
|
placeholders = ','.join(['?' for _ in batch])
|
|
|
|
query = f"""
|
|
SELECT [生产订单号]
|
|
FROM [productionContractData].[26年压力表合同数据]
|
|
WHERE [总排号] IN ({placeholders})
|
|
"""
|
|
|
|
with get_connection() as conn:
|
|
results = conn.execute_query(query, tuple(batch))
|
|
# 提取生产订单号并去除空值
|
|
batch_numbers = [row['生产订单号'] for row in results if row['生产订单号']]
|
|
all_results.extend(batch_numbers)
|
|
|
|
return all_results
|