原始数据分表处理
This commit is contained in:
@@ -168,13 +168,24 @@ class ComprehensiveDataService:
|
||||
}
|
||||
|
||||
def get_level_and_original_data(self, db: Session,
|
||||
account_id: int,
|
||||
id: Optional[int] = None,
|
||||
bfpcode: Optional[str] = None,
|
||||
bffb: Optional[str] = None,
|
||||
nyid: Optional[str] = None,
|
||||
linecode: Optional[str] = None,
|
||||
bfpl: Optional[str] = None) -> Dict[str, Any]:
|
||||
"""根据条件获取水准数据+原始数据的组合查询"""
|
||||
"""
|
||||
根据条件获取水准数据+原始数据的组合查询
|
||||
|
||||
Args:
|
||||
db: 数据库会话
|
||||
account_id: 账号ID,必填
|
||||
其他查询条件...
|
||||
|
||||
Returns:
|
||||
查询结果字典
|
||||
"""
|
||||
# 查询水准数据
|
||||
level_data = self.level_service.search_level_data(
|
||||
db,
|
||||
@@ -182,17 +193,40 @@ class ComprehensiveDataService:
|
||||
linecode=linecode
|
||||
)
|
||||
|
||||
# 查询原始数据
|
||||
# 查询原始数据 - 传递account_id
|
||||
original_data = self.original_service.search_original_data(
|
||||
db,
|
||||
account_id=account_id,
|
||||
bfpcode=bfpcode,
|
||||
bffb=bffb,
|
||||
nyid=nyid,
|
||||
bfpl=bfpl
|
||||
)
|
||||
|
||||
result = []
|
||||
original_count = 0
|
||||
for level in level_data:
|
||||
# 将原始数据转换为字典格式
|
||||
original_datas_for_level = []
|
||||
for orig in original_data:
|
||||
# 处理SQL查询结果(可能是Row对象或字典)
|
||||
try:
|
||||
# 尝试访问属性
|
||||
orig_nyid = orig.NYID if hasattr(orig, 'NYID') else orig.get('NYID') if isinstance(orig, dict) else None
|
||||
if orig_nyid == level.NYID:
|
||||
original_datas_for_level.append({
|
||||
"id": orig.id if hasattr(orig, 'id') else orig.get('id'),
|
||||
"bfpcode": orig.bfpcode if hasattr(orig, 'bfpcode') else orig.get('bfpcode'),
|
||||
"mtime": str(orig.mtime) if hasattr(orig, 'mtime') else str(orig.get('mtime')) if orig.get('mtime') else None,
|
||||
"bffb": orig.bffb if hasattr(orig, 'bffb') else orig.get('bffb'),
|
||||
"bfpl": orig.bfpl if hasattr(orig, 'bfpl') else orig.get('bfpl'),
|
||||
"bfpvalue": orig.bfpvalue if hasattr(orig, 'bfpvalue') else orig.get('bfpvalue'),
|
||||
"NYID": orig.NYID if hasattr(orig, 'NYID') else orig.get('NYID'),
|
||||
"sort": orig.sort if hasattr(orig, 'sort') else orig.get('sort')
|
||||
})
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
data = {
|
||||
"id": level.id,
|
||||
"linecode": level.linecode,
|
||||
@@ -201,20 +235,9 @@ class ComprehensiveDataService:
|
||||
"mtype": level.mtype,
|
||||
"NYID": level.NYID,
|
||||
"createDate": level.createDate,
|
||||
"originalDatas": [
|
||||
{
|
||||
"id": orig.id,
|
||||
"bfpcode": orig.bfpcode,
|
||||
"mtime": orig.mtime,
|
||||
"bffb": orig.bffb,
|
||||
"bfpl": orig.bfpl,
|
||||
"bfpvalue": orig.bfpvalue,
|
||||
"NYID": orig.NYID,
|
||||
"sort": orig.sort
|
||||
} for orig in original_data if orig.NYID == level.NYID
|
||||
]
|
||||
"originalDatas": original_datas_for_level
|
||||
}
|
||||
original_count += len(data["originalDatas"])
|
||||
original_count += len(original_datas_for_level)
|
||||
result.append(data)
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user