|
@@ -6,6 +6,7 @@ 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
|
|
@@ -52,52 +53,57 @@ def count_town_village(location_list:list,db):
|
|
|
}
|
|
|
response = requests.post(url=url, headers=headers, json=location_list, verify=False)
|
|
|
if response.status_code==200:
|
|
|
- data_list = response.json('data')
|
|
|
+ data_list = response.json()['data']
|
|
|
+
|
|
|
for data in data_list:
|
|
|
township = data['townshipCode']
|
|
|
if township not in town_list:
|
|
|
town_count+=1
|
|
|
- result.append({'township':data['township'],"townshipCode":data['townshipCode'],"villages":[]})
|
|
|
+ town_list.append(township)
|
|
|
+ # result.append({'township':data['township'],"townshipCode":data['townshipCode'],"villages":[]})
|
|
|
+ result.append({'township':data['township'],"townshipCode":data['townshipCode'],"village":'-',"villageCode":'-',"populationSize":0,"areaSize":0,"GDP":0})
|
|
|
village = data['villageCode']
|
|
|
if village not in village_list:
|
|
|
village_count+=1
|
|
|
- for town in result:
|
|
|
- if town['townshipCode']==data['townshipCode']:
|
|
|
- town["villages"].append({'village': data['village'], "villageCode": data['villageCode']})
|
|
|
+ village_list.append(village)
|
|
|
+ # for town in result:
|
|
|
+ # if town['townshipCode']==data['townshipCode']:
|
|
|
+ # town["villages"].append({'village': data['village'], "villageCode": data['villageCode']})
|
|
|
|
|
|
+ result.append({'township':data['township'],"townshipCode":data['townshipCode'],'village': data['village'], "villageCode": data['villageCode'],"populationSize":0,"areaSize":0,"GDP":0})
|
|
|
|
|
|
return result,town_count,village_count
|
|
|
|
|
|
def count_emergency_expert(location_list:list,db):
|
|
|
location = convert_to_polygon(location_list)
|
|
|
|
|
|
- sql = f"""SELECT * FROM emergency_expert WHERE ST_Contains(ST_PolygonFromText( '{location}', 4326 ),ST_PointFromText(CONCAT('POINT(', latitude, ' ', longitude, ')'), 4326))"""
|
|
|
+ sql = text(f"""SELECT * FROM emergency_expert WHERE ST_Contains(ST_PolygonFromText( '{location}', 4326 ),ST_PointFromText(CONCAT('POINT(', latitude, ' ', longitude, ')'), 4326))""")
|
|
|
|
|
|
- return db.execute(sql).rowcount()
|
|
|
+ return len(db.execute(sql).all())
|
|
|
|
|
|
def count_emergency_management(location_list: list, db):
|
|
|
|
|
|
location = convert_to_polygon(location_list)
|
|
|
|
|
|
- sql = f"""SELECT DISTINCT management_unit FROM `rescue_materia` WHERE ST_Contains(ST_PolygonFromText( '{location}', 4326 ),ST_PointFromText(CONCAT('POINT(', latitude, ' ', longitude, ')'), 4326))"""
|
|
|
+ sql = text(f"""SELECT DISTINCT management_unit FROM `rescue_materia` WHERE ST_Contains(ST_PolygonFromText( '{location}', 4326 ),ST_PointFromText(CONCAT('POINT(', latitude, ' ', longitude, ')'), 4326))""")
|
|
|
|
|
|
- return db.execute(sql).rowcount()
|
|
|
+ return len(db.execute(sql).all())
|
|
|
|
|
|
-class location(BaseModel):
|
|
|
+class location_c(BaseModel):
|
|
|
x:float
|
|
|
y:float
|
|
|
|
|
|
class mine(BaseModel):
|
|
|
- location : List[location]=[]
|
|
|
+ location : List=[]
|
|
|
|
|
|
@router.post('/get_info')
|
|
|
async def mine(request: Request,from_data:mine,body = Depends(remove_xss_json),db: Session = Depends(get_db)):
|
|
|
try:
|
|
|
# 验证必需的字段
|
|
|
- required_fields = ['location']
|
|
|
- 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)}")
|
|
|
+ # 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)
|