monitor.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. from fastapi import APIRouter, Request, Depends, Form, Body, File, UploadFile
  4. from database import get_db
  5. from utils.StripTagsHTMLParser import *
  6. from sqlalchemy.orm import Session
  7. from datetime import datetime, timedelta
  8. import jwt
  9. from passlib.context import CryptContext
  10. from models import *
  11. from sqlalchemy import text, exists, and_, or_, not_
  12. from sqlalchemy.sql import func
  13. from models import *
  14. from extensions import logger
  15. from utils import *
  16. import traceback
  17. router = APIRouter()
  18. # 2.2.2.5.在线监测报警
  19. # 2.2.2.5.1.监测指标信息
  20. @router.post('/info', description='提交监测指标信息')
  21. async def index(
  22. request: Request,
  23. db: Session = Depends(get_db),
  24. data: dict = Depends(remove_xss_json)
  25. ):
  26. try:
  27. id = get_req_param(data, 'id')
  28. company_industry = db.query(DangerMonitorInfo).filter(DangerMonitorInfo.id == id).first()
  29. if company_industry is None:
  30. new_entity = DangerMonitorInfo(**data)
  31. db.add(new_entity)
  32. else:
  33. db.query(DangerMonitorInfo).filter(DangerMonitorInfo.id == id).update(data)
  34. db.commit()
  35. return {
  36. "code":1,
  37. "message":"成功",
  38. "data":{}
  39. }
  40. except Exception as e:
  41. traceback.print_exc()
  42. return {
  43. "code":0,
  44. "message":"更新异常,错误信息:" + str(e),
  45. "data":{}
  46. }
  47. # 2.2.2.5.2.监测指标实时数据
  48. @router.post('/data', description='提交监测指标实时数据')
  49. async def index(
  50. request: Request,
  51. db: Session = Depends(get_db),
  52. data: dict = Depends(remove_xss_json)
  53. ):
  54. try:
  55. id = get_req_param(data, 'id')
  56. company_industry = db.query(DangerMonitorData).filter(DangerMonitorData.id == id).first()
  57. if company_industry is None:
  58. new_entity = DangerMonitorData(**data)
  59. db.add(new_entity)
  60. else:
  61. db.query(DangerMonitorData).filter(DangerMonitorData.id == id).update(data)
  62. db.commit()
  63. return {
  64. "code":1,
  65. "message":"成功",
  66. "data":{}
  67. }
  68. except Exception as e:
  69. traceback.print_exc()
  70. return {
  71. "code":0,
  72. "message":"更新异常,错误信息:" + str(e),
  73. "data":{}
  74. }
  75. # 2.2.2.5.3.报警数据报文
  76. @router.post('/alarm', description='提交报警数据报文')
  77. async def index(
  78. request: Request,
  79. db: Session = Depends(get_db),
  80. data: dict = Depends(remove_xss_json)
  81. ):
  82. try:
  83. id = get_req_param(data, 'id')
  84. company_industry = db.query(DangerMonitorAlarm).filter(DangerMonitorAlarm.id == id).first()
  85. if company_industry is None:
  86. new_entity = DangerMonitorAlarm(**data)
  87. db.add(new_entity)
  88. else:
  89. db.query(DangerMonitorAlarm).filter(DangerMonitorAlarm.id == id).update(data)
  90. db.commit()
  91. return {
  92. "code":1,
  93. "message":"成功",
  94. "data":{}
  95. }
  96. except Exception as e:
  97. traceback.print_exc()
  98. return {
  99. "code":0,
  100. "message":"更新异常,错误信息:" + str(e),
  101. "data":{}
  102. }
  103. # 2.2.2.5.4.视频智能监控数据
  104. @router.post('/video', description='提交视频智能监控数据')
  105. async def index(
  106. request: Request,
  107. db: Session = Depends(get_db),
  108. data: dict = Depends(remove_xss_json)
  109. ):
  110. try:
  111. id = get_req_param(data, 'id')
  112. company_industry = db.query(DangerMonitorVideo).filter(DangerMonitorVideo.id == id).first()
  113. if company_industry is None:
  114. new_entity = DangerMonitorVideo(**data)
  115. db.add(new_entity)
  116. else:
  117. db.query(DangerMonitorVideo).filter(DangerMonitorVideo.id == id).update(data)
  118. db.commit()
  119. return {
  120. "code":1,
  121. "message":"成功",
  122. "data":{}
  123. }
  124. except Exception as e:
  125. traceback.print_exc()
  126. return {
  127. "code":0,
  128. "message":"更新异常,错误信息:" + str(e),
  129. "data":{}
  130. }