|
@@ -248,6 +248,8 @@ END """
|
|
|
@router.get('/get_waterlogged_all_video_info')
|
|
|
async def get_waterlogged_all_video_info(
|
|
|
radius:int = Query(None),
|
|
|
+ longitude:str = Query(None),
|
|
|
+ latitude:str = Query(None),
|
|
|
db: Session = Depends(get_db),
|
|
|
body=Depends(remove_xss_json),
|
|
|
page: int = Query(1, gt=0, description='页码'),
|
|
@@ -257,31 +259,36 @@ async def get_waterlogged_all_video_info(
|
|
|
try:
|
|
|
if radius is None:
|
|
|
radius=500
|
|
|
- print(1,datetime.now)
|
|
|
- sql = f"""SELECT * from mid_waterlogged_roads """
|
|
|
- waterlogged_data = db.execute(sql).all()
|
|
|
- resutl = []
|
|
|
- print(2,datetime.now)
|
|
|
- tj = []
|
|
|
- for location_1 in waterlogged_data:
|
|
|
- location = f"POINT({location_1.lng} {location_1.lat})"
|
|
|
- tj.append(f"ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', longitude, ' ', latitude, ')')),ST_GeomFromText(CONCAT('{location}'))) <= '{radius}'")
|
|
|
- tj = ' or '.join(tj)
|
|
|
- sql = text(f"""SELECT indexcode,`name`,longitude,latitude FROM (
|
|
|
- SELECT indexcode,`name`,longitude,latitude
|
|
|
- FROM tp_video_base where longitude is not null and latitude is not null and ({tj}) and `status`='ON'
|
|
|
+ # print(1,datetime.now)
|
|
|
+ # sql = f"""SELECT * from mid_waterlogged_roads """
|
|
|
+ # waterlogged_data = db.execute(sql).all()
|
|
|
+ # resutl = []
|
|
|
+ # print(2,datetime.now)
|
|
|
+ # tj = []
|
|
|
+ # for location_1 in waterlogged_data:
|
|
|
+ if longitude is None or latitude is None:
|
|
|
+ tj ="1=1"
|
|
|
+ px = "1"
|
|
|
+ else:
|
|
|
+ location = f"POINT({longitude} {latitude})"
|
|
|
+ tj = f"ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', longitude, ' ', latitude, ')')),ST_GeomFromText(CONCAT('{location}'))) <= '{radius}'"
|
|
|
+ px = f"ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', longitude, ' ', latitude, ')')),ST_GeomFromText(CONCAT('{location}'))) "
|
|
|
+ # tj = ' or '.join(tj)
|
|
|
+ sql = text(f"""SELECT indexcode,`name`,longitude,latitude,status FROM (
|
|
|
+ SELECT gbIndexCode as indexcode,`name`,longitude,latitude ,status
|
|
|
+ FROM tp_video_info where longitude is not null and latitude is not null and ({tj}) and `unitIndexCode`='eab0ed85ff9e4369a0e52680301c3160'
|
|
|
+ order by {px}
|
|
|
) T limit {pageSize*(page-1)}, {pageSize}""")
|
|
|
resutl=db.execute(sql).all()
|
|
|
|
|
|
- print(3, datetime.now)
|
|
|
total_items = len(resutl)
|
|
|
- print(4,datetime.now)
|
|
|
return {
|
|
|
"code": 200,
|
|
|
"msg": "成功",
|
|
|
- "data": {"list":[{"indexcode":info.indexcode,"name":info.name,"longitude":info.longitude,"latitude":info.latitude} for info in resutl[(page - 1) * pageSize:(page - 1) * pageSize+pageSize]]},
|
|
|
+ "data": {"list":[{"indexcode":info.indexcode,"name":info.name,"longitude":info.longitude,"latitude":info.latitude,"status":info.status} for info in resutl[(page - 1) * pageSize:(page - 1) * pageSize+pageSize]]},
|
|
|
"page": page,
|
|
|
"pageSize": pageSize,
|
|
|
+ "total":total_items,
|
|
|
"totalPages": (total_items + pageSize - 1) // pageSize
|
|
|
}
|
|
|
|