qyyjya.py 6.1 KB

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