|
@@ -3,7 +3,7 @@
|
|
|
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 case,or_
|
|
|
from sqlalchemy import text
|
|
|
from utils import *
|
|
|
from utils.ry_system_util import *
|
|
@@ -11,6 +11,7 @@ from utils.video_util import *
|
|
|
from common.security import valid_access_token
|
|
|
from fastapi.responses import JSONResponse
|
|
|
import traceback
|
|
|
+from datetime import datetime
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
@@ -106,27 +107,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'
|
|
|
+ ) T limit {pageSize*(page-1)}, {pageSize}""")
|
|
|
+ # ,
|
|
|
+ # ST_Distance_Sphere(
|
|
|
+ # ST_GeomFromText(CONCAT('POINT(', longitude, ' ', latitude, ')')),
|
|
|
+ # ST_PointFromText('{location}')
|
|
|
+ # )
|
|
|
+ # AS
|
|
|
+ # distance ,"distance":info.distance ORDER BY distance ASC
|
|
|
+ resutl=db.execute(sql).all()
|
|
|
|
|
|
- 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()
|
|
|
+ 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,"distance":info.distance} 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} for info in resutl[(page - 1) * pageSize:(page - 1) * pageSize+pageSize]]},
|
|
|
"page": page,
|
|
|
"pageSize": pageSize,
|
|
|
"totalPages": (total_items + pageSize - 1) // pageSize
|
|
@@ -291,6 +301,7 @@ async def get_video_tag_info(
|
|
|
@router.get('/get_lx_hy_video_tag_info')
|
|
|
async def get_lx_hy_video_tag_info(
|
|
|
dict_value:str = Query(None),
|
|
|
+ type:str= Query(None),
|
|
|
db: Session = Depends(get_db),
|
|
|
body=Depends(remove_xss_json),
|
|
|
page: int = Query(1, gt=0, description='页码'),
|
|
@@ -298,11 +309,51 @@ async def get_lx_hy_video_tag_info(
|
|
|
user_id=Depends(valid_access_token)
|
|
|
):
|
|
|
try:
|
|
|
- if dict_value is None:
|
|
|
+
|
|
|
+ if dict_value is None or dict_value =='':
|
|
|
+ query = db.query(SysDictData)
|
|
|
+ query = query.filter(SysDictData.del_flag != '2')
|
|
|
+ query = query.filter(SysDictData.dict_type == 'video_type')
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if type=='lx':
|
|
|
+ query_1 = db.query(SysDictData)
|
|
|
+ query_1 = query_1.filter(SysDictData.del_flag != '2')
|
|
|
+ query_1 = query_1.filter(SysDictData.dict_type == 'video_tag_type')
|
|
|
+ elif type == 'hy':
|
|
|
+ query_1 = db.query(SysDictData)
|
|
|
+ query_1 = query_1.filter(SysDictData.del_flag != '2')
|
|
|
+ query_1 = query_1.filter(SysDictData.dict_type == 'video_tag_industry')
|
|
|
+ else:
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "成功",
|
|
|
+ "data": []
|
|
|
+ }
|
|
|
+ # for i in query_1.all():
|
|
|
+ query = query.filter(or_(SysDictData.remark.like(f'%{i.dict_value};%') for i in query_1.all()))
|
|
|
+ total_items = query.count()
|
|
|
+ # 排序
|
|
|
+ query = query.order_by(SysDictData.create_time.desc())
|
|
|
+ # 执行分页查询
|
|
|
+ dicts = query.offset((page - 1) * pageSize).limit(pageSize).all()
|
|
|
+ tag = []
|
|
|
+
|
|
|
+ for info in dicts:
|
|
|
+ tag.append({
|
|
|
+ "dict_type": info.dict_type,
|
|
|
+ "dict_value": info.dict_value,
|
|
|
+ "dict_label": info.dict_label,
|
|
|
+ "dict_code": info.dict_code})
|
|
|
return {
|
|
|
"code": 200,
|
|
|
"msg": "成功",
|
|
|
- "data": []
|
|
|
+ "data": tag,
|
|
|
+ "total": total_items,
|
|
|
+ "page": page,
|
|
|
+ "pageSize": pageSize,
|
|
|
+ "totalPages": (total_items + pageSize - 1) // pageSize
|
|
|
}
|
|
|
query = db.query(SysDictData)
|
|
|
query = query.filter(SysDictData.del_flag != '2')
|