#!/usr/bin/env python3 # -*- coding: utf-8 -*- from fastapi import APIRouter, Request, Depends, Form, Body, File, UploadFile from database import get_db from utils.StripTagsHTMLParser import * from sqlalchemy.orm import Session from datetime import datetime, timedelta from passlib.context import CryptContext from models import * from sqlalchemy import text, exists, and_, or_, not_ from sqlalchemy.sql import func from models import * from extensions import logger from utils import * import traceback router = APIRouter() # 2.2.6.1.门禁/卡口管理信息基础信息管理 # 2.2.6.1.1.访客信息 @router.post('/insular/getVisitorInfo', description='提交访客信息') async def index( request: Request, db: Session = Depends(get_db), data: dict = Depends(remove_xss_json) ): try: id = get_req_param(data, 'id') info = db.query(DangerTopinfoInsularVisitorInfo).filter(DangerTopinfoInsularVisitorInfo.id == id).first() if info is None: new_entity = DangerTopinfoInsularVisitorInfo(**data) db.add(new_entity) else: db.query(DangerTopinfoInsularVisitorInfo).filter(DangerTopinfoInsularVisitorInfo.id == id).update(data) db.commit() return { "code":1, "message":"成功", "data":{} } except Exception as e: traceback.print_exc() return { "code":0, "message":"更新异常,错误信息:" + str(e), "data":{} } # 2.2.6.1.2.其他车辆信息 @router.post('/insular/getOtherCarInfo', description='其他车辆信息') async def index( request: Request, db: Session = Depends(get_db), data: dict = Depends(remove_xss_json) ): try: id = get_req_param(data, 'id') info = db.query(DangerTopinfoInsularOtherCarInfo).filter(DangerTopinfoInsularOtherCarInfo.id == id).first() if info is None: new_entity = DangerTopinfoInsularOtherCarInfo(**data) db.add(new_entity) else: db.query(DangerTopinfoInsularOtherCarInfo).filter(DangerTopinfoInsularOtherCarInfo.id == id).update(data) db.commit() return { "code":1, "message":"成功", "data":{} } except Exception as e: traceback.print_exc() return { "code":0, "message":"更新异常,错误信息:" + str(e), "data":{} } # 2.2.6.2.应急演练实施过程记录信息 @router.post('/emergencerecord/addOrUpdate', description='应急演练实施过程记录信息') async def index( request: Request, db: Session = Depends(get_db), data: dict = Depends(remove_xss_json) ): try: id = get_req_param(data, 'id') info = db.query(DangerTopinfoInsularEmergenceRecord).filter(DangerTopinfoInsularEmergenceRecord.id == id).first() if info is None: new_entity = DangerTopinfoInsularEmergenceRecord(**data) db.add(new_entity) else: db.query(DangerTopinfoInsularEmergenceRecord).filter(DangerTopinfoInsularEmergenceRecord.id == id).update(data) db.commit() return { "code":1, "message":"成功", "data":{} } except Exception as e: traceback.print_exc() return { "code":0, "message":"更新异常,错误信息:" + str(e), "data":{} }