qyjcxx.py 5.5 KB

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