原查询数据条件分页优化
This commit is contained in:
@@ -22,7 +22,7 @@ class SectionDataService(BaseService[SectionData]):
|
||||
return sections[0] if sections else None
|
||||
def get_by_account_id(self, db: Session, account_id: str) -> Optional[SectionData]:
|
||||
"""根据账号ID获取断面数据"""
|
||||
accounts = self.get_by_field(db, "account_id", account_id)
|
||||
accounts = self.get_by_field(db, "account_id", account_id)
|
||||
return accounts if accounts else None
|
||||
def get_by_number(self, db: Session, number: str) -> List[SectionData]:
|
||||
"""根据桥梁墩(台)编号获取断面数据"""
|
||||
@@ -36,7 +36,9 @@ class SectionDataService(BaseService[SectionData]):
|
||||
number: Optional[str] = None,
|
||||
status: Optional[str] = None,
|
||||
basic_types: Optional[str] = None,
|
||||
account_id: Optional[str] = None) -> List[SectionData]:
|
||||
account_id: Optional[str] = None,
|
||||
skip: int = 0,
|
||||
limit: Optional[int] = None) -> List[SectionData]:
|
||||
"""根据多个条件搜索断面数据"""
|
||||
conditions = {}
|
||||
if section_id is not None:
|
||||
@@ -56,7 +58,7 @@ class SectionDataService(BaseService[SectionData]):
|
||||
if account_id is not None:
|
||||
conditions['account_id'] = account_id
|
||||
|
||||
return self.search_by_conditions(db, conditions)
|
||||
return self.search_by_conditions(db, conditions, skip, limit)
|
||||
|
||||
def search_sections_with_checkpoints(self, db: Session,
|
||||
id: Optional[int] = None,
|
||||
@@ -65,9 +67,32 @@ class SectionDataService(BaseService[SectionData]):
|
||||
work_site: Optional[str] = None,
|
||||
number: Optional[str] = None,
|
||||
status: Optional[str] = None,
|
||||
account_id: Optional[str] = None) -> List[Dict[str, Any]]:
|
||||
"""查询断面数据并返回带观测点的结果"""
|
||||
sections = self.search_section_data(db, id, section_id, mileage, work_site, number, status, account_id=account_id)
|
||||
account_id: Optional[str] = None,
|
||||
skip: int = 0,
|
||||
limit: Optional[int] = None) -> Dict[str, Any]:
|
||||
"""查询断面数据并返回带观测点的结果(支持分页)"""
|
||||
# 构建查询条件
|
||||
conditions = {}
|
||||
if section_id is not None:
|
||||
conditions["section_id"] = section_id
|
||||
if work_site is not None:
|
||||
conditions["work_site"] = work_site
|
||||
if number is not None:
|
||||
conditions["number"] = number
|
||||
if status is not None:
|
||||
conditions["status"] = status
|
||||
if id is not None:
|
||||
conditions['id'] = id
|
||||
if mileage is not None:
|
||||
conditions['mileage'] = mileage
|
||||
if account_id is not None:
|
||||
conditions['account_id'] = account_id
|
||||
|
||||
# 获取总数
|
||||
total_count = self.search_by_conditions_count(db, conditions)
|
||||
|
||||
# 获取分页数据
|
||||
sections = self.search_by_conditions(db, conditions, skip, limit)
|
||||
|
||||
result = []
|
||||
for section in sections:
|
||||
@@ -101,7 +126,12 @@ class SectionDataService(BaseService[SectionData]):
|
||||
}
|
||||
result.append(section_dict)
|
||||
|
||||
return result
|
||||
return {
|
||||
"data": result,
|
||||
"total": total_count,
|
||||
"skip": skip,
|
||||
"limit": limit
|
||||
}
|
||||
|
||||
def get_section_with_checkpoints(self, db: Session, section_id: str) -> Dict[str, Any]:
|
||||
"""获取断面数据及其关联的观测点"""
|
||||
|
||||
Reference in New Issue
Block a user