123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- #!/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) #[],0,0#
- # emergency_expert_count = count_emergency_expert(from_data.location,db)
- # emergency_management_count = count_emergency_management(from_data.location,db)
- point_type_to_list = {
- 1: "专家",
- 2: "救援物资仓库",
- 3: "应急避难场所",
- 4: "易涝点",
- 5: "学校",
- 6: "医院",
- 7: "加油站",
- 8: "非煤矿山企业",
- 9: "危化企业",
- 10: "船舶动态",
- 11: "危险化学品经营企业",
- 12: "危险化学品生产企业",
- 13: "危险化学品使用企业",
- 14: "化工企业",
- 15: "无人机",
- 16: "雨窝点",
- 17: "地质灾害隐患点",
- 18: "矿山施工",
- # 19: "工矿商贸",
- 20: "气象灾害防御重点单位",
- 21: "建筑工程",
- 22: "储罐",
- 23: "重大危险源",
- 24: "客运站",
- 25: "堆场",
- 26: "旅游景点",
- 27: "在建工地",
- 28: "运输资源",
- 29: "灾害信息员", #govdata_disaster_info_officer
- 30: "路网视频",
- 31: "江河湖库视频",
- 32: "防溺水视频",
- 33: "森林火灾视频",
- 34: "防灾救援视频",
- 35: "救援人员单位",
- # 36: "灾害信息员", #govdata_disaster_info_officer
- 37: "水利工程",
- 38: "人防工程",
- 39: "救助站"
- }
- # 初始化所有列表
- lists = {key: [] for key in point_type_to_list}
- # 填充列表
- for point in get_point_list(body, db):
- if point.dataType in lists:
- lists[point.dataType].append({
- "id": point.id,
- "dataType": point.dataType,
- "name": point.name,
- "longitude": point.longitude,
- "latitude": point.latitude,
- })
- # 构建最终的 list_1,仅包含非空列表
- list_1 = [{"name": point_type_to_list[dataType], "num": len(lst), "list": lst}
- for dataType, lst in lists.items() if lst]
- # list_1 = []
- # point_list = get_point_list(body,db)
- # emergency_expert_list = [] #专家 1
- # rescue_materia_warehouse_list = [] #救援物资-仓库 2
- # emergency_shelter_list = [] # 应急避难场所 3
- # waterlogged_roads_list = [] # 易涝点 4
- # school_list = [] # 学校 5
- # hospital_list = [] #医院 6
- # gasoline_station_list = [] #加油站 7
- # mining_company_list = []# 非煤矿山企业 8
- # chemical_company_list = [] #危化企业 9
- # ship_realtilme_positioninfo_list = []# 船舶动态 10
- # for point in point_list:
- # if point.dataType == 1:
- # emergency_expert_list.append({"id": point.id, "dataType": point.dataType, "name": point.name, "longitude": point.longitude, "latitude": point.latitude})
- # elif point.dataType == 2:
- # rescue_materia_warehouse_list.append({"id": point.id, "dataType": point.dataType, "name": point.name, "longitude": point.longitude,
- # "latitude": point.latitude})
- # elif point.dataType == 3:
- # emergency_shelter_list.append(
- # {"id": point.id, "dataType": point.dataType, "name": point.name, "longitude": point.longitude,
- # "latitude": point.latitude})
- # elif point.dataType == 4:
- # waterlogged_roads_list.append(
- # {"id": point.id, "dataType": point.dataType, "name": point.name, "longitude": point.longitude,
- # "latitude": point.latitude})
- # elif point.dataType == 5:
- # school_list.append(
- # {"id": point.id, "dataType": point.dataType, "name": point.name, "longitude": point.longitude,
- # "latitude": point.latitude})
- # elif point.dataType == 6:
- # hospital_list.append(
- # {"id": point.id, "dataType": point.dataType, "name": point.name, "longitude": point.longitude,
- # "latitude": point.latitude})
- # elif point.dataType == 7:
- # gasoline_station_list.append(
- # {"id": point.id, "dataType": point.dataType, "name": point.name, "longitude": point.longitude,
- # "latitude": point.latitude})
- # elif point.dataType == 8:
- # mining_company_list.append(
- # {"id": point.id, "dataType": point.dataType, "name": point.name, "longitude": point.longitude,
- # "latitude": point.latitude})
- # elif point.dataType == 9:
- # chemical_company_list.append(
- # {"id": point.id, "dataType": point.dataType, "name": point.name, "longitude": point.longitude,
- # "latitude": point.latitude})
- # elif point.dataType == 10:
- # ship_realtilme_positioninfo_list.append(
- # {"id": point.id, "dataType": point.dataType, "name": point.name, "longitude": point.longitude,
- # "latitude": point.latitude})
- # num = len(emergency_expert_list)
- # if num>0:
- # list_1.append({"name":"专家","num":num,"list":emergency_expert_list})
- # num = len(rescue_materia_warehouse_list)
- # if num>0:
- # list_1.append({"name":"救援物资仓库","num":num,"list":rescue_materia_warehouse_list})
- # num = len(emergency_shelter_list)
- # if num>0:
- # list_1.append({"name":"应急避难场所","num":num,"list":emergency_shelter_list})
- # num = len(waterlogged_roads_list)
- # if num>0:
- # list_1.append({"name":"易涝点","num":num,"list":waterlogged_roads_list})
- # num = len(school_list)
- # if num>0:
- # list_1.append({"name":"学校","num":num,"list":school_list})
- # num = len(hospital_list)
- # if num>0:
- # list_1.append({"name":"医院","num":num,"list":hospital_list})
- # num = len(gasoline_station_list)
- # if num>0:
- # list_1.append({"name":"加油站","num":num,"list":gasoline_station_list})
- # num = len(mining_company_list)
- # if num>0:
- # list_1.append({"name":"非煤矿山企业","num":num,"list":mining_company_list})
- # num = len(chemical_company_list)
- # if num>0:
- # list_1.append({"name":"危化企业","num":num,"list":chemical_company_list})
- # num = len(ship_realtilme_positioninfo_list)
- # if num>0:
- # list_1.append({"name":"船舶动态","num":num,"list":ship_realtilme_positioninfo_list})
- # 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":list_1
- # [{
- # "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)}")
- @router.get('/get_mms_area_info')
- async def mine(request: Request,body = Depends(remove_xss_json),db: Session = Depends(get_db)):
- try:
- with open('/home/python3/xh_twapi01/routers/api/spatialAnalysis/茂名市.json','r', encoding='utf-8') as f:
- data = json.load(f)
- features = data['features']
- result = [{'name': '高','color': '#ff2f3c',"points":[]},
- {'name': '较高', 'color': '#ffaf00',"points":[]},
- {'name': '较低', 'color': '#ffd800',"points":[]},
- {'name': '低', 'color': '#40c75f',"points":[]},]
- adcode_dit = {'高':['440902','440983'],"较高":['440904'],"较低":['440981'],"低":['440982']}
- # "440902":{'name': '高','color': '#ff2f3c'},
- # "440904": {'name': '较高', 'color': '#ffaf00'},
- # "440981": {'name': '较低', 'color': '#ffd800'},
- # "440982": {'name': '低', 'color': '#40c75f'},
- # "440983": {'name': '高', 'color': '#ff2f3c'},
- # }
- area_data = {}
- for feature in features:
- properties = feature['properties']
- area_code = properties['adcode']
- geometry = feature['geometry']
- coordinates = geometry['coordinates']
- area_data[str(area_code)]=[]
- for i in coordinates:
- area_data[str(area_code)] += i
- # result.append({"name":adcode_dit[str(area_code)]['name'],
- # "color":adcode_dit[str(area_code)]['color'],
- # "area_name":area_name,
- # "area_code":area_code,
- # "points":i})
- for i in result:
- for x in adcode_dit[i['name']]:
- i['points']+=area_data[x]
- return {
- "code": 200,
- "msg": "成功",
- "data": result}
- except Exception as e:
- traceback.print_exc()
- raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|