yhpcsb.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. router = APIRouter()
  11. @router.post("/accept")
  12. async def accept(
  13. request: Request,
  14. ext_info: str = Depends(yst_pass_ext),
  15. param: dict = Depends(yst_request_param),
  16. db: Session = Depends(get_db)
  17. ):
  18. bzid = get_req_param(param, 'uuid')
  19. print(param)
  20. new_yhpcsb = YstYhpcsbEntity(
  21. bzid = bzid,
  22. fzdc = get_req_param(param, 'fzdc'),
  23. fzr = get_req_param(param, 'fzr'),
  24. fzrdh = get_req_param(param, 'fzrdh'),
  25. gm = get_req_param(param, 'gm'),
  26. gzcs = get_req_param(param, 'gzcs'),
  27. qzjjss = get_req_param(param, 'qzjjss'),
  28. swxrs = get_req_param(param, 'swxrs'),
  29. szdq = get_req_param(param, 'szdq'),
  30. xxdz = get_req_param(param, 'xxdz'),
  31. yhdmc = get_req_param(param, 'yhdmc'),
  32. yhdzt = get_req_param(param, 'yhdzt'),
  33. ywfzya = get_req_param(param, 'ywfzya'),
  34. zhlx = get_req_param(param, 'zhlx'),
  35. create_time = datetime.now()
  36. )
  37. db.add(new_yhpcsb)
  38. db.commit()
  39. db.query(YssYstUploadFileEntity).filter(YssYstUploadFileEntity.uuid == bzid).update({"bzid": bzid})
  40. db.commit()
  41. resp = {
  42. 'ret': 0,
  43. 'msg': "您的隐患排查上报已成功提交。"
  44. }
  45. return yst_response(resp)
  46. @router.post("/query")
  47. async def query(
  48. request: Request,
  49. ext_info: str = Depends(yst_pass_ext),
  50. param: dict = Depends(yst_request_param),
  51. db: Session = Depends(get_db)
  52. ):
  53. rows = db.query(YstYhpcsbEntity).all()
  54. data = [
  55. {
  56. "id": row.id,
  57. "yhdmc": row.yhdmc,
  58. "yhdzt": row.yhdzt,
  59. "szdq": row.szdq,
  60. "create_time": get_datetime_str(row.create_time)
  61. }
  62. for row in rows
  63. ]
  64. resp = {
  65. 'ret': 0,
  66. 'data': data
  67. }
  68. return yst_response(resp)
  69. @router.post("/detail")
  70. async def detail(
  71. request: Request,
  72. ext_info: str = Depends(yst_pass_ext),
  73. param: dict = Depends(yst_request_param),
  74. db: Session = Depends(get_db)
  75. ):
  76. id = get_req_param(param, 'id')
  77. row = db.query(YstYhpcsbEntity).filter(YstYhpcsbEntity.id == id).first()
  78. data = get_model_dict(row)
  79. data["create_time"] = get_datetime_str(row.create_time)
  80. resp = {
  81. 'ret': 0,
  82. 'msg': '',
  83. 'data': data
  84. }
  85. return yst_response(resp)