12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- from fastapi import APIRouter, Request, Depends, Query, HTTPException, status
- from common.security import valid_access_token
- from sqlalchemy.orm import Session
- from sqlalchemy.sql import func
- from common.auth_user import *
- from sqlalchemy import text
- from pydantic import BaseModel
- from common.BigDataCenterAPI import *
- from database import get_db
- from typing import List
- from utils import *
- from utils.risk import *
- import json
- import traceback
- router = APIRouter()
- @router.post('/get_max_hazardous')
- async def mine(request: Request,db: Session = Depends(get_db)):
- try:
- body = await request.json()
- result = get_max_forest_level(db)
- result = get_warning_description(result)
- #print(result)
- return {
- "code": 200,
- "msg": "成功",
- "data":
- {"max_level":result}
- }
- except Exception as e:
- db.rollback()
- traceback.print_exc()
- raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
- def get_warning_description(level):
- if level == 1:
- return "轻风险"
- elif level == 2:
- return "一般风险"
- elif level == 3:
- return "较大风险"
- elif level == 4:
- return "重大风险"
- else:
- return "未知等级"
- @router.post('/hazardous_warrning')
- async def mine(request: Request,db: Session = Depends(get_db)):
- try:
- result = "电白区、信宜市"
- #print(result)
- return {
- "code": 200,
- "msg": "成功",
- "data":
- {"result":result}
- }
- except Exception as e:
- db.rollback()
- traceback.print_exc()
- raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
- @router.post('/hazardous_warrning_count')
- async def mine(request: Request,db: Session = Depends(get_db)):
- try:
- result = get_hazardous_warring_count(db)
- #print(result)
- return {
- "code": 200,
- "msg": "成功",
- "data":
- {"result":result}
- }
- except Exception as e:
- db.rollback()
- traceback.print_exc()
- raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|