yhpcsb.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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(YstQyjcxxEntity).filter(YstQyjcxxEntity.bzid == bzid).filter(YstQyjcxxEntity.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(YstYhpcsbEntity).filter(YstYhpcsbEntity.bzid == bzid).filter(YstYhpcsbEntity.status == 0).delete()
  40. db.commit()
  41. new_yhpcsb = YstYhpcsbEntity(
  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. fzdc = get_req_param(param, 'fzdc'),
  49. fzr = get_req_param(param, 'fzr'),
  50. fzrdh = get_req_param(param, 'fzrdh'),
  51. gm = get_req_param(param, 'gm'),
  52. gzcs = get_req_param(param, 'gzcs'),
  53. qzjjss = get_req_param(param, 'qzjjss'),
  54. swxrs = get_req_param(param, 'swxrs'),
  55. szdq = get_req_param(param, 'szdq'),
  56. xxdz = get_req_param(param, 'xxdz'),
  57. yhdmc = get_req_param(param, 'yhdmc'),
  58. yhdzt = get_req_param(param, 'yhdzt'),
  59. ywfzya = get_req_param(param, 'ywfzya'),
  60. zhlx = get_req_param(param, 'zhlx'),
  61. status = 1,
  62. create_time = datetime.now()
  63. )
  64. db.add(new_yhpcsb)
  65. db.commit()
  66. db.query(YssYstUploadFileEntity).filter(YssYstUploadFileEntity.uuid == bzid).update({"bzid": bzid})
  67. db.commit()
  68. resp = {
  69. 'ret': 0,
  70. 'msg': "您的隐患排查上报已成功提交。"
  71. }
  72. return yst_response(resp)
  73. except AppException as e:
  74. traceback.print_exc()
  75. result = {
  76. 'ret': 1,
  77. 'msg': "服务异常,本次办理提交失败,您可尝试重新提交。"
  78. }
  79. return pt_sg_response(result)
  80. @router.post("/query")
  81. async def query(
  82. request: Request,
  83. ext_info: str = Depends(yst_pass_ext),
  84. param: dict = Depends(yst_request_param),
  85. db: Session = Depends(get_db)
  86. ):
  87. sfzh = ext_info['cid']
  88. rows = db.query(YstYhpcsbEntity).filter(YstYhpcsbEntity.sfzh == sfzh).filter(YstYhpcsbEntity.status == 1).order_by(YstYhpcsbEntity.create_time.desc()).all()
  89. data = [
  90. {
  91. "id": row.id,
  92. "yhdmc": row.yhdmc,
  93. "yhdzt": row.yhdzt,
  94. "xxdz": row.xxdz,
  95. "szdq": row.szdq,
  96. "create_time": get_datetime_str(row.create_time)
  97. }
  98. for row in rows
  99. ]
  100. resp = {
  101. 'ret': 0,
  102. 'data': data
  103. }
  104. return yst_response(resp)
  105. @router.post("/detail")
  106. async def detail(
  107. request: Request,
  108. ext_info: str = Depends(yst_pass_ext),
  109. param: dict = Depends(yst_request_param),
  110. db: Session = Depends(get_db)
  111. ):
  112. try:
  113. sfzh = ext_info['cid']
  114. id = get_req_param(param, 'id')
  115. row = db.query(YstYhpcsbEntity).filter(YstYhpcsbEntity.sfzh == sfzh).filter(YstYhpcsbEntity.id == id).first()
  116. bzid = row.bzid
  117. data = get_model_dict(row)
  118. data["create_time"] = get_datetime_str(row.create_time)
  119. data["update_time"] = get_datetime_str(row.update_time)
  120. qtFile = []
  121. imageUrls = []
  122. rows = db.query(YssYstUploadFileEntity).filter(and_(YssYstUploadFileEntity.bzid == bzid, YssYstUploadFileEntity.file_type == 'yyzz')).all()
  123. for row in rows:
  124. imageUrls.append("/mmh5_yjxm_yst/ebus/yst_mmsyjjzhyjxt/api/yst/file/show?thumb=1&file_name={}".format(row.file_name))
  125. if len(imageUrls) > 0:
  126. qtFile.append({'fileName': '隐患点图片', 'imageUrls': imageUrls})
  127. resp = {
  128. 'ret': 0,
  129. 'msg': '',
  130. 'data': data,
  131. 'qtFile': qtFile
  132. }
  133. return yst_response(resp)
  134. except AppException as e:
  135. traceback.print_exc()
  136. result = {
  137. 'ret': 1,
  138. 'msg': "服务异常"
  139. }
  140. return pt_sg_response(result)