#!/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":{} }