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:
|
if not production_ids:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
# 构建 IN 子句的占位符
|
# SQL Server 限制每个查询最多 2100 个参数
|
||||||
placeholders = ','.join(['?' for _ in production_ids])
|
BATCH_SIZE = 2000
|
||||||
|
all_results = []
|
||||||
|
|
||||||
query = f"""
|
# 分批查询
|
||||||
SELECT [生产订单号]
|
for i in range(0, len(production_ids), BATCH_SIZE):
|
||||||
FROM [productionContractData].[26年压力表合同数据]
|
batch = production_ids[i:i + BATCH_SIZE]
|
||||||
WHERE [总排号] IN ({placeholders})
|
placeholders = ','.join(['?' for _ in batch])
|
||||||
"""
|
|
||||||
|
|
||||||
with get_connection() as conn:
|
query = f"""
|
||||||
results = conn.execute_query(query, tuple(production_ids))
|
SELECT [生产订单号]
|
||||||
# 提取生产订单号并去除空值
|
FROM [productionContractData].[26年压力表合同数据]
|
||||||
production_order_numbers = [row['生产订单号'] for row in results if row['生产订单号']]
|
WHERE [总排号] IN ({placeholders})
|
||||||
return production_order_numbers
|
"""
|
||||||
|
|
||||||
|
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
|
||||||
|
|||||||
@@ -43,8 +43,10 @@ class MaterialStatusValidator:
|
|||||||
List[str]: 去重后的材料名称列表
|
List[str]: 去重后的材料名称列表
|
||||||
"""
|
"""
|
||||||
df = pd.read_excel(excel_file)
|
df = pd.read_excel(excel_file)
|
||||||
# Q列索引为16(Python从0开始)
|
# R列索引为17(Python从0开始)
|
||||||
material_names = df.iloc[:, 16].dropna().unique().tolist()
|
material_names = df.iloc[:, 17].dropna().unique().tolist()
|
||||||
|
# 确保所有元素都是字符串类型
|
||||||
|
material_names = [str(name) for name in material_names]
|
||||||
return material_names
|
return material_names
|
||||||
|
|
||||||
def match_materials(self, material_names: List[str],
|
def match_materials(self, material_names: List[str],
|
||||||
|
|||||||
Reference in New Issue
Block a user