|
@@ -1,14 +1,18 @@
|
|
|
#!/usr/bin/env python3
|
|
|
# -*- coding: utf-8 -*-
|
|
|
from fastapi import APIRouter, Request, Depends,Query,HTTPException,status
|
|
|
+from fastapi.responses import StreamingResponse
|
|
|
from database import get_db
|
|
|
from sqlalchemy.orm import Session
|
|
|
from sqlalchemy import case,or_
|
|
|
+from sqlalchemy import inspect
|
|
|
from sqlalchemy import text
|
|
|
from utils import *
|
|
|
from utils.ry_system_util import *
|
|
|
from utils.video_util import *
|
|
|
from common.security import valid_access_token
|
|
|
+from common.db import db_czrz
|
|
|
+from common.auth_user import *
|
|
|
from fastapi.responses import JSONResponse
|
|
|
import traceback
|
|
|
from datetime import datetime
|
|
@@ -554,6 +558,13 @@ def parent_id_get_video_info(db, unitIndexCode,status):
|
|
|
if status:
|
|
|
query = query.filter(TPVideoInfo.status == status)
|
|
|
return query.all()
|
|
|
+def region_path_get_video_info(db, regionPath,status):
|
|
|
+ query = db.query(TPVideoInfo)
|
|
|
+ query = query.filter(TPVideoInfo.regionPath.like(f"%{regionPath}%"))
|
|
|
+ query = query.order_by(TPVideoInfo.gbIndexCode.asc())
|
|
|
+ if status:
|
|
|
+ query = query.filter(TPVideoInfo.status == status)
|
|
|
+ return query.all()
|
|
|
@router.get('/get_video_forest_fire_index_code')
|
|
|
async def get_dict_data_by_type(
|
|
|
db: Session = Depends(get_db)
|
|
@@ -585,6 +596,65 @@ async def get_dict_data_by_type(
|
|
|
traceback.print_exc()
|
|
|
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
|
|
|
|
|
+@router.get('/get_video_forest_fire_export')
|
|
|
+async def get_video_forest_fire_list(
|
|
|
+ request: Request,
|
|
|
+ indexCode:str = Query('4409000000216202502'),
|
|
|
+ status:str = Query(None),
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+ user_id: AuthUser = Depends(find_auth_user),
|
|
|
+ body=Depends(remove_xss_json)):
|
|
|
+
|
|
|
+ try:
|
|
|
+ data = region_path_get_video_info(db, indexCode, status)
|
|
|
+ data = [{
|
|
|
+ "摄像头索引码": info.cameraIndexCode,
|
|
|
+ "国标索引码": info.gbIndexCode,
|
|
|
+ "摄像头名称": info.name,
|
|
|
+ "经度": info.longitude,
|
|
|
+ "纬度": info.latitude,
|
|
|
+ "海拔": info.altitude,
|
|
|
+ "像素": info.pixel,
|
|
|
+ "摄像头类型代码": info.cameraType,
|
|
|
+ "摄像头类型名称": info.cameraTypeName,
|
|
|
+ "安装位置": info.installPlace,
|
|
|
+ "所属组织编号": info.unitIndexCode,
|
|
|
+ "机构路径": info.regionPath,
|
|
|
+ "更新时间": info.updateTime,
|
|
|
+ "创建时间": info.createTime,
|
|
|
+ "状态码": info.status,
|
|
|
+ "状态名称": info.statusName
|
|
|
+ } for info in data]
|
|
|
+ import pandas as pd
|
|
|
+ from io import BytesIO
|
|
|
+ # 将查询结果转换为 DataFrame
|
|
|
+ df = pd.DataFrame(data)
|
|
|
+
|
|
|
+ # 将 DataFrame 导出为 Excel 文件
|
|
|
+ output = BytesIO()
|
|
|
+ with pd.ExcelWriter(output, engine='openpyxl') as writer:
|
|
|
+ df.to_excel(writer, index=False, sheet_name='用户列表')
|
|
|
+
|
|
|
+ # 设置响应头
|
|
|
+ output.seek(0)
|
|
|
+ from urllib.parse import quote
|
|
|
+ encoded_filename = f'森防视频{datetime.now().strftime("%Y%m%d%H%mi%s")}.xlsx'
|
|
|
+ encoded_filename = quote(encoded_filename, encoding='utf-8')
|
|
|
+ headers = {
|
|
|
+ 'Content-Disposition': f'attachment; filename*=UTF-8\'\'{encoded_filename}',
|
|
|
+ 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
|
+ }
|
|
|
+
|
|
|
+ db_czrz.log(db, user_id, "全域地图", f"全域地图导出森防视频数据成功", request.client.host)
|
|
|
+
|
|
|
+ # 返回文件流
|
|
|
+ return StreamingResponse(output, headers=headers)
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ return JSONResponse(status_code=500, content={"code": 500, "msg": f"Internal server error: {str(e)}"})
|
|
|
+
|
|
|
+
|
|
|
@router.get('/get_video_forest_fire_list')
|
|
|
async def get_video_forest_fire_list(
|
|
|
indexCode:str = Query('4409000000216202502'),
|