yjylzj.py 5.7 KB

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