Apply Black formatter to the entire codebase for consistent code style. Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
99 lines
3.4 KiB
Python
99 lines
3.4 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.base_dao import BaseDAO
|
|
from db.connection import get_connection
|
|
from config.schema import DatabaseType
|
|
|
|
|
|
class ProductionContractDataDAO(BaseDAO):
|
|
"""Data Access Object for production contract data queries"""
|
|
|
|
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]
|
|
placeholder = self._get_placeholder()
|
|
placeholders = ",".join([placeholder for _ in batch])
|
|
|
|
# 根据数据库类型选择表名
|
|
table_name = self._convert_sql(
|
|
"[productionContractData].[26年压力表合同数据]"
|
|
)
|
|
|
|
# 根据数据库类型选择列名格式
|
|
if self._db_type == DatabaseType.MYSQL:
|
|
sql = f"""
|
|
SELECT 总排号, 生产订单号, 序号, 订单号, 客户名称, 产品型号
|
|
FROM {table_name}
|
|
WHERE 总排号 IN ({placeholders})
|
|
ORDER BY 序号
|
|
"""
|
|
else:
|
|
sql = f"""
|
|
SELECT [总排号], [生产订单号], [序号], [订单号], [客户名称], [产品型号]
|
|
FROM {table_name}
|
|
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("生产订单号")
|
|
}
|