qyyjya.py 6.2 KB

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