__init__.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 source, monitor
  18. router = APIRouter()
  19. router.include_router(source.router, prefix="/source")
  20. router.include_router(monitor.router, prefix="/monitor")
  21. # 2.2.1.12.生产过程基础信息
  22. @router.post('/process/info', description='提交生产过程基础信息')
  23. async def index(
  24. request: Request,
  25. db: Session = Depends(get_db),
  26. data: dict = Depends(remove_xss_json)
  27. ):
  28. try:
  29. id = get_req_param(data, 'id')
  30. company_industry = db.query(DangerProcessInfo).filter(DangerProcessInfo.id == id).first()
  31. if company_industry is None:
  32. new_entity = DangerProcessInfo(**data)
  33. db.add(new_entity)
  34. else:
  35. db.query(DangerProcessInfo).filter(DangerProcessInfo.id == id).update(data)
  36. db.commit()
  37. return {
  38. "code":1,
  39. "message":"成功",
  40. "data":{}
  41. }
  42. except Exception as e:
  43. traceback.print_exc()
  44. return {
  45. "code":0,
  46. "message":"更新异常,错误信息:" + str(e),
  47. "data":{}
  48. }
  49. # 2.2.2.1.安全承诺详情数据
  50. @router.post('/manager/promise', description='提交安全承诺详情数据')
  51. async def index(
  52. request: Request,
  53. db: Session = Depends(get_db),
  54. data: dict = Depends(remove_xss_json)
  55. ):
  56. try:
  57. id = get_req_param(data, 'id')
  58. company_industry = db.query(DangerManagerPromise).filter(DangerManagerPromise.id == id).first()
  59. if company_industry is None:
  60. new_entity = DangerManagerPromise(**data)
  61. db.add(new_entity)
  62. else:
  63. db.query(DangerManagerPromise).filter(DangerManagerPromise.id == id).update(data)
  64. db.commit()
  65. return {
  66. "code":1,
  67. "message":"成功",
  68. "data":{}
  69. }
  70. except Exception as e:
  71. traceback.print_exc()
  72. return {
  73. "code":0,
  74. "message":"更新异常,错误信息:" + str(e),
  75. "data":{}
  76. }
  77. # 2.2.2.2.预警推送数据表
  78. @router.post('/warn/event', description='提交预警推送数据表')
  79. async def index(
  80. request: Request,
  81. db: Session = Depends(get_db),
  82. data: dict = Depends(remove_xss_json)
  83. ):
  84. try:
  85. id = get_req_param(data, 'id')
  86. company_industry = db.query(DangerWarnEvent).filter(DangerWarnEvent.id == id).first()
  87. if company_industry is None:
  88. new_entity = DangerWarnEvent(**data)
  89. db.add(new_entity)
  90. else:
  91. db.query(DangerWarnEvent).filter(DangerWarnEvent.id == id).update(data)
  92. db.commit()
  93. return {
  94. "code":1,
  95. "message":"成功",
  96. "data":{}
  97. }
  98. except Exception as e:
  99. traceback.print_exc()
  100. return {
  101. "code":0,
  102. "message":"更新异常,错误信息:" + str(e),
  103. "data":{}
  104. }
  105. @router.post('/warn/getEvent', description='获取预警推送数据表')
  106. async def index(
  107. request: Request,
  108. db: Session = Depends(get_db),
  109. data: dict = Depends(remove_xss_json)
  110. ):
  111. try:
  112. credit_code = get_req_param(data, 'credit_code')
  113. page = get_req_param_optional(data, 'page')
  114. limit = get_req_param_optional(data, 'limit')
  115. page = int(page) if page != '' else 1
  116. limit = int(page) if limit != '' else 10
  117. data_list = []
  118. query = db.query(DangerWarnEvent).filter(DangerWarnEvent.deleted == '0').filter(DangerWarnEvent.credit_code == credit_code)
  119. query = query.order_by(DangerWarnEvent.create_date.asc())
  120. # 计算总条目数
  121. total_items = query.count()
  122. # 执行分页查询
  123. rows = query.offset((page - 1) * limit).limit(limit).all()
  124. for row in rows:
  125. data_list.append({
  126. "id": row.id,
  127. "credit_code": row.credit_code,
  128. "rank": row.rank,
  129. "message": row.message,
  130. "start_time": get_datetime_str(row.start_time)
  131. })
  132. return {
  133. "code":1,
  134. "message":"成功",
  135. "data": {
  136. "page": page,
  137. "limit": limit,
  138. "total": total_items,
  139. "list": data_list
  140. }
  141. }
  142. except Exception as e:
  143. traceback.print_exc()
  144. return {
  145. "code":0,
  146. "message":"获取异常,错误信息:" + str(e),
  147. "data":{}
  148. }