123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- #!/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
- import jwt
- 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.2.5.在线监测报警
- # 2.2.2.5.1.监测指标信息
- @router.post('/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')
- company_industry = db.query(DangerMonitorInfo).filter(DangerMonitorInfo.id == id).first()
- if company_industry is None:
- new_entity = DangerMonitorInfo(**data)
- db.add(new_entity)
- else:
- db.query(DangerMonitorInfo).filter(DangerMonitorInfo.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.2.5.2.监测指标实时数据
- @router.post('/data', description='提交监测指标实时数据')
- async def index(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerMonitorData).filter(DangerMonitorData.id == id).first()
- if company_industry is None:
- new_entity = DangerMonitorData(**data)
- db.add(new_entity)
- else:
- db.query(DangerMonitorData).filter(DangerMonitorData.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.2.5.3.报警数据报文
- @router.post('/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')
- company_industry = db.query(DangerMonitorAlarm).filter(DangerMonitorAlarm.id == id).first()
- if company_industry is None:
- new_entity = DangerMonitorAlarm(**data)
- db.add(new_entity)
- else:
- db.query(DangerMonitorAlarm).filter(DangerMonitorAlarm.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.2.5.4.视频智能监控数据
- @router.post('/video', description='提交视频智能监控数据')
- async def index(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerMonitorVideo).filter(DangerMonitorVideo.id == id).first()
- if company_industry is None:
- new_entity = DangerMonitorVideo(**data)
- db.add(new_entity)
- else:
- db.query(DangerMonitorVideo).filter(DangerMonitorVideo.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":{}
- }
|