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>
This commit is contained in:
50
db/production_order_query.py
Normal file
50
db/production_order_query.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""
|
||||
生产订单号查询组件
|
||||
从 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 []
|
||||
|
||||
# 构建 IN 子句的占位符
|
||||
placeholders = ','.join(['?' for _ in production_ids])
|
||||
|
||||
query = f"""
|
||||
SELECT [生产订单号]
|
||||
FROM [productionContractData].[26年压力表合同数据]
|
||||
WHERE [总排号] IN ({placeholders})
|
||||
"""
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user