jm_homework.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from re import S
  2. from typing import Optional
  3. from fastapi import APIRouter
  4. from fastapi import Depends
  5. from sqlalchemy.orm import Session
  6. from app import schemas
  7. from app.common.decorators import verify_all
  8. from app.common.hive import hiveDs
  9. from app.crud import jm_homework
  10. from app.services.jm_homework import create_jm_homework_services, update_jm_homework_service
  11. from app.services.jm_job import red_dag_and_format
  12. from utils.sx_time import sxtimeit
  13. from utils.sx_web import web_try
  14. from fastapi_pagination import Page, add_pagination, paginate, Params
  15. import app.crud as crud
  16. from app import get_db
  17. from configs.globals import g
  18. from configs.settings import DefaultOption, config
  19. DATABASE_NAME = config.get('HIVE', 'DATABASE_NAME')
  20. router = APIRouter(
  21. prefix="/jpt/jm_homework",
  22. tags=["jm_homework-作业管理"],
  23. )
  24. @router.post("/", dependencies=[Depends(verify_all)])
  25. @web_try()
  26. @sxtimeit
  27. def create_jm_homework(item: schemas.JmHomeworkCreate, db: Session = Depends(get_db)):
  28. return create_jm_homework_services(db, item)
  29. @router.get("/", dependencies=[Depends(verify_all)])
  30. @web_try()
  31. @sxtimeit
  32. def get_jm_homeworks(db: Session = Depends(get_db)):
  33. return crud.get_jm_homeworks(db, g.project_id)
  34. @router.get("/info", dependencies=[Depends(verify_all)])
  35. @web_try()
  36. @sxtimeit
  37. def get_jm_homework_info(homework_id: str, db: Session = Depends(get_db)):
  38. return crud.get_jm_homework_info(db, homework_id)
  39. @router.put("/", dependencies=[Depends(verify_all)])
  40. @web_try()
  41. @sxtimeit
  42. def update_jm_homework(jm_id: int, update_item: schemas.JmHomeworkUpdate, db: Session = Depends(get_db)):
  43. return update_jm_homework_service(db, jm_id, update_item)
  44. @router.delete("/", dependencies=[Depends(verify_all)])
  45. @web_try()
  46. @sxtimeit
  47. def delete_jm_homework(jm_id: int, db: Session = Depends(get_db)):
  48. jm_log_infos = crud.get_jm_job_infos(db)
  49. jm_job_ids = [jm_job.id for jm_job in jm_log_infos]
  50. res = crud.find_by_homework_and_job(db, jm_job_ids,jm_id)
  51. if len(res) > 0:
  52. raise Exception("该作业正在被定时任务使用,不可删除")
  53. return crud.delete_jm_homework(db, jm_id)