__init__.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. from . import device, company, certificate, third
  18. router = APIRouter()
  19. router.include_router(device.router, prefix="/device")
  20. router.include_router(company.router, prefix="/company")
  21. router.include_router(certificate.router, prefix="/certificate")
  22. router.include_router(third.router, prefix="/third")
  23. # 2.2.1.13.人员基础信息
  24. @router.post('/staff/info', description='提交人员基础信息')
  25. async def post_company_industry(
  26. request: Request,
  27. db: Session = Depends(get_db),
  28. data: dict = Depends(remove_xss_json)
  29. ):
  30. try:
  31. id = get_req_param(data, 'id')
  32. info = db.query(DangerBaseStaffInfo).filter(DangerBaseStaffInfo.id == id).first()
  33. if info is None:
  34. new_entity = DangerBaseStaffInfo(**data)
  35. db.add(new_entity)
  36. else:
  37. db.query(DangerBaseStaffInfo).filter(DangerBaseStaffInfo.id == id).update(data)
  38. db.commit()
  39. return {
  40. "code":1,
  41. "message":"成功",
  42. "data":{}
  43. }
  44. except Exception as e:
  45. traceback.print_exc()
  46. return {
  47. "code":0,
  48. "message":"更新异常,错误信息:" + str(e),
  49. "data":{}
  50. }
  51. # 2.2.1.14.值班值守
  52. @router.post('/duty/info', description='提交值班值守信息')
  53. async def post_duty_info(
  54. request: Request,
  55. db: Session = Depends(get_db),
  56. data: dict = Depends(remove_xss_json)
  57. ):
  58. try:
  59. id = get_req_param(data, 'id')
  60. info = db.query(DangerBaseDutyInfo).filter(DangerBaseDutyInfo.id == id).first()
  61. if info is None:
  62. new_entity = DangerBaseDutyInfo(**data)
  63. db.add(new_entity)
  64. else:
  65. db.query(DangerBaseDutyInfo).filter(DangerBaseDutyInfo.id == id).update(data)
  66. db.commit()
  67. return {
  68. "code":1,
  69. "message":"成功",
  70. "data":{}
  71. }
  72. except Exception as e:
  73. traceback.print_exc()
  74. return {
  75. "code":0,
  76. "message":"更新异常,错误信息:" + str(e),
  77. "data":{}
  78. }
  79. # 2.2.1.16.摄像头信息
  80. @router.post('/video/info', description='提交摄像头信息')
  81. async def post_video_info(
  82. request: Request,
  83. db: Session = Depends(get_db),
  84. data: dict = Depends(remove_xss_json)
  85. ):
  86. try:
  87. id = get_req_param(data, 'id')
  88. info = db.query(DangerBaseVideoInfo).filter(DangerBaseVideoInfo.id == id).first()
  89. if info is None:
  90. new_entity = DangerBaseVideoInfo(**data)
  91. db.add(new_entity)
  92. else:
  93. db.query(DangerBaseVideoInfo).filter(DangerBaseVideoInfo.id == id).update(data)
  94. db.commit()
  95. return {
  96. "code":1,
  97. "message":"成功",
  98. "data":{}
  99. }
  100. except Exception as e:
  101. traceback.print_exc()
  102. return {
  103. "code":0,
  104. "message":"更新异常,错误信息:" + str(e),
  105. "data":{}
  106. }
  107. # 2.2.1.17.1.10.危险化学品目录信息表
  108. @router.get('/medium/menu')
  109. @router.post('/medium/menu', description='获取危险化学品目录信息表')
  110. async def get_medium_menu(
  111. request: Request,
  112. db: Session = Depends(get_db),
  113. data: dict = Depends(remove_xss_json)
  114. ):
  115. try:
  116. data = []
  117. rows = db.query(DangerBaseMediumMenu).all()
  118. for row in rows:
  119. data.append({
  120. "id": row.id,
  121. "medium": row.medium,
  122. "alias": row.alias,
  123. "cas": row.cas,
  124. "description": row.description,
  125. "deleted": row.deleted
  126. })
  127. return {
  128. "code":1,
  129. "message":"成功",
  130. "time": unixstamp(),
  131. "data": data
  132. }
  133. except Exception as e:
  134. traceback.print_exc()
  135. return {
  136. "code":0,
  137. "message":"获取异常,错误信息:" + str(e),
  138. "data":{}
  139. }