1.新增通过point_id获取沉降数据
This commit is contained in:
@@ -505,6 +505,40 @@ def get_settlement_by_nyid(
|
||||
total=0,
|
||||
data=[]
|
||||
)
|
||||
|
||||
@router.post("/get_settlement_by_point", response_model=DataResponse)
|
||||
def get_settlement_by_point(
|
||||
request: NYIDRequest, # 假设定义了接收nyid的请求模型
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
try:
|
||||
nyid = request.NYID # 从请求体中获取nyid
|
||||
point_id = request.point_id # 从请求体中获取point_id
|
||||
logger.info(f"接口请求:根据nyid={nyid}和point_id={point_id}查询沉降数据")
|
||||
|
||||
settlement = SettlementDataService()
|
||||
# 获取模型实例列表
|
||||
checkpoint_instances = settlement.get_by_point_id(db, point_id=point_id)
|
||||
# 转为字典列表(核心修正)
|
||||
checkpoint_data = [instance.__dict__ for instance in checkpoint_instances]
|
||||
# 清理 SQLAlchemy 内部属性(可选,避免多余字段)
|
||||
checkpoint_data = [{k: v for k, v in item.items() if not k.startswith('_sa_')} for item in checkpoint_data]
|
||||
|
||||
return DataResponse(
|
||||
code=ResponseCode.SUCCESS,
|
||||
message=f"查询成功,共获取{len(checkpoint_data)}条沉降数据,nyid={nyid}",
|
||||
total=len(checkpoint_data),
|
||||
data=checkpoint_data
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"查询沉降数据失败:{str(e)}", exc_info=True)
|
||||
return DataResponse(
|
||||
code=ResponseCode.QUERY_FAILED,
|
||||
message=f"查询失败:{str(e)}",
|
||||
total=0,
|
||||
data=[]
|
||||
)
|
||||
@router.post("/get_today_data", response_model=DataResponse)
|
||||
def get_today_data(request: TodayDataRequest, db: Session = Depends(get_db)):
|
||||
"""接口:通过POST请求触发调度器中的 scheduled_get_max_nyid_by_point_id 定时任务"""
|
||||
|
||||
Reference in New Issue
Block a user