qyyjya.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 import *
  7. from utils.sg_auth import *
  8. from models 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. try:
  21. bzid = get_req_param(param, 'uuid')
  22. print(param)
  23. sfzh = ext_info['cid']
  24. xm = ext_info['name']
  25. qydm = ext_info['corp']['cid']
  26. redis_key = "mmyj_yhxx_" + bzid
  27. yhxx_info = redis_get_json(redis_key)
  28. if yhxx_info is None:
  29. raise AppException(code=1, msg="数据异常")
  30. db_entity = db.query(YstQyyjyaEntity).filter(YstQyyjyaEntity.bzid == bzid).filter(YstQyyjyaEntity.status == 1).first()
  31. if db_entity is not None:
  32. result = {
  33. 'ret': 0,
  34. 'msg': '您的应急预案上报已提交成功,请耐心等待审核。',
  35. 'data': {
  36. 'ywid': db_entity.bzid
  37. }
  38. }
  39. return pt_sg_response(result)
  40. db.query(YstQyyjyaEntity).filter(YstQyyjyaEntity.bzid == bzid).filter(YstQyyjyaEntity.status == 0).delete()
  41. db.commit()
  42. new_yhpcsb = YstQyyjyaEntity(
  43. bzid = bzid,
  44. sfzh = sfzh,
  45. xm = xm,
  46. qydm = qydm,
  47. qymc = get_req_param(param, 'qymc'),
  48. qydz = get_req_param(param, 'qydz'),
  49. qyjb = get_req_param(param, 'qyjb'),
  50. bzmd = get_req_param(param, 'bzmd'),
  51. bzyj = get_req_param(param, 'bzyj'),
  52. qygk = get_req_param(param, 'qygk'),
  53. wxxfx = get_req_param(param, 'wxxfx'),
  54. syfw = get_req_param(param, 'syfw'),
  55. yjjyyz = get_req_param(param, 'yjjyyz'),
  56. yjczcs = get_req_param(param, 'yjczcs'),
  57. yjxy = get_req_param(param, 'yjxy'),
  58. status = 1,
  59. create_time = datetime.now()
  60. )
  61. db.add(new_yhpcsb)
  62. db.commit()
  63. db.query(YssYstUploadFileEntity).filter(YssYstUploadFileEntity.uuid == bzid).update({"bzid": bzid})
  64. db.commit()
  65. # 已提交状态
  66. jdsm = '您的应急企业基础信息已提交成功,请耐心等待茂名市应急管理局审核。'
  67. process_entity = YstProcessEntity(bzid=bzid, 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=bzid, 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': bzid
  80. }
  81. }
  82. return yst_response(result)
  83. except AppException as e:
  84. traceback.print_exc()
  85. result = {
  86. 'ret': 1,
  87. 'msg': "服务异常,本次办理提交失败,您可尝试重新提交。",
  88. 'data': {
  89. 'ywid': db_entity.bzid
  90. }
  91. }
  92. return pt_sg_response(result)
  93. @router.post("/detail")
  94. async def detail(
  95. request: Request,
  96. ext_info: str = Depends(yst_pass_ext),
  97. param: dict = Depends(yst_request_param),
  98. db: Session = Depends(get_db)
  99. ):
  100. sfzh = ext_info['cid']
  101. bzid = get_req_param(param, 'bzid')
  102. q = db.query(YstProcessEntity)
  103. rows = q.filter(YstProcessEntity.bzid == bzid).order_by(YstProcessEntity.djsj.desc()).all()
  104. # 进度页
  105. timeline = []
  106. row_count = len(rows)
  107. for i in range(0, row_count):
  108. timeline.append(format_process_rec(i, row_count, rows[i]))
  109. # 详情页
  110. row = db.query(YstQyyjyaEntity).filter(YstQyyjyaEntity.bzid == bzid).first()
  111. if row is None:
  112. resp = {
  113. 'ret': 1,
  114. 'msg': '记录为空'
  115. }
  116. return yst_response(resp)
  117. data = get_model_dict(row)
  118. qyxxMap = {
  119. '企业名称': data['qymc'],
  120. '企业级别': data['qyjb'],
  121. '企业地址': data['qydz']
  122. }
  123. yjyaMap = {
  124. '编制目的': data['bzmd'],
  125. '编制依据': data['bzyj'],
  126. '企业概况': data['qygk'],
  127. '危险性分析': data['wxxfx'],
  128. '适用范围': data['syfw'],
  129. '应急救援原则': data['yjjyyz'],
  130. '应急处置措施': data['yjczcs'],
  131. '应急响应': data['yjxy']
  132. }
  133. qtFile = []
  134. imageUrls = []
  135. rows = db.query(YssYstUploadFileEntity).filter(and_(YssYstUploadFileEntity.bzid == bzid, YssYstUploadFileEntity.file_type == 'yjya')).all()
  136. for row in rows:
  137. imageUrls.append(row.file_name)
  138. if len(imageUrls) > 0:
  139. qtFile.append({'fileName': '预案附件', 'imageUrls': imageUrls})
  140. resp = {
  141. 'ret': 0,
  142. 'timeline': timeline,
  143. 'qyxxMap': qyxxMap,
  144. 'yjyaMap': yjyaMap,
  145. 'qtFile': qtFile
  146. }
  147. return yst_response(resp)
  148. def format_process_rec(i: int, count: int, row: YstProcessEntity):
  149. icon = ''
  150. title = row.ztsm
  151. desc = row.jdsm
  152. time_str = from_timestamp(row.djsj)
  153. action = 0
  154. action_text = ''
  155. active = 0
  156. if i == 0 and row.zt == 10: # 审核中
  157. icon = 'pending'
  158. elif i == 0 and row.zt == 1: # 审核通过
  159. icon = ''
  160. elif i == 0 and row.zt == 4: # 已办结
  161. icon = 'success'
  162. elif i == 0 and row.zt == 9: # 拒绝
  163. icon = 'warn'
  164. action = 1
  165. action_text = '重新提交'
  166. elif i == 0 and row.zt == 3: # 再次申请
  167. icon = 'warn'
  168. action = 1
  169. action_text = '重新提交'
  170. return {
  171. 'icon': icon,
  172. 'title':title,
  173. 'desc': desc,
  174. 'time': time_str,
  175. 'action': action,
  176. 'action_text': action_text,
  177. 'active': active
  178. }