yhpcsb.py 4.9 KB

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