1.新增通过point_id获取测点信息接口
This commit is contained in:
@@ -18,7 +18,8 @@ from ..schemas.comprehensive_data import (
|
||||
LevelDataQueryRequest,
|
||||
LinecodeRequest,
|
||||
NYIDRequest,
|
||||
SectionByAccountRequest
|
||||
SectionByAccountRequest,
|
||||
PointByAccountRequest
|
||||
)
|
||||
from ..services.daily import DailyDataService
|
||||
from ..services.section_data import SectionDataService
|
||||
@@ -436,6 +437,37 @@ def get_all_checkpoint_by_section(request: SectionByAccountRequest, db: Session
|
||||
checkpoint_service = CheckpointService()
|
||||
result_data = checkpoint_service.get_by_section_id(db, section_id=section_id)
|
||||
data_list = [item.to_dict() for item in result_data] if result_data else []
|
||||
return DataResponse(
|
||||
code=ResponseCode.SUCCESS,
|
||||
message="查询成功",
|
||||
total=len(data_list),
|
||||
data=data_list
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Query section data failed: {str(e)}")
|
||||
return DataResponse(
|
||||
code=ResponseCode.QUERY_FAILED,
|
||||
message=f"{ResponseMessage.QUERY_FAILED}: {str(e)}",
|
||||
total=0,
|
||||
data=[]
|
||||
)
|
||||
@router.post("/get_checkpoint_by_point", response_model=DataResponse)
|
||||
def get_checkpoint_by_point(request: PointByAccountRequest, db: Session = Depends(get_db)):
|
||||
"""根据观测点ID获取观测点"""
|
||||
try:
|
||||
point_id = request.point_id
|
||||
checkpoint_service = CheckpointService()
|
||||
result_data = checkpoint_service.get_by_point_id(db, point_id=point_id)
|
||||
|
||||
# 使用 __dict__ 转换(过滤内部属性)
|
||||
if result_data:
|
||||
# 复制字典并排除 SQLAlchemy 内部属性
|
||||
data_dict = result_data.__dict__.copy()
|
||||
data_dict.pop('_sa_instance_state', None) # 移除ORM内部状态属性
|
||||
data_list = [data_dict]
|
||||
else:
|
||||
data_list = []
|
||||
|
||||
return DataResponse(
|
||||
code=ResponseCode.SUCCESS,
|
||||
message="查询成功",
|
||||
|
||||
Reference in New Issue
Block a user