123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- #!/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_
- from exceptions import *
- import traceback
- 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)
- ):
- try:
- bzid = get_req_param(param, 'uuid')
- print(param)
- sfzh = ext_info['cid']
- redis_key = "mmyj_yhxx_" + bzid
- yhxx_info = redis_get_json(redis_key)
- if yhxx_info is None:
- raise AppException(code=1, msg="数据异常")
- db_entity = db.query(YstQyjcxxEntity).filter(YstQyjcxxEntity.bzid == bzid).filter(YstQyjcxxEntity.status == 1).first()
- if db_entity is not None:
- result = {
- 'ret': 0,
- 'msg': '您的隐患排查上报已成功提交。',
- 'data': {
- 'ywid': db_entity.bzid
- }
- }
- return pt_sg_response(result)
-
- db.query(YstYhpcsbEntity).filter(YstYhpcsbEntity.bzid == bzid).filter(YstYhpcsbEntity.status == 0).delete()
- db.commit()
- new_yhpcsb = YstYhpcsbEntity(
- bzid = bzid,
- sfzh = sfzh,
- qymc = get_req_param(param, 'qymc'),
- qydz = get_req_param(param, 'qydz'),
- qyjb = get_req_param(param, 'qyjb'),
- 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'),
- status = 1,
- 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)
-
- except AppException as e:
- traceback.print_exc()
- result = {
- 'ret': 1,
- 'msg': "服务异常,本次办理提交失败,您可尝试重新提交。"
- }
- return pt_sg_response(result)
- @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)
- ):
- sfzh = ext_info['cid']
- rows = db.query(YstYhpcsbEntity).filter(YstYhpcsbEntity.sfzh == sfzh).filter(YstYhpcsbEntity.status == 1).order_by(YstYhpcsbEntity.create_time.desc()).all()
- data = [
- {
- "id": row.id,
- "yhdmc": row.yhdmc,
- "yhdzt": row.yhdzt,
- "xxdz": row.xxdz,
- "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)
- ):
- try:
- sfzh = ext_info['cid']
- id = get_req_param(param, 'id')
- row = db.query(YstYhpcsbEntity).filter(YstYhpcsbEntity.sfzh == sfzh).filter(YstYhpcsbEntity.id == id).first()
- bzid = row.bzid
- data = get_model_dict(row)
- data["create_time"] = get_datetime_str(row.create_time)
- qtFile = []
- imageUrls = []
- rows = db.query(YssYstUploadFileEntity).filter(and_(YssYstUploadFileEntity.bzid == bzid, YssYstUploadFileEntity.file_type == 'yyzz')).all()
- for row in rows:
- imageUrls.append("/mmh5_yjxm_yst/ebus/yst_mmsyjjzhyjxt/api/yst/file/show?thumb=1&file_name={}".format(row.file_name))
- if len(imageUrls) > 0:
- qtFile.append({'fileName': '隐患点图片', 'imageUrls': imageUrls})
- resp = {
- 'ret': 0,
- 'msg': '',
- 'data': data,
- 'qtFile': qtFile
- }
- return yst_response(resp)
-
- except AppException as e:
- traceback.print_exc()
- result = {
- 'ret': 1,
- 'msg': "服务异常"
- }
- return pt_sg_response(result)
|