qyjcxx.py 5.6 KB

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