location.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. from passlib.context import CryptContext
  9. from models import *
  10. from sqlalchemy import text, exists, and_, or_, not_
  11. from sqlalchemy.sql import func
  12. from models import *
  13. from extensions import logger
  14. from utils import *
  15. import traceback
  16. router = APIRouter()
  17. # 2.2.5.人员定位信息
  18. # 2.2.5.1.区域边界信息
  19. @router.post('/zone/info', description='提交区域边界信息')
  20. async def index(
  21. request: Request,
  22. db: Session = Depends(get_db),
  23. data: dict = Depends(remove_xss_json)
  24. ):
  25. try:
  26. id = get_req_param(data, 'id')
  27. info = db.query(DangerLocationZoneInfo).filter(DangerLocationZoneInfo.id == id).first()
  28. if info is None:
  29. new_entity = DangerLocationZoneInfo(**data)
  30. db.add(new_entity)
  31. else:
  32. db.query(DangerLocationZoneInfo).filter(DangerLocationZoneInfo.id == id).update(data)
  33. db.commit()
  34. return {
  35. "code":1,
  36. "message":"成功",
  37. "data":{}
  38. }
  39. except Exception as e:
  40. traceback.print_exc()
  41. return {
  42. "code":0,
  43. "message":"更新异常,错误信息:" + str(e),
  44. "data":{}
  45. }
  46. # 2.2.5.2.人员实时定位数据
  47. @router.post('/person/info', description='提交人员定位实时数据')
  48. async def index(
  49. request: Request,
  50. db: Session = Depends(get_db),
  51. data: dict = Depends(remove_xss_json)
  52. ):
  53. try:
  54. id = get_req_param(data, 'id')
  55. info = db.query(DangerLocationPersonInfo).filter(DangerLocationPersonInfo.id == id).first()
  56. if info is None:
  57. new_entity = DangerLocationPersonInfo(**data)
  58. db.add(new_entity)
  59. else:
  60. db.query(DangerLocationPersonInfo).filter(DangerLocationPersonInfo.id == id).update(data)
  61. db.commit()
  62. return {
  63. "code":1,
  64. "message":"成功",
  65. "data":{}
  66. }
  67. except Exception as e:
  68. traceback.print_exc()
  69. return {
  70. "code":0,
  71. "message":"更新异常,错误信息:" + str(e),
  72. "data":{}
  73. }
  74. # 2.2.5.3.人员聚集数据
  75. @router.post('/person/area', description='提交人员聚集数据')
  76. async def index(
  77. request: Request,
  78. db: Session = Depends(get_db),
  79. data: dict = Depends(remove_xss_json)
  80. ):
  81. try:
  82. id = get_req_param(data, 'id')
  83. info = db.query(DangerLocationPersonArea).filter(DangerLocationPersonArea.id == id).first()
  84. if info is None:
  85. new_entity = DangerLocationPersonArea(**data)
  86. db.add(new_entity)
  87. else:
  88. db.query(DangerLocationPersonArea).filter(DangerLocationPersonArea.id == id).update(data)
  89. db.commit()
  90. return {
  91. "code":1,
  92. "message":"成功",
  93. "data":{}
  94. }
  95. except Exception as e:
  96. traceback.print_exc()
  97. return {
  98. "code":0,
  99. "message":"更新异常,错误信息:" + str(e),
  100. "data":{}
  101. }
  102. # 2.2.5.4.人员报警数据
  103. @router.post('/person/alarm', description='提交人员报警数据')
  104. async def index(
  105. request: Request,
  106. db: Session = Depends(get_db),
  107. data: dict = Depends(remove_xss_json)
  108. ):
  109. try:
  110. id = get_req_param(data, 'id')
  111. info = db.query(DangerLocationPersonAlarm).filter(DangerLocationPersonAlarm.id == id).first()
  112. if info is None:
  113. new_entity = DangerLocationPersonAlarm(**data)
  114. db.add(new_entity)
  115. else:
  116. db.query(DangerLocationPersonAlarm).filter(DangerLocationPersonAlarm.id == id).update(data)
  117. db.commit()
  118. return {
  119. "code":1,
  120. "message":"成功",
  121. "data":{}
  122. }
  123. except Exception as e:
  124. traceback.print_exc()
  125. return {
  126. "code":0,
  127. "message":"更新异常,错误信息:" + str(e),
  128. "data":{}
  129. }
  130. # 2.2.5.5.区域报警数据
  131. @router.post('/zone/alarm', description='提交区域报警数据')
  132. async def index(
  133. request: Request,
  134. db: Session = Depends(get_db),
  135. data: dict = Depends(remove_xss_json)
  136. ):
  137. try:
  138. id = get_req_param(data, 'id')
  139. info = db.query(DangerLocationZoneAlarm).filter(DangerLocationZoneAlarm.id == id).first()
  140. if info is None:
  141. new_entity = DangerLocationZoneAlarm(**data)
  142. db.add(new_entity)
  143. else:
  144. db.query(DangerLocationZoneAlarm).filter(DangerLocationZoneAlarm.id == id).update(data)
  145. db.commit()
  146. return {
  147. "code":1,
  148. "message":"成功",
  149. "data":{}
  150. }
  151. except Exception as e:
  152. traceback.print_exc()
  153. return {
  154. "code":0,
  155. "message":"更新异常,错误信息:" + str(e),
  156. "data":{}
  157. }