123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- #!/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.5.人员定位信息
- # 2.2.5.1.区域边界信息
- @router.post('/zone/info', 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(DangerLocationZoneInfo).filter(DangerLocationZoneInfo.id == id).first()
- if info is None:
- new_entity = DangerLocationZoneInfo(**data)
- db.add(new_entity)
- else:
- db.query(DangerLocationZoneInfo).filter(DangerLocationZoneInfo.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.5.2.人员实时定位数据
- @router.post('/person/info', 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(DangerLocationPersonInfo).filter(DangerLocationPersonInfo.id == id).first()
- if info is None:
- new_entity = DangerLocationPersonInfo(**data)
- db.add(new_entity)
- else:
- db.query(DangerLocationPersonInfo).filter(DangerLocationPersonInfo.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.5.3.人员聚集数据
- @router.post('/person/area', 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(DangerLocationPersonArea).filter(DangerLocationPersonArea.id == id).first()
- if info is None:
- new_entity = DangerLocationPersonArea(**data)
- db.add(new_entity)
- else:
- db.query(DangerLocationPersonArea).filter(DangerLocationPersonArea.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.5.4.人员报警数据
- @router.post('/person/alarm', 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(DangerLocationPersonAlarm).filter(DangerLocationPersonAlarm.id == id).first()
- if info is None:
- new_entity = DangerLocationPersonAlarm(**data)
- db.add(new_entity)
- else:
- db.query(DangerLocationPersonAlarm).filter(DangerLocationPersonAlarm.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.5.5.区域报警数据
- @router.post('/zone/alarm', 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(DangerLocationZoneAlarm).filter(DangerLocationZoneAlarm.id == id).first()
- if info is None:
- new_entity = DangerLocationZoneAlarm(**data)
- db.add(new_entity)
- else:
- db.query(DangerLocationZoneAlarm).filter(DangerLocationZoneAlarm.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":{}
- }
|