123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- #!/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.13.第三方单位管理
- # 2.2.1.20.1.第三方单位基本信息
- @router.post('/company', description='提交第三方单位信息')
- async def index(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- info = db.query(DangerBaseThirdCompany).filter(DangerBaseThirdCompany.id == id).first()
- if info is None:
- new_entity = DangerBaseThirdCompany(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseThirdCompany).filter(DangerBaseThirdCompany.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.20.2.第三方人员信息
- @router.post('/staff', description='提交第三方人员基础信息')
- async def index(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- info = db.query(DangerBaseThirdStaff).filter(DangerBaseThirdStaff.id == id).first()
- if info is None:
- new_entity = DangerBaseThirdStaff(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseThirdStaff).filter(DangerBaseThirdStaff.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.20.3.第三方人员证书信息
- @router.post('/staffCertificate', description='提交第三方人员证书信息')
- async def index(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- info = db.query(DangerBaseThirdStaffCertificate).filter(DangerBaseThirdStaffCertificate.id == id).first()
- if info is None:
- new_entity = DangerBaseThirdStaffCertificate(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseThirdStaffCertificate).filter(DangerBaseThirdStaffCertificate.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.20.4.第三方单位资质信息
- @router.post('/companyCertificate', description='提交第三方单位资质信息')
- async def index(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- info = db.query(DangerBaseThirdCompanyCertificate).filter(DangerBaseThirdCompanyCertificate.id == id).first()
- if info is None:
- new_entity = DangerBaseThirdCompanyCertificate(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseThirdCompanyCertificate).filter(DangerBaseThirdCompanyCertificate.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.20.5.第三方单位安全教育培训记录
- @router.post('/staffTrain', description='提交第三方单位安全教育培训信息')
- async def index(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- info = db.query(DangerBaseThirdStaffTrain).filter(DangerBaseThirdStaffTrain.id == id).first()
- if info is None:
- new_entity = DangerBaseThirdStaffTrain(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseThirdStaffTrain).filter(DangerBaseThirdStaffTrain.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.20.6.第三方单位违规记录
- @router.post('/violation', description='提交第三方单位违规记录信息')
- async def index(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- info = db.query(DangerBaseThirdViolation).filter(DangerBaseThirdViolation.id == id).first()
- if info is None:
- new_entity = DangerBaseThirdViolation(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseThirdViolation).filter(DangerBaseThirdViolation.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.20.7.第三方单位服务记录
- @router.post('/serve', description='提交第三方单位服务记录信息')
- async def index(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- info = db.query(DangerBaseThirdServe).filter(DangerBaseThirdServe.id == id).first()
- if info is None:
- new_entity = DangerBaseThirdServe(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseThirdServe).filter(DangerBaseThirdServe.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":{}
- }
|