diff --git a/app/api/chat/ai/chat_router.py b/app/api/chat/ai/chat_router.py index 849f9f0..48eb3ea 100644 --- a/app/api/chat/ai/chat_router.py +++ b/app/api/chat/ai/chat_router.py @@ -412,17 +412,17 @@ async def get_scenic_parking(request: Request, req: ScenicParkingRequest): # 构建验证数据 data = { - "scenic_name": req.scenic_name, + "id": req.id, "distance": req.distance, "timestamp": req.timestamp } if not verify_signature(data, req.sign): raise HTTPException(status_code=401, detail="无效的签名") - if not req.scenic_name: + if not req.id: return { "code": 400, - "message": "景区名称不能为空", + "message": "景区id不能为空", "data": [] } @@ -434,7 +434,7 @@ async def get_scenic_parking(request: Request, req: ScenicParkingRequest): } try: - data = await get_scenic_parking_data(request, req.scenic_name, req.distance) + data = await get_scenic_parking_data(request, req.id, req.distance) if not data: return { diff --git a/app/api/chat/ai/chat_service.py b/app/api/chat/ai/chat_service.py index 3b7944b..b83907e 100644 --- a/app/api/chat/ai/chat_service.py +++ b/app/api/chat/ai/chat_service.py @@ -625,13 +625,13 @@ async def get_scenic_detail_data(request: Request, id: int) -> dict: # 在chat_service.py末尾添加新的停车场查询函数 -async def get_scenic_parking_data(request: Request, scenic_name: str, distance: int) -> list: +async def get_scenic_parking_data(request: Request, scenic_id: int, distance: int) -> list: """ 查询景区附近的停车场信息 Args: request: FastAPI请求对象 - scenic_name: 景区名称 + scenic_id: 景区id distance: 查询距离(米),>=1000时查询全部 Returns: @@ -644,32 +644,30 @@ async def get_scenic_parking_data(request: Request, scenic_name: str, distance: # 构建基础查询 base_query = """ SELECT - t3.park_name AS park_name, - t3.total_count AS total_parking_spaces, - COALESCE(t4.space, 0) AS available_spaces, - t1.distance_value AS distance_meters + t3.park_name AS park_name, + t3.total_count AS total_parking_spaces, + COALESCE(t4.space, 0) AS available_spaces, + t1.distance_value AS distance_meters FROM - cyjcpt_bd.scenic_pack_distance t1 + cyjcpt_bd.scenic_pack_distance t1 LEFT JOIN - cyjcpt_bd.zhly_scenic_basic t2 ON t1.scenic_id = t2.id + cyjcpt_bd.park_info t3 ON t1.park_code = t3.park_code LEFT JOIN - cyjcpt_bd.park_info t3 ON t1.park_code = t3.park_code - LEFT JOIN - equipment_passenger_flow.park_current t4 ON t1.park_code = t4.park_code + equipment_passenger_flow.park_current t4 ON t1.park_code = t4.park_code WHERE - t2.`name` LIKE %s - AND t3.total_count > 0 + t1.scenic_id = %s + AND t3.total_count > 0 """ # 根据距离参数构建WHERE条件 if distance >= 1000: # 距离>=1000米,查询全部停车场 where_condition = "" - params = (f"%{scenic_name}%",) + params = (scenic_id,) else: # 距离<1000米,按指定距离查询 where_condition = " AND t1.distance_value <= %s" - params = (f"%{scenic_name}%", distance) + params = (scenic_id, distance) # 完整的查询语句 query = base_query + where_condition + " ORDER BY t1.distance_value ASC" diff --git a/app/models/ChatIn.py b/app/models/ChatIn.py index 6098256..98572c3 100644 --- a/app/models/ChatIn.py +++ b/app/models/ChatIn.py @@ -20,7 +20,7 @@ class ScenicDetailRequest(BaseModel): class ScenicParkingRequest(BaseModel): - scenic_name: str + id: int distance: int = 1000 timestamp: int sign: str \ No newline at end of file