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>
This commit is contained in:
@@ -34,17 +34,25 @@ def query_production_order_numbers(production_ids):
|
||||
if not production_ids:
|
||||
return []
|
||||
|
||||
# 构建 IN 子句的占位符
|
||||
placeholders = ','.join(['?' for _ in production_ids])
|
||||
# SQL Server 限制每个查询最多 2100 个参数
|
||||
BATCH_SIZE = 2000
|
||||
all_results = []
|
||||
|
||||
query = f"""
|
||||
SELECT [生产订单号]
|
||||
FROM [productionContractData].[26年压力表合同数据]
|
||||
WHERE [总排号] IN ({placeholders})
|
||||
"""
|
||||
# 分批查询
|
||||
for i in range(0, len(production_ids), BATCH_SIZE):
|
||||
batch = production_ids[i:i + BATCH_SIZE]
|
||||
placeholders = ','.join(['?' for _ in batch])
|
||||
|
||||
with get_connection() as conn:
|
||||
results = conn.execute_query(query, tuple(production_ids))
|
||||
# 提取生产订单号并去除空值
|
||||
production_order_numbers = [row['生产订单号'] for row in results if row['生产订单号']]
|
||||
return production_order_numbers
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user