增加account_id条件获取沉降数据
This commit is contained in:
@@ -124,3 +124,9 @@ class CheckpointService(BaseService[Checkpoint]):
|
||||
def get_by_section_id(self, db: Session, section_id: str) -> List[Checkpoint]:
|
||||
"""根据section_id获取所有相关的测点信息"""
|
||||
return self.get_by_field(db, "section_id", section_id)
|
||||
|
||||
def get_by_section_ids_batch(self, db: Session, section_ids: List[str]) -> List[Checkpoint]:
|
||||
"""批量根据section_id列表获取所有观测点数据(使用IN查询优化性能)"""
|
||||
if not section_ids:
|
||||
return []
|
||||
return db.query(Checkpoint).filter(Checkpoint.section_id.in_(section_ids)).all()
|
||||
|
||||
@@ -20,10 +20,16 @@ class SectionDataService(BaseService[SectionData]):
|
||||
"""根据断面ID获取断面数据"""
|
||||
sections = self.get_by_field(db, "section_id", section_id)
|
||||
return sections[0] if sections else None
|
||||
def get_by_account_id(self, db: Session, account_id: str) -> Optional[SectionData]:
|
||||
def get_by_account_id(self, db: Session, account_id: str) -> List[SectionData]:
|
||||
"""根据账号ID获取断面数据"""
|
||||
accounts = self.get_by_field(db, "account_id", account_id)
|
||||
return accounts if accounts else None
|
||||
return accounts if accounts else []
|
||||
|
||||
def get_by_account_id_batch(self, db: Session, account_ids: List[str]) -> List[SectionData]:
|
||||
"""批量根据账号ID列表获取断面数据(使用IN查询优化性能)"""
|
||||
if not account_ids:
|
||||
return []
|
||||
return db.query(SectionData).filter(SectionData.account_id.in_(account_ids)).all()
|
||||
def get_by_number(self, db: Session, number: str) -> List[SectionData]:
|
||||
"""根据桥梁墩(台)编号获取断面数据"""
|
||||
return self.get_by_field(db, "number", number)
|
||||
|
||||
@@ -70,6 +70,100 @@ class SettlementDataService(BaseService[SettlementData]):
|
||||
|
||||
return query.all()
|
||||
|
||||
def search_settlement_data_by_point_ids_formatted(self, db: Session,
|
||||
point_ids: List[str],
|
||||
id: Optional[int] = None,
|
||||
nyid: Optional[str] = None,
|
||||
sjName: Optional[str] = None,
|
||||
workinfoname: Optional[str] = None,
|
||||
skip: int = 0,
|
||||
limit: Optional[int] = None) -> Dict[str, Any]:
|
||||
"""
|
||||
支持多个point_id的沉降数据批量查询(优化版本)
|
||||
一次性查询,避免多次数据库访问
|
||||
"""
|
||||
if not point_ids:
|
||||
return {
|
||||
"data": [],
|
||||
"total": 0,
|
||||
"skip": skip,
|
||||
"limit": limit
|
||||
}
|
||||
|
||||
# 先获取总数(不计分页)
|
||||
count_query = db.query(SettlementData)
|
||||
if id is not None:
|
||||
count_query = count_query.filter(SettlementData.id == id)
|
||||
if nyid is not None:
|
||||
count_query = count_query.filter(SettlementData.NYID == nyid)
|
||||
if sjName is not None:
|
||||
count_query = count_query.filter(SettlementData.sjName == sjName)
|
||||
if workinfoname is not None:
|
||||
count_query = count_query.filter(SettlementData.workinfoname == workinfoname)
|
||||
|
||||
# 支持多个point_id(使用IN查询)
|
||||
count_query = count_query.filter(SettlementData.point_id.in_(point_ids))
|
||||
total_count = count_query.count()
|
||||
|
||||
# 获取分页数据(使用相同的过滤条件)
|
||||
query = db.query(SettlementData)
|
||||
if id is not None:
|
||||
query = query.filter(SettlementData.id == id)
|
||||
if nyid is not None:
|
||||
query = query.filter(SettlementData.NYID == nyid)
|
||||
if sjName is not None:
|
||||
query = query.filter(SettlementData.sjName == sjName)
|
||||
if workinfoname is not None:
|
||||
query = query.filter(SettlementData.workinfoname == workinfoname)
|
||||
|
||||
# 支持多个point_id
|
||||
query = query.filter(SettlementData.point_id.in_(point_ids))
|
||||
|
||||
# 按上传时间倒序排序
|
||||
query = query.order_by(SettlementData.createdate.desc())
|
||||
|
||||
# 添加分页支持
|
||||
if skip > 0:
|
||||
query = query.offset(skip)
|
||||
if limit is not None and limit > 0:
|
||||
query = query.limit(limit)
|
||||
|
||||
settlement_data = query.all()
|
||||
|
||||
# 格式化结果
|
||||
result = []
|
||||
for settlement in settlement_data:
|
||||
settlement_dict = {
|
||||
"id": settlement.id,
|
||||
"point_id": settlement.point_id,
|
||||
"CVALUE": settlement.CVALUE,
|
||||
"MAVALUE": settlement.MAVALUE,
|
||||
"MTIME_W": settlement.MTIME_W,
|
||||
"NYID": settlement.NYID,
|
||||
"PRELOADH": settlement.PRELOADH,
|
||||
"PSTATE": settlement.PSTATE,
|
||||
"REMARK": settlement.REMARK,
|
||||
"WORKINFO": settlement.WORKINFO,
|
||||
"createdate": settlement.createdate,
|
||||
"day": settlement.day,
|
||||
"day_jg": settlement.day_jg,
|
||||
"isgzjdxz": settlement.isgzjdxz,
|
||||
"mavalue_bc": settlement.mavalue_bc,
|
||||
"mavalue_lj": settlement.mavalue_lj,
|
||||
"sjName": settlement.sjName,
|
||||
"useflag": settlement.useflag,
|
||||
"workinfoname": settlement.workinfoname,
|
||||
"upd_remark": settlement.upd_remark
|
||||
}
|
||||
result.append(settlement_dict)
|
||||
|
||||
return {
|
||||
"data": result,
|
||||
"total": total_count,
|
||||
"skip": skip,
|
||||
"limit": limit
|
||||
}
|
||||
|
||||
def search_settlement_data_formatted(self, db: Session,
|
||||
id: Optional[int] = None,
|
||||
point_id: Optional[str] = None,
|
||||
|
||||
Reference in New Issue
Block a user