123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525 |
- #!/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.1.7.设备基本信息
- @router.post('/info', description='提交设备基本信息')
- async def post_device_info(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerBaseDeviceInfo).filter(DangerBaseDeviceInfo.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseDeviceInfo(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseDeviceInfo).filter(DangerBaseDeviceInfo.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.1.8.特种设备登记信息
- @router.post('/special', description='提交特种设备登记信息')
- async def post_company_industry(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerBaseDeviceSpecial).filter(DangerBaseDeviceSpecial.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseDeviceSpecial(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseDeviceSpecial).filter(DangerBaseDeviceSpecial.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.1.9.安全阀信息
- @router.post('/safetyValve', description='提交安全阀信息')
- async def post_company_industry(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerBaseDeviceSafetyValve).filter(DangerBaseDeviceSafetyValve.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseDeviceSafetyValve(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseDeviceSafetyValve).filter(DangerBaseDeviceSafetyValve.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.1.10.爆破片信息
- @router.post('/burst', description='提交爆破片信息')
- async def post_company_industry(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerBaseDeviceBurst).filter(DangerBaseDeviceBurst.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseDeviceBurst(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseDeviceBurst).filter(DangerBaseDeviceBurst.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.1.11.安全仪表连锁信息
- @router.post('/instrument', description='提交安全仪表连锁信息')
- async def post_company_industry(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerBaseDeviceInstrument).filter(DangerBaseDeviceInstrument.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseDeviceInstrument(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseDeviceInstrument).filter(DangerBaseDeviceInstrument.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.1.17.1.1.监测设备信息
- @router.post('/detect', description='提交监测设备信息')
- async def post_device_detect(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerBaseDeviceDetect).filter(DangerBaseDeviceDetect.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseDeviceDetect(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseDeviceDetect).filter(DangerBaseDeviceDetect.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.1.17.1.2.储罐基础信息
- @router.post('/tank', description='提交储罐基础信息')
- async def post_device_tank(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerBaseDeviceTank).filter(DangerBaseDeviceTank.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseDeviceTank(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseDeviceTank).filter(DangerBaseDeviceTank.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.1.17.1.3.装置基础信息
- @router.post('/system', description='提交装置基础信息')
- async def post_device_system(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerBaseDeviceSystem).filter(DangerBaseDeviceSystem.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseDeviceSystem(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseDeviceSystem).filter(DangerBaseDeviceSystem.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.1.17.1.4.气体泄漏点基础信息
- @router.post('/gas', description='提交气体泄漏点基础信息')
- async def post_device_gas(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerBaseDeviceGas).filter(DangerBaseDeviceGas.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseDeviceGas(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseDeviceGas).filter(DangerBaseDeviceGas.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.1.17.1.5.仓库基础信息
- @router.post('/store', description='提交仓库基础信息')
- async def post_device_store(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerBaseDeviceStore).filter(DangerBaseDeviceStore.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseDeviceStore(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseDeviceStore).filter(DangerBaseDeviceStore.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.1.17.1.6.装卸台基础信息
- @router.post('/dock', description='提交仓库基础信息')
- async def post_device_dock(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerBaseDeviceStore).filter(DangerBaseDeviceStore.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseDeviceStore(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseDeviceStore).filter(DangerBaseDeviceStore.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.1.17.1.7.设备停用记录表
- @router.post('/stop', description='提交设备停用记录表')
- async def post_device_stop(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerBaseDeviceStop).filter(DangerBaseDeviceStop.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseDeviceStop(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseDeviceStop).filter(DangerBaseDeviceStop.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.1.17.1.8.设备介质基础信息表
- @router.post('/medium', description='提交设备介质基础信息表')
- async def post_device_medium(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerBaseDeviceMedium).filter(DangerBaseDeviceMedium.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseDeviceMedium(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseDeviceMedium).filter(DangerBaseDeviceMedium.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.1.17.1.9.设备介质组分信息表
- @router.post('/mediumGroup', description='提交设备介质组分信息表')
- async def post_device_mediumGroup(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerBaseDeviceMediumGroup).filter(DangerBaseDeviceMediumGroup.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseDeviceMediumGroup(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseDeviceMediumGroup).filter(DangerBaseDeviceMediumGroup.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.1.12.装置开停车和大检修备案
- # 2.2.1.12.1.装置大检修备案
- @router.post('/systemMaintenance', description='提交装置大检修备案记录信息')
- async def post_systemMaintenance(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerBaseDeviceSystemMaintenance).filter(DangerBaseDeviceSystemMaintenance.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseDeviceSystemMaintenance(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseDeviceSystemMaintenance).filter(DangerBaseDeviceSystemMaintenance.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.1.12.2.装置开停车管理
- @router.post('/systemStartStop', 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(DangerBaseDeviceSystemStartstop).filter(DangerBaseDeviceSystemStartstop.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseDeviceSystemStartstop(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseDeviceSystemStartstop).filter(DangerBaseDeviceSystemStartstop.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":{}
- }
|