|
@@ -1,7 +1,10 @@
|
|
|
-from fastapi import APIRouter, HTTPException, Depends, Body,Query
|
|
|
+# from fastapi import APIRouter, HTTPException, Depends, Body,Query
|
|
|
+from fastapi import APIRouter, Request, Depends, HTTPException, Query, BackgroundTasks
|
|
|
+from fastapi.responses import JSONResponse
|
|
|
+import os
|
|
|
# from sqlalchemy.orm import Session
|
|
|
from sqlalchemy.orm import Session, joinedload
|
|
|
-
|
|
|
+import xlrd
|
|
|
from database import get_db
|
|
|
from models import *
|
|
|
from typing import List, Optional
|
|
@@ -9,12 +12,10 @@ from pydantic import BaseModel,Extra, Field
|
|
|
import uuid
|
|
|
from common.security import valid_access_token
|
|
|
from pydantic import BaseModel
|
|
|
-from common.enc import mpfun, sys_menu_data, sys_menu_layer_data
|
|
|
-from common.auth_user import *
|
|
|
-from common.db import db_czrz
|
|
|
+from exceptions import AppException, HmacException
|
|
|
+from common.security import valid_access_token
|
|
|
import traceback
|
|
|
-from exceptions import HmacException
|
|
|
-
|
|
|
+from utils import *
|
|
|
from sqlalchemy import create_engine, Column, Integer, String, Boolean, MetaData, Table, \
|
|
|
inspect, exists,or_,text,insert,asc,desc
|
|
|
|
|
@@ -63,9 +64,32 @@ def create_projects(project_list_data: WaterResourceProjectListSchema, db: Sessi
|
|
|
try:
|
|
|
new_projects = [] # 创建一个空列表来存储新对象
|
|
|
for project_data in projects:
|
|
|
- new_project = WaterResourceProject(**project_data.dict(exclude_none=True))
|
|
|
+ # new_project = WaterResourceProject(**project_data.dict(exclude_none=True))
|
|
|
+ # db.add(new_project)
|
|
|
+ # new_projects.append(new_project)
|
|
|
+
|
|
|
+ project_data = project_data.dict(exclude_none=True)
|
|
|
+ n_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ project_data["cd_time"] = n_time
|
|
|
+ project_data["etl_time"] = n_time
|
|
|
+ project_data["cd_operation"] = 'I'
|
|
|
+ project_data["cd_batch"] = ''
|
|
|
+
|
|
|
+ new_project = WaterResourceProject(**project_data)
|
|
|
db.add(new_project)
|
|
|
new_projects.append(new_project)
|
|
|
+
|
|
|
+ # new_units = []
|
|
|
+ # for unit_data in units:
|
|
|
+ # unit_data = unit_data.dict(exclude_none=True)
|
|
|
+ # n_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ # unit_data["add_time"] = n_time
|
|
|
+ #
|
|
|
+ # new_unit = Unit(**unit_data)
|
|
|
+ # db.add(new_unit)
|
|
|
+ # new_units.append(new_unit)
|
|
|
+
|
|
|
+
|
|
|
db.commit()
|
|
|
project_ids = [project.id for project in new_projects] # 获取所有新对象的ID
|
|
|
return {"code": 200, "msg": "创建成功", "project_ids": project_ids}
|
|
@@ -99,7 +123,7 @@ def get_projects(page: int = Query(default=1, gt=0),
|
|
|
pageSize: int = Query(default=10, gt=0),
|
|
|
db: Session = Depends(get_db), user_id=Depends(valid_access_token)):
|
|
|
data_query = db.query(WaterResourceProject).filter(WaterResourceProject.is_delete == 0)
|
|
|
-
|
|
|
+ data_query = data_query.order_by(WaterResourceProject.cd_time.desc())
|
|
|
# 计算总数
|
|
|
total_count = data_query.count()
|
|
|
|
|
@@ -169,15 +193,7 @@ class UnitSchema(BaseModel):
|
|
|
latitude: float = None,
|
|
|
position:str = None,
|
|
|
team_size:int = None,
|
|
|
- supervisor_unit:str=None
|
|
|
- unit_propt:str=None
|
|
|
- unit_levelt:str=None
|
|
|
- unit_favort:str=None
|
|
|
- supervisor_unit_phonet:str=None
|
|
|
- supervisor_unit_contactt:str=None
|
|
|
- responsible_person_phonet:str=None
|
|
|
- areat:str=None
|
|
|
- founding_timet:str=None
|
|
|
+ supervisor_unit:str=None,
|
|
|
is_delete: int = 0
|
|
|
|
|
|
class UnitListSchema(BaseModel):
|
|
@@ -290,7 +306,7 @@ def update_unit(unit_id: int, update_data: UnitSchema, db: Session = Depends(get
|
|
|
db.refresh(unit)
|
|
|
return {"code": 200, "msg": "更新成功", "unit": unit.to_dict()}
|
|
|
except Exception as e:
|
|
|
- traceback.print_exc()
|
|
|
+ db.rollback()
|
|
|
raise HTTPException(status_code=400, detail=str(e))
|
|
|
|
|
|
|
|
@@ -648,8 +664,19 @@ def create_defense_projects(defense_project_list_data: DefenseProjectListSchema,
|
|
|
try:
|
|
|
new_projects = [] # 创建一个空列表来存储新对象
|
|
|
for project_data in projects:
|
|
|
- new_project = DefenseProject(**project_data.dict(exclude_none=True))
|
|
|
- new_projects.append(new_project)
|
|
|
+ # new_project = DefenseProject(**project_data.dict(exclude_none=True))
|
|
|
+ # new_projects.append(new_project)
|
|
|
+
|
|
|
+ project_data = project_data.dict(exclude_none=True)
|
|
|
+ n_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ project_data["add_time"] = n_time
|
|
|
+ project_data["cd_batch"] = ""
|
|
|
+ project_data["cd_operation"] = "I"
|
|
|
+
|
|
|
+ new_unit = DefenseProject(**project_data)
|
|
|
+ db.add(new_unit)
|
|
|
+ new_projects.append(new_unit)
|
|
|
+
|
|
|
db.add_all(new_projects)
|
|
|
db.commit()
|
|
|
project_ids = [project.id for project in new_projects] # 获取所有新对象的ID
|
|
@@ -687,7 +714,7 @@ def get_defense_projects(page: int = Query(default=1, gt=0),
|
|
|
pageSize: int = Query(default=10, gt=0), db: Session = Depends(get_db)):
|
|
|
# 应用过滤条件,仅查询未被删除的项目
|
|
|
data_query = db.query(DefenseProject).filter(DefenseProject.is_delete == False)
|
|
|
-
|
|
|
+ data_query = data_query.order_by(DefenseProject.add_time.desc())
|
|
|
# 计算总数
|
|
|
total_count = data_query.count()
|
|
|
|
|
@@ -777,8 +804,16 @@ def create_shelters(shelter_list_data: ShelterListSchema, db: Session = Depends(
|
|
|
try:
|
|
|
new_shelters = []
|
|
|
for shelter_data in shelters:
|
|
|
- new_shelter = Shelter(**shelter_data.dict(exclude_none=True))
|
|
|
- new_shelters.append(new_shelter)
|
|
|
+ # new_shelter = Shelter(**shelter_data.dict(exclude_none=True))
|
|
|
+ # new_shelters.append(new_shelter)
|
|
|
+ shelter_data = shelter_data.dict(exclude_none=True)
|
|
|
+ n_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ shelter_data["created_time"] = n_time
|
|
|
+ shelter_data["data_id"] = uuid.uuid1()
|
|
|
+
|
|
|
+ new_unit = Shelter(**shelter_data)
|
|
|
+ db.add(new_unit)
|
|
|
+ new_shelters.append(new_unit)
|
|
|
db.add_all(new_shelters)
|
|
|
db.commit()
|
|
|
shelter_ids = [shelter.id for shelter in new_shelters]
|
|
@@ -808,6 +843,8 @@ def delete_shelter(shelter_id: int, db: Session = Depends(get_db)):
|
|
|
def get_shelters(page: int = Query(default=1, gt=0),
|
|
|
pageSize: int = Query(default=10, gt=0), db: Session = Depends(get_db)):
|
|
|
data_query = db.query(Shelter).filter(Shelter.is_delete == False)
|
|
|
+ data_query = data_query.order_by(Shelter.created_time.desc())
|
|
|
+
|
|
|
total_count = data_query.count()
|
|
|
offset = (page - 1) * pageSize
|
|
|
shelters = data_query.offset(offset).limit(pageSize).all()
|
|
@@ -850,3 +887,767 @@ def update_shelter(shelter_id: int, update_data: ShelterSchema, db: Session = De
|
|
|
raise HTTPException(status_code=400, detail=str(e))
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def import_data(db, file_path, user_id, file_info):
|
|
|
+ import_status = True
|
|
|
+ print(file_path)
|
|
|
+ try:
|
|
|
+ book = xlrd.open_workbook(file_path)
|
|
|
+ sheet = book.sheet_by_index(0)
|
|
|
+ except:
|
|
|
+ file_info.remark = file_info.remark + f'\n文件打开失败,请核实文件格式为xlsx/xlx>'
|
|
|
+ file_info.error_num += 1
|
|
|
+ import_status = False
|
|
|
+ data = []
|
|
|
+ for row in range(1, sheet.nrows):
|
|
|
+
|
|
|
+ # 姓名
|
|
|
+ jsdwzjlx = sheet.cell(row, 0).value
|
|
|
+ lxfs = sheet.cell(row, 1).value
|
|
|
+ sjtgbmtyshxydm = sheet.cell(row, 2).value
|
|
|
+ jdgljgbm = sheet.cell(row, 3).value
|
|
|
+ cd_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ sjtgbmmc = sheet.cell(row, 4).value
|
|
|
+ ggmj = sheet.cell(row, 5).value
|
|
|
+ sjtgbmxzqhdm = sheet.cell(row, 6).value
|
|
|
+ jsdwzjhm = sheet.cell(row, 7).value
|
|
|
+ xzqhdm = sheet.cell(row, 8).value
|
|
|
+ cd_operation = "I"
|
|
|
+ zdmj = sheet.cell(row, 9).value
|
|
|
+ d_bmmc = sheet.cell(row, 10).value
|
|
|
+ etl_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ jssj = sheet.cell(row, 11).value
|
|
|
+ jsdwmc = sheet.cell(row, 12).value
|
|
|
+ slsshslgcmc = sheet.cell(row, 13).value
|
|
|
+ # cd_batch = Column(String(200), comment='数据批次号')
|
|
|
+ slsshslgcdd = sheet.cell(row, 14).value
|
|
|
+ jdgljg = sheet.cell(row, 15).value
|
|
|
+ jingdu = sheet.cell(row, 16).value
|
|
|
+ weidu = sheet.cell(row, 17).value
|
|
|
+
|
|
|
+ new_water = WaterResourceProject(
|
|
|
+ jsdwzjlx=jsdwzjlx,
|
|
|
+ lxfs=lxfs,
|
|
|
+ sjtgbmtyshxydm=sjtgbmtyshxydm,
|
|
|
+ jdgljgbm=jdgljgbm,
|
|
|
+ cd_time=cd_time,
|
|
|
+ sjtgbmmc=sjtgbmmc,
|
|
|
+ ggmj=ggmj,
|
|
|
+ sjtgbmxzqhdm=sjtgbmxzqhdm,
|
|
|
+ jsdwzjhm=jsdwzjhm,
|
|
|
+ xzqhdm=xzqhdm,
|
|
|
+ cd_operation=cd_operation,
|
|
|
+ zdmj=zdmj,
|
|
|
+ d_bmmc=d_bmmc,
|
|
|
+ etl_time=etl_time,
|
|
|
+ jssj=jssj,
|
|
|
+ jsdwmc=jsdwmc,
|
|
|
+ slsshslgcmc=slsshslgcmc,
|
|
|
+ slsshslgcdd=slsshslgcdd,
|
|
|
+ jdgljg=jdgljg,
|
|
|
+ jingdu=jingdu,
|
|
|
+ weidu=weidu
|
|
|
+ )
|
|
|
+ data.append(new_water)
|
|
|
+ db.add(new_water)
|
|
|
+ db.commit()
|
|
|
+ db.commit()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+@router.post('/createImport/projects')
|
|
|
+async def create_contact(
|
|
|
+ request: Request,
|
|
|
+ background_tasks: BackgroundTasks,
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+ body=Depends(remove_xss_json),
|
|
|
+ # auth_user: AuthUser = Depends(find_auth_user),
|
|
|
+ user_id=Depends(valid_access_token)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ # 提取请求数据
|
|
|
+ filename = body['filename']
|
|
|
+ file_name_desc = body['file_name_desc']
|
|
|
+ if len(filename) == 0:
|
|
|
+ raise Exception()
|
|
|
+
|
|
|
+ # file_path = f'/data/upload/mergefile/uploads/{filename}'
|
|
|
+ file_path = f'D:\\Desktop\\mm\\{filename}'
|
|
|
+ # print(file_path)
|
|
|
+
|
|
|
+ # 检查文件是否存在
|
|
|
+ if not os.path.isfile(file_path):
|
|
|
+ return JSONResponse(status_code=404, content={
|
|
|
+ 'errcode': 404,
|
|
|
+ 'errmsg': f'{filename}不存在'
|
|
|
+ })
|
|
|
+
|
|
|
+ new_file = ResourceImportFileStatus(
|
|
|
+ file_uuid=filename,
|
|
|
+ file_name=file_name_desc,
|
|
|
+ status='1',
|
|
|
+ remark='',
|
|
|
+ user_id=user_id,
|
|
|
+ resource_type = '水利'
|
|
|
+ )
|
|
|
+ db.add(new_file)
|
|
|
+ db.commit()
|
|
|
+ background_tasks.add_task(import_data, db, file_path, user_id, new_file)
|
|
|
+
|
|
|
+ # db_czrz.log(db, auth_user, "系统管理", f"后台管理导入三防责任人管理人员信息成功", request.client.host)
|
|
|
+
|
|
|
+ # 返回创建成功的响应
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "成功",
|
|
|
+ "data": None
|
|
|
+ }
|
|
|
+
|
|
|
+ except AppException as e:
|
|
|
+ return {
|
|
|
+ "code": 500,
|
|
|
+ "msg": e.msg
|
|
|
+ }
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ # 处理异常
|
|
|
+ db.rollback()
|
|
|
+ raise HTTPException(status_code=500, detail=str(e))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def rescue_units_import_data(db, file_path, user_id, file_info):
|
|
|
+ import_status = True
|
|
|
+ print(file_path)
|
|
|
+ try:
|
|
|
+ book = xlrd.open_workbook(file_path)
|
|
|
+ sheet = book.sheet_by_index(0)
|
|
|
+ except:
|
|
|
+ file_info.remark = file_info.remark + f'\n文件打开失败,请核实文件格式为xlsx/xlx>'
|
|
|
+ file_info.error_num += 1
|
|
|
+ import_status = False
|
|
|
+ data = []
|
|
|
+ for row in range(1, sheet.nrows):
|
|
|
+
|
|
|
+ # 姓名
|
|
|
+ name = sheet.cell(row, 0).value
|
|
|
+ category = sheet.cell(row, 1).value
|
|
|
+ address = sheet.cell(row, 2).value
|
|
|
+ equipment = sheet.cell(row, 3).value
|
|
|
+ training = sheet.cell(row, 4).value
|
|
|
+ responsible_person = sheet.cell(row, 5).value
|
|
|
+ contact_number = sheet.cell(row, 6).value
|
|
|
+ longitude = sheet.cell(row, 7).value
|
|
|
+ latitude = sheet.cell(row, 8).value
|
|
|
+ position = sheet.cell(row, 9).value
|
|
|
+ team_size = sheet.cell(row, 10).value
|
|
|
+ supervisor_unit = sheet.cell(row, 11).value
|
|
|
+ add_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+
|
|
|
+ # 创建 Unit 对象
|
|
|
+ new_Unit = Unit(
|
|
|
+ name=name,
|
|
|
+ category=category,
|
|
|
+ address=address,
|
|
|
+ equipment=equipment,
|
|
|
+ training=training,
|
|
|
+ responsible_person=responsible_person,
|
|
|
+ contact_number=contact_number,
|
|
|
+ longitude=longitude,
|
|
|
+ latitude=latitude,
|
|
|
+ position=position,
|
|
|
+ team_size=team_size,
|
|
|
+ supervisor_unit=supervisor_unit,
|
|
|
+ add_time=add_time
|
|
|
+ )
|
|
|
+ data.append(new_Unit)
|
|
|
+ db.add(new_Unit)
|
|
|
+ db.commit()
|
|
|
+ db.commit()
|
|
|
+
|
|
|
+@router.post('/createImport/rescue_units')
|
|
|
+async def create_contact(
|
|
|
+ request: Request,
|
|
|
+ background_tasks: BackgroundTasks,
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+ body=Depends(remove_xss_json),
|
|
|
+ # auth_user: AuthUser = Depends(find_auth_user),
|
|
|
+ user_id=Depends(valid_access_token)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ # 提取请求数据
|
|
|
+ filename = body['filename']
|
|
|
+ file_name_desc = body['file_name_desc']
|
|
|
+ if len(filename) == 0:
|
|
|
+ raise Exception()
|
|
|
+
|
|
|
+ # file_path = f'/data/upload/mergefile/uploads/{filename}'
|
|
|
+ file_path = f'D:\\Desktop\\mm\\{filename}'
|
|
|
+ # print(file_path)
|
|
|
+
|
|
|
+ # 检查文件是否存在
|
|
|
+ if not os.path.isfile(file_path):
|
|
|
+ return JSONResponse(status_code=404, content={
|
|
|
+ 'errcode': 404,
|
|
|
+ 'errmsg': f'{filename}不存在'
|
|
|
+ })
|
|
|
+
|
|
|
+ new_file = ResourceImportFileStatus(
|
|
|
+ file_uuid=filename,
|
|
|
+ file_name=file_name_desc,
|
|
|
+ status='1',
|
|
|
+ remark='',
|
|
|
+ user_id=user_id,
|
|
|
+ resource_type = '救援人员单位管理'
|
|
|
+ )
|
|
|
+ db.add(new_file)
|
|
|
+ db.commit()
|
|
|
+ background_tasks.add_task(rescue_units_import_data, db, file_path, user_id, new_file)
|
|
|
+
|
|
|
+ # db_czrz.log(db, auth_user, "系统管理", f"后台管理导入三防责任人管理人员信息成功", request.client.host)
|
|
|
+
|
|
|
+ # 返回创建成功的响应
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "成功",
|
|
|
+ "data": None
|
|
|
+ }
|
|
|
+
|
|
|
+ except AppException as e:
|
|
|
+ return {
|
|
|
+ "code": 500,
|
|
|
+ "msg": e.msg
|
|
|
+ }
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ # 处理异常
|
|
|
+ db.rollback()
|
|
|
+ raise HTTPException(status_code=500, detail=str(e))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def rescue_personnel_import_data(db, file_path, user_id, file_info):
|
|
|
+ import_status = True
|
|
|
+ print(file_path)
|
|
|
+ try:
|
|
|
+ book = xlrd.open_workbook(file_path)
|
|
|
+ sheet = book.sheet_by_index(0)
|
|
|
+ except:
|
|
|
+ file_info.remark = file_info.remark + f'\n文件打开失败,请核实文件格式为xlsx/xlx>'
|
|
|
+ file_info.error_num += 1
|
|
|
+ import_status = False
|
|
|
+ data = []
|
|
|
+ for row in range(1, sheet.nrows):
|
|
|
+
|
|
|
+ # 姓名
|
|
|
+ name = sheet.cell(row, 0).value
|
|
|
+ contact_number = sheet.cell(row, 1).value
|
|
|
+ gender = sheet.cell(row, 2).value
|
|
|
+ current_address = sheet.cell(row, 3).value
|
|
|
+ position = sheet.cell(row, 4).value
|
|
|
+ unit_id = sheet.cell(row, 5).value
|
|
|
+ unit_name = sheet.cell(row, 6).value
|
|
|
+ created_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+
|
|
|
+ # 创建 Unit 对象
|
|
|
+ new_RescuePersonnel = RescuePersonnel(
|
|
|
+ name=name,
|
|
|
+ contact_number=contact_number,
|
|
|
+ gender=gender,
|
|
|
+ current_address=current_address,
|
|
|
+ position=position,
|
|
|
+ unit_id=unit_id,
|
|
|
+ unit_name=unit_name,
|
|
|
+ created_time=created_time
|
|
|
+ )
|
|
|
+ data.append(new_RescuePersonnel)
|
|
|
+ db.add(new_RescuePersonnel)
|
|
|
+ db.commit()
|
|
|
+ db.commit()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+@router.post('/createImport/rescue_personnel')
|
|
|
+async def create_contact(
|
|
|
+ request: Request,
|
|
|
+ background_tasks: BackgroundTasks,
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+ body=Depends(remove_xss_json),
|
|
|
+ # auth_user: AuthUser = Depends(find_auth_user),
|
|
|
+ user_id=Depends(valid_access_token)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ # 提取请求数据
|
|
|
+ filename = body['filename']
|
|
|
+ file_name_desc = body['file_name_desc']
|
|
|
+ if len(filename) == 0:
|
|
|
+ raise Exception()
|
|
|
+
|
|
|
+ # file_path = f'/data/upload/mergefile/uploads/{filename}'
|
|
|
+ file_path = f'D:\\Desktop\\mm\\{filename}'
|
|
|
+ # print(file_path)
|
|
|
+
|
|
|
+ # 检查文件是否存在
|
|
|
+ if not os.path.isfile(file_path):
|
|
|
+ return JSONResponse(status_code=404, content={
|
|
|
+ 'errcode': 404,
|
|
|
+ 'errmsg': f'{filename}不存在'
|
|
|
+ })
|
|
|
+
|
|
|
+ new_file = ResourceImportFileStatus(
|
|
|
+ file_uuid=filename,
|
|
|
+ file_name=file_name_desc,
|
|
|
+ status='1',
|
|
|
+ remark='',
|
|
|
+ user_id=user_id,
|
|
|
+ resource_type = '救援人员单位'
|
|
|
+ )
|
|
|
+ db.add(new_file)
|
|
|
+ db.commit()
|
|
|
+ background_tasks.add_task(rescue_personnel_import_data, db, file_path, user_id, new_file)
|
|
|
+
|
|
|
+ # db_czrz.log(db, auth_user, "系统管理", f"后台管理导入三防责任人管理人员信息成功", request.client.host)
|
|
|
+
|
|
|
+ # 返回创建成功的响应
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "成功",
|
|
|
+ "data": None
|
|
|
+ }
|
|
|
+
|
|
|
+ except AppException as e:
|
|
|
+ return {
|
|
|
+ "code": 500,
|
|
|
+ "msg": e.msg
|
|
|
+ }
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ # 处理异常
|
|
|
+ db.rollback()
|
|
|
+ raise HTTPException(status_code=500, detail=str(e))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def rescue_stations_import_data(db, file_path, user_id, file_info):
|
|
|
+ import_status = True
|
|
|
+ print(file_path)
|
|
|
+ try:
|
|
|
+ book = xlrd.open_workbook(file_path)
|
|
|
+ sheet = book.sheet_by_index(0)
|
|
|
+ except:
|
|
|
+ file_info.remark = file_info.remark + f'\n文件打开失败,请核实文件格式为xlsx/xlx>'
|
|
|
+ file_info.error_num += 1
|
|
|
+ import_status = False
|
|
|
+ data = []
|
|
|
+ for row in range(1, sheet.nrows):
|
|
|
+
|
|
|
+ # 姓名
|
|
|
+ data_id = uuid.uuid1()
|
|
|
+ fwdx = sheet.cell(row, 0).value
|
|
|
+ zj = sheet.cell(row, 1).value
|
|
|
+ lng = sheet.cell(row, 2).value
|
|
|
+ cd_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ fwdmc = sheet.cell(row, 3).value
|
|
|
+ fwnr = sheet.cell(row, 4).value
|
|
|
+ add_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ cd_operation = "I"
|
|
|
+ fwdlx = sheet.cell(row, 5).value
|
|
|
+ lxdh = sheet.cell(row, 6).value
|
|
|
+ kfsj = sheet.cell(row, 7).value
|
|
|
+ lat = sheet.cell(row, 8).value
|
|
|
+ fwdjj = sheet.cell(row, 9).value
|
|
|
+ lxr = sheet.cell(row, 10).value
|
|
|
+ fid = sheet.cell(row, 11).value
|
|
|
+ fwdzt = sheet.cell(row, 12).value
|
|
|
+ fwdaddr = sheet.cell(row, 13).value
|
|
|
+ ssqx = sheet.cell(row, 14).value
|
|
|
+
|
|
|
+
|
|
|
+ new_RescueStation = RescueStation(
|
|
|
+ data_id=data_id,
|
|
|
+ fwdx=fwdx,
|
|
|
+ zj=zj,
|
|
|
+ lng=lng,
|
|
|
+ cd_time=cd_time,
|
|
|
+ fwdmc=fwdmc,
|
|
|
+ fwnr=fwnr,
|
|
|
+ add_time=add_time,
|
|
|
+ cd_operation=cd_operation,
|
|
|
+ fwdlx=fwdlx,
|
|
|
+ lxdh=lxdh,
|
|
|
+ kfsj=kfsj,
|
|
|
+ lat=lat,
|
|
|
+ fwdjj=fwdjj,
|
|
|
+ lxr=lxr,
|
|
|
+ fid=fid,
|
|
|
+ fwdzt=fwdzt,
|
|
|
+ fwdaddr=fwdaddr,
|
|
|
+ ssqx=ssqx
|
|
|
+ )
|
|
|
+ data.append(new_RescueStation)
|
|
|
+ db.add(new_RescueStation)
|
|
|
+ db.commit()
|
|
|
+ db.commit()
|
|
|
+
|
|
|
+@router.post('/createImport/rescue_stations')
|
|
|
+async def create_contact(
|
|
|
+ request: Request,
|
|
|
+ background_tasks: BackgroundTasks,
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+ body=Depends(remove_xss_json),
|
|
|
+ # auth_user: AuthUser = Depends(find_auth_user),
|
|
|
+ user_id=Depends(valid_access_token)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ # 提取请求数据
|
|
|
+ filename = body['filename']
|
|
|
+ file_name_desc = body['file_name_desc']
|
|
|
+ if len(filename) == 0:
|
|
|
+ raise Exception()
|
|
|
+
|
|
|
+ # file_path = f'/data/upload/mergefile/uploads/{filename}'
|
|
|
+ file_path = f'D:\\Desktop\\mm\\{filename}'
|
|
|
+ # print(file_path)
|
|
|
+
|
|
|
+ # 检查文件是否存在
|
|
|
+ if not os.path.isfile(file_path):
|
|
|
+ return JSONResponse(status_code=404, content={
|
|
|
+ 'errcode': 404,
|
|
|
+ 'errmsg': f'{filename}不存在'
|
|
|
+ })
|
|
|
+
|
|
|
+ new_file = ResourceImportFileStatus(
|
|
|
+ file_uuid=filename,
|
|
|
+ file_name=file_name_desc,
|
|
|
+ status='1',
|
|
|
+ remark='',
|
|
|
+ user_id=user_id,
|
|
|
+ resource_type = '救助站'
|
|
|
+ )
|
|
|
+ db.add(new_file)
|
|
|
+ db.commit()
|
|
|
+ background_tasks.add_task(rescue_stations_import_data, db, file_path, user_id, new_file)
|
|
|
+
|
|
|
+ # db_czrz.log(db, auth_user, "系统管理", f"后台管理导入三防责任人管理人员信息成功", request.client.host)
|
|
|
+
|
|
|
+ # 返回创建成功的响应
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "成功",
|
|
|
+ "data": None
|
|
|
+ }
|
|
|
+
|
|
|
+ except AppException as e:
|
|
|
+ return {
|
|
|
+ "code": 500,
|
|
|
+ "msg": e.msg
|
|
|
+ }
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ # 处理异常
|
|
|
+ db.rollback()
|
|
|
+ raise HTTPException(status_code=500, detail=str(e))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+#人防工程
|
|
|
+def defense_projects_import_data(db, file_path, user_id, file_info):
|
|
|
+ import_status = True
|
|
|
+ try:
|
|
|
+ book = xlrd.open_workbook(file_path)
|
|
|
+ sheet = book.sheet_by_index(0)
|
|
|
+ except:
|
|
|
+ file_info.remark = file_info.remark + f'\n文件打开失败,请核实文件格式为xlsx/xlx>'
|
|
|
+ file_info.error_num += 1
|
|
|
+ import_status = False
|
|
|
+ data = []
|
|
|
+ for row in range(1, sheet.nrows):
|
|
|
+ # print(row)
|
|
|
+ # print(sheet.cell(row, 0).value)
|
|
|
+
|
|
|
+ data_id = uuid.uuid1()
|
|
|
+ # id = Column(BigInteger, primary_key=True, autoincrement=True, comment='数字自增ID')
|
|
|
+ gcmc = sheet.cell(row, 0).value
|
|
|
+ jsdw = sheet.cell(row, 1).value
|
|
|
+ whdw = sheet.cell(row, 2).value
|
|
|
+ rfzyjlgcs = sheet.cell(row, 3).value
|
|
|
+ jsdd = sheet.cell(row, 4).value
|
|
|
+ cd_operation = "I"
|
|
|
+
|
|
|
+ yjdxsmj = sheet.cell(row, 5).value
|
|
|
+ sjdxsmj = sheet.cell(row, 6).value
|
|
|
+ cd_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ add_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ jldw = sheet.cell(row, 7).value
|
|
|
+ jsdwdm = sheet.cell(row, 8).value
|
|
|
+ kgsj = sheet.cell(row, 9).value
|
|
|
+ stdw = sheet.cell(row, 10).value
|
|
|
+ # cd_batch = Column(String(100), comment='批次号') # 新增
|
|
|
+ rfsjdwdm = sheet.cell(row, 11).value
|
|
|
+ rfsjdw = sheet.cell(row, 12).value
|
|
|
+ ybrs = sheet.cell(row, 13).value
|
|
|
+ stdwdm = sheet.cell(row, 14).value
|
|
|
+ whdwdm = sheet.cell(row, 15).value
|
|
|
+ jldwdm = sheet.cell(row, 16).value
|
|
|
+ rfzjlgcs = sheet.cell(row, 17).value
|
|
|
+ # gcid = Column(String(50), comment='主键')
|
|
|
+ extend2 = sheet.cell(row, 18).value
|
|
|
+ data_area = sheet.cell(row, 19).value
|
|
|
+ extend1 = sheet.cell(row, 20).value
|
|
|
+ jgsj = sheet.cell(row, 21).value
|
|
|
+ rffhsbdw = sheet.cell(row, 22).value
|
|
|
+ rffhsbdwdm = sheet.cell(row, 23).value
|
|
|
+ jingdu = sheet.cell(row, 24).value
|
|
|
+ weidu = sheet.cell(row, 25).value
|
|
|
+
|
|
|
+ new_DefenseProject = DefenseProject(
|
|
|
+ data_id=data_id,
|
|
|
+ gcmc=gcmc,
|
|
|
+ jsdw=jsdw,
|
|
|
+ whdw=whdw,
|
|
|
+ rfzyjlgcs=rfzyjlgcs,
|
|
|
+ jsdd=jsdd,
|
|
|
+ cd_operation=cd_operation,
|
|
|
+ yjdxsmj=yjdxsmj,
|
|
|
+ sjdxsmj=sjdxsmj,
|
|
|
+ cd_time=cd_time,
|
|
|
+ add_time=add_time,
|
|
|
+ jldw=jldw,
|
|
|
+ jsdwdm=jsdwdm,
|
|
|
+ kgsj=kgsj,
|
|
|
+ stdw=stdw,
|
|
|
+ rfsjdwdm=rfsjdwdm,
|
|
|
+ rfsjdw=rfsjdw,
|
|
|
+ ybrs=ybrs,
|
|
|
+ stdwdm=stdwdm,
|
|
|
+ whdwdm=whdwdm,
|
|
|
+ jldwdm=jldwdm,
|
|
|
+ rfzjlgcs=rfzjlgcs,
|
|
|
+ extend2=extend2,
|
|
|
+ data_area=data_area,
|
|
|
+ extend1=extend1,
|
|
|
+ jgsj=jgsj,
|
|
|
+ rffhsbdw=rffhsbdw,
|
|
|
+ rffhsbdwdm=rffhsbdwdm,
|
|
|
+ jingdu=jingdu,
|
|
|
+ weidu=weidu
|
|
|
+ )
|
|
|
+ data.append(new_DefenseProject)
|
|
|
+ db.add(new_DefenseProject)
|
|
|
+ db.commit()
|
|
|
+ db.commit()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+@router.post('/createImport/defense_projects')
|
|
|
+async def create_contact(
|
|
|
+ request: Request,
|
|
|
+ background_tasks: BackgroundTasks,
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+ body=Depends(remove_xss_json),
|
|
|
+ # auth_user: AuthUser = Depends(find_auth_user),
|
|
|
+ user_id=Depends(valid_access_token)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ # 提取请求数据
|
|
|
+ filename = body['filename']
|
|
|
+ file_name_desc = body['file_name_desc']
|
|
|
+ if len(filename) == 0:
|
|
|
+ raise Exception()
|
|
|
+
|
|
|
+ # file_path = f'/data/upload/mergefile/uploads/{filename}'
|
|
|
+ file_path = f'D:\\Desktop\\mm\\{filename}'
|
|
|
+ # print(file_path)
|
|
|
+
|
|
|
+ # 检查文件是否存在
|
|
|
+ if not os.path.isfile(file_path):
|
|
|
+ return JSONResponse(status_code=404, content={
|
|
|
+ 'errcode': 404,
|
|
|
+ 'errmsg': f'{filename}不存在'
|
|
|
+ })
|
|
|
+
|
|
|
+ new_file = ResourceImportFileStatus(
|
|
|
+ file_uuid=filename,
|
|
|
+ file_name=file_name_desc,
|
|
|
+ status='1',
|
|
|
+ remark='',
|
|
|
+ user_id=user_id,
|
|
|
+ resource_type = '人防工程'
|
|
|
+ )
|
|
|
+ db.add(new_file)
|
|
|
+ db.commit()
|
|
|
+ background_tasks.add_task(defense_projects_import_data, db, file_path, user_id, new_file)
|
|
|
+
|
|
|
+ # db_czrz.log(db, auth_user, "系统管理", f"后台管理导入三防责任人管理人员信息成功", request.client.host)
|
|
|
+
|
|
|
+ # 返回创建成功的响应
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "成功",
|
|
|
+ "data": None
|
|
|
+ }
|
|
|
+
|
|
|
+ except AppException as e:
|
|
|
+ return {
|
|
|
+ "code": 500,
|
|
|
+ "msg": e.msg
|
|
|
+ }
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ # 处理异常
|
|
|
+ db.rollback()
|
|
|
+ raise HTTPException(status_code=500, detail=str(e))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+#人防工程
|
|
|
+def shelters_import_data(db, file_path, user_id, file_info):
|
|
|
+ import_status = True
|
|
|
+ try:
|
|
|
+ book = xlrd.open_workbook(file_path)
|
|
|
+ sheet = book.sheet_by_index(0)
|
|
|
+ except:
|
|
|
+ file_info.remark = file_info.remark + f'\n文件打开失败,请核实文件格式为xlsx/xlx>'
|
|
|
+ file_info.error_num += 1
|
|
|
+ import_status = False
|
|
|
+ data = []
|
|
|
+ for row in range(1, sheet.nrows):
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ data_id = uuid.uuid1()
|
|
|
+ admin_area = sheet.cell(row, 0).value
|
|
|
+ full_name = sheet.cell(row, 0).value
|
|
|
+ address = sheet.cell(row, 0).value
|
|
|
+ incident_type = sheet.cell(row, 0).value
|
|
|
+ shelter_type = sheet.cell(row, 0).value
|
|
|
+ total_area = sheet.cell(row, 0).value
|
|
|
+ indoor_area = sheet.cell(row, 0).value
|
|
|
+ capacity = sheet.cell(row, 0).value
|
|
|
+ supplies = sheet.cell(row, 0).value
|
|
|
+ facilities = sheet.cell(row, 0).value
|
|
|
+ modified_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ created_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+
|
|
|
+ new_Shelter = Shelter(
|
|
|
+ data_id=data_id,
|
|
|
+ admin_area=admin_area,
|
|
|
+ full_name=full_name,
|
|
|
+ address=address,
|
|
|
+ incident_type=incident_type,
|
|
|
+ shelter_type=shelter_type,
|
|
|
+ total_area=total_area,
|
|
|
+ indoor_area=indoor_area,
|
|
|
+ capacity=capacity,
|
|
|
+ supplies=supplies,
|
|
|
+ facilities=facilities,
|
|
|
+ modified_time=modified_time,
|
|
|
+ created_time=created_time
|
|
|
+ )
|
|
|
+ data.append(new_Shelter)
|
|
|
+ db.add(new_Shelter)
|
|
|
+ db.commit()
|
|
|
+ db.commit()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+@router.post('/createImport/shelters')
|
|
|
+async def create_contact(
|
|
|
+ request: Request,
|
|
|
+ background_tasks: BackgroundTasks,
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+ body=Depends(remove_xss_json),
|
|
|
+ # auth_user: AuthUser = Depends(find_auth_user),
|
|
|
+ user_id=Depends(valid_access_token)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ # 提取请求数据
|
|
|
+ filename = body['filename']
|
|
|
+ file_name_desc = body['file_name_desc']
|
|
|
+ if len(filename) == 0:
|
|
|
+ raise Exception()
|
|
|
+
|
|
|
+ # file_path = f'/data/upload/mergefile/uploads/{filename}'
|
|
|
+ file_path = f'D:\\Desktop\\mm\\{filename}'
|
|
|
+ # print(file_path)
|
|
|
+
|
|
|
+ # 检查文件是否存在
|
|
|
+ if not os.path.isfile(file_path):
|
|
|
+ return JSONResponse(status_code=404, content={
|
|
|
+ 'errcode': 404,
|
|
|
+ 'errmsg': f'{filename}不存在'
|
|
|
+ })
|
|
|
+
|
|
|
+ new_file = ResourceImportFileStatus(
|
|
|
+ file_uuid=filename,
|
|
|
+ file_name=file_name_desc,
|
|
|
+ status='1',
|
|
|
+ remark='',
|
|
|
+ user_id=user_id,
|
|
|
+ resource_type = '避难场所'
|
|
|
+ )
|
|
|
+ db.add(new_file)
|
|
|
+ db.commit()
|
|
|
+ background_tasks.add_task(shelters_import_data, db, file_path, user_id, new_file)
|
|
|
+
|
|
|
+ # db_czrz.log(db, auth_user, "系统管理", f"后台管理导入三防责任人管理人员信息成功", request.client.host)
|
|
|
+
|
|
|
+ # 返回创建成功的响应
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "成功",
|
|
|
+ "data": None
|
|
|
+ }
|
|
|
+
|
|
|
+ except AppException as e:
|
|
|
+ return {
|
|
|
+ "code": 500,
|
|
|
+ "msg": e.msg
|
|
|
+ }
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ # 处理异常
|
|
|
+ db.rollback()
|
|
|
+ raise HTTPException(status_code=500, detail=str(e))
|