123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- #!/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']
- xm = ext_info['name']
- qydm = ext_info['corp']['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(YstQyyjyaEntity).filter(YstQyyjyaEntity.bzid == bzid).filter(YstQyyjyaEntity.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(YstQyyjyaEntity).filter(YstQyyjyaEntity.bzid == bzid).filter(YstQyyjyaEntity.status == 0).delete()
- db.commit()
- new_yhpcsb = YstQyyjyaEntity(
- bzid = bzid,
- sfzh = sfzh,
- xm = xm,
- qydm = qydm,
- qymc = get_req_param(param, 'qymc'),
- qydz = get_req_param(param, 'qydz'),
- qyjb = get_req_param(param, 'qyjb'),
- bzmd = get_req_param(param, 'bzmd'),
- bzyj = get_req_param(param, 'bzyj'),
- qygk = get_req_param(param, 'qygk'),
- wxxfx = get_req_param(param, 'wxxfx'),
- syfw = get_req_param(param, 'syfw'),
- yjjyyz = get_req_param(param, 'yjjyyz'),
- yjczcs = get_req_param(param, 'yjczcs'),
- yjxy = get_req_param(param, 'yjxy'),
-
- status = 1,
- create_time = datetime.now()
- )
- db.add(new_yhpcsb)
- db.commit()
- db.query(YssYstUploadFileEntity).filter(YssYstUploadFileEntity.uuid == bzid).update({"bzid": bzid})
- db.commit()
- # 已提交状态
- jdsm = '您的应急企业基础信息已提交成功,请耐心等待茂名市应急管理局审核。'
- process_entity = YstProcessEntity(bzid=bzid, sfzh=sfzh, sqly='yss', zt=0, ztsm='已提交', jdsm=jdsm, djsj=unixstamp(), bzlx='应急预案上报')
- db.add(process_entity)
- db.commit()
- # 审核中
- jdsm = '茂名市应急管理局正在审核您所递交的申请材料。'
- process_entity = YstProcessEntity(bzid=bzid, sfzh=sfzh, sqly='yst', zt=10, ztsm='审核中', jdsm=jdsm, djsj=unixstamp()+1, bzlx='应急预案上报')
- db.add(process_entity)
- db.commit()
- result = {
- 'ret': 0,
- 'msg': '您的应急预案上报已提交成功,请耐心等待审核。',
- 'data': {
- 'ywid': bzid
- }
- }
- return yst_response(result)
-
- except AppException as e:
- traceback.print_exc()
- result = {
- 'ret': 1,
- 'msg': "服务异常,本次办理提交失败,您可尝试重新提交。",
- 'data': {
- 'ywid': db_entity.bzid
- }
- }
- return pt_sg_response(result)
-
- @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)
- ):
- sfzh = ext_info['cid']
- bzid = get_req_param(param, 'bzid')
- q = db.query(YstProcessEntity)
- rows = q.filter(YstProcessEntity.bzid == bzid).order_by(YstProcessEntity.djsj.desc()).all()
-
- # 进度页
- timeline = []
- row_count = len(rows)
- for i in range(0, row_count):
- timeline.append(format_process_rec(i, row_count, rows[i]))
- # 详情页
- row = db.query(YstQyyjyaEntity).filter(YstQyyjyaEntity.bzid == bzid).first()
- if row is None:
- resp = {
- 'ret': 1,
- 'msg': '记录为空'
- }
- return yst_response(resp)
- data = get_model_dict(row)
- qyxxMap = {
- '企业名称': data['qymc'],
- '企业级别': data['qyjb'],
- '企业地址': data['qydz']
- }
- yjyaMap = {
- '编制目的': data['bzmd'],
- '编制依据': data['bzyj'],
- '企业概况': data['qygk'],
- '危险性分析': data['wxxfx'],
- '适用范围': data['syfw'],
- '应急救援原则': data['yjjyyz'],
- '应急处置措施': data['yjczcs'],
- '应急响应': data['yjxy']
- }
- qtFile = []
- imageUrls = []
- rows = db.query(YssYstUploadFileEntity).filter(and_(YssYstUploadFileEntity.bzid == bzid, YssYstUploadFileEntity.file_type == 'yjya')).all()
- for row in rows:
- imageUrls.append(row.file_name)
- if len(imageUrls) > 0:
- qtFile.append({'fileName': '预案附件', 'imageUrls': imageUrls})
- resp = {
- 'ret': 0,
- 'timeline': timeline,
- 'qyxxMap': qyxxMap,
- 'yjyaMap': yjyaMap,
- 'qtFile': qtFile
- }
- return yst_response(resp)
- def format_process_rec(i: int, count: int, row: YstProcessEntity):
- icon = ''
- title = row.ztsm
- desc = row.jdsm
- time_str = from_timestamp(row.djsj)
- action = 0
- action_text = ''
- active = 0
- if i == 0 and row.zt == 10: # 审核中
- icon = 'pending'
- elif i == 0 and row.zt == 1: # 审核通过
- icon = ''
- elif i == 0 and row.zt == 4: # 已办结
- icon = 'success'
- elif i == 0 and row.zt == 9: # 拒绝
- icon = 'warn'
- action = 1
- action_text = '重新提交'
- elif i == 0 and row.zt == 3: # 再次申请
- icon = 'warn'
- action = 1
- action_text = '重新提交'
-
- return {
- 'icon': icon,
- 'title':title,
- 'desc': desc,
- 'time': time_str,
- 'action': action,
- 'action_text': action_text,
- 'active': active
- }
|