123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- #!/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.1.企业基本信息
- @router.post('/info', description='提交企业基本信息')
- async def post_company_info(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_info = db.query(DangerBaseCompanyInfo).filter(DangerBaseCompanyInfo.id == id).first()
- if company_info is None:
- new_entity = DangerBaseCompanyInfo(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseCompanyInfo).filter(DangerBaseCompanyInfo.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.2.企业隶属化工行业关系表
- @router.post('/industry', 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(DangerBaseCompanyIndustry).filter(DangerBaseCompanyIndustry.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseCompanyIndustry(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseCompanyIndustry).filter(DangerBaseCompanyIndustry.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.3.企业隶属重点行业关系表
- @router.post('/keyIndustry', 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(DangerBaseCompanyKeyIndustry).filter(DangerBaseCompanyKeyIndustry.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseCompanyKeyIndustry(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseCompanyKeyIndustry).filter(DangerBaseCompanyKeyIndustry.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.4.危险化学品信息
- @router.post('/chemical', description='提交危险化学品信息')
- async def post_company_chemical(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerBaseCompanyChemical).filter(DangerBaseCompanyChemical.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseCompanyChemical(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseCompanyChemical).filter(DangerBaseCompanyChemical.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.5.企业重点监管工艺信息
- @router.post('/crafts', description='提交企业重点监管工艺信息')
- async def post_company_crafts(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- company_industry = db.query(DangerBaseCompanyCrafts).filter(DangerBaseCompanyCrafts.id == id).first()
- if company_industry is None:
- new_entity = DangerBaseCompanyCrafts(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseCompanyCrafts).filter(DangerBaseCompanyCrafts.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.15.企业事故事件
- @router.post('/accident', description='提交企业事故事件信息')
- async def post_company_accident(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- info = db.query(DangerBaseCompanyAccident).filter(DangerBaseCompanyAccident.id == id).first()
- if info is None:
- new_entity = DangerBaseCompanyAccident(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseCompanyAccident).filter(DangerBaseCompanyAccident.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.18.1.企业“三同时”监管
- @router.post('/supervise', description='提交企业“三同时”监管')
- async def post_company_supervise(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- id = get_req_param(data, 'id')
- info = db.query(DangerBaseCompanySupervise).filter(DangerBaseCompanySupervise.id == id).first()
- if info is None:
- new_entity = DangerBaseCompanySupervise(**data)
- db.add(new_entity)
- else:
- db.query(DangerBaseCompanySupervise).filter(DangerBaseCompanySupervise.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":{}
- }
|