|
@@ -1,12 +1,14 @@
|
|
|
#!/usr/bin/env python3
|
|
|
# -*- coding: utf-8 -*-
|
|
|
-from fastapi import APIRouter, Request, Depends,Query
|
|
|
+from fastapi import APIRouter, Request, Depends,Query,HTTPException
|
|
|
from database import get_db
|
|
|
from sqlalchemy.orm import Session
|
|
|
from sqlalchemy import case
|
|
|
+from sqlalchemy import text
|
|
|
from utils import *
|
|
|
from utils.ry_system_util import *
|
|
|
from common.security import valid_access_token
|
|
|
+import traceback
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
@@ -54,4 +56,45 @@ async def get_video_url_by_id(
|
|
|
"page": page,
|
|
|
"pageSize": pageSize,
|
|
|
"totalPages": (total_items + pageSize - 1) // pageSize
|
|
|
- }
|
|
|
+ }
|
|
|
+@router.get('/get_waterlogged_all_video_info')
|
|
|
+async def get_waterlogged_all_video_info(
|
|
|
+ radius:int = Query(None),
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+ body=Depends(remove_xss_json),
|
|
|
+ page: int = Query(1, gt=0, description='页码'),
|
|
|
+ pageSize: int = Query(10, gt=0, description='每页条目数量'),
|
|
|
+ user_id=Depends(valid_access_token)):
|
|
|
+
|
|
|
+ try:
|
|
|
+ if radius is None:
|
|
|
+ radius=500
|
|
|
+ sql = f"""SELECT * from mid_waterlogged_roads """
|
|
|
+ waterlogged_data = db.execute(sql).all()
|
|
|
+ resutl = []
|
|
|
+ for location_1 in waterlogged_data:
|
|
|
+ location = f"POINT({location_1.lng} {location_1.lat})"
|
|
|
+
|
|
|
+ sql = text(f"""SELECT indexcode,`name`,longitude,latitude,distance FROM (
|
|
|
+ SELECT indexcode,`name`,longitude,latitude,
|
|
|
+ ST_Distance_Sphere(
|
|
|
+ ST_GeomFromText(CONCAT('POINT(', longitude, ' ', latitude, ')')),
|
|
|
+ ST_PointFromText('{location}')
|
|
|
+ ) AS distance
|
|
|
+ FROM tp_video_base where longitude is not null and latitude is not null and ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', longitude, ' ', latitude, ')')),ST_GeomFromText(CONCAT('{location}'))) <= '{radius}' and `status`='ON'
|
|
|
+ ORDER BY distance ASC ) T""")
|
|
|
+
|
|
|
+ resutl+=db.execute(sql).all()
|
|
|
+ total_items = len(resutl)
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "成功",
|
|
|
+ "data": {"list":[{"indexcode":info.indexcode,"name":info.name,"longitude":info.longitude,"latitude":info.latitude,"distance":info.distance} for info in resutl[(page - 1) * pageSize:(page - 1) * pageSize+pageSize]]},
|
|
|
+ "page": page,
|
|
|
+ "pageSize": pageSize,
|
|
|
+ "totalPages": (total_items + pageSize - 1) // pageSize
|
|
|
+ }
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|