123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- #!/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.sg_auth import *
- from models import *
- from utils 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)
- ):
- logger.info(param)
- try:
- uuid_str = get_req_param(param, 'uuid')
- qydz = get_req_param(param, 'qydz')
- qymc = get_req_param(param, 'qymc')
- qyjb = get_req_param(param, 'qyjb')
- szdq = get_req_param(param, 'szdq')
- xxdz = get_req_param(param, 'xxdz')
- zrrxm = get_req_param(param, 'zrrxm')
- zrrdh = get_req_param(param, 'zrrdh')
- sfzh = ext_info['cid']
- xm = ext_info['name']
-
- redis_key = "mmyj_yhxx_" + uuid_str
- 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 == uuid_str).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(YstQyjcxxEntity).filter(YstQyjcxxEntity.bzid == uuid_str).filter(YstQyjcxxEntity.status == 0).delete()
- db.commit()
- db_entity = YstQyjcxxEntity()
- db_entity.bzid = uuid_str
- db_entity.sfzh = sfzh
- db_entity.xm = xm
- db_entity.qymc = qymc
- db_entity.qydz = qydz
- db_entity.qyjb = qyjb
- db_entity.szdq = szdq
- db_entity.xxdz = xxdz
- db_entity.zrrxm = zrrxm
- db_entity.zrrdh = zrrdh
- db_entity.status = 1
- db_entity.create_time = datetime.now()
- db.add(db_entity)
- db.commit()
-
- # 已提交状态
- jdsm = '您的应急企业基础信息已提交成功,请耐心等待茂名市应急管理局审核。'
- process_entity = YstProcessEntity(bzid=uuid_str, sfzh=sfzh, sqly='yss', zt=0, ztsm='已提交', jdsm=jdsm, djsj=unixstamp(), bzlx='应急企业基础信息')
- db.add(process_entity)
- db.commit()
- # 审核中
- jdsm = '茂名市应急管理局正在审核您所递交的申请材料。'
- process_entity = YstProcessEntity(bzid=uuid_str, 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': uuid_str
- }
- }
- return yst_response(result)
-
- except AppException as e:
- traceback.print_exc()
- result = {
- 'ret': 1,
- 'msg': "服务异常,本次办理提交失败,您可尝试重新提交。"
- }
- 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(YstQyjcxxEntity).filter(YstQyjcxxEntity.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']
- }
- jcxxMap = {
- '所在地区': data['szdq'],
- '详细地址': data['xxdz'],
- '责任人姓名': xm_tuomin(data['zrrxm']),
- '责任人电话': sj_tuomin(data['zrrdh'])
- }
- resp = {
- 'ret': 0,
- 'timeline': timeline,
- 'qyxxMap': qyxxMap,
- 'jcxxMap': jcxxMap
- }
- 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
- }
|