123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- #!/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
- from . import source, monitor
- router = APIRouter()
- router.include_router(source.router, prefix="/source")
- router.include_router(monitor.router, prefix="/monitor")
- # 2.2.1.12.生产过程基础信息
- @router.post('/process/info', 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(DangerProcessInfo).filter(DangerProcessInfo.id == id).first()
- if company_industry is None:
- new_entity = DangerProcessInfo(**data)
- db.add(new_entity)
- else:
- db.query(DangerProcessInfo).filter(DangerProcessInfo.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.2.1.安全承诺详情数据
- @router.post('/manager/promise', 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(DangerManagerPromise).filter(DangerManagerPromise.id == id).first()
- if company_industry is None:
- new_entity = DangerManagerPromise(**data)
- db.add(new_entity)
- else:
- db.query(DangerManagerPromise).filter(DangerManagerPromise.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.2.2.预警推送数据表
- @router.post('/warn/event', 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(DangerWarnEvent).filter(DangerWarnEvent.id == id).first()
- if company_industry is None:
- new_entity = DangerWarnEvent(**data)
- db.add(new_entity)
- else:
- db.query(DangerWarnEvent).filter(DangerWarnEvent.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":{}
- }
-
- @router.post('/warn/getEvent', description='获取预警推送数据表')
- async def index(
- request: Request,
- db: Session = Depends(get_db),
- data: dict = Depends(remove_xss_json)
- ):
- try:
- credit_code = get_req_param(data, 'credit_code')
- page = get_req_param_optional(data, 'page')
- limit = get_req_param_optional(data, 'limit')
- page = int(page) if page != '' else 1
- limit = int(page) if limit != '' else 10
- data_list = []
- query = db.query(DangerWarnEvent).filter(DangerWarnEvent.deleted == '0').filter(DangerWarnEvent.credit_code == credit_code)
- query = query.order_by(DangerWarnEvent.create_date.asc())
- # 计算总条目数
- total_items = query.count()
- # 执行分页查询
- rows = query.offset((page - 1) * limit).limit(limit).all()
- for row in rows:
- data_list.append({
- "id": row.id,
- "credit_code": row.credit_code,
- "rank": row.rank,
- "message": row.message,
- "start_time": get_datetime_str(row.start_time)
- })
- return {
- "code":1,
- "message":"成功",
- "data": {
- "page": page,
- "limit": limit,
- "total": total_items,
- "list": data_list
- }
- }
- except Exception as e:
- traceback.print_exc()
- return {
- "code":0,
- "message":"获取异常,错误信息:" + str(e),
- "data":{}
- }
-
|