#!/usr/bin/env python3 # -*- coding: utf-8 -*- from fastapi import APIRouter, Request, Depends from database import get_db from sqlalchemy.orm import Session from utils import * from utils.sg_auth import * from models import * from sqlalchemy import text, exists, and_, or_, not_ router = APIRouter() @router.post("/accept") async def accept( request: Request, ext_info: str = Depends(yst_pass_ext), param: dict = Depends(yst_request_param), db: Session = Depends(get_db) ): bzid = get_req_param(param, 'uuid') print(param) new_yhpcsb = YstYhpcsbEntity( bzid = bzid, fzdc = get_req_param(param, 'fzdc'), fzr = get_req_param(param, 'fzr'), fzrdh = get_req_param(param, 'fzrdh'), gm = get_req_param(param, 'gm'), gzcs = get_req_param(param, 'gzcs'), qzjjss = get_req_param(param, 'qzjjss'), swxrs = get_req_param(param, 'swxrs'), szdq = get_req_param(param, 'szdq'), xxdz = get_req_param(param, 'xxdz'), yhdmc = get_req_param(param, 'yhdmc'), yhdzt = get_req_param(param, 'yhdzt'), ywfzya = get_req_param(param, 'ywfzya'), zhlx = get_req_param(param, 'zhlx'), create_time = datetime.now() ) db.add(new_yhpcsb) db.commit() db.query(YssYstUploadFileEntity).filter(YssYstUploadFileEntity.uuid == bzid).update({"bzid": bzid}) db.commit() resp = { 'ret': 0, 'msg': "您的隐患排查上报已成功提交。" } return yst_response(resp) @router.post("/query") async def query( request: Request, ext_info: str = Depends(yst_pass_ext), param: dict = Depends(yst_request_param), db: Session = Depends(get_db) ): rows = db.query(YstYhpcsbEntity).all() data = [ { "id": row.id, "yhdmc": row.yhdmc, "yhdzt": row.yhdzt, "szdq": row.szdq, "create_time": get_datetime_str(row.create_time) } for row in rows ] resp = { 'ret': 0, 'data': data } return yst_response(resp) @router.post("/detail") async def detail( request: Request, ext_info: str = Depends(yst_pass_ext), param: dict = Depends(yst_request_param), db: Session = Depends(get_db) ): id = get_req_param(param, 'id') row = db.query(YstYhpcsbEntity).filter(YstYhpcsbEntity.id == id).first() data = get_model_dict(row) data["create_time"] = get_datetime_str(row.create_time) resp = { 'ret': 0, 'msg': '', 'data': data } return yst_response(resp)