定位刷新超时返回最近一次位置
This commit is contained in:
@@ -202,7 +202,12 @@ def _row_to_ai_conversation_item(row: Mapping) -> DeviceAiConversationItem:
|
||||
)
|
||||
|
||||
|
||||
def _row_to_current_location_response(row: Mapping) -> DeviceLocationCurrentResponse:
|
||||
def _row_to_current_location_response(
|
||||
row: Mapping,
|
||||
*,
|
||||
stale: bool = False,
|
||||
realtime: bool = True,
|
||||
) -> DeviceLocationCurrentResponse:
|
||||
return DeviceLocationCurrentResponse(
|
||||
child_id=int(row["child_id"]),
|
||||
child_name=row.get("child_name"),
|
||||
@@ -219,6 +224,8 @@ def _row_to_current_location_response(row: Mapping) -> DeviceLocationCurrentResp
|
||||
device_time=row["device_time"],
|
||||
server_time=row["server_time"],
|
||||
updated_at=row["updated_at"],
|
||||
stale=stale,
|
||||
realtime=realtime,
|
||||
)
|
||||
|
||||
|
||||
@@ -681,10 +688,21 @@ async def get_current_device_location(
|
||||
|
||||
await asyncio.sleep(1)
|
||||
|
||||
if row is None:
|
||||
raise HTTPException(status_code=408, detail="GPS数据上报超时")
|
||||
if row is not None:
|
||||
logger.info(
|
||||
"device stale location returned",
|
||||
extra={
|
||||
"event": "device_stale_location",
|
||||
"request_id": getattr(request.state, "request_id", None),
|
||||
"user_id": current_user_id,
|
||||
"device_id": device_id,
|
||||
"child_id": int(row["child_id"]),
|
||||
"location_updated_at": row.get("updated_at"),
|
||||
},
|
||||
)
|
||||
return _row_to_current_location_response(row, stale=True, realtime=False)
|
||||
|
||||
raise HTTPException(status_code=408, detail="GPS数据未刷新")
|
||||
raise HTTPException(status_code=408, detail="GPS数据上报超时")
|
||||
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=408, detail=f"GPS数据上报失败: {e}")
|
||||
|
||||
@@ -35,6 +35,8 @@ class DeviceLocationPoint(BaseModel):
|
||||
|
||||
class DeviceLocationCurrentResponse(DeviceLocationPoint):
|
||||
updated_at: datetime
|
||||
stale: bool = False
|
||||
realtime: bool = True
|
||||
|
||||
|
||||
class DeviceLocationReportResponse(DeviceLocationCurrentResponse):
|
||||
|
||||
Reference in New Issue
Block a user