1.修改每日数据的赛选条
This commit is contained in:
@@ -94,7 +94,7 @@ class DailyDataService(BaseService[DailyData]):
|
||||
max_num: int = 1
|
||||
) -> List[List[dict]]:
|
||||
"""
|
||||
获取指定point_id的记录,修复子查询中模型对象访问错误
|
||||
获取指定point_id的记录,修复子查询中模型对象访问错误,同时过滤useflag=0的数据
|
||||
"""
|
||||
# 处理参数默认值
|
||||
point_ids = point_ids or []
|
||||
@@ -110,11 +110,22 @@ class DailyDataService(BaseService[DailyData]):
|
||||
# 子查询:查询模型的所有字段 + 行号(不保留模型对象,只展平字段)
|
||||
# 先获取模型的所有字段列表
|
||||
model_columns = [getattr(SettlementData, col.name) for col in SettlementData.__table__.columns]
|
||||
# -------------------------- 新增过滤条件:useflag IS NOT NULL AND useflag != 0 --------------------------
|
||||
# 基础条件:过滤useflag为0或不存在的记录
|
||||
base_conditions = [
|
||||
SettlementData.useflag.isnot(None), # 确保useflag字段存在(非NULL)
|
||||
SettlementData.useflag != 0 # 确保useflag值不为0
|
||||
]
|
||||
# 若指定了point_ids,添加point_id过滤条件
|
||||
if point_ids:
|
||||
base_conditions.append(SettlementData.point_id.in_(point_ids))
|
||||
|
||||
subquery = (
|
||||
select(*model_columns, row_num) # 展开所有字段 + 行号
|
||||
.where(SettlementData.point_id.in_(point_ids) if point_ids else True)
|
||||
.where(*base_conditions) # 应用组合条件(包含useflag过滤)
|
||||
.subquery()
|
||||
)
|
||||
# ------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 主查询:筛选行号<=max_num的记录
|
||||
query = (
|
||||
|
||||
Reference in New Issue
Block a user