#!/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 models import * from utils import * from utils.spatial import * import json import traceback router = APIRouter() class location_c(BaseModel): x:float y:float class mine(BaseModel): location : List=[] @router.post('/get_info') async def mine(request: Request,body = Depends(remove_xss_json),db: Session = Depends(get_db)): try: # 验证必需的字段 # required_fields = ['location','location_c'] # missing_fields = [field for field in required_fields if field not in body] # if missing_fields: # raise HTTPException(status_code=401, detail=f"Missing required fields: {', '.join(missing_fields)}") # 行政镇、行政村数据 # town_village_data,town_count,village_count = count_town_village(from_data.location,db) # town_village_data,town_count = get_town_list(body) town_village_data,town_count,village_count = get_town_village_list(body,db) # emergency_expert_count = count_emergency_expert(from_data.location,db) # emergency_management_count = count_emergency_management(from_data.location,db) hospital_list = get_hospital_list(body,db) emergency_shelter_list = get_emergency_shelter_list(body,db) waterlogged_roads_list = get_waterlogged_roads_list(body,db) return { "code": 200, "msg": "成功", "data": { "townData":town_village_data, "townCount":town_count, "villageCount":village_count, # "villageCount":village_count, "populationSize":0, "areaSize":0, "GDP":0, "list":[{ "name":"应急避难场所","num":len(emergency_shelter_list),"list":[{"name":shelter.name,"longitude":shelter.longitude,"latitude":shelter.latitude} for shelter in emergency_shelter_list] },{ "name":"易涝点","num":len(waterlogged_roads_list),"list":[{"name":waterlogged.name,"longitude":waterlogged.longitude,"latitude":waterlogged.latitude} for waterlogged in waterlogged_roads_list] },{ "name":"医院","num":len(hospital_list),"list":[{"name":hospital.name,"longitude":hospital.longitude,"latitude":hospital.latitude} for hospital in hospital_list] } ] # "emergencyExpertCount":emergency_expert_count, # "emergencyManagementCount":emergency_management_count } } except Exception as e: db.rollback() traceback.print_exc() raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")