yjylzj.py 5.7 KB

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