qyjcxx.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. from fastapi import APIRouter, Request, Depends
  4. from database import get_db
  5. from sqlalchemy.orm import Session
  6. from utils.sg_auth import *
  7. from models import *
  8. from utils import *
  9. from sqlalchemy import text, exists, and_, or_, not_
  10. from exceptions import *
  11. import traceback
  12. router = APIRouter()
  13. @router.post("/accept")
  14. async def accept(
  15. request: Request,
  16. ext_info: str = Depends(yst_pass_ext),
  17. param: dict = Depends(yst_request_param),
  18. db: Session = Depends(get_db)
  19. ):
  20. logger.info(param)
  21. try:
  22. uuid_str = get_req_param(param, 'uuid')
  23. qydz = get_req_param(param, 'qydz')
  24. qymc = get_req_param(param, 'qymc')
  25. qyjb = get_req_param(param, 'qyjb')
  26. szdq = get_req_param(param, 'szdq')
  27. xxdz = get_req_param(param, 'xxdz')
  28. zrrxm = get_req_param(param, 'zrrxm')
  29. zrrdh = get_req_param(param, 'zrrdh')
  30. sfzh = ext_info['cid']
  31. redis_key = "mmyj_yhxx_" + uuid_str
  32. yhxx_info = redis_get_json(redis_key)
  33. if yhxx_info is None:
  34. raise AppException(code=1, msg="数据异常")
  35. db_entity = db.query(YstQyjcxxEntity).filter(YstQyjcxxEntity.bzid == uuid_str).filter(YstQyjcxxEntity.status == 1).first()
  36. if db_entity is not None:
  37. result = {
  38. 'ret': 0,
  39. 'msg': '您的应急企业基础信息已提交成功,请耐心等待审核。',
  40. 'data': {
  41. 'ywid': db_entity.bzid
  42. }
  43. }
  44. return pt_sg_response(result)
  45. db.query(YstQyjcxxEntity).filter(YstQyjcxxEntity.bzid == uuid_str).filter(YstQyjcxxEntity.status == 0).delete()
  46. db.commit()
  47. db_entity = YstQyjcxxEntity()
  48. db_entity.bzid = uuid_str
  49. db_entity.sfzh = sfzh
  50. db_entity.qymc = qymc
  51. db_entity.qydz = qydz
  52. db_entity.qyjb = qyjb
  53. db_entity.szdq = szdq
  54. db_entity.xxdz = xxdz
  55. db_entity.zrrxm = zrrxm
  56. db_entity.zrrdh = zrrdh
  57. db_entity.status = 1
  58. db_entity.create_time = datetime.now()
  59. db.add(db_entity)
  60. db.commit()
  61. # 已提交状态
  62. jdsm = '您的应急企业基础信息已提交成功,请耐心等待茂名市应急管理局审核。'
  63. process_entity = YstProcessEntity(bzid=uuid_str, sfzh=sfzh, sqly='yss', zt=0, ztsm='已提交', jdsm=jdsm, djsj=unixstamp(), bzlx='应急企业基础信息')
  64. db.add(process_entity)
  65. db.commit()
  66. # 审核中
  67. jdsm = '茂名市应急管理局正在审核您所递交的申请材料。'
  68. process_entity = YstProcessEntity(bzid=uuid_str, sfzh=sfzh, sqly='yst', zt=10, ztsm='审核中', jdsm=jdsm, djsj=unixstamp()+1, bzlx='应急企业基础信息')
  69. db.add(process_entity)
  70. db.commit()
  71. result = {
  72. 'ret': 0,
  73. 'msg': '您的应急企业基础信息已提交成功,请耐心等待审核。',
  74. 'data': {
  75. 'ywid': uuid_str
  76. }
  77. }
  78. return yst_response(result)
  79. except AppException as e:
  80. traceback.print_exc()
  81. result = {
  82. 'ret': 1,
  83. 'msg': "服务异常,本次办理提交失败,您可尝试重新提交。"
  84. }
  85. return pt_sg_response(result)
  86. @router.post("/detail")
  87. async def detail(
  88. request: Request,
  89. ext_info: str = Depends(yst_pass_ext),
  90. param: dict = Depends(yst_request_param),
  91. db: Session = Depends(get_db)
  92. ):
  93. sfzh = ext_info['cid']
  94. bzid = get_req_param(param, 'bzid')
  95. q = db.query(YstProcessEntity)
  96. rows = q.filter(YstProcessEntity.bzid == bzid).order_by(YstProcessEntity.djsj.desc()).all()
  97. # 进度页
  98. timeline = []
  99. row_count = len(rows)
  100. for i in range(0, row_count):
  101. timeline.append(format_process_rec(i, row_count, rows[i]))
  102. # 详情页
  103. row = db.query(YstQyjcxxEntity).filter(YstQyjcxxEntity.bzid == bzid).first()
  104. if row is None:
  105. resp = {
  106. 'ret': 1,
  107. 'msg': '记录为空'
  108. }
  109. return yst_response(resp)
  110. data = get_model_dict(row)
  111. qyxxMap = {
  112. '企业名称': data['qymc'],
  113. '企业级别': data['qyjb'],
  114. '企业地址': data['qydz']
  115. }
  116. jcxxMap = {
  117. '所在地区': data['szdq'],
  118. '详细地址': data['xxdz'],
  119. '责任人姓名': xm_tuomin(data['zrrxm']),
  120. '责任人电话': sj_tuomin(data['zrrdh'])
  121. }
  122. resp = {
  123. 'ret': 0,
  124. 'timeline': timeline,
  125. 'qyxxMap': qyxxMap,
  126. 'jcxxMap': jcxxMap
  127. }
  128. return yst_response(resp)
  129. def format_process_rec(i: int, count: int, row: YstProcessEntity):
  130. icon = ''
  131. title = row.ztsm
  132. desc = row.jdsm
  133. time_str = from_timestamp(row.djsj)
  134. action = 0
  135. action_text = ''
  136. active = 0
  137. if i == 0 and row.zt == 10: # 审核中
  138. icon = 'pending'
  139. elif i == 0 and row.zt == 1: # 审核通过
  140. icon = ''
  141. elif i == 0 and row.zt == 4: # 已办结
  142. icon = 'success'
  143. elif i == 0 and row.zt == 9: # 拒绝
  144. icon = 'warn'
  145. action = 1
  146. action_text = '重新提交'
  147. elif i == 0 and row.zt == 3: # 再次申请
  148. icon = 'warn'
  149. action = 1
  150. action_text = '重新提交'
  151. return {
  152. 'icon': icon,
  153. 'title':title,
  154. 'desc': desc,
  155. 'time': time_str,
  156. 'action': action,
  157. 'action_text': action_text,
  158. 'active': active
  159. }